use of org.eclipse.xtend.core.xtend.XtendTypeDeclaration in project xtext-xtend by eclipse.
the class XtendImportsConfiguration method getLocallyDefinedTypes.
@Override
public Iterable<JvmDeclaredType> getLocallyDefinedTypes(XtextResource resource) {
XtendFile xtendFile = getXtendFile(resource);
if (xtendFile == null)
return emptyList();
final List<JvmDeclaredType> locallyDefinedTypes = newArrayList();
for (XtendTypeDeclaration xtendType : xtendFile.getXtendTypes()) {
for (EObject inferredElement : associations.getJvmElements(xtendType)) {
if (inferredElement instanceof JvmDeclaredType) {
JvmDeclaredType declaredType = (JvmDeclaredType) inferredElement;
locallyDefinedTypes.add(declaredType);
addInnerTypes(declaredType, new IAcceptor<JvmDeclaredType>() {
@Override
public void accept(JvmDeclaredType t) {
locallyDefinedTypes.add(t);
}
});
}
}
}
return locallyDefinedTypes;
}
use of org.eclipse.xtend.core.xtend.XtendTypeDeclaration in project xtext-xtend by eclipse.
the class XtendJvmModelInferrer method infer.
@Override
public void infer(/* @Nullable */
EObject object, final /* @NonNull */
IJvmDeclaredTypeAcceptor acceptor, boolean preIndexingPhase) {
if (!(object instanceof XtendFile))
return;
final Set<JvmDeclaredType> types = new LinkedHashSet<JvmDeclaredType>();
final IJvmDeclaredTypeAcceptor wrapper = new IJvmDeclaredTypeAcceptor() {
@SuppressWarnings("deprecation")
@Override
public <T extends JvmDeclaredType> IPostIndexingInitializing<T> accept(T type) {
types.add(type);
return acceptor.accept(type);
}
@Override
public <T extends JvmDeclaredType> void accept(T type, Procedure1<? super T> lateInitialization) {
types.add(type);
acceptor.accept(type, lateInitialization);
}
};
final XtendFile xtendFile = (XtendFile) object;
generatorConfig = generatorConfigProvider.get(xtendFile);
final List<Runnable> doLater = newArrayList();
for (final XtendTypeDeclaration declaration : xtendFile.getXtendTypes()) {
inferTypeSceleton(declaration, wrapper, preIndexingPhase, xtendFile, doLater, null);
}
ActiveAnnotationContexts contexts = null;
BatchLinkableResource resource = (BatchLinkableResource) xtendFile.eResource();
try {
compilerPhases.setIndexing(xtendFile, true);
try {
contexts = contextProvider.computeContext(xtendFile);
} catch (Throwable t) {
operationCanceledManager.propagateAsErrorIfCancelException(t);
logger.error("Couldn't create annotation contexts", t);
return;
}
try {
contexts.before(ActiveAnnotationContexts.AnnotationCallback.INDEXING);
for (ActiveAnnotationContext ctx : contexts.getContexts().values()) {
try {
annotationProcessor.indexingPhase(ctx, wrapper, CancelIndicator.NullImpl);
} catch (Throwable t) {
operationCanceledManager.propagateAsErrorIfCancelException(t);
ctx.handleProcessingError(xtendFile.eResource(), t);
}
}
} finally {
contexts.after(ActiveAnnotationContexts.AnnotationCallback.INDEXING);
}
} finally {
compilerPhases.setIndexing(xtendFile, false);
resource.getCache().clear(resource);
}
if (!preIndexingPhase) {
final ActiveAnnotationContexts finalContexts = contexts;
Runnable lateInit = new Runnable() {
@Override
public void run() {
for (Runnable runnable : doLater) {
runnable.run();
}
try {
finalContexts.before(ActiveAnnotationContexts.AnnotationCallback.INFERENCE);
for (ActiveAnnotationContext ctx : finalContexts.getContexts().values()) {
try {
annotationProcessor.inferencePhase(ctx, CancelIndicator.NullImpl);
} catch (Throwable t) {
operationCanceledManager.propagateAsErrorIfCancelException(t);
ctx.handleProcessingError(xtendFile.eResource(), t);
}
}
} finally {
finalContexts.after(ActiveAnnotationContexts.AnnotationCallback.INFERENCE);
}
}
};
resource.addJvmMemberInitializer(lateInit);
}
}
use of org.eclipse.xtend.core.xtend.XtendTypeDeclaration in project xtext-xtend by eclipse.
the class XtendJvmModelInferrer method inferTypeSceleton.
protected void inferTypeSceleton(final XtendTypeDeclaration declaration, final IJvmDeclaredTypeAcceptor acceptor, boolean preIndexingPhase, XtendFile xtendFile, List<Runnable> doLater, JvmDeclaredType containerSceleton) {
JvmDeclaredType inferredSceleton = doInferTypeSceleton(declaration, acceptor, preIndexingPhase, xtendFile, doLater);
if (inferredSceleton != null) {
setNameAndAssociate(xtendFile, declaration, inferredSceleton);
if (containerSceleton != null)
containerSceleton.getMembers().add(inferredSceleton);
acceptor.accept(inferredSceleton);
for (XtendMember member : declaration.getMembers()) {
if (member instanceof XtendTypeDeclaration)
inferTypeSceleton((XtendTypeDeclaration) member, acceptor, preIndexingPhase, xtendFile, doLater, inferredSceleton);
}
}
}
use of org.eclipse.xtend.core.xtend.XtendTypeDeclaration in project xtext-xtend by eclipse.
the class OverrideHelperTest method checkFindOverriddenOperation_03.
@Test
public void checkFindOverriddenOperation_03() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package foo");
_builder.newLine();
_builder.newLine();
_builder.append("import java.util.Map");
_builder.newLine();
_builder.newLine();
_builder.append("class Foo implements Bar {");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("override bar(Map<?, ?> map) {}");
_builder.newLine();
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("interface Bar {");
_builder.newLine();
_builder.append("\t");
_builder.append("def void bar(Map<?, ?> map)");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendFile xtendFile = this.file(_builder.toString());
EObject _primaryJvmElement = this._iJvmModelAssociations.getPrimaryJvmElement(IterableExtensions.<XtendFunction>head(Iterables.<XtendFunction>filter(IterableExtensions.<XtendTypeDeclaration>head(xtendFile.getXtendTypes()).getMembers(), XtendFunction.class)));
final JvmOperation operation = ((JvmOperation) _primaryJvmElement);
Assert.assertNotNull(this.overrideHelper.findOverriddenOperation(operation));
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtend.core.xtend.XtendTypeDeclaration in project xtext-xtend by eclipse.
the class AmbiguityValidationTest method assertAmbiguous.
protected void assertAmbiguous(final CharSequence contents, final String... messageParts) {
final XtendFile file = this.getParsedXtendFile(contents);
final EList<Resource.Diagnostic> errors = file.eResource().getErrors();
Assert.assertEquals(errors.toString(), 1, errors.size());
Resource.Diagnostic _head = IterableExtensions.<Resource.Diagnostic>head(errors);
final AbstractDiagnostic singleError = ((AbstractDiagnostic) _head);
Assert.assertEquals(singleError.getMessage(), IssueCodes.AMBIGUOUS_FEATURE_CALL, singleError.getCode());
final Function1<String, String> _function = (String it) -> {
return Strings.toUnixLineSeparator(it);
};
final Consumer<String> _function_1 = (String it) -> {
final String message = singleError.getMessage();
boolean _contains = message.contains(it);
boolean _not = (!_contains);
if (_not) {
Assert.assertEquals(it, message);
}
};
ListExtensions.<String, String>map(((List<String>) Conversions.doWrapArray(messageParts)), _function).forEach(_function_1);
final XtendTypeDeclaration firstType = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
XtendMember _head_1 = IterableExtensions.<XtendMember>head(firstType.getMembers());
final XtendFunction firstMember = ((XtendFunction) _head_1);
XExpression _expression = firstMember.getExpression();
final XBlockExpression block = ((XBlockExpression) _expression);
XExpression _last = IterableExtensions.<XExpression>last(block.getExpressions());
final XAbstractFeatureCall featureCall = ((XAbstractFeatureCall) _last);
final IFeatureLinkingCandidate linkingCandidate = this._iBatchTypeResolver.resolveTypes(file).getLinkingCandidate(featureCall);
Assert.assertTrue((linkingCandidate instanceof IAmbiguousLinkingCandidate));
}
Aggregations