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

The following examples show how to use org.eclipse.xtext.common.types.JvmFormalParameter#getAnnotations() . 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: ReflectionTypeFactory.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected JvmFormalParameter createFormalParameter(Type parameterType, String paramName,
		JvmMember container, GenericDeclaration member, Annotation[] annotations) {
	JvmFormalParameter result = TypesFactory.eINSTANCE.createJvmFormalParameter();
	result.setName(paramName);
	if (isLocal(parameterType, member)) {
		result.setParameterType(createLocalTypeReference(parameterType, (JvmTypeParameterDeclarator) container,
				member));
	} else {
		result.setParameterType(createTypeReference(parameterType));
	}
	if (annotations.length != 0) {
		InternalEList<JvmAnnotationReference> annotationsReferences = (InternalEList<JvmAnnotationReference>)result.getAnnotations();
		for (Annotation annotation : annotations) {
			annotationsReferences.addUnique(createAnnotationReference(annotation));
		}
	}
	return result;
}
 
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: JvmModelGeneratorTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testBug380754_2() {
  try {
    final XExpression expression = this.expression("null");
    final JvmAnnotationReferenceBuilder jvmAnnotationReferenceBuilder = this.jvmAnnotationReferenceBuilderFactory.create(expression.eResource().getResourceSet());
    final Procedure1<JvmGenericType> _function = (JvmGenericType it) -> {
      EList<JvmMember> _members = it.getMembers();
      final Procedure1<JvmOperation> _function_1 = (JvmOperation it_1) -> {
        this.builder.setBody(it_1, expression);
        final JvmFormalParameter parameter = this.builder.toParameter(expression, "s", this.references.getTypeForName(String.class, expression));
        EList<JvmFormalParameter> _parameters = it_1.getParameters();
        this.builder.<JvmFormalParameter>operator_add(_parameters, parameter);
        EList<JvmAnnotationReference> _annotations = parameter.getAnnotations();
        JvmAnnotationReference _annotationRef = jvmAnnotationReferenceBuilder.annotationRef(TestAnnotation.class);
        this.builder.<JvmAnnotationReference>operator_add(_annotations, _annotationRef);
        EList<JvmAnnotationReference> _annotations_1 = parameter.getAnnotations();
        JvmAnnotationReference _annotationRef_1 = jvmAnnotationReferenceBuilder.annotationRef(TestAnnotation2.class);
        this.builder.<JvmAnnotationReference>operator_add(_annotations_1, _annotationRef_1);
      };
      JvmOperation _method = this.builder.toMethod(expression, "doStuff", this.references.getTypeForName("java.lang.Object", expression), _function_1);
      this.builder.<JvmOperation>operator_add(_members, _method);
    };
    final JvmGenericType clazz = this.builder.toClass(expression, "my.test.Foo", _function);
    this.compile(expression.eResource(), clazz);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 4
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 5
Source File: JdtBasedTypeFactory.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected JvmFormalParameter createFormalParameter(ITypeBinding parameterType, String paramName, IAnnotationBinding[] annotations) {
	JvmFormalParameter result = TypesFactory.eINSTANCE.createJvmFormalParameter();
	if (paramName != null)
		result.setName(paramName);
	result.setParameterType(createTypeReference(parameterType));
	if (annotations != null && annotations.length > 0) {
		InternalEList<JvmAnnotationReference> parameterAnnotations = (InternalEList<JvmAnnotationReference>)result.getAnnotations();
		for (IAnnotationBinding annotation : annotations) {
			parameterAnnotations.addUnique(createAnnotationReference(annotation));
		}
	}
	return result;
}
 
Example 6
Source File: InferredJvmModelTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testExtensionToAnnotation_02() throws Exception {
	XtendFile xtendFile = file("class C { def void m(extension String s) {} }");
	JvmGenericType inferredType = getInferredType(xtendFile);
	JvmOperation jvmOperation = (JvmOperation) inferredType.getMembers().get(1);
	List<JvmFormalParameter> parameters = jvmOperation.getParameters();
	JvmFormalParameter singleParameter = parameters.get(0);
	List<JvmAnnotationReference> annotations = singleParameter.getAnnotations();
	assertEquals(1, annotations.size());
	assertEquals(Extension.class.getCanonicalName(), annotations.get(0).getAnnotation().getQualifiedName());
}
 
Example 7
Source File: JvmExecutableBuilder.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public AnnotationVisitor visitParameterAnnotation(final int parameter, final String desc, final boolean visible) {
		JvmFormalParameter formalParameter = result.getParameters().get(parameter);
		return new JvmAnnotationReferenceBuilder(
				(InternalEList<JvmAnnotationReference>) formalParameter.getAnnotations(), desc, proxies);
}