Search in sources :

Example 26 with XtendFile

use of org.eclipse.xtend.core.xtend.XtendFile in project xtext-xtend by eclipse.

the class XtendBatchCompiler method getXtendFile.

/* @Nullable */
protected XtendFile getXtendFile(Resource resource) {
    XtextResource xtextResource = (XtextResource) resource;
    IParseResult parseResult = xtextResource.getParseResult();
    if (parseResult != null) {
        EObject model = parseResult.getRootASTElement();
        if (model instanceof XtendFile) {
            XtendFile xtendFile = (XtendFile) model;
            return xtendFile;
        }
    }
    return null;
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) EObject(org.eclipse.emf.ecore.EObject) XtextResource(org.eclipse.xtext.resource.XtextResource) IParseResult(org.eclipse.xtext.parser.IParseResult)

Example 27 with XtendFile

use of org.eclipse.xtend.core.xtend.XtendFile 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;
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) EObject(org.eclipse.emf.ecore.EObject) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType)

Example 28 with XtendFile

use of org.eclipse.xtend.core.xtend.XtendFile 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);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) LinkedHashSet(java.util.LinkedHashSet) BatchLinkableResource(org.eclipse.xtext.xbase.resource.BatchLinkableResource) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) ActiveAnnotationContexts(org.eclipse.xtend.core.macro.ActiveAnnotationContexts) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) ActiveAnnotationContext(org.eclipse.xtend.core.macro.ActiveAnnotationContext) IJvmDeclaredTypeAcceptor(org.eclipse.xtext.xbase.jvmmodel.IJvmDeclaredTypeAcceptor)

Example 29 with XtendFile

use of org.eclipse.xtend.core.xtend.XtendFile 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);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) Test(org.junit.Test)

Example 30 with XtendFile

use of org.eclipse.xtend.core.xtend.XtendFile in project xtext-xtend by eclipse.

the class AmbiguityBug427352Test method assertUnambiguous.

@Override
public void assertUnambiguous(final CharSequence contents) {
    final XtendFile file = this.getParsedXtendFile(contents);
    this._validationTestHelper.assertNoErrors(file, IssueCodes.AMBIGUOUS_FEATURE_CALL);
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile)

Aggregations

XtendFile (org.eclipse.xtend.core.xtend.XtendFile)855 Test (org.junit.Test)782 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)372 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)229 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)182 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)126 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)119 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)98 XExpression (org.eclipse.xtext.xbase.XExpression)82 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)64 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)62 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)62 EObject (org.eclipse.emf.ecore.EObject)50 Resource (org.eclipse.emf.ecore.resource.Resource)47 XMemberFeatureCall (org.eclipse.xtext.xbase.XMemberFeatureCall)46 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)42 XtextResource (org.eclipse.xtext.resource.XtextResource)34 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)29 XtendField (org.eclipse.xtend.core.xtend.XtendField)23 IResolvedTypes (org.eclipse.xtext.xbase.typesystem.IResolvedTypes)21