Java Code Examples for org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference#isPrimitiveVoid()
The following examples show how to use
org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference#isPrimitiveVoid() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SARLCodeMiningProvider.java From sarl with Apache License 2.0 | 6 votes |
/** Replies the type for a variable declaration that is initialized with the given expression. * * @param expr the expression. * @return the variable type. */ protected LightweightTypeReference getTypeForVariableDeclaration(XExpression expr) { final IResolvedTypes resolvedTypes = getResolvedTypes(expr); LightweightTypeReference actualType = resolvedTypes.getActualType(expr); if (actualType.isPrimitiveVoid()) { LightweightTypeReference expectedType = resolvedTypes.getExpectedType(expr); if (expectedType == null) { expectedType = resolvedTypes.getExpectedReturnType(expr); if (expectedType == null) { expectedType = resolvedTypes.getReturnType(expr); } } if (expectedType != null && !expectedType.isPrimitiveVoid()) { actualType = expectedType; } } return actualType; }
Example 2
Source File: XbaseProposalProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
protected void createReceiverProposals(XExpression receiver, CrossReference crossReference, ContentAssistContext contentAssistContext, ICompletionProposalAcceptor acceptor) { // long time = System.currentTimeMillis(); String ruleName = getConcreteSyntaxRuleName(crossReference); Function<IEObjectDescription, ICompletionProposal> proposalFactory = getProposalFactory(ruleName, contentAssistContext); IResolvedTypes resolvedTypes = typeResolver.resolveTypes(receiver); LightweightTypeReference receiverType = resolvedTypes.getActualType(receiver); if (receiverType == null || receiverType.isPrimitiveVoid()) { return; } IExpressionScope expressionScope = resolvedTypes.getExpressionScope(receiver, IExpressionScope.Anchor.RECEIVER); // TODO exploit the type name information IScope scope; if (contentAssistContext.getCurrentModel() != receiver) { EObject currentModel = contentAssistContext.getCurrentModel(); if (currentModel instanceof XMemberFeatureCall && ((XMemberFeatureCall) currentModel).getMemberCallTarget() == receiver) { scope = filterByConcreteSyntax(expressionScope.getFeatureScope((XAbstractFeatureCall) currentModel), crossReference); } else { scope = filterByConcreteSyntax(expressionScope.getFeatureScope(), crossReference); } } else { scope = filterByConcreteSyntax(expressionScope.getFeatureScope(), crossReference); } getCrossReferenceProposalCreator().lookupCrossReference(scope, receiver, XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, acceptor, getFeatureDescriptionPredicate(contentAssistContext), proposalFactory); // System.out.printf("XbaseProposalProvider.createReceiverProposals = %d\n", System.currentTimeMillis() - time); }
Example 3
Source File: XbaseTypeComputer.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
public void process(ITypeComputationResult result) { resultProcessed = true; if (result.getConformanceFlags() != 0 /* equivalent to getActualExpressionType != null */) { nonNullResultProcessed = true; } LightweightTypeReference expressionReturnType = result.getReturnType(); if (expressionReturnType != null) { boolean isExit = (result.getCheckedConformanceFlags() & ConformanceFlags.NO_IMPLICIT_RETURN) != 0; if (earlyExit && isExit && !expressionReturnType.isPrimitiveVoid()) { earlyExit = false; } if (allPrimitive && isExit && !expressionReturnType.isPrimitive()) { allPrimitive = false; } if (allVoid || allPrimitive) { LightweightTypeReference expressionType = result.getActualExpressionType(); if (allVoid && !(expressionType != null && expressionType.isPrimitiveVoid())) { allVoid = false; } if (allPrimitive && !(expressionType != null && expressionType.isPrimitive() || expressionReturnType.isPrimitive())) { allPrimitive = false; } } } }
Example 4
Source File: XtendValidator.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@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); } } }
Example 5
Source File: XbaseTypeComputer.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected void checkValidReturnExpression(XExpression returnValue, ITypeComputationState expressionState) { ITypeComputationResult result = expressionState.computeTypes(returnValue); LightweightTypeReference actualType = result.getActualExpressionType(); int conformanceFlags = result.getConformanceFlags(); if (actualType.isPrimitiveVoid() && (conformanceFlags & ConformanceFlags.NO_IMPLICIT_RETURN) != 0) { String message = "Invalid return's expression."; if (returnValue instanceof XReturnExpression) { // when the return's expression is directory a return // we provide a more detailed error message = "Return cannot be nested."; } expressionState.addDiagnostic(new EObjectDiagnosticImpl( Severity.ERROR, IssueCodes.INVALID_RETURN, message, returnValue, null, -1, new String[] { })); } }
Example 6
Source File: RawTypeConformanceComputer.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected int doIsConformant(FunctionTypeReference left, FunctionTypeReference right, int flags) { if (left.getType() == right.getType()) { return flags | SUCCESS; } if ((flags & ALLOW_FUNCTION_CONVERSION) == 0) return flags; // function types can be converted to native function types which will be raw assignable if their // number of parameters matches and the function type kind if (left.getParameterTypes().size() == right.getParameterTypes().size()) { LightweightTypeReference leftReturnType = left.getReturnType(); LightweightTypeReference rightReturnType = right.getReturnType(); if (leftReturnType == rightReturnType) { return flags | SUCCESS; } if (leftReturnType != null && rightReturnType != null && leftReturnType.isPrimitiveVoid() == rightReturnType.isPrimitiveVoid()) { return flags | SUCCESS; } } return flags; }
Example 7
Source File: AbstractXbaseCompiler.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected LightweightTypeReference getTypeForVariableDeclaration(XExpression expr) { IResolvedTypes resolvedTypes = getResolvedTypes(expr); LightweightTypeReference actualType = resolvedTypes.getActualType(expr); if (actualType.isPrimitiveVoid()) { LightweightTypeReference expectedType = resolvedTypes.getExpectedType(expr); if (expectedType == null) { expectedType = resolvedTypes.getExpectedReturnType(expr); if (expectedType == null) { expectedType = resolvedTypes.getReturnType(expr); } } if (expectedType != null && !expectedType.isPrimitiveVoid()) { actualType = expectedType; } } return actualType; }
Example 8
Source File: ReferencedInvalidTypeFinder.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
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); }
Example 9
Source File: CommonSuperTypeTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
private boolean isPrimitiveOrVoid(final LightweightTypeReference computedSuperType) { boolean _xblockexpression = false; { if ((computedSuperType == null)) { return false; } _xblockexpression = (computedSuperType.isPrimitiveVoid() || computedSuperType.isPrimitive()); } return _xblockexpression; }
Example 10
Source File: AbstractResolvedFeature.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected LightweightTypeReference getResolvedReference(/* @Nullable */ JvmTypeReference unresolved) { ITypeReferenceOwner owner = getContextType().getOwner(); if (unresolved == null) { return owner.newReferenceToObject(); } LightweightTypeReference unresolvedLightweight = owner.toLightweightTypeReference(unresolved); if (unresolvedLightweight.isPrimitive() || unresolvedLightweight.isPrimitiveVoid()) return unresolvedLightweight; TypeParameterSubstitutor<?> substitutor = getSubstitutor(); LightweightTypeReference result = substitutor.substitute(unresolvedLightweight); return result; }
Example 11
Source File: AbstractLinkingCandidate.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void accept(ObservableTypeExpectation expectation, LightweightTypeReference actual) { LightweightTypeReference expectedType = expectation.getExpectedType(); if (expectedType == null || actual instanceof AnyTypeReference || actual.isPrimitiveVoid()) { return; } resolveAgainstActualType(expectedType, actual, expectation.getState()); }
Example 12
Source File: TypeConformanceComputer.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected LightweightTypeReference findConformsToAllOrVoid(final List<LightweightTypeReference> types) { for(LightweightTypeReference type: types) { LightweightTypeReference conformantType = conformsToAll(type, types); if (conformantType != null) return conformantType; if (type.isPrimitiveVoid()) { // we saw void but was not all were void return type; } } return null; }
Example 13
Source File: CastedExpressionTypeComputationState.java From sarl with Apache License 2.0 | 5 votes |
/** Replies if the linking to the cast operator functions is enabled. * * @param cast the cast operator. * @return {@code true} if the linking is enabled. */ public boolean isCastOperatorLinkingEnabled(SarlCastedExpression cast) { final LightweightTypeReference sourceType = getStackedResolvedTypes().getReturnType(cast.getTarget()); final LightweightTypeReference destinationType = getReferenceOwner().toLightweightTypeReference(cast.getType()); if (sourceType.isPrimitiveVoid() || destinationType.isPrimitiveVoid()) { return false; } if (sourceType.isPrimitive() && destinationType.isPrimitive()) { return false; } return !sourceType.isSubtypeOf(destinationType.getType()); }
Example 14
Source File: ClosureWithoutExpectationHelper.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected FunctionTypeReference processExpressionType(FunctionTypeReference incompleteClosureType, ITypeComputationResult expressionResult) { LightweightTypeReference expressionResultType = expressionResult.getReturnType(); if (expressionResultType == null || !expressionResultType.isPrimitiveVoid()) { FunctionTypeReference result = getFunctionTypeReference(false); LightweightTypeReference expectedReturnType = result.getTypeArguments().get(result.getTypeArguments().size() - 1); if (expressionResultType != null && !expressionResultType.isAny()) { result.setReturnType(expressionResultType); deferredBindTypeArgument(expectedReturnType, expressionResultType, BoundTypeArgumentSource.INFERRED); } else { LightweightTypeReference objectTypeReference = incompleteClosureType.getOwner().newReferenceToObject(); result.setReturnType(objectTypeReference); deferredBindTypeArgument(expectedReturnType, objectTypeReference, BoundTypeArgumentSource.INFERRED); } List<LightweightTypeReference> incompleteParameterTypes = incompleteClosureType.getParameterTypes(); for(int i = 0; i < incompleteParameterTypes.size(); i++) { result.addParameterType(incompleteParameterTypes.get(i)); } List<LightweightTypeReference> incompleteTypeArguments = incompleteClosureType.getTypeArguments(); List<LightweightTypeReference> resultTypeArguments = result.getTypeArguments(); for(int i = 0; i < incompleteTypeArguments.size(); i++) { deferredBindTypeArgument(resultTypeArguments.get(i), incompleteTypeArguments.get(i), BoundTypeArgumentSource.INFERRED); } return result; } else { incompleteClosureType.setReturnType(expressionResultType); return incompleteClosureType; } }
Example 15
Source File: XbaseValidator.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@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); } }
Example 16
Source File: XbaseValidator.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
protected void checkCast(JvmTypeReference concreteSyntax, LightweightTypeReference toType, LightweightTypeReference fromType) { if (toType == null || fromType == null) return; if (fromType.getType() instanceof JvmDeclaredType || fromType.isPrimitive()) { // if one of the types is an interface and the other is a non final class (or interface) there always can be a subtype if ((!isInterface(fromType) || isFinal(toType)) && (!isInterface(toType) || isFinal(fromType))) { if (!toType.isAssignableFrom(fromType)) { if ( isFinal(fromType) || isFinal(toType) || isClass(fromType) && isClass(toType)) { if (!fromType.isAssignableFrom(toType)) { // no upcast error("Cannot cast from " + getNameOfTypes(fromType) + " to " + canonicalName(toType), concreteSyntax, null, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, INVALID_CAST); } } } } } else if (fromType.isPrimitiveVoid()) { error("Cannot cast from void to " + canonicalName(toType), concreteSyntax, null, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, INVALID_CAST); } if(toType.isPrimitive() && !(fromType.isPrimitive() || fromType.isWrapper())) { error("Cannot cast from " + getNameOfTypes(fromType) + " to " + canonicalName(toType), concreteSyntax, null, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, INVALID_CAST); } /* * TODO: JDT reports no unnecessary cast of List<?> but for List<String> ... why is there an exception? * * */ // List<? extends String> list = Collections.emptyList(); // if (((List<? extends String>)list).isEmpty()) {} // List<String> list = Collections.emptyList(); // if (((List<String>)list).isEmpty()) {} // List list = Collections.emptyList(); // if (((List)list).isEmpty()) {} if (toType.getIdentifier().equals(fromType.getIdentifier())) { addIssue("Unnecessary cast from " + fromType.getHumanReadableName() + " to " + toType.getHumanReadableName(), concreteSyntax, IssueCodes.OBSOLETE_CAST); } }
Example 17
Source File: ClosureWithExpectationHelper.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
/** * Returns an indicator how compatible the expression type result is to the expected type. * Either * <ul> * <li>{@link ConformanceFlags#NONE},</li> * <li>{@link ConformanceFlags#INCOMPATIBLE}, or</li> * <li>{@link ConformanceFlags#LAMBDA_RAW_COMPATIBLE}</li> * <li>{@link ConformanceFlags#LAMBDA_VOID_COMPATIBLE}</li> * </ul> */ protected int processExpressionType(ITypeComputationResult expressionResult) { LightweightTypeReference expressionResultType = expressionResult.getReturnType(); if (expressionResultType == null || expressionResultType instanceof AnyTypeReference) { LightweightTypeReference returnType = expectedClosureType.getReturnType(); if (returnType == null) throw new IllegalStateException("return type shall not be null"); resultClosureType.setReturnType(returnType); if (validParameterTypes && returnType.isPrimitiveVoid()) { return ConformanceFlags.INCOMPATIBLE; } } else { LightweightTypeReference expectedReturnType = expectedClosureType.getReturnType(); if (expectedReturnType == null) throw new IllegalStateException("expected return type may not be null"); if (!expressionResultType.isPrimitiveVoid()) { if (expectedReturnType.isPrimitiveVoid()) { resultClosureType.setReturnType(expectedReturnType); if (isImplicitReturn(expressionResult)) { return ConformanceFlags.NONE; } else { return ConformanceFlags.INCOMPATIBLE; } } else { deferredBindTypeArgument(expectedReturnType, expressionResultType, BoundTypeArgumentSource.INFERRED); } } else if (expectedReturnType.isPrimitiveVoid()) { resultClosureType.setReturnType(expressionResultType); if (validParameterTypes && isImplicitReturn(expressionResult)) { return ConformanceFlags.LAMBDA_VOID_COMPATIBLE; } return ConformanceFlags.NONE; } if (expectedReturnType.isAssignableFrom(expressionResultType)) { resultClosureType.setReturnType(expressionResultType); } else if (expectedReturnType.isPrimitiveVoid()) { resultClosureType.setReturnType(expectedReturnType); return ConformanceFlags.INCOMPATIBLE; } else { resultClosureType.setReturnType(expectedReturnType); return ConformanceFlags.LAMBDA_RAW_COMPATIBLE; } } return ConformanceFlags.NONE; }
Example 18
Source File: AbstractXbaseCompiler.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
protected boolean isPrimitiveVoid(XExpression xExpression) { LightweightTypeReference type = getLightweightType(xExpression); return type != null && type.isPrimitiveVoid(); }
Example 19
Source File: ResolvedTypes.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
private void enhanceMergeData(List<TypeData> values, MergeData mergeData) { for (int i = 0, size = values.size(); i < size; i++) { TypeData value = values.get(i); LightweightTypeReference reference = value.getActualType().getUpperBoundSubstitute(); int flags = value.getConformanceFlags(); if (reference.isPrimitiveVoid()) { if ((flags & ConformanceFlags.EXPLICIT_VOID_RETURN) != 0) { mergeData.references.clear(); mergeData.references.add(reference); mergeData.mergedFlags = flags; mergeData.expectation = value.getExpectation(); mergeData.voidSeen = false; return; } mergeData.voidSeen = true; } else { mergeData.references.add(reference); } mergeData.allNoImplicitReturn = mergeData.allNoImplicitReturn && (flags & ConformanceFlags.NO_IMPLICIT_RETURN) != 0; mergeData.allThrownException = mergeData.allThrownException && (flags & ConformanceFlags.THROWN_EXCEPTION) != 0; if (!reference.isUnknown()) { mergeData.mergedFlags |= flags; } if (mergeData.expectation == null) { mergeData.expectation = value.getExpectation(); } else if (mergeData.expectation.getExpectedType() == null) { ITypeExpectation knownExpectation = value.getExpectation(); if (knownExpectation.getExpectedType() != null) { mergeData.expectation = knownExpectation; } } } if (mergeData.mergedFlags == ConformanceFlags.MERGED) { mergeData.mergedFlags |= ConformanceFlags.CHECKED_SUCCESS; } if (!mergeData.allNoImplicitReturn) { mergeData.mergedFlags &= ~ConformanceFlags.NO_IMPLICIT_RETURN; } if (!mergeData.allThrownException) { mergeData.mergedFlags &= ~ConformanceFlags.THROWN_EXCEPTION; } if ((mergeData.mergedFlags & (ConformanceFlags.CHECKED | ConformanceFlags.UNCHECKED)) == (ConformanceFlags.CHECKED | ConformanceFlags.UNCHECKED)) { mergeData.mergedFlags &= ~(ConformanceFlags.CHECKED | ConformanceFlags.CHECK_RESULTS); } if ((mergeData.mergedFlags & ConformanceFlags.UNCHECKED) != 0) { mergeData.mergedFlags &= ~ConformanceFlags.SEALED; } }
Example 20
Source File: XbaseValidator.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
protected boolean isValueExpectedRecursive(XExpression expr) { EStructuralFeature feature = expr.eContainingFeature(); EObject container = expr.eContainer(); // is part of block if (container instanceof XBlockExpression) { XBlockExpression blockExpression = (XBlockExpression) container; final List<XExpression> expressions = blockExpression.getExpressions(); if (expressions.get(expressions.size()-1) != expr) { return false; } } // no expectation cases if (feature == XbasePackage.Literals.XTRY_CATCH_FINALLY_EXPRESSION__FINALLY_EXPRESSION || feature == XbasePackage.Literals.XABSTRACT_WHILE_EXPRESSION__BODY || feature == XbasePackage.Literals.XFOR_LOOP_EXPRESSION__EACH_EXPRESSION) { return false; } // is value expected if (container instanceof XAbstractFeatureCall || container instanceof XConstructorCall || container instanceof XAssignment || container instanceof XVariableDeclaration || container instanceof XReturnExpression || container instanceof XThrowExpression || feature == XbasePackage.Literals.XFOR_LOOP_EXPRESSION__FOR_EXPRESSION || feature == XbasePackage.Literals.XSWITCH_EXPRESSION__SWITCH || feature == XbasePackage.Literals.XCASE_PART__CASE || feature == XbasePackage.Literals.XIF_EXPRESSION__IF || feature == XbasePackage.Literals.XABSTRACT_WHILE_EXPRESSION__PREDICATE || feature == XbasePackage.Literals.XBASIC_FOR_LOOP_EXPRESSION__EXPRESSION || feature == XbasePackage.Literals.XSYNCHRONIZED_EXPRESSION__PARAM) { return true; } if (isLocalClassSemantics(container) || logicalContainerProvider.getLogicalContainer(expr) != null) { LightweightTypeReference expectedReturnType = typeResolver.resolveTypes(expr).getExpectedReturnType(expr); return expectedReturnType == null || !expectedReturnType.isPrimitiveVoid(); } if (container instanceof XCasePart || container instanceof XCatchClause) { container = container.eContainer(); } if (container instanceof XExpression) { return isValueExpectedRecursive((XExpression) container); } return true; }