Search in sources :

Example 16 with JvmGenericType

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

the class XtendCompiler method internalCanCompileToJavaExpression.

@Override
protected boolean internalCanCompileToJavaExpression(XExpression expression, ITreeAppendable appendable) {
    if (expression instanceof AnonymousClass) {
        AnonymousClass anonymousClass = (AnonymousClass) expression;
        JvmGenericType inferredLocalClass = associations.getInferredType(anonymousClass);
        return inferredLocalClass.isAnonymous();
    } else
        return super.internalCanCompileToJavaExpression(expression, appendable);
}
Also used : AnonymousClass(org.eclipse.xtend.core.xtend.AnonymousClass) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType)

Example 17 with JvmGenericType

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

the class AnonymousClassUtil method getSuperType.

/* @Nullable */
public JvmGenericType getSuperType(AnonymousClass anonymousClass) {
    JvmConstructor constructor = anonymousClass.getConstructorCall().getConstructor();
    if (constructor != null && !constructor.eIsProxy()) {
        JvmDeclaredType declaringType = constructor.getDeclaringType();
        JvmType superType = Iterables.getLast(declaringType.getSuperTypes()).getType();
        if (superType instanceof JvmGenericType)
            return (JvmGenericType) superType;
    }
    return null;
}
Also used : JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmType(org.eclipse.xtext.common.types.JvmType)

Example 18 with JvmGenericType

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

the class XtendJvmModelInferrer method initialize.

protected void initialize(XtendClass source, JvmGenericType inferredJvmType) {
    inferredJvmType.setVisibility(source.getVisibility());
    boolean isStatic = source.isStatic() && !isTopLevel(source);
    if (!isStatic) {
        JvmDeclaredType declaringType = inferredJvmType.getDeclaringType();
        if (declaringType instanceof JvmGenericType) {
            if (((JvmGenericType) declaringType).isInterface())
                isStatic = true;
        } else if (declaringType instanceof JvmAnnotationType) {
            isStatic = true;
        }
    }
    inferredJvmType.setStatic(isStatic);
    inferredJvmType.setAbstract(source.isAbstract());
    inferredJvmType.setStrictFloatingPoint(source.isStrictFloatingPoint());
    if (!inferredJvmType.isAbstract()) {
        inferredJvmType.setFinal(source.isFinal());
    }
    translateAnnotationsTo(source.getAnnotations(), inferredJvmType);
    JvmTypeReference extendsClause = source.getExtends();
    if (extendsClause == null || extendsClause.getType() == null) {
        JvmTypeReference typeRefToObject = typeReferences.getTypeForName(Object.class, source);
        if (typeRefToObject != null)
            inferredJvmType.getSuperTypes().add(typeRefToObject);
    } else {
        inferredJvmType.getSuperTypes().add(jvmTypesBuilder.cloneWithProxies(extendsClause));
    }
    for (JvmTypeReference intf : source.getImplements()) {
        inferredJvmType.getSuperTypes().add(jvmTypesBuilder.cloneWithProxies(intf));
    }
    fixTypeParameters(inferredJvmType);
    addDefaultConstructor(source, inferredJvmType);
    for (XtendMember member : source.getMembers()) {
        if (member instanceof XtendField || (member instanceof XtendFunction && ((XtendFunction) member).getName() != null) || member instanceof XtendConstructor) {
            transform(member, inferredJvmType, true);
        }
    }
    appendSyntheticDispatchMethods(source, inferredJvmType);
    jvmTypesBuilder.copyDocumentationTo(source, inferredJvmType);
    nameClashResolver.resolveNameClashes(inferredJvmType);
}
Also used : JvmAnnotationType(org.eclipse.xtext.common.types.JvmAnnotationType) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) XtendConstructor(org.eclipse.xtend.core.xtend.XtendConstructor) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) XtendField(org.eclipse.xtend.core.xtend.XtendField)

Example 19 with JvmGenericType

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

the class AbstractReusableActiveAnnotationTests method testMarkReadAndInitialized.

@Test
public void testMarkReadAndInitialized() {
    Pair<String, String> _mappedTo = Pair.<String, String>of("myannotation/InitAnnotation.xtend", "\n\t\t\t\tpackage myannotation\n\t\t\t\t\n\t\t\t\timport java.util.List\n\t\t\t\timport org.eclipse.xtend.lib.macro.Active\n\t\t\t\timport org.eclipse.xtend.lib.macro.TransformationContext\n\t\t\t\timport org.eclipse.xtend.lib.macro.TransformationParticipant\n\t\t\t\timport org.eclipse.xtend.lib.macro.declaration.MutableFieldDeclaration\n\t\t\t\timport org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration\n\n\t\t\t\t@Active(InitProcessor)\n\t\t\t\tannotation Init { }\n\t\t\t\tclass InitProcessor implements TransformationParticipant<MutableFieldDeclaration> {\n\t\t\t\t\t\n\t\t\t\t\toverride doTransform(List<? extends MutableFieldDeclaration> annotatedTargetFields, extension TransformationContext context) {\n\t\t\t\t\t\tval ctor = annotatedTargetFields.head.declaringType.addConstructor [\n\t\t\t\t\t\t\tprimarySourceElement = declaringType\n\t\t\t\t\t\t\tbody = [\'\'\'\n\t\t\t\t\t\t\t\t�FOR f : annotatedTargetFields�\n\t\t\t\t\t\t\t\t\tthis.�f.simpleName� = \"foo\";\n\t\t\t\t\t\t\t\t�ENDFOR�\n\t\t\t\t\t\t\t\'\'\']\n\t\t\t\t\t\t]\n\t\t\t\t\t\tannotatedTargetFields.forEach [ field |\n\t\t\t\t\t\t\tfield.setFinal(true)\n\t\t\t\t\t\t\tfield.markAsRead\n\t\t\t\t\t\t\tfield.markAsInitializedBy(ctor)\n\t\t\t\t\t\t]\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t");
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("package myusercode");
    _builder.newLine();
    _builder.newLine();
    _builder.append("class MyClass {");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("@myannotation.Init String myField");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    Pair<String, String> _mappedTo_1 = Pair.<String, String>of("myusercode/MyClass.xtend", _builder.toString());
    final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
        MutableClassDeclaration _findClass = it.getTypeLookup().findClass("myusercode.MyClass");
        final JvmGenericType clazz = ((MutableJvmClassDeclarationImpl) _findClass).getDelegate();
        this.validator.assertNoIssues(clazz);
    };
    this.assertProcessing(_mappedTo, _mappedTo_1, _function);
}
Also used : CompilationUnitImpl(org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) MutableClassDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration) Test(org.junit.Test)

Example 20 with JvmGenericType

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

the class NonOverridableTypesProviderTest method testInheritMiddle_02.

@Test
public void testInheritMiddle_02() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package foo");
        _builder.newLine();
        _builder.newLine();
        _builder.append("import types.OuterClass");
        _builder.newLine();
        _builder.newLine();
        _builder.append("class Foo extends OuterClass.MiddleClass {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def foo() ");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendClass xtendClass = this.clazz(_builder.toString());
        final JvmGenericType inferredType = this.associations.getInferredType(xtendClass);
        this.assertTypeInScope("Foo", inferredType);
        this.assertTypeInScope("InnerMostClass", inferredType);
        this.assertNotInScope("OuterClass.MiddleClass", inferredType);
        this.assertNotInScope("MiddleClass", inferredType);
        this.assertNotInScope("OuterClass", inferredType);
        this.assertNotInScope("PrivateMiddleClass", inferredType);
        final XtendMember method = xtendClass.getMembers().get(0);
        final JvmOperation operation = this.associations.getDirectlyInferredOperation(((XtendFunction) method));
        this.assertTypeInScope("Foo", operation);
        this.assertTypeInScope("InnerMostClass", operation);
        this.assertNotInScope("OuterClass.MiddleClass", operation);
        this.assertNotInScope("MiddleClass", operation);
        this.assertNotInScope("OuterClass", operation);
        this.assertNotInScope("PrivateMiddleClass", inferredType);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) Test(org.junit.Test)

Aggregations

JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)155 Test (org.junit.Test)106 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)71 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)64 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)56 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)33 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)30 EObject (org.eclipse.emf.ecore.EObject)23 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)23 JvmMember (org.eclipse.xtext.common.types.JvmMember)21 JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)19 JvmField (org.eclipse.xtext.common.types.JvmField)19 JvmType (org.eclipse.xtext.common.types.JvmType)13 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)11 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)11 JvmTypeParameter (org.eclipse.xtext.common.types.JvmTypeParameter)11 DispatchHelper (org.eclipse.xtend.core.jvmmodel.DispatchHelper)10 Resource (org.eclipse.emf.ecore.resource.Resource)9 Check (org.eclipse.xtext.validation.Check)9 DispatchSignature (org.eclipse.xtend.core.jvmmodel.DispatchHelper.DispatchSignature)8