use of org.eclipse.xtend.core.xtend.XtendAnnotationTarget in project xtext-xtend by eclipse.
the class XAnnotationExtensions method getAnnotatedTarget.
public XtendAnnotationTarget getAnnotatedTarget(final XAnnotation annotation) {
XtendAnnotationTarget _switchResult = null;
EObject _eContainer = annotation.eContainer();
final EObject container = _eContainer;
boolean _matched = false;
if (container instanceof XtendAnnotationType) {
_matched = true;
}
if (!_matched) {
if (container instanceof XtendClass) {
_matched = true;
}
}
if (!_matched) {
if (container instanceof XtendInterface) {
_matched = true;
}
}
if (!_matched) {
if (container instanceof XtendEnum) {
_matched = true;
}
}
if (!_matched) {
if (container instanceof XtendField) {
_matched = true;
}
}
if (!_matched) {
if (container instanceof XtendFunction) {
_matched = true;
}
}
if (!_matched) {
if (container instanceof XtendConstructor) {
_matched = true;
}
}
if (!_matched) {
if (container instanceof XtendEnumLiteral) {
_matched = true;
}
}
if (!_matched) {
if (container instanceof XtendParameter) {
_matched = true;
}
}
if (_matched) {
_switchResult = ((XtendAnnotationTarget) container);
}
if (!_matched) {
if (container instanceof XtendAnnotationTarget) {
_matched = true;
XtendAnnotationTarget _xblockexpression = null;
{
final EObject containerContainer = ((XtendAnnotationTarget) container).eContainer();
XtendAnnotationTarget _xifexpression = null;
if ((containerContainer instanceof XtendAnnotationTarget)) {
_xifexpression = ((XtendAnnotationTarget) containerContainer);
} else {
_xifexpression = ((XtendAnnotationTarget) container);
}
_xblockexpression = _xifexpression;
}
_switchResult = _xblockexpression;
}
}
if (!_matched) {
if (container instanceof XAnnotation) {
_matched = true;
_switchResult = this.getAnnotatedTarget(((XAnnotation) container));
}
}
if (!_matched) {
_switchResult = null;
}
return _switchResult;
}
use of org.eclipse.xtend.core.xtend.XtendAnnotationTarget in project xtext-xtend by eclipse.
the class CompilationUnitImpl method handleProcessingError.
public void handleProcessingError(final Iterable<? extends EObject> sourceElements, final Resource resource, final Throwable t) {
if ((t instanceof VirtualMachineError)) {
throw ((VirtualMachineError) t);
}
boolean _equals = Objects.equal(this.lastPhase, ActiveAnnotationContexts.AnnotationCallback.GENERATION);
if (_equals) {
Throwables.throwIfUnchecked(t);
String _messageWithoutStackTrace = this.getMessageWithoutStackTrace(t);
throw new RuntimeException(_messageWithoutStackTrace, t);
}
final String msg = this.getMessageWithStackTrace(t);
final EList<Resource.Diagnostic> errors = resource.getErrors();
for (final EObject target : sourceElements) {
boolean _matched = false;
if (target instanceof XtendAnnotationTarget) {
_matched = true;
final EList<XAnnotation> annotations = ((XtendAnnotationTarget) target).getAnnotations();
EObject _xifexpression = null;
boolean _isEmpty = annotations.isEmpty();
if (_isEmpty) {
_xifexpression = target;
} else {
_xifexpression = IterableExtensions.<XAnnotation>head(annotations);
}
EObjectDiagnosticImpl _eObjectDiagnosticImpl = new EObjectDiagnosticImpl(Severity.ERROR, IssueCodes.PROCESSING_ERROR, msg, _xifexpression, null, (-1), null);
errors.add(_eObjectDiagnosticImpl);
}
if (!_matched) {
EObjectDiagnosticImpl _eObjectDiagnosticImpl = new EObjectDiagnosticImpl(Severity.ERROR, IssueCodes.PROCESSING_ERROR, msg, target, null, (-1), null);
errors.add(_eObjectDiagnosticImpl);
}
}
}
use of org.eclipse.xtend.core.xtend.XtendAnnotationTarget 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);
StringConcatenation _builder = new StringConcatenation();
_builder.append("Problem while loading annotation processor: ");
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();
}
_builder.append(_switchResult);
final String msg = _builder.toString();
ActiveAnnotationContextProvider.logger.error(msg, e_1);
EList<Resource.Diagnostic> _errors = file.eResource().getErrors();
XAnnotation _value = it.getValue();
EObjectDiagnosticImpl _eObjectDiagnosticImpl = new EObjectDiagnosticImpl(Severity.ERROR, IssueCodes.PROCESSING_ERROR, msg, _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();
}
}
use of org.eclipse.xtend.core.xtend.XtendAnnotationTarget in project xtext-xtend by eclipse.
the class XtendGenerator method callMacroProcessors.
public void callMacroProcessors(final Resource input) {
final ActiveAnnotationContexts ctxs = ActiveAnnotationContexts.find(input);
if ((ctxs == null)) {
return;
}
try {
ctxs.before(ActiveAnnotationContexts.AnnotationCallback.GENERATION);
Collection<ActiveAnnotationContext> _values = ctxs.getContexts().values();
for (final ActiveAnnotationContext context : _values) {
try {
Object _processorInstance = context.getProcessorInstance();
final Object processor = _processorInstance;
boolean _matched = false;
if (processor instanceof CodeGenerationParticipant) {
_matched = true;
CodeGenerationContextImpl _codeGenerationContextImpl = new CodeGenerationContextImpl();
final Procedure1<CodeGenerationContextImpl> _function = (CodeGenerationContextImpl it) -> {
it.setUnit(context.getCompilationUnit());
};
final CodeGenerationContextImpl codeGenServices = ObjectExtensions.<CodeGenerationContextImpl>operator_doubleArrow(_codeGenerationContextImpl, _function);
final Function1<XtendAnnotationTarget, MemberDeclaration> _function_1 = (XtendAnnotationTarget it) -> {
return context.getCompilationUnit().toXtendMemberDeclaration(((XtendMember) it));
};
final List<MemberDeclaration> elements = ListExtensions.<XtendAnnotationTarget, MemberDeclaration>map(context.getAnnotatedSourceElements(), _function_1);
((CodeGenerationParticipant<NamedElement>) processor).doGenerateCode(elements, codeGenServices);
}
} catch (final Throwable _t) {
if (_t instanceof Throwable) {
final Throwable t = (Throwable) _t;
this.operationCanceledManager.propagateAsErrorIfCancelException(t);
context.handleProcessingError(input, t);
} else {
throw Exceptions.sneakyThrow(_t);
}
}
}
} finally {
ctxs.after(ActiveAnnotationContexts.AnnotationCallback.GENERATION);
}
}
Aggregations