Search in sources :

Example 41 with JvmType

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

the class XtendValidator method checkSuperTypes.

@Check
public void checkSuperTypes(AnonymousClass anonymousClass) {
    JvmGenericType inferredType = associations.getInferredType(anonymousClass);
    if (inferredType != null) {
        JvmTypeReference superTypeRef = Iterables.getLast(inferredType.getSuperTypes());
        JvmType superType = superTypeRef.getType();
        if (superType instanceof JvmGenericType && ((JvmGenericType) superType).isFinal())
            error("Attempt to override final class", anonymousClass.getConstructorCall(), XCONSTRUCTOR_CALL__CONSTRUCTOR, INSIGNIFICANT_INDEX, OVERRIDDEN_FINAL);
    }
}
Also used : JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmType(org.eclipse.xtext.common.types.JvmType) Check(org.eclipse.xtext.validation.Check)

Example 42 with JvmType

use of org.eclipse.xtext.common.types.JvmType 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 JvmType

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

the class XtendValidator method contributesToConflict.

/**
 * Determine whether the given type contributes to the conflict caused by the given default interface implementation.
 */
private boolean contributesToConflict(JvmGenericType rootType, ConflictingDefaultOperation conflictingDefaultOperation) {
    Set<JvmDeclaredType> involvedInterfaces = Sets.newHashSet();
    involvedInterfaces.add(conflictingDefaultOperation.getDeclaration().getDeclaringType());
    for (IResolvedOperation conflictingOperation : conflictingDefaultOperation.getConflictingOperations()) {
        involvedInterfaces.add(conflictingOperation.getDeclaration().getDeclaringType());
    }
    RecursionGuard<JvmDeclaredType> recursionGuard = new RecursionGuard<JvmDeclaredType>();
    if (rootType.isInterface()) {
        int contributingCount = 0;
        for (JvmTypeReference typeRef : rootType.getExtendedInterfaces()) {
            JvmType rawType = typeRef.getType();
            if (rawType instanceof JvmDeclaredType && contributesToConflict((JvmDeclaredType) rawType, involvedInterfaces, recursionGuard)) {
                contributingCount++;
            }
        }
        return contributingCount >= 2;
    } else {
        return contributesToConflict(rootType, involvedInterfaces, recursionGuard);
    }
}
Also used : JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) RecursionGuard(org.eclipse.xtext.xbase.typesystem.util.RecursionGuard) JvmType(org.eclipse.xtext.common.types.JvmType) IResolvedOperation(org.eclipse.xtext.xbase.typesystem.override.IResolvedOperation)

Example 44 with JvmType

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

the class XtendValidator method validateInferredType.

protected void validateInferredType(JvmTypeReference inferredType, XtendMember member, String messagePrefix, EAttribute location) {
    if (inferredType != null) {
        TreeIterator<EObject> iterator = EcoreUtil2.eAll(inferredType);
        while (iterator.hasNext()) {
            EObject next = iterator.next();
            if (next instanceof JvmParameterizedTypeReference) {
                JvmParameterizedTypeReference candidate = (JvmParameterizedTypeReference) next;
                JvmType type = candidate.getType();
                if (type instanceof JvmGenericType && !((JvmGenericType) type).getTypeParameters().isEmpty()) {
                    if (candidate.getArguments().isEmpty()) {
                        StringBuilder message = new StringBuilder(messagePrefix);
                        message = proxyAwareUIStrings.visit(inferredType, message);
                        if (message != null) {
                            message.append(" uses the raw type ");
                            message.append(type.getSimpleName());
                            message.append(". References to generic type ");
                            message = proxyAwareUIStrings.appendTypeSignature(type, message);
                            message.append(" should be parameterized");
                            warning(message.toString(), member, location, org.eclipse.xtext.xbase.validation.IssueCodes.RAW_TYPE);
                        }
                        return;
                    }
                }
            } else if (next instanceof XComputedTypeReference) {
                validateInferredType(((XComputedTypeReference) next).getEquivalent(), member, messagePrefix, location);
                iterator.prune();
            }
        }
    }
}
Also used : ToStringBuilder(org.eclipse.xtext.xbase.lib.util.ToStringBuilder) EObject(org.eclipse.emf.ecore.EObject) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) XComputedTypeReference(org.eclipse.xtext.xtype.XComputedTypeReference) JvmType(org.eclipse.xtext.common.types.JvmType) JvmParameterizedTypeReference(org.eclipse.xtext.common.types.JvmParameterizedTypeReference)

Example 45 with JvmType

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

the class Declarators method getDeclaratorData.

public Declarators.DeclaratorsData getDeclaratorData(final TargetURIs targetURIs, final IReferenceFinder.IResourceAccess resourceAccess) {
    Declarators.DeclaratorsData result = targetURIs.<Declarators.DeclaratorsData>getUserData(Declarators.KEY);
    if ((result != null)) {
        return result;
    }
    final HashSet<QualifiedName> declaratorNames = CollectionLiterals.<QualifiedName>newHashSet();
    final Consumer<URI> _function = (URI uri) -> {
        final IUnitOfWork<Object, ResourceSet> _function_1 = (ResourceSet it) -> {
            Object _xblockexpression = null;
            {
                final Consumer<URI> _function_2 = (URI objectURI) -> {
                    final EObject object = it.getEObject(objectURI, true);
                    if ((object != null)) {
                        final JvmType type = EcoreUtil2.<JvmType>getContainerOfType(object, JvmType.class);
                        if ((type != null)) {
                            QualifiedName _lowerCase = this.nameConverter.toQualifiedName(type.getIdentifier()).toLowerCase();
                            declaratorNames.add(_lowerCase);
                            QualifiedName _lowerCase_1 = this.nameConverter.toQualifiedName(type.getQualifiedName('.')).toLowerCase();
                            declaratorNames.add(_lowerCase_1);
                        }
                    }
                };
                targetURIs.getEObjectURIs(uri).forEach(_function_2);
                _xblockexpression = null;
            }
            return _xblockexpression;
        };
        resourceAccess.<Object>readOnly(uri, _function_1);
    };
    targetURIs.getTargetResourceURIs().forEach(_function);
    Declarators.DeclaratorsData _declaratorsData = new Declarators.DeclaratorsData(declaratorNames);
    result = _declaratorsData;
    targetURIs.<Declarators.DeclaratorsData>putUserData(Declarators.KEY, result);
    return result;
}
Also used : QualifiedName(org.eclipse.xtext.naming.QualifiedName) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) JvmType(org.eclipse.xtext.common.types.JvmType) URI(org.eclipse.emf.common.util.URI) IUnitOfWork(org.eclipse.xtext.util.concurrent.IUnitOfWork) Consumer(java.util.function.Consumer) EObject(org.eclipse.emf.ecore.EObject) EObject(org.eclipse.emf.ecore.EObject)

Aggregations

JvmType (org.eclipse.xtext.common.types.JvmType)73 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)29 EObject (org.eclipse.emf.ecore.EObject)18 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)17 Test (org.junit.Test)17 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)14 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)12 XExpression (org.eclipse.xtext.xbase.XExpression)12 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)11 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)11 JvmAnnotationType (org.eclipse.xtext.common.types.JvmAnnotationType)10 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)9 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)9 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)8 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)8 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)8 Resource (org.eclipse.emf.ecore.resource.Resource)7 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)7 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)6 JvmEnumerationType (org.eclipse.xtext.common.types.JvmEnumerationType)6