Search in sources :

Example 41 with XtendField

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

the class XtendReentrantTypeResolver method computeTypes.

protected void computeTypes(ResolvedTypes resolvedTypes, IFeatureScopeSession featureScopeSession, XtendMember member) {
    XExpression expression = null;
    if (member instanceof XtendFunction) {
        XtendFunction function = (XtendFunction) member;
        expression = function.getExpression();
        CreateExtensionInfo createInfo = function.getCreateExtensionInfo();
        if (createInfo != null) {
            computeDanglingExpressionType(resolvedTypes, featureScopeSession, function, createInfo.getCreateExpression());
        }
        for (XtendParameter parameter : function.getParameters()) {
            computeXtendAnnotationTypes(resolvedTypes, featureScopeSession, parameter.getAnnotations());
        }
    } else if (member instanceof XtendConstructor) {
        XtendConstructor constructor = (XtendConstructor) member;
        expression = constructor.getExpression();
        for (XtendParameter parameter : constructor.getParameters()) {
            computeXtendAnnotationTypes(resolvedTypes, featureScopeSession, parameter.getAnnotations());
        }
    } else if (member instanceof XtendField) {
        expression = ((XtendField) member).getInitialValue();
    }
    if (expression != null) {
        computeDanglingExpressionType(resolvedTypes, featureScopeSession, member, expression);
    }
    computeXtendAnnotationTypes(resolvedTypes, featureScopeSession, member.getAnnotations());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendParameter(org.eclipse.xtend.core.xtend.XtendParameter) XtendConstructor(org.eclipse.xtend.core.xtend.XtendConstructor) XExpression(org.eclipse.xtext.xbase.XExpression) CreateExtensionInfo(org.eclipse.xtend.core.xtend.CreateExtensionInfo) XtendField(org.eclipse.xtend.core.xtend.XtendField)

Example 42 with XtendField

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

the class XtendValidator method checkAnnotationTarget.

@Check
public void checkAnnotationTarget(XAnnotation annotation) {
    JvmType annotationType = annotation.getAnnotationType();
    if (annotationType == null || annotationType.eIsProxy() || !(annotationType instanceof JvmAnnotationType)) {
        return;
    }
    Set<ElementType> targets = annotationUtil.getAnnotationTargets((JvmAnnotationType) annotationType);
    if (targets.isEmpty())
        return;
    final EObject eContainer = getContainingAnnotationTarget(annotation);
    Class<? extends EObject> clazz = eContainer.getClass();
    if (eContainer instanceof XtendField && eContainer.eContainer() instanceof XtendAnnotationType) {
        clazz = XtendFunction.class;
    }
    for (Entry<Class<?>, Collection<ElementType>> mapping : targetInfos.asMap().entrySet()) {
        if (mapping.getKey().isAssignableFrom(clazz)) {
            targets.retainAll(mapping.getValue());
            if (targets.isEmpty()) {
                error("The annotation @" + annotation.getAnnotationType().getSimpleName() + " is disallowed for this location.", annotation, null, INSIGNIFICANT_INDEX, ANNOTATION_WRONG_TARGET);
            }
        }
    }
}
Also used : JvmAnnotationType(org.eclipse.xtext.common.types.JvmAnnotationType) ElementType(java.lang.annotation.ElementType) XtendAnnotationType(org.eclipse.xtend.core.xtend.XtendAnnotationType) EObject(org.eclipse.emf.ecore.EObject) Collection(java.util.Collection) AnonymousClass(org.eclipse.xtend.core.xtend.AnonymousClass) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmType(org.eclipse.xtext.common.types.JvmType) XtendField(org.eclipse.xtend.core.xtend.XtendField) Check(org.eclipse.xtext.validation.Check)

Example 43 with XtendField

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

the class XtendJvmModelInferrer method inferLocalClass.

/**
 * Anonymous classes are not inferred in the type inference phase, but later during type resolution.
 */
public void inferLocalClass(AnonymousClass anonymousClass, String localClassName, JvmFeature container) {
    final JvmGenericType inferredType = typesFactory.createJvmGenericType();
    inferredType.setSimpleName(localClassName);
    inferredType.setAnonymous(!hasAdditionalMembers(anonymousClass));
    inferredType.setFinal(true);
    inferredType.setVisibility(JvmVisibility.DEFAULT);
    inferredType.getSuperTypes().add(jvmTypesBuilder.inferredType(anonymousClass));
    container.getLocalClasses().add(inferredType);
    associator.associatePrimary(anonymousClass, inferredType);
    for (XtendMember member : anonymousClass.getMembers()) {
        if (member instanceof XtendField || (member instanceof XtendFunction && ((XtendFunction) member).getName() != null) || member instanceof XtendConstructor) {
            transform(member, inferredType, true);
        }
    }
    appendSyntheticDispatchMethods(anonymousClass, inferredType);
    nameClashResolver.resolveNameClashes(inferredType);
    final XConstructorCall constructorCall = anonymousClass.getConstructorCall();
    for (XExpression actualParameter : constructorCall.getArguments()) {
        associator.associateLogicalContainer(actualParameter, container);
    }
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) XtendConstructor(org.eclipse.xtend.core.xtend.XtendConstructor) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) XConstructorCall(org.eclipse.xtext.xbase.XConstructorCall) XExpression(org.eclipse.xtext.xbase.XExpression) XtendField(org.eclipse.xtend.core.xtend.XtendField)

Example 44 with XtendField

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

the class InsertionOffsets method getNewFieldInsertOffset.

public int getNewFieldInsertOffset(final EObject call, final XtendTypeDeclaration ownerType) {
    boolean _isEmpty = ownerType.getMembers().isEmpty();
    if (_isEmpty) {
        return this.inEmpty(ownerType);
    }
    final XtendField callingMember = EcoreUtil2.<XtendField>getContainerOfType(call, XtendField.class);
    if (((callingMember != null) && ownerType.getMembers().contains(callingMember))) {
        return this.before(callingMember);
    }
    final XtendField lastDefinedField = IterableExtensions.<XtendField>last(Iterables.<XtendField>filter(ownerType.getMembers(), XtendField.class));
    if ((lastDefinedField == null)) {
        return this.before(IterableExtensions.<XtendMember>head(ownerType.getMembers()));
    } else {
        return this.after(lastDefinedField);
    }
}
Also used : XtendField(org.eclipse.xtend.core.xtend.XtendField)

Example 45 with XtendField

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

the class XtendUIValidationTests method testDiscouragedConstructorCall.

@Test
public void testDiscouragedConstructorCall() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("import org.eclipse.xtend.core.tests.internal.InternalClass");
        _builder.newLine();
        _builder.append("class Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("InternalClass x = new InternalClass");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile xtendFile = this.testHelper.xtendFile("Clazz.xtend", _builder.toString());
        this.helper.assertWarning(xtendFile.getImportSection().getImportDeclarations().get(0), XtypePackage.Literals.XIMPORT_DECLARATION, org.eclipse.xtext.xbase.validation.IssueCodes.DISCOURAGED_REFERENCE);
        XtendMember _head = IterableExtensions.<XtendMember>head(IterableExtensions.<XtendClass>head(Iterables.<XtendClass>filter(xtendFile.getXtendTypes(), XtendClass.class)).getMembers());
        final XtendField field = ((XtendField) _head);
        this.helper.assertWarning(field.getType(), TypesPackage.Literals.JVM_TYPE_REFERENCE, org.eclipse.xtext.xbase.validation.IssueCodes.DISCOURAGED_REFERENCE);
        this.helper.assertWarning(field.getInitialValue(), XbasePackage.Literals.XCONSTRUCTOR_CALL, org.eclipse.xtext.xbase.validation.IssueCodes.DISCOURAGED_REFERENCE);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendField(org.eclipse.xtend.core.xtend.XtendField) Test(org.junit.Test)

Aggregations

XtendField (org.eclipse.xtend.core.xtend.XtendField)71 Test (org.junit.Test)50 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)38 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)33 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)29 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)23 XExpression (org.eclipse.xtext.xbase.XExpression)23 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)14 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)12 EObject (org.eclipse.emf.ecore.EObject)8 RichString (org.eclipse.xtend.core.xtend.RichString)7 XtendConstructor (org.eclipse.xtend.core.xtend.XtendConstructor)6 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)6 XClosure (org.eclipse.xtext.xbase.XClosure)6 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)5 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)5 XtendAnnotationType (org.eclipse.xtend.core.xtend.XtendAnnotationType)4 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)4 IResolvedTypes (org.eclipse.xtext.xbase.typesystem.IResolvedTypes)4 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)3