Search in sources :

Example 56 with JvmDeclaredType

use of org.eclipse.xtext.common.types.JvmDeclaredType in project xtext-xtend by eclipse.

the class LocalClassAwareTypeNames method doVisitParameterizedTypeReference.

@Override
protected void doVisitParameterizedTypeReference(ParameterizedTypeReference reference, StringBuilder param) {
    JvmType type = reference.getType();
    if (type instanceof JvmDeclaredType) {
        boolean local = ((JvmDeclaredType) type).isLocal();
        if (local) {
            param.append("new ");
            Iterables.getLast(reference.getSuperTypes()).accept(this, param);
            param.append("(){}");
            return;
        }
    }
    super.doVisitParameterizedTypeReference(reference, param);
}
Also used : JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmType(org.eclipse.xtext.common.types.JvmType)

Example 57 with JvmDeclaredType

use of org.eclipse.xtext.common.types.JvmDeclaredType in project xtext-xtend by eclipse.

the class NestedTypesScope method doGetSingleElement.

@Override
protected IEObjectDescription doGetSingleElement(QualifiedName name, String firstSegment, int dollarIndex) {
    JvmDeclaredType declaredType = innermost;
    while (declaredType != null) {
        IEObjectDescription result = doGetSingleElement(declaredType, name, firstSegment, dollarIndex);
        if (result != null) {
            return result;
        }
        declaredType = EcoreUtil2.getContainerOfType(declaredType.eContainer(), JvmDeclaredType.class);
    }
    if (dollarIndex > 0 && name.getSegmentCount() == 1) {
        QualifiedName splitted = QualifiedName.create(Strings.split(name.getFirstSegment(), '$'));
        IEObjectDescription result = doGetSingleElement(splitted, splitted.getFirstSegment(), -1);
        if (result != null) {
            return new AliasedEObjectDescription(name, result);
        }
    }
    return null;
}
Also used : AliasedEObjectDescription(org.eclipse.xtext.resource.impl.AliasedEObjectDescription) QualifiedName(org.eclipse.xtext.naming.QualifiedName) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 58 with JvmDeclaredType

use of org.eclipse.xtext.common.types.JvmDeclaredType in project xtext-xtend by eclipse.

the class TypeScopeWithWildcardImports method doGetElements.

@Override
protected void doGetElements(JvmType type, List<IEObjectDescription> result) {
    if (!(type instanceof JvmDeclaredType)) {
        return;
    }
    JvmDeclaredType declaredType = (JvmDeclaredType) type;
    String packageName = declaredType.getPackageName();
    if (!Strings.isEmpty(packageName)) {
        QualifiedName qualifiedPackageName = QualifiedName.create(Strings.split(packageName, '.'));
        QualifiedName withDot = null;
        String withDollar = null;
        for (int i = 0; i < imports.length; i++) {
            ImportNormalizer[] chunk = imports[i];
            for (int j = 0; j < chunk.length; j++) {
                ImportNormalizer normalizer = chunk[j];
                QualifiedName namespacePrefix = normalizer.getImportedNamespacePrefix();
                if (namespacePrefix.equals(qualifiedPackageName)) {
                    if (withDot == null) {
                        withDot = QualifiedName.create(Strings.split(type.getQualifiedName('.'), '.'));
                        withDollar = type.eContainer() instanceof JvmType ? type.getQualifiedName('$').substring(packageName.length() + 1) : null;
                    }
                    result.add(EObjectDescription.create(withDot.skipFirst(qualifiedPackageName.getSegmentCount()), type));
                    if (withDollar != null) {
                        result.add(EObjectDescription.create(withDollar, type));
                    }
                }
            }
        }
    }
    if (parent != null) {
        parent.doGetElements(type, result);
    } else {
        Iterables.addAll(result, typeScope.getElements(type));
    }
}
Also used : ImportNormalizer(org.eclipse.xtext.scoping.impl.ImportNormalizer) QualifiedName(org.eclipse.xtext.naming.QualifiedName) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmType(org.eclipse.xtext.common.types.JvmType)

Example 59 with JvmDeclaredType

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

Example 60 with JvmDeclaredType

use of org.eclipse.xtext.common.types.JvmDeclaredType in project xtext-xtend by eclipse.

the class AbstractXtendCompilerTest method compile.

private ArrayList<CharSequence> compile(final XtendFile file, final CharSequence input, final GeneratorConfig config) {
    try {
        final ArrayList<CharSequence> results = CollectionLiterals.<CharSequence>newArrayList();
        Iterable<JvmDeclaredType> _filter = Iterables.<JvmDeclaredType>filter(file.eResource().getContents(), JvmDeclaredType.class);
        for (final JvmDeclaredType inferredType : _filter) {
            {
                Assert.assertFalse(DisableCodeGenerationAdapter.isDisabled(inferredType));
                CharSequence javaCode = this.generator.generateType(inferredType, config);
                javaCode = this.postProcessor.postProcess(null, javaCode);
                results.add(javaCode);
                if ((this.useJavaCompiler && (input != null))) {
                    final IAcceptor<CompilationTestHelper.Result> _function = (CompilationTestHelper.Result it) -> {
                        it.getCompiledClass();
                    };
                    this.compilationTestHelper.compile(input, _function);
                }
            }
        }
        return results;
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : CompilationTestHelper(org.eclipse.xtext.xbase.testing.CompilationTestHelper) IAcceptor(org.eclipse.xtext.util.IAcceptor) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType)

Aggregations

JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)138 Test (org.junit.Test)41 EObject (org.eclipse.emf.ecore.EObject)26 JvmType (org.eclipse.xtext.common.types.JvmType)24 JvmMember (org.eclipse.xtext.common.types.JvmMember)21 JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)18 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)18 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)16 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)16 JvmAnnotationReference (org.eclipse.xtext.common.types.JvmAnnotationReference)15 JvmAnnotationType (org.eclipse.xtext.common.types.JvmAnnotationType)13 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)11 JvmAnnotationTarget (org.eclipse.xtext.common.types.JvmAnnotationTarget)10 TestAnnotation (org.eclipse.xtext.common.types.testSetups.TestAnnotation)10 Resource (org.eclipse.emf.ecore.resource.Resource)8 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)8 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)7 JvmArrayType (org.eclipse.xtext.common.types.JvmArrayType)7 JvmParameterizedTypeReference (org.eclipse.xtext.common.types.JvmParameterizedTypeReference)7 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)6