@Override protected LightweightTypeReference doVisitTypeReference(final LightweightTypeReference reference) { boolean _isUnknown = reference.isUnknown(); if (_isUnknown) { return reference; } return null; }
@Override public boolean isUnknown() { return component.isUnknown(); }
@Override public boolean isUnknown() { if (internalIsResolved()) { return resolvedTo.isUnknown(); } return false; }
/** * Announce a synonym type with the given conformance hints. */ protected final boolean announceSynonym(LightweightTypeReference synonym, EnumSet<ConformanceHint> hints, Acceptor acceptor) { if (synonym.isUnknown()) { return true; } return acceptor.accept(synonym, hints); }
/** * Announce a synonym type with the given conformance hint. */ protected final boolean announceSynonym(LightweightTypeReference synonym, ConformanceHint hint, Acceptor acceptor) { if (synonym.isUnknown()) { return true; } return acceptor.accept(synonym, hint); }
/** * Announce a synonym type with the given conformance flags. * @see ConformanceFlags */ protected final boolean announceSynonym(LightweightTypeReference synonym, int flags, Acceptor acceptor) { if (synonym.isUnknown()) { return true; } return acceptor.accept(synonym, flags | ConformanceFlags.CHECKED_SUCCESS); }
protected boolean isUnknownReceiverType(LightweightTypeReference receiverType) { if (receiverType.isUnknown()) { return true; } if (receiverType instanceof UnboundTypeReference) { List<LightweightBoundTypeArgument> hints = ((UnboundTypeReference) receiverType).getAllHints(); for(LightweightBoundTypeArgument hint: hints) { LightweightTypeReference typeReference = hint.getTypeReference(); if (typeReference != null && typeReference.isUnknown()) return true; } } return false; }
@Override public JvmArrayType getType() { JvmType componentType = component.toJavaType().getType(); if (componentType instanceof JvmComponentType) { return Preconditions.checkNotNull(((JvmComponentType) componentType).getArrayType()); } if (component.isUnknown() || componentType.eIsProxy()) { return null; } throw new IllegalStateException("component type seems to be invalid: " + componentType + " / " + component); }
@Override public void addExtensionsToCurrentScope(List<? extends JvmIdentifiableElement> extensionProviders) { if (extensionProviders.isEmpty()) return; if (extensionProviders.size() == 1) { addExtensionToCurrentScope(extensionProviders.get(0)); return; } Map<XExpression, LightweightTypeReference> prototypeToType = Maps2.newLinkedHashMapWithExpectedSize(extensionProviders.size()); for(JvmIdentifiableElement extensionProvider: extensionProviders) { LightweightTypeReference knownType = getResolvedTypes().getActualType(extensionProvider); if (knownType != null && !knownType.isAny() && !knownType.isUnknown()) { XFeatureCall prototype = getResolver().getXbaseFactory().createXFeatureCall(); prototype.setFeature(extensionProvider); prototypeToType.put(prototype, knownType); } } if (!prototypeToType.isEmpty()) featureScopeSession = featureScopeSession.addToExtensionScope(prototypeToType); }
protected IScope createImplicitStaticScope(QualifiedName implicitName, XAbstractFeatureCall featureCall, IFeatureScopeSession session, IResolvedTypes resolvedTypes, IScope parent) { IEObjectDescription thisDescription = session.getLocalElement(implicitName); if (thisDescription != null) { JvmIdentifiableElement thisElement = (JvmIdentifiableElement) thisDescription.getEObjectOrProxy(); LightweightTypeReference type = resolvedTypes.getActualType(thisElement); if (type != null && !type.isUnknown()) { TypeBucket receiverBucket = new TypeBucket(-1, Collections.singletonList(type.getType()), resolvedFeaturesProvider); return createStaticFeatureScope(featureCall, null, type, receiverBucket, parent, session); } } return parent; }
protected IScope createConstructorDelegates(EObject context, IScope parent, IFeatureScopeSession session, IResolvedTypes resolvedTypes) { if (session.isConstructorContext()) { IEObjectDescription thisDescription = session.getLocalElement(THIS); if (thisDescription != null) { JvmIdentifiableElement thisElement = (JvmIdentifiableElement) thisDescription.getEObjectOrProxy(); LightweightTypeReference type = resolvedTypes.getActualType(thisElement); if (type != null && !type.isUnknown()) { return createConstructorDelegateScope(context, type, parent, session); } } } return parent; }
@Override public void addExtensionToCurrentScope(JvmIdentifiableElement extensionProvider) { LightweightTypeReference knownType = getResolvedTypes().getActualType(extensionProvider); if (knownType != null && !knownType.isAny() && !knownType.isUnknown()) { XFeatureCall prototype = getResolver().getXbaseFactory().createXFeatureCall(); prototype.setFeature(extensionProvider); featureScopeSession = featureScopeSession.addToExtensionScope(Collections.<XExpression, LightweightTypeReference>singletonMap(prototype, knownType)); } }
protected IScope createImplicitExtensionScope(QualifiedName implicitName, EObject featureCall, IFeatureScopeSession session, IResolvedTypes resolvedTypes, IScope parent) { IEObjectDescription thisDescription = session.getLocalElement(implicitName); if (thisDescription != null) { JvmIdentifiableElement thisElement = (JvmIdentifiableElement) thisDescription.getEObjectOrProxy(); LightweightTypeReference type = resolvedTypes.getActualType(thisElement); if (type != null && !type.isUnknown()) { XFeatureCall implicitReceiver = xbaseFactory.createXFeatureCall(); implicitReceiver.setFeature(thisElement); return createStaticExtensionsScope(featureCall, implicitReceiver, type, true, parent, session); } } return parent; }
@Check public void checkJUnitMethodReturnType(XtendFunction function) { JvmOperation operation = associations.getDirectlyInferredOperation(function); /* * Active annotations could also change the return type. * Checking that the JvmOperation really has a JUnit annotation. */ if(hasJUnitAnnotation(operation)) { LightweightTypeReference actualType = determineReturnType(operation); if(actualType !=null && !actualType.isUnknown() && !actualType.isPrimitiveVoid()) { String message = String.format("JUnit method %s() must be void but is %s.", function.getName(), actualType.getHumanReadableName()); EAttribute location = XTEND_FUNCTION__NAME; error(message, function, location, INVALID_RETURN_TYPE_IN_CASE_OF_JUNIT_ANNOTATION); } } }
public void acceptHint(LightweightBoundTypeArgument hint) { if (internalIsResolved()) { throw new IllegalStateException("Cannot add hints to a resolved reference"); } if (hint.getSource() == BoundTypeArgumentSource.EXPLICIT) { LightweightTypeReference reference = hint.getTypeReference(); if (!(reference instanceof ParameterizedTypeReference) && !reference.isArray() && !reference.isUnknown()) { throw new IllegalArgumentException("cannot set " + hint + " as explicit hint"); } if (!getAllHints().isEmpty()) { throw new IllegalStateException("Cannot set explicit hint if other hints are present: " + getAllHints()); } this.resolvedTo = reference; getOwner().acceptHint(getHandle(), new LightweightBoundTypeArgument(resolvedTo, BoundTypeArgumentSource.RESOLVED, this, hint.getDeclaredVariance(), hint.getActualVariance())); return; } getOwner().acceptHint(this.getHandle(), hint); }
protected IScope createDynamicExtensionsScope(QualifiedName implicitFirstArgumentName, IEObjectDescription firstArgumentDescription, EObject featureCall, IFeatureScopeSession captureLayer, IFeatureScopeSession session, IResolvedTypes resolvedTypes, IScope parent) { JvmIdentifiableElement feature = (JvmIdentifiableElement) firstArgumentDescription.getEObjectOrProxy(); if (feature instanceof JvmType && THIS.equals(implicitFirstArgumentName) && !session.isInstanceContext()) { return parent; } LightweightTypeReference type = resolvedTypes.getActualType(feature); if (type != null && !type.isUnknown()) { XFeatureCall implicitArgument = xbaseFactory.createXFeatureCall(); implicitArgument.setFeature(feature); return createDynamicExtensionsScope(featureCall, implicitArgument, type, true, parent, captureLayer); } return parent; }
protected IScope createImplicitFeatureCallScope(QualifiedName implicitName, EObject featureCall, IFeatureScopeSession session, IResolvedTypes resolvedTypes, IScope parent) { IEObjectDescription thisDescription = session.getLocalElement(implicitName); if (thisDescription != null) { JvmIdentifiableElement thisElement = (JvmIdentifiableElement) thisDescription.getEObjectOrProxy(); boolean validStaticScope = true; if (thisElement instanceof JvmType && THIS.equals(implicitName) && !session.isInstanceContext()) { validStaticScope = false; } LightweightTypeReference type = resolvedTypes.getActualType(thisElement); if (type !=null && !type.isUnknown()) { XFeatureCall implicitReceiver = xbaseFactory.createXFeatureCall(); implicitReceiver.setFeature(thisElement); return createFeatureScopeForTypeRef(implicitReceiver, type, true, featureCall, session, thisElement, parent, validStaticScope); } } return parent; }
protected boolean isPotentialTypeLiteralImpl(XExpression featureCall, /* @Nullable */ IResolvedTypes resolvedTypes, boolean staticNotation) { if (featureCall instanceof XMemberFeatureCall) { XMemberFeatureCall casted = (XMemberFeatureCall) featureCall; if (casted.isExplicitOperationCallOrBuilderSyntax() || casted.isNullSafe()) { return false; } XExpression target = casted.getMemberCallTarget(); if (casted.isExplicitStatic() != staticNotation) { return false; } return isPotentialTypeLiteralImpl(target, resolvedTypes, staticNotation); } if (featureCall instanceof XFeatureCall) { XFeatureCall casted = (XFeatureCall) featureCall; if (casted.isExplicitOperationCallOrBuilderSyntax()) { return false; } if (resolvedTypes == null) return true; LightweightTypeReference knownType = resolvedTypes.getActualType(casted); if (knownType == null || knownType.isUnknown()) { return true; } } return false; }
@Override public Type getType() { Type _switchResult = null; LightweightTypeReference _delegate = this.getDelegate(); final LightweightTypeReference it = _delegate; boolean _matched = false; boolean _isUnknown = it.isUnknown(); if (_isUnknown) { _matched=true; CompilationUnitImpl _compilationUnit = this.getCompilationUnit(); String _packageName = this.getCompilationUnit().getPackageName(); String _plus = (_packageName + "."); String _simpleName = it.getSimpleName(); String _plus_1 = (_plus + _simpleName); _switchResult = new UnknownType(_compilationUnit, _plus_1); } if (!_matched) { _switchResult = this.getCompilationUnit().toType(it.getType()); } return _switchResult; }
@Check public void checkInstanceOf(XInstanceOfExpression instanceOfExpression) { LightweightTypeReference leftType = getActualType(instanceOfExpression.getExpression()); final LightweightTypeReference rightType = toLightweightTypeReference(instanceOfExpression.getType(), true); if (leftType == null || rightType == null || rightType.getType() == null || rightType.getType().eIsProxy()) { return; } if (containsTypeArgs(rightType)) { error("Cannot perform instanceof check against parameterized type " + getNameOfTypes(rightType), null, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, INVALID_INSTANCEOF); return; } if (leftType.isAny() || leftType.isUnknown()) { return; // null / unknown is ok } if (rightType.isPrimitive()) { error("Cannot perform instanceof check against primitive type " + this.getNameOfTypes(rightType), null, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, INVALID_INSTANCEOF); return; } if (leftType.isPrimitive() || rightType.isArray() && !(leftType.isArray() || leftType.isType(Object.class) || leftType.isType(Cloneable.class) || leftType.isType(Serializable.class)) || isFinal(rightType) && !memberOfTypeHierarchy(rightType, leftType) || isFinal(leftType) && !memberOfTypeHierarchy(leftType, rightType)) { error("Incompatible conditional operand types " + this.getNameOfTypes(leftType)+" and "+this.getNameOfTypes(rightType), null, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, INVALID_INSTANCEOF); return; } if (!isIgnored(OBSOLETE_INSTANCEOF) && rightType.isAssignableFrom(leftType, new TypeConformanceComputationArgument(false, false, true, true, false, false))) { addIssueToState(OBSOLETE_INSTANCEOF, "The expression of type " + getNameOfTypes(leftType) + " is already of type " + canonicalName(rightType), null); } }