use of org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation in project xtext-xtend by eclipse.
the class ErrorTest method testErrorModel_006.
@Test
public void testErrorModel_006() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("@Data class A {}");
_builder.newLine();
_builder.append("@");
_builder.newLine();
final XtendFile file = this.processWithoutException(_builder);
final XtendTypeDeclaration typeDeclaration = IterableExtensions.<XtendTypeDeclaration>last(file.getXtendTypes());
final EList<XAnnotation> annotations = typeDeclaration.getAnnotations();
final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(IterableExtensions.<XAnnotation>head(annotations));
Assert.assertNotNull(resolvedTypes.getActualType(IterableExtensions.<XAnnotation>head(annotations)));
}
use of org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation in project xtext-xtend by eclipse.
the class XtendJvmModelInferrer method transform.
protected void transform(XtendEnumLiteral literal, JvmEnumerationType container) {
if (literal.getName() == null)
return;
JvmEnumerationLiteral jvmLiteral = typesFactory.createJvmEnumerationLiteral();
associator.associatePrimary(literal, jvmLiteral);
jvmLiteral.setSimpleName(literal.getName());
jvmLiteral.setVisibility(JvmVisibility.PUBLIC);
jvmLiteral.setStatic(true);
jvmLiteral.setFinal(true);
jvmTypesBuilder.copyDocumentationTo(literal, jvmLiteral);
for (XAnnotation anno : literal.getAnnotations()) {
if (!annotationTranslationFilter.apply(anno))
continue;
JvmAnnotationReference annotationReference = jvmTypesBuilder.getJvmAnnotationReference(anno);
if (annotationReference != null)
jvmLiteral.getAnnotations().add(annotationReference);
}
container.getMembers().add(jvmLiteral);
}
use of org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation in project xtext-xtend by eclipse.
the class XtendJvmModelInferrer method transform.
protected void transform(XtendField source, JvmGenericType container) {
if ((source.isExtension() && source.getType() != null) || source.getName() != null) {
JvmField field = typesFactory.createJvmField();
final String computeFieldName = computeFieldName(source);
field.setSimpleName(computeFieldName);
container.getMembers().add(field);
associator.associatePrimary(source, field);
field.setVisibility(source.getVisibility());
field.setStatic(source.isStatic());
field.setTransient(source.isTransient());
field.setVolatile(source.isVolatile());
field.setFinal(source.isFinal());
if (source.getType() != null) {
field.setType(jvmTypesBuilder.cloneWithProxies(source.getType()));
} else if (source.getInitialValue() != null) {
field.setType(jvmTypesBuilder.inferredType(source.getInitialValue()));
}
for (XAnnotation anno : source.getAnnotations()) {
if (!annotationTranslationFilter.apply(anno))
continue;
JvmAnnotationReference annotationReference = jvmTypesBuilder.getJvmAnnotationReference(anno);
if (annotationReference != null)
field.getAnnotations().add(annotationReference);
}
if (source.isExtension() && typeReferences.findDeclaredType(Extension.class, source) != null) {
field.getAnnotations().add(_annotationTypesBuilder.annotationRef(Extension.class));
}
jvmTypesBuilder.copyDocumentationTo(source, field);
jvmTypesBuilder.setInitializer(field, source.getInitialValue());
initializeLocalTypes(field, source.getInitialValue());
}
}
use of org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation in project xtext-xtend by eclipse.
the class XtendFormatter method formatAnnotations.
protected void formatAnnotations(final XtendAnnotationTarget target, @Extension final IFormattableDocument document, final Procedure1<? super IHiddenRegionFormatter> configKey) {
boolean _isEmpty = target.getAnnotations().isEmpty();
if (_isEmpty) {
return;
}
EList<XAnnotation> _annotations = target.getAnnotations();
for (final XAnnotation a : _annotations) {
{
document.<XAnnotation>format(a);
document.<XAnnotation>append(a, configKey);
}
}
}
use of org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation in project xtext-xtend by eclipse.
the class ActiveAnnotationContextProvider method computeContext.
public ActiveAnnotationContexts computeContext(final XtendFile file) {
final Stopwatches.StoppedTask task = Stopwatches.forTask("[macros] findActiveAnnotations (ActiveAnnotationContextProvider.computeContext)");
task.start();
try {
final ActiveAnnotationContexts result = ActiveAnnotationContexts.installNew(file.eResource());
final CompilationUnitImpl compilationUnit = this.compilationUnitProvider.get();
compilationUnit.setXtendFile(file);
result.compilationUnit = compilationUnit;
final IAcceptor<Pair<JvmAnnotationType, XAnnotation>> _function = (Pair<JvmAnnotationType, XAnnotation> it) -> {
boolean _containsKey = result.getContexts().containsKey(it.getKey());
boolean _not = (!_containsKey);
if (_not) {
final ActiveAnnotationContext fa = new ActiveAnnotationContext();
fa.setCompilationUnit(compilationUnit);
final JvmType processorType = this._xAnnotationExtensions.getProcessorType(it.getKey());
try {
final Object processorInstance = this._processorInstanceForJvmTypeProvider.getProcessorInstance(processorType);
if ((processorInstance == null)) {
String _identifier = processorType.getIdentifier();
String _plus = ("Couldn\'t instantiate the annotation processor of type \'" + _identifier);
String _plus_1 = (_plus + "\'. This is usually the case when the processor resides in the same project as the annotated element.");
throw new IllegalStateException(_plus_1);
}
fa.setProcessorInstance(processorInstance);
} catch (final Throwable _t) {
if (_t instanceof VirtualMachineError) {
final VirtualMachineError e = (VirtualMachineError) _t;
throw e;
} else if (_t instanceof Throwable) {
final Throwable e_1 = (Throwable) _t;
this.operationCanceledManager.propagateAsErrorIfCancelException(e_1);
String _switchResult = null;
boolean _matched = false;
if (e_1 instanceof ExceptionInInitializerError) {
_matched = true;
_switchResult = ((ExceptionInInitializerError) e_1).getException().getMessage();
}
if (!_matched) {
_switchResult = e_1.getMessage();
}
final String msg = _switchResult;
EList<Resource.Diagnostic> _errors = file.eResource().getErrors();
StringConcatenation _builder = new StringConcatenation();
_builder.append("Problem while loading annotation processor: ");
_builder.append(msg);
XAnnotation _value = it.getValue();
EObjectDiagnosticImpl _eObjectDiagnosticImpl = new EObjectDiagnosticImpl(Severity.ERROR, IssueCodes.PROCESSING_ERROR, _builder.toString(), _value, XAnnotationsPackage.Literals.XANNOTATION__ANNOTATION_TYPE, (-1), null);
_errors.add(_eObjectDiagnosticImpl);
} else {
throw Exceptions.sneakyThrow(_t);
}
}
result.getContexts().put(it.getKey(), fa);
}
List<XtendAnnotationTarget> _annotatedSourceElements = result.getContexts().get(it.getKey()).getAnnotatedSourceElements();
XtendAnnotationTarget _annotatedTarget = this._xAnnotationExtensions.getAnnotatedTarget(it.getValue());
_annotatedSourceElements.add(_annotatedTarget);
};
this.searchAnnotatedElements(file, _function);
return result;
} catch (final Throwable _t) {
if (_t instanceof Throwable) {
final Throwable e = (Throwable) _t;
this.operationCanceledManager.propagateAsErrorIfCancelException(e);
boolean _matched = false;
if (e instanceof VirtualMachineError) {
_matched = true;
throw ((VirtualMachineError) e);
}
if (!_matched) {
if (e instanceof LinkageError) {
_matched = true;
throw ((LinkageError) e);
}
}
ActiveAnnotationContextProvider.logger.warn("Error finding the elements to be processed by active annotations", e);
return ActiveAnnotationContexts.installNew(file.eResource());
} else {
throw Exceptions.sneakyThrow(_t);
}
} finally {
task.stop();
}
}
Aggregations