Java 类org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference 实例源码

项目:xtext-extras    文件:XbaseCompiler.java   
protected void appendImmutableCollectionExpression(XCollectionLiteral literal,
        ITreeAppendable b, String collectionsMethod, Class<?> guavaHelper, String guavaHelperMethod) {
    LightweightTypeReference collectionElementType = getCollectionElementType(literal);
    b.append(Collections.class);
    b.append(".<").append(collectionElementType).append(">").append(collectionsMethod).append("(");
    b.append(guavaHelper).append(".<").append(collectionElementType).append(">").append(guavaHelperMethod).append("(");
    boolean isFirst = true;
    for(XExpression element: literal.getElements())  {
        if(!isFirst)
            b.append(", ");
        isFirst = false;
        if(element instanceof XNullLiteral) {
            b.append("(").append(collectionElementType).append(")");
        }
        internalToJavaExpression(element, b);
    }
    b.append("))");
    return;
}
项目:xtext-extras    文件:XbaseTypeComputer.java   
protected void _computeTypes(XInstanceOfExpression object, ITypeComputationState state) {
    ITypeComputationState expressionState = state.withExpectation(state.getReferenceOwner().newReferenceToObject());
    expressionState.computeTypes(object.getExpression());
    JvmTypeReference type = object.getType();
    if (type != null && type.getType() instanceof JvmTypeParameter) {
        LightweightTypeReference lightweightReference = state.getReferenceOwner().toLightweightTypeReference(type);
        LightweightTypeReference rawTypeRef = lightweightReference.getRawTypeReference();
        state.addDiagnostic(new EObjectDiagnosticImpl(
                Severity.ERROR,
                IssueCodes.INVALID_USE_OF_TYPE_PARAMETER,
                "Cannot perform instanceof check against type parameter "+lightweightReference.getHumanReadableName()+". Use its erasure "+rawTypeRef.getHumanReadableName()+" instead since further generic type information will be erased at runtime.",
                object.getType(),
                null,
                -1,
                new String[] { 
                }));
    }
    LightweightTypeReference bool = getRawTypeForName(Boolean.TYPE, state);
    state.acceptActualType(bool);
}
项目:xtext-extras    文件:TypeConvertingCompiler.java   
private void convertMultiType(LightweightTypeReference expectation, CompoundTypeReference multiType, XExpression context,
        ITreeAppendable b, Later expression) {
    LightweightTypeReference castTo = null;
    List<LightweightTypeReference> components = multiType.getMultiTypeComponents();
    ITypeReferenceOwner owner = multiType.getOwner();
    LightweightTypeReference commonType = owner.getServices().getTypeConformanceComputer().getCommonSuperType(components, owner);
    if (!isJavaConformant(expectation, commonType)) {
        for(LightweightTypeReference candidate: multiType.getMultiTypeComponents()) {
            if (isJavaConformant(expectation, candidate)) {
                castTo = candidate;
                break;
            }
        }
    }
    if (castTo != null && mustInsertTypeCast(context, castTo)) {
        b.append("((");
        b.append(castTo);
        b.append(")");
        expression.exec(b);
        b.append(")");
    } else {
        expression.exec(b);
    }
}
项目:xtext-extras    文件:XbaseValidator.java   
@Check
public void checkCatchClausesOrder(XTryCatchFinallyExpression expression) {
    ITypeReferenceOwner owner = new StandardTypeReferenceOwner(getServices(), expression);
    List<LightweightTypeReference> previousTypeReferences = new ArrayList<LightweightTypeReference>();
    for (XCatchClause catchClause : expression.getCatchClauses()) {
        LightweightTypeReference actualTypeReference = owner.toLightweightTypeReference(catchClause.getDeclaredParam().getParameterType());
        if (actualTypeReference == null) {
            continue;
        }
        if (isHandled(actualTypeReference, previousTypeReferences)) {
            error("Unreachable code: The catch block can never match. It is already handled by a previous condition.", catchClause.getDeclaredParam().getParameterType(), null, IssueCodes.UNREACHABLE_CATCH_BLOCK);
            continue;
        }
        previousTypeReferences.add(actualTypeReference);
    }
}
项目:xtext-extras    文件:XSwitchExpressions.java   
/**
 * Determine whether the given switch expression is valid for Java version 6 or lower.
 */
public boolean isJavaSwitchExpression(final XSwitchExpression it) {
  boolean _xblockexpression = false;
  {
    final LightweightTypeReference switchType = this.getSwitchVariableType(it);
    if ((switchType == null)) {
      return false;
    }
    boolean _isSubtypeOf = switchType.isSubtypeOf(Integer.TYPE);
    if (_isSubtypeOf) {
      return true;
    }
    boolean _isSubtypeOf_1 = switchType.isSubtypeOf(Enum.class);
    if (_isSubtypeOf_1) {
      return true;
    }
    _xblockexpression = false;
  }
  return _xblockexpression;
}
项目:xtext-extras    文件:WrapperTypeLookup.java   
public static LightweightTypeReference getWrapperType(LightweightTypeReference context, Primitive primitiveKind) {
    switch(primitiveKind) {
        case Boolean:
            return findTopLevelType(context, "java.lang.Boolean");
        case Byte:
            return findTopLevelType(context, "java.lang.Byte");
        case Char:
            return findTopLevelType(context, "java.lang.Character");
        case Double:
            return findTopLevelType(context, "java.lang.Double");
        case Float:
            return findTopLevelType(context, "java.lang.Float");
        case Int:
            return findTopLevelType(context, "java.lang.Integer");
        case Long:
            return findTopLevelType(context, "java.lang.Long");
        case Short:
            return findTopLevelType(context, "java.lang.Short");
        case Void:
            return findTopLevelType(context, "java.lang.Void");
        default:
            throw new IllegalArgumentException("Unknown primitive type: " + primitiveKind);
    }
}
项目:xtext-extras    文件:RawTypeConformanceComputer.java   
protected int isConformantMergeResult(LightweightMergedBoundTypeArgument mergeResult, LightweightTypeReference right,
        int flags) {
    LightweightTypeReference mergeResultReference = mergeResult.getTypeReference();
    if (right.isWildcard() && mergeResultReference.isWildcard()) {
        if (right.getLowerBoundSubstitute().isAny()) {
            LightweightTypeReference lowerBoundMergeResult = mergeResultReference.getLowerBoundSubstitute();
            if (!lowerBoundMergeResult.isAny()) {
                mergeResultReference = lowerBoundMergeResult;
            }
        } else {
            flags = flags | AS_TYPE_ARGUMENT;
        }
    } else if (mergeResultReference.isWildcard()) {
        flags = flags | AS_TYPE_ARGUMENT;
    }
    return isConformant(mergeResultReference, right, flags);
}
项目:xtext-extras    文件:ResolvedFeature.java   
@Override
protected void resolveArgumentType(XExpression argument, /* @Nullable */ LightweightTypeReference declaredType, ITypeComputationState argumentState) {
    if (argument == getSyntacticReceiver()) {
        LightweightTypeReference receiverType = getSyntacticReceiverType();
        if (receiverType == null) {
            throw new IllegalStateException("Cannot determine the receiver's type");
        }
        resolveKnownArgumentType(argument, receiverType, declaredType, argumentState);
    } else if (argument == getImplicitFirstArgument()) {
        LightweightTypeReference argumentType = getImplicitFirstArgumentType();
        if (argumentType == null) {
            throw new IllegalStateException("Cannot determine the implicit argument's type");
        }
        resolveKnownArgumentType(argument, argumentType, declaredType, argumentState);
    } else {
        super.resolveArgumentType(argument, declaredType, argumentState);
    }
}
项目:xtext-extras    文件:ValidatingReassigningResolvedTypes.java   
@Override
public LightweightTypeReference acceptType(final XExpression expression, final AbstractTypeExpectation expectation, final LightweightTypeReference type, final boolean returnType, final int hints) {
  LightweightTypeReference _xblockexpression = null;
  {
    boolean _isOwnedBy = expectation.isOwnedBy(this.getReferenceOwner());
    boolean _not = (!_isOwnedBy);
    if (_not) {
      throw new IllegalArgumentException("expectation is not owned by this resolved types");
    }
    boolean _isOwnedBy_1 = type.isOwnedBy(this.getReferenceOwner());
    boolean _not_1 = (!_isOwnedBy_1);
    if (_not_1) {
      throw new IllegalArgumentException("type is not owned by this resolved types");
    }
    _xblockexpression = super.acceptType(expression, expectation, type, returnType, hints);
  }
  return _xblockexpression;
}
项目:xtext-extras    文件:TypeParameterByConstraintSubstitutor.java   
@Override
/* @Nullable */
protected LightweightTypeReference getUnmappedSubstitute(ParameterizedTypeReference reference, JvmTypeParameter type, ConstraintVisitingInfo visiting) {
    if (!ignoreDeclaredTypeParameters) {
        if (isDeclaredTypeParameter(type)) {
            return reference;
        }
    }
    ConstraintAwareTypeArgumentCollector collector = new ConstraintAwareTypeArgumentCollector(getOwner());
    LightweightTraversalData data = new LightweightTraversalData();
    data.getTypeParameterMapping().putAll(getTypeParameterMapping());
    reference.accept(collector, data);
    LightweightMergedBoundTypeArgument boundTypeArgument = data.getTypeParameterMapping().get(type);
    if (boundTypeArgument != null && boundTypeArgument.getTypeReference() != reference) {
        return boundTypeArgument.getTypeReference().accept(this, visiting);
    }
    if (boundTypeArgument != null)
        return boundTypeArgument.getTypeReference();
    return null;
}
项目:xtext-extras    文件:RecomputingReentrantTypeResolver.java   
protected void _assertEqualLinkingData(final IFeatureLinkingCandidate left, final IFeatureLinkingCandidate right) {
  try {
    Assert.assertEquals("feature", left.getFeature(), right.getFeature());
    Assert.assertEquals("featureCall", left.getFeatureCall(), right.getFeatureCall());
    this.doAssertEqualLinkingData(left, right);
    Assert.assertEquals("receiver", this._reflectExtensions.invoke(left, "getReceiver"), this._reflectExtensions.invoke(right, "getReceiver"));
    this.assertEqualTypes("receiverType", this.<LightweightTypeReference>invokeAndCast(left, "getReceiverType"), this.<LightweightTypeReference>invokeAndCast(left, "getReceiverType"));
    Assert.assertEquals("implicitReceiver", this._reflectExtensions.invoke(left, "getImplicitReceiver"), this._reflectExtensions.invoke(right, "getImplicitReceiver"));
    this.assertEqualTypes("implicitReceiverType", this.<LightweightTypeReference>invokeAndCast(left, "getImplicitReceiverType"), this.<LightweightTypeReference>invokeAndCast(left, "getImplicitReceiverType"));
    Assert.assertEquals("implicitFirstArgument", this._reflectExtensions.invoke(left, "getImplicitFirstArgument"), this._reflectExtensions.invoke(right, "getImplicitFirstArgument"));
    this.assertEqualTypes("implicitFirstArgumentType", this.<LightweightTypeReference>invokeAndCast(left, "getImplicitFirstArgumentType"), this.<LightweightTypeReference>invokeAndCast(left, "getImplicitFirstArgumentType"));
    Assert.assertEquals("syntacticReceiver", this._reflectExtensions.invoke(left, "getSyntacticReceiver"), this._reflectExtensions.invoke(right, "getSyntacticReceiver"));
    this.assertEqualTypes("syntacticReceiverType", this.<LightweightTypeReference>invokeAndCast(left, "getSyntacticReceiverType"), this.<LightweightTypeReference>invokeAndCast(left, "getSyntacticReceiverType"));
    Assert.assertEquals("isStatic", Boolean.valueOf(left.isStatic()), Boolean.valueOf(right.isStatic()));
    Assert.assertEquals("isTypeLiteral", Boolean.valueOf(left.isTypeLiteral()), Boolean.valueOf(right.isTypeLiteral()));
    Assert.assertEquals("syntacticReceiver", this._reflectExtensions.invoke(left, "getSyntacticReceiver"), this._reflectExtensions.invoke(right, "getSyntacticReceiver"));
    Assert.assertEquals("isExtension", Boolean.valueOf(left.isExtension()), Boolean.valueOf(right.isExtension()));
    Assert.assertEquals("syntacticArguments", this._reflectExtensions.invoke(left, "getSyntacticArguments"), this._reflectExtensions.invoke(right, "getSyntacticArguments"));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
项目:xtext-extras    文件:RecomputingReentrantTypeResolver.java   
public void doAssertEqualLinkingData(final ILinkingCandidate left, final ILinkingCandidate right) {
  try {
    this.assertEqualReferences("typeArguments", left.getTypeArguments(), right.getTypeArguments());
    this.assertEqualReferences("syntacticTypeArguments", this.<List<LightweightTypeReference>>invokeAndCast(left, "getSyntacticTypeArguments"), this.<List<LightweightTypeReference>>invokeAndCast(right, "getSyntacticTypeArguments"));
    Assert.assertEquals("arguments", this._reflectExtensions.invoke(left, "getArguments"), this._reflectExtensions.invoke(right, "getArguments"));
    Assert.assertEquals("declaredTypeParameters", this._reflectExtensions.invoke(left, "getDeclaredTypeParameters"), this._reflectExtensions.invoke(right, "getDeclaredTypeParameters"));
    this.assertEqualMapping("typeParameterMapping", this.<Map<JvmTypeParameter, LightweightMergedBoundTypeArgument>>invokeAndCast(left, "getTypeParameterMapping"), this.<Map<JvmTypeParameter, LightweightMergedBoundTypeArgument>>invokeAndCast(right, "getTypeParameterMapping"));
    this.assertEqualMapping("declaratorParameterMapping", this.<Map<JvmTypeParameter, LightweightMergedBoundTypeArgument>>invokeAndCast(left, "getDeclaratorParameterMapping"), this.<Map<JvmTypeParameter, LightweightMergedBoundTypeArgument>>invokeAndCast(right, "getDeclaratorParameterMapping"));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
项目:xtext-extras    文件:OverrideTester.java   
protected void addReturnTypeDetails(AbstractResolvedOperation overriding, AbstractResolvedOperation overridden,
        EnumSet<OverrideCheckDetails> result) {
    LightweightTypeReference overridingReturnType = overriding.getResolvedReturnType();
    LightweightTypeReference overriddenReturnType = overridden.getResolvedReturnType();
    TypeConformanceComputationArgument conformanceArgument = new TypeConformanceComputationArgument(false, false, false, false, false, false);
    if (!overriddenReturnType.isAssignableFrom(overridingReturnType, conformanceArgument)) {
        if (overriding.getTypeParameters().isEmpty() && !overridden.getTypeParameters().isEmpty()) {
            TypeConformanceComputationArgument rawConformanceArgument = new TypeConformanceComputationArgument(true, false, false, false, false, false);
            if (!overriddenReturnType.isAssignableFrom(overridingReturnType, rawConformanceArgument)) {
                result.add(OverrideCheckDetails.RETURN_MISMATCH);       
            } else {
                result.add(OverrideCheckDetails.UNCHECKED_CONVERSION_REQUIRED);
                if (overridingReturnType.getRawTypeReference().getType() != overriddenReturnType.getRawTypeReference().getType()) {
                    result.add(OverrideCheckDetails.COVARIANT_RETURN);
                }
            }
        } else {
            result.add(OverrideCheckDetails.RETURN_MISMATCH);
        }
    } else if (!overriddenReturnType.getJavaIdentifier().equals(overridingReturnType.getJavaIdentifier())) {
        if (!overridden.isRawTypeInheritance() && overriding.getTypeParameters().isEmpty() && !overridden.getTypeParameters().isEmpty()) {
            if (overridden.getTypeParameters().contains(overridden.getDeclaration().getReturnType().getType())) {
                result.add(OverrideCheckDetails.UNCHECKED_CONVERSION_REQUIRED);
            }
        }
        result.add(OverrideCheckDetails.COVARIANT_RETURN);
    }
}
项目:xtext-extras    文件:XbaseValidator.java   
@Check
public void checkVariableIsNotInferredAsVoid(XVariableDeclaration declaration) {
    if (declaration.getType() != null)
        return;
    LightweightTypeReference variableType = typeResolver.resolveTypes(declaration).getActualType((JvmIdentifiableElement) declaration);
    // TODO move to type resolver
    if (variableType != null && variableType.isPrimitiveVoid()) {
        error("void is an invalid type for the variable " + declaration.getName(), declaration,
                XbasePackage.Literals.XVARIABLE_DECLARATION__NAME, INVALID_USE_OF_TYPE);
    }
}
项目:xtext-extras    文件:ResolvedTypes.java   
protected List<LightweightTypeReference> doGetActualTypeArguments(XExpression expression) {
    if (expression == null || expression.eClass() == XbasePackage.Literals.XCLOSURE) {
        return Collections.emptyList();
    }
    ILinkingCandidate result = (ILinkingCandidate) basicGetLinkingMap().get(expression);
    if (result != null) {
        return result.getTypeArguments();
    }
    return Collections.emptyList();
}
项目:xtext-extras    文件:XbaseValidator.java   
@Check
public void checkTypes(XCatchClause catchClause) {
    LightweightTypeReference parameterType = getActualType(catchClause, catchClause.getDeclaredParam());
    if (parameterType != null && !parameterType.isSubtypeOf(Throwable.class)) {
        error("No exception of type " + parameterType.getHumanReadableName()
                + " can be thrown; an exception type must be a subclass of Throwable",
                catchClause.getDeclaredParam(), TypesPackage.Literals.JVM_FORMAL_PARAMETER__PARAMETER_TYPE,
                ValidationMessageAcceptor.INSIGNIFICANT_INDEX, INCOMPATIBLE_TYPES);
    }
}
项目:xtext-extras    文件:UnresolvableConstructorCall.java   
@Override
public List<LightweightTypeReference> getTypeArguments() {
    XConstructorCall constructorCall = getConstructorCall();
    List<JvmTypeReference> typeArguments = constructorCall.getTypeArguments();
    if (typeArguments.isEmpty())
        return Collections.emptyList();
    List<LightweightTypeReference> result = Lists.newArrayList();
    for(JvmTypeReference typeArgument: typeArguments) {
        result.add(getState().getReferenceOwner().toLightweightTypeReference(typeArgument));
    }
    return result;
}
项目:xtext-extras    文件:AbstractTypeExpectation.java   
@Override
public String toString() {
    LightweightTypeReference expectedType = getExpectedType();
    String expectedTypeString = "";
    if (expectedType != null) {
        expectedTypeString = expectedType.toString();
    } else if (isNoTypeExpectation()) {
        expectedTypeString = "<no expectation>";
    } else if (isVoidTypeAllowed()) {
        expectedTypeString = "<void allowed>";
    } else {
        expectedTypeString = "<void not allowed>";
    }
    return getClass().getSimpleName() + " [expectation=" + expectedTypeString + "]";
}
项目:xtext-extras    文件:ValidatingStackedResolvedTypes.java   
@Override
public void setType(final JvmIdentifiableElement identifiable, final LightweightTypeReference reference) {
  boolean _isOwnedBy = reference.isOwnedBy(this.getReferenceOwner());
  boolean _not = (!_isOwnedBy);
  if (_not) {
    throw new IllegalArgumentException("reference is not owned by this resolved types");
  }
  super.setType(identifiable, reference);
}
项目:xtext-extras    文件:DynamicExtensionsScope.java   
protected BucketedEObjectDescription createReceiverDescription(QualifiedName name, JvmFeature feature, XExpression receiver,
        LightweightTypeReference receiverType, Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> receiverTypeParameterMapping, ExpressionBucket bucket, boolean validStaticState) {
    return new InstanceFeatureDescriptionWithImplicitReceiver(
            name,
            feature,
            receiver,
            receiverType, 
            receiverTypeParameterMapping,
            ConformanceFlags.CHECKED_SUCCESS,
            bucket.getId(),
            getSession().isVisible(feature),
            validStaticState);
}
项目:xtext-extras    文件:TypeConformanceComputer.java   
protected void addComponentType(LightweightTypeReference reference, List<LightweightTypeReference> result) {
    if (reference.isArray()) {
        result.add(((ArrayTypeReference) reference).getComponentType());
    } else {
        result.add(reference);
    }
}
项目:xtext-extras    文件:AbstractXbaseCompiler.java   
protected String getDefaultValueLiteral(XExpression expr) {
    LightweightTypeReference type = getTypeForVariableDeclaration(expr);
    if (type.isPrimitive()) {
        if (type.getPrimitiveKind() == Primitives.Primitive.Boolean) {
            return "false";
        } else {
            return "(" + type.getSimpleName() + ") 0";
        }
    }
    return "null";
}
项目:xtext-extras    文件:ReferencedInvalidTypeFinder.java   
protected LightweightTypeReference _internalFindReferencedInvalidType(final JvmField field) {
  final LightweightTypeReference type = this.toLightweightTypeReference(field.getType());
  boolean _isPrimitiveVoid = type.isPrimitiveVoid();
  if (_isPrimitiveVoid) {
    return type;
  }
  return this.findUnknownType(type);
}
项目:xtext-extras    文件:UIStrings.java   
protected String referenceToString(LightweightTypeReference reference) {
    if (reference == null) {
        return "[null]";
    }
    if (reference.isAny()) {
        return "Object";
    }
    return reference.getHumanReadableName();
}
项目:xtext-extras    文件:XbaseTypeComputer.java   
protected void _computeTypes(XReturnExpression object, ITypeComputationState state) {
    XExpression returnValue = object.getExpression();
    ITypeComputationState expressionState = state.withReturnExpectation();

    checkValidReturn(object, state);

    LightweightTypeReference primitiveVoid = getPrimitiveVoid(state);
    if (returnValue != null) {
        checkValidReturnExpression(returnValue, expressionState);
        state.acceptActualType(primitiveVoid, ConformanceFlags.NO_IMPLICIT_RETURN);
    } else {
        state.acceptActualType(primitiveVoid, ConformanceFlags.EXPLICIT_VOID_RETURN);
        state.acceptActualType(primitiveVoid, ConformanceFlags.NO_IMPLICIT_RETURN);
    }
}
项目:xtext-extras    文件:AbstractTypeExpectation.java   
@Override
public boolean isVoidTypeAllowed() {
    LightweightTypeReference expectedType = getExpectedType();
    if (expectedType != null && expectedType.isType(Void.TYPE)) {
        return true;
    }
    return false;
}
项目:xtext-extras    文件:ValidatingReassigningResolvedTypes.java   
@Override
public LightweightTypeReference getActualType(final JvmIdentifiableElement identifiable) {
  final LightweightTypeReference result = super.getActualType(identifiable);
  boolean _isOwnedBy = result.isOwnedBy(this.getReferenceOwner());
  boolean _not = (!_isOwnedBy);
  if (_not) {
    throw new IllegalArgumentException("result is not owned by this resolved types");
  }
  return result;
}
项目:xtext-extras    文件:ConstructorLinkingCandidate.java   
@Override
protected LightweightTypeReference deferredBindTypeArgument(ITypeExpectation expectation, LightweightTypeReference type) {
    LightweightTypeReference result = super.deferredBindTypeArgument(expectation, type);
    LightweightTypeReference expectedType = expectation.getExpectedType();
    if (expectedType != null && getConstructorCall().getTypeArguments().isEmpty() && !result.isRawType() && !getDeclaredTypeParameters().isEmpty()) {
        if (!expectedType.isAssignableFrom(result, new TypeConformanceComputationArgument())) {
            LightweightTypeReference rawFeatureType = result.getRawTypeReference();
            if (expectedType.isAssignableFrom(rawFeatureType)) {
                result = rawFeatureType;
                getTypeParameterMapping().clear();
            }
        }
    }
    return result;
}
项目:xtext-extras    文件:CollectionLiteralsTypeComputer.java   
/**
 * Specializes the super implementation such that is allows an empty list of types.
 * Returns {@code null} for those.
 * 
 * {@inheritDoc}
 */
@Override
protected LightweightTypeReference getCommonSuperType(List<LightweightTypeReference> types, ITypeComputationState state) {
    if (types.isEmpty()) {
        return null;
    }
    LightweightTypeReference result = super.getCommonSuperType(types, state);
    return result;
}
项目:xtext-extras    文件:TypeConvertingCompiler.java   
private void doCastConversion(final LightweightTypeReference castTo, final ITreeAppendable b, final Later expression) {
    b.append("((");
    b.append(castTo);
    b.append(")");
    expression.exec(b);
    b.append(")");
}
项目:xtext-extras    文件:AbstractBatchReturnTypeTest.java   
public void doResolvesTo(final String expression, final String type) {
  try {
    final XExpression parsedExpression = this.expression(expression, false);
    final IResolvedTypes resolvedTypes = this.getTypeResolver().resolveTypes(parsedExpression);
    final LightweightTypeReference resolvedType = resolvedTypes.getReturnType(parsedExpression);
    Assert.assertEquals(expression, type, resolvedType.getSimpleName());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
项目:xtext-extras    文件:AnnotationValueTypeComputationState.java   
@Override
/* @Nullable */
protected LightweightTypeReference getExpectedType() {
    JvmOperation operation = annotationValue.getOperation();
    LightweightTypeReference result = getResolvedTypes().getActualType(operation);
    if (result != null && result.isArray()) {
        return result.getComponentType();
    }
    return result;
}
项目:xtext-extras    文件:AbstractResolvedExecutable.java   
@Override
public List<LightweightTypeReference> getResolvedExceptions() {
    JvmExecutable declaration = getDeclaration();
    if (declaration.getExceptions().isEmpty())
        return Collections.emptyList();
    if (declaredExceptions != null)
        return declaredExceptions;
    return declaredExceptions = getResolvedReferences(declaration.getExceptions());
}
项目:xtext-extras    文件:OperationBodyComputationState.java   
@Override
/* @Nullable */
protected LightweightTypeReference getExpectedType() {
    JvmOperation operation = (JvmOperation) getMember();
    LightweightTypeReference expectedType = ((LogicalContainerAwareReentrantTypeResolver)getResolver()).getReturnTypeOfOverriddenOperation(operation, resolvedTypes, getFeatureScopeSession());
    if (expectedType != null) {
        InferredTypeIndicator.resolveTo(operation.getReturnType(), expectedType.toJavaCompliantTypeReference());
        return expectedType;
    }
    return getResolvedTypes().getExpectedTypeForAssociatedExpression(getMember(), getNonNullRootExpression());
}
项目:xtext-extras    文件:CollectionLiteralsTypeComputer.java   
/**
 * The expected collection type may drive the type of the elements in the collection if the type is used as an
 * invariant type. In other word, an expectation of the form
 * {@code Collection<CharSequence>} may yield a type {@code List<CharSequence>} for the literal
 * {@code ['a']} even though it would be {@code List<? extends String>} if no expectation was given.
 */
protected LightweightTypeReference normalizeElementType(LightweightTypeReference collectionElementType, LightweightTypeReference expectedCollectionType, ITypeReferenceOwner owner) {
    if (isIterableExpectation(expectedCollectionType)) {
        LightweightTypeReference expectedElementType = getElementOrComponentType(expectedCollectionType, owner);
        return doNormalizeElementType(collectionElementType, expectedElementType);
    }
    return normalizeFunctionTypeReference(collectionElementType);
}
项目:xtext-extras    文件:AbstractExpectationTest.java   
public void recordExpectation(final XExpression expression, final ITypeComputationState state) {
  List<? extends ITypeExpectation> _expectations = state.getExpectations();
  Iterables.<ITypeExpectation>addAll(this.finalExpectations, _expectations);
  final Function1<ITypeExpectation, String> _function = (ITypeExpectation it) -> {
    LightweightTypeReference _expectedType = it.getExpectedType();
    String _simpleName = null;
    if (_expectedType!=null) {
      _simpleName=_expectedType.getSimpleName();
    }
    return _simpleName;
  };
  List<String> _map = ListExtensions.map(state.getExpectations(), _function);
  Iterables.<String>addAll(this.expectations, _map);
  this.expressions.add(expression);
}
项目:xtext-extras    文件:TypeParameterSubstitutor.java   
/**
 * @param type the type of the reference. May be used by subtypes. 
 */
protected LightweightTypeReference enhanceParameterizedTypeReference(ParameterizedTypeReference origin, JvmType type, ParameterizedTypeReference result, Visiting visiting) {
    for(LightweightTypeReference argument: origin.getTypeArguments()) {
        result.addTypeArgument(visitTypeArgument(argument, visiting));
    }
    return result;
}
项目:xtext-extras    文件:CompoundTypeComputationState.java   
@Override
public ITypeComputationState withExpectation(LightweightTypeReference expectation) {
    AbstractTypeComputationState[] result = new AbstractTypeComputationState[components.length];
    for (int i = 0; i < components.length; i++) {
        result[i] = components[i].withExpectation(expectation);
    }
    return new CompoundTypeComputationState(owner, result);
}
项目:xtext-extras    文件:FeatureCallCompiler.java   
protected void appendArgument(XExpression argument, ITreeAppendable b, boolean doLineWrappingIfSourceWasWrapped) {
    final String referenceName = getReferenceName(argument, b);
    /*
     * This is done to support better debugging experience.
     * Consider the following xbase expression:
     * 
     * foo(
     *   new String())
     *   
     *  The compiler could translate that to a single line, but then the two lines in the source would map
     *  to the same line in the Java code, so it's not possible to have two steps. 
     *  Therefore we add a newline in the Java if the user had one the expression defined in a new line.
     */
    final boolean needsNewLine = doLineWrappingIfSourceWasWrapped && referenceName == null && isDeclaredInNewLine(argument);
    if (needsNewLine) {
        b.increaseIndentation();
        b.newLine();
    }
    if (referenceName == null && isVariableDeclarationRequired(argument, b, true)) {
        if (canCompileToJavaExpression(argument, b)) {
            internalToJavaExpression(argument, b);
        } else {
            LightweightTypeReference type = getLightweightExpectedType(argument);
            if (type == null)
                type = getLightweightType(argument);
            compileAsJavaExpression(argument, b, type);
        }
    } else {
        internalToJavaExpression(argument, b);
    }
    if (needsNewLine) {
        b.decreaseIndentation();
    }
}
项目:xtext-extras    文件:ClosureTypeComputerUnitTest.java   
@Test
public void testPrepareComputation_09() throws Exception {
    JvmType runnableType = getTypeForName(Runnable.class, state);
    ParameterizedTypeReference runnableTypeReference = state.getReferenceOwner().newParameterizedTypeReference(runnableType);
    assertTrue(runnableTypeReference.isResolved());

    TypeExpectation expectation = new TypeExpectation(runnableTypeReference, state, false);
    ClosureTypeComputer computer = new ClosureTypeComputer(closure("[|]", getContextResourceSet()), expectation, state);
    computer.selectStrategy();
    LightweightTypeReference closureType = computer.getExpectedClosureType();
    assertEquals("java.lang.Runnable.run()", computer.getOperation().getIdentifier());
    assertEquals("Runnable", getEquivalentSimpleName(closureType));
    assertEquals("()=>void", closureType.getSimpleName());
}