use of org.eclipse.xtend.core.xtend.XtendAnnotationType in project xtext-xtend by eclipse.
the class XtendValidator method checkAnnotationTarget.
@Check
public void checkAnnotationTarget(XAnnotation annotation) {
JvmType annotationType = annotation.getAnnotationType();
if (annotationType == null || annotationType.eIsProxy() || !(annotationType instanceof JvmAnnotationType)) {
return;
}
Set<ElementType> targets = annotationUtil.getAnnotationTargets((JvmAnnotationType) annotationType);
if (targets.isEmpty())
return;
final EObject eContainer = getContainingAnnotationTarget(annotation);
Class<? extends EObject> clazz = eContainer.getClass();
if (eContainer instanceof XtendField && eContainer.eContainer() instanceof XtendAnnotationType) {
clazz = XtendFunction.class;
}
for (Entry<Class<?>, Collection<ElementType>> mapping : targetInfos.asMap().entrySet()) {
if (mapping.getKey().isAssignableFrom(clazz)) {
targets.retainAll(mapping.getValue());
if (targets.isEmpty()) {
error("The annotation @" + annotation.getAnnotationType().getSimpleName() + " is disallowed for this location.", annotation, null, INSIGNIFICANT_INDEX, ANNOTATION_WRONG_TARGET);
}
}
}
}
use of org.eclipse.xtend.core.xtend.XtendAnnotationType in project xtext-xtend by eclipse.
the class XtendJvmModelInferrer method doInferTypeSceleton.
protected JvmDeclaredType doInferTypeSceleton(final XtendTypeDeclaration declaration, final IJvmDeclaredTypeAcceptor acceptor, boolean preIndexingPhase, XtendFile xtendFile, List<Runnable> doLater) {
if (Strings.isEmpty(declaration.getName()))
return null;
if (declaration instanceof XtendAnnotationType) {
final JvmAnnotationType annotation = typesFactory.createJvmAnnotationType();
if (!preIndexingPhase) {
doLater.add(new Runnable() {
@Override
public void run() {
initialize((XtendAnnotationType) declaration, annotation);
}
});
}
return annotation;
} else if (declaration instanceof XtendClass) {
XtendClass xtendClass = (XtendClass) declaration;
final JvmGenericType javaType = typesFactory.createJvmGenericType();
copyTypeParameters(xtendClass.getTypeParameters(), javaType);
if (!preIndexingPhase) {
doLater.add(new Runnable() {
@Override
public void run() {
initialize((XtendClass) declaration, javaType);
}
});
}
return javaType;
} else if (declaration instanceof XtendInterface) {
XtendInterface xtendInterface = (XtendInterface) declaration;
final JvmGenericType javaType = typesFactory.createJvmGenericType();
javaType.setInterface(true);
copyTypeParameters(xtendInterface.getTypeParameters(), javaType);
if (!preIndexingPhase) {
doLater.add(new Runnable() {
@Override
public void run() {
initialize((XtendInterface) declaration, javaType);
}
});
}
return javaType;
} else if (declaration instanceof XtendEnum) {
final JvmEnumerationType javaType = typesFactory.createJvmEnumerationType();
if (!preIndexingPhase) {
doLater.add(new Runnable() {
@Override
public void run() {
initialize((XtendEnum) declaration, javaType);
}
});
}
return javaType;
} else {
return null;
}
}
use of org.eclipse.xtend.core.xtend.XtendAnnotationType in project xtext-xtend by eclipse.
the class JavaConverterTest method testAnnotationDeclaration.
@Test
public void testAnnotationDeclaration() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("import java.lang.annotation.Documented;");
_builder.newLine();
_builder.append("import java.lang.annotation.ElementType;");
_builder.newLine();
_builder.append("import java.lang.annotation.Target;");
_builder.newLine();
_builder.append(" ");
_builder.newLine();
_builder.append("@Documented");
_builder.newLine();
_builder.append("@Target(ElementType.METHOD)");
_builder.newLine();
_builder.append("public @interface MyAnno{");
_builder.newLine();
_builder.append("\t");
_builder.append("String author() default \"me\";");
_builder.newLine();
_builder.append("\t");
_builder.append("String date();");
_builder.newLine();
_builder.append("\t");
_builder.append("int revision() default 1;");
_builder.newLine();
_builder.append("\t");
_builder.append("String comments();");
_builder.newLine();
_builder.append("}");
final String javaBody = _builder.toString();
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append(javaBody);
final XtendAnnotationType clazz = this.toValidXtendAnnotation(_builder_1.toString());
Assert.assertNotNull(clazz);
String body = this.toXtendCode(javaBody);
StringConcatenation _builder_2 = new StringConcatenation();
_builder_2.append("import java.lang.annotation.Documented");
_builder_2.newLine();
_builder_2.append("import java.lang.annotation.ElementType");
_builder_2.newLine();
_builder_2.append("import java.lang.annotation.Target");
_builder_2.newLine();
_builder_2.append("@Documented @Target(ElementType.METHOD)public annotation MyAnno {");
_builder_2.newLine();
_builder_2.append("String author = \"me\"");
_builder_2.newLine();
_builder_2.append("String date");
_builder_2.newLine();
_builder_2.append("int revision = 1");
_builder_2.newLine();
_builder_2.append("String comments");
_builder_2.newLine();
_builder_2.append("}");
Assert.assertEquals(_builder_2.toString(), body);
}
use of org.eclipse.xtend.core.xtend.XtendAnnotationType in project xtext-xtend by eclipse.
the class CompilationUnitImpl method toXtendTypeDeclaration.
public XtendTypeDeclarationImpl<? extends XtendTypeDeclaration> toXtendTypeDeclaration(final XtendTypeDeclaration delegate) {
final Function1<XtendTypeDeclaration, XtendTypeDeclarationImpl<? extends XtendTypeDeclaration>> _function = (XtendTypeDeclaration it) -> {
XtendTypeDeclarationImpl<? extends XtendTypeDeclaration> _switchResult = null;
boolean _matched = false;
if (delegate instanceof XtendClass) {
_matched = true;
XtendClassDeclarationImpl _xtendClassDeclarationImpl = new XtendClassDeclarationImpl();
final Procedure1<XtendClassDeclarationImpl> _function_1 = (XtendClassDeclarationImpl it_1) -> {
it_1.setDelegate(((XtendClass) delegate));
it_1.setCompilationUnit(this);
};
_switchResult = ObjectExtensions.<XtendClassDeclarationImpl>operator_doubleArrow(_xtendClassDeclarationImpl, _function_1);
}
if (!_matched) {
if (delegate instanceof XtendInterface) {
_matched = true;
XtendInterfaceDeclarationImpl _xtendInterfaceDeclarationImpl = new XtendInterfaceDeclarationImpl();
final Procedure1<XtendInterfaceDeclarationImpl> _function_1 = (XtendInterfaceDeclarationImpl it_1) -> {
it_1.setDelegate(((XtendInterface) delegate));
it_1.setCompilationUnit(this);
};
_switchResult = ObjectExtensions.<XtendInterfaceDeclarationImpl>operator_doubleArrow(_xtendInterfaceDeclarationImpl, _function_1);
}
}
if (!_matched) {
if (delegate instanceof XtendAnnotationType) {
_matched = true;
XtendAnnotationTypeDeclarationImpl _xtendAnnotationTypeDeclarationImpl = new XtendAnnotationTypeDeclarationImpl();
final Procedure1<XtendAnnotationTypeDeclarationImpl> _function_1 = (XtendAnnotationTypeDeclarationImpl it_1) -> {
it_1.setDelegate(((XtendAnnotationType) delegate));
it_1.setCompilationUnit(this);
};
_switchResult = ObjectExtensions.<XtendAnnotationTypeDeclarationImpl>operator_doubleArrow(_xtendAnnotationTypeDeclarationImpl, _function_1);
}
}
if (!_matched) {
if (delegate instanceof XtendEnum) {
_matched = true;
XtendEnumerationDeclarationImpl _xtendEnumerationDeclarationImpl = new XtendEnumerationDeclarationImpl();
final Procedure1<XtendEnumerationDeclarationImpl> _function_1 = (XtendEnumerationDeclarationImpl it_1) -> {
it_1.setDelegate(((XtendEnum) delegate));
it_1.setCompilationUnit(this);
};
_switchResult = ObjectExtensions.<XtendEnumerationDeclarationImpl>operator_doubleArrow(_xtendEnumerationDeclarationImpl, _function_1);
}
}
return _switchResult;
};
return this.<XtendTypeDeclaration, XtendTypeDeclarationImpl<? extends XtendTypeDeclaration>>getOrCreate(delegate, _function);
}
use of org.eclipse.xtend.core.xtend.XtendAnnotationType in project xtext-xtend by eclipse.
the class XtendValidationTest method testAnnotationTarget_11.
@Test
public void testAnnotationTarget_11() throws Exception {
XtendAnnotationType annotationType = annotationType("annotation A { @testdata.Annotation6 String value = 'Issue206'}");
helper.assertNoErrors(annotationType);
}
Aggregations