Java Code Examples for org.eclipse.xtext.common.types.JvmFormalParameter#getName()

The following examples show how to use org.eclipse.xtext.common.types.JvmFormalParameter#getName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XbaseValidator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Check
public void checkLocalUsageOfSwitchParameter(XSwitchExpression switchExpression) {
	JvmFormalParameter switchParam = switchExpression.getDeclaredParam();
	if(!isIgnored(UNUSED_LOCAL_VARIABLE) && switchParam != null && !isLocallyUsed(switchParam, switchExpression)){
		String message = "The value of the local variable " + switchParam.getName() + " is not used";
		addIssue(message, switchParam, TypesPackage.Literals.JVM_FORMAL_PARAMETER__NAME, UNUSED_LOCAL_VARIABLE);
	}
}
 
Example 2
Source File: AbstractTypeProviderPerformanceTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected JvmDeclaredType loadAndResolve(String name, boolean accessMembers, boolean accessAnnotations, boolean accessTypeParams, boolean accessParameter, boolean accessParameterNames) {
	JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(name);
	EcoreUtil.resolveAll(type.eResource());
	EcoreUtil.resolveAll(type.eResource().getResourceSet());
	Assert.assertNotNull(name, type);
	
	if (accessAnnotations) {
		type.getAnnotations();
	}
	
	if (accessMembers) {
		EList<JvmMember> members = type.getMembers();
		for (JvmMember member : members) {
			if (accessAnnotations) {
				member.getAnnotations();
			}
			if (member instanceof JvmExecutable) {
				JvmExecutable operation = (JvmExecutable) member;
				if (accessParameter) {
					EList<JvmFormalParameter> parameters = operation.getParameters();
					for (JvmFormalParameter jvmFormalParameter : parameters) {
						if (accessAnnotations) {
							jvmFormalParameter.getAnnotations();
						}
						if (accessParameterNames) {
							jvmFormalParameter.getName();
						}
					}
				}
			}
		}
	}
	return type;
}
 
Example 3
Source File: AbstractTypeProviderPerformanceTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected JvmDeclaredType loadAndResolve(String name, boolean accessMembers, boolean accessAnnotations, boolean accessTypeParams, boolean accessParameter, boolean accessParameterNames) {
	JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName(name);
	EcoreUtil.resolveAll(type.eResource());
	EcoreUtil.resolveAll(type.eResource().getResourceSet());
	Assert.assertNotNull(name, type);
	
	if (accessAnnotations) {
		type.getAnnotations();
	}
	
	if (accessMembers) {
		EList<JvmMember> members = type.getMembers();
		for (JvmMember member : members) {
			if (accessAnnotations) {
				member.getAnnotations();
			}
			if (member instanceof JvmExecutable) {
				JvmExecutable operation = (JvmExecutable) member;
				if (accessParameter) {
					EList<JvmFormalParameter> parameters = operation.getParameters();
					for (JvmFormalParameter jvmFormalParameter : parameters) {
						if (accessAnnotations) {
							jvmFormalParameter.getAnnotations();
						}
						if (accessParameterNames) {
							jvmFormalParameter.getName();
						}
					}
				}
			}
		}
	}
	return type;
}
 
Example 4
Source File: XbaseLabelProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected String text(JvmFormalParameter parameter) {
	JvmTypeReference parameterType = parameter.getParameterType();
	if (parameterType == null) {
		return parameter.getName();
	} else {
		return parameterType.getSimpleName() + " " + parameter.getName();
	}
}
 
Example 5
Source File: XbaseDeclarativeHoverSignatureProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected String _signature(JvmFormalParameter parameter, boolean typeAtEnd) {
	EObject container = parameter.eContainer();
	LightweightTypeReference parameterType = typeResolver.resolveTypes(parameter).getActualType(parameter);
	if (parameterType != null) {
		String signature = parameter.getName();
		String signatureOfFather = getSimpleSignature(container);
		if(signatureOfFather != null){
			signature += JavaElementLabels.CONCAT_STRING + signatureOfFather;
		}
		if (typeAtEnd)
			return signature + " : " + parameterType.getHumanReadableName();
		return parameterType.getHumanReadableName() + " " + signature;
	}
	return parameter.getName();
}
 
Example 6
Source File: JdtBasedTypeFactory.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private void synthesizeNames(List<JvmFormalParameter> parameters) {
	int i = 0;
	for (JvmFormalParameter p : parameters) {
		if (p.getName() == null) {
			p.setName("arg"+i);
		}
		i++;
	}
}
 
Example 7
Source File: XtendReentrantTypeResolver.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected JvmConstructor inferAnonymousClassConstructor(AnonymousClass anonymousClass, JvmGenericType inferredLocalClass, JvmConstructor superConstructor, boolean visible) {
	JvmConstructor constructor = TypesFactory.eINSTANCE.createJvmConstructor();
	inferredLocalClass.getMembers().add(constructor);
	associator.associatePrimary(anonymousClass.getConstructorCall(), constructor);
	if (visible) {
		constructor.setVisibility(JvmVisibility.DEFAULT);
	} else
		constructor.setVisibility(JvmVisibility.PRIVATE);
	constructor.setSimpleName(inferredLocalClass.getSimpleName());
	constructor.setVarArgs(superConstructor.isVarArgs());
	final List<JvmFormalParameter> parameters = superConstructor.getParameters();
	for(JvmFormalParameter parameter: parameters) {
		parameter.getName(); // trigger name computation
		constructor.getParameters().add(typesBuilder.cloneWithProxies(parameter));
	}
	
	for (JvmTypeReference exception : superConstructor.getExceptions()) 
		constructor.getExceptions().add(typesBuilder.cloneWithProxies(exception));
	
	if (!parameters.isEmpty()) {
		typesBuilder.setBody(constructor, new Procedures.Procedure1<ITreeAppendable>() {
			@Override
			public void apply(ITreeAppendable a) {
				a.append("super(");
				for(int i = 0; i < parameters.size(); i++) {
					if (i != 0) {
						a.append(", ");
					}
					a.append(parameters.get(i).getSimpleName());
				}
				a.append(");");
			}
			
		});
	}
	return constructor;
}