Java Code Examples for org.eclipse.xtext.xbase.XAbstractFeatureCall#isTypeLiteral()

The following examples show how to use org.eclipse.xtext.xbase.XAbstractFeatureCall#isTypeLiteral() . 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: XbaseValidator.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void checkNoJavaStyleTypeCasting(INode node) {
	BidiTreeIterator<INode> iterator = node.getAsTreeIterable().reverse().iterator();
	ILeafNode child = getFirstLeafNode(iterator);
	if (child != null && child.getGrammarElement() == grammarAccess.getXParenthesizedExpressionAccess().getRightParenthesisKeyword_2()) {
		INode expressionNode = getNode(iterator, grammarAccess.getXParenthesizedExpressionAccess().getXExpressionParserRuleCall_1());
		EObject semanticObject = NodeModelUtils.findActualSemanticObjectFor(expressionNode);
		if (semanticObject instanceof XFeatureCall || semanticObject instanceof XMemberFeatureCall) {
			XAbstractFeatureCall featureCall = (XAbstractFeatureCall) semanticObject;
			if (featureCall.isTypeLiteral()) {
				ICompositeNode parenthesizedNode = child.getParent();
				ITextRegion parenthesizedRegion = parenthesizedNode.getTextRegion();
				addIssue("Use 'as' keyword for type casting.", featureCall, parenthesizedRegion.getOffset(), parenthesizedRegion.getLength(), JAVA_STYLE_TYPE_CAST);
			}
		}
	}
}
 
Example 2
Source File: XbaseLocationInFileProvider.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public ITextRegion getSignificantTextRegion(EObject element) {
	if (element instanceof XAbstractFeatureCall) {
		XAbstractFeatureCall typeLiteral = typeLiteralHelper.getRootTypeLiteral((XAbstractFeatureCall) element);
		if (typeLiteral != null) {
			if (typeLiteral instanceof XMemberFeatureCall) {
				XAbstractFeatureCall target = (XAbstractFeatureCall) ((XMemberFeatureCall) typeLiteral).getMemberCallTarget();
				if (target.isTypeLiteral()) {
					return super.getSignificantTextRegion(typeLiteral);
				}
			}
			INode node = NodeModelUtils.findActualNodeFor(typeLiteral);
			if (node != null) {
				return toZeroBasedRegion(node.getTextRegionWithLineInformation());
			}
		}
	}
	return super.getSignificantTextRegion(element);
}
 
Example 3
Source File: FeatureCallAsTypeLiteralHelper.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
public XAbstractFeatureCall getRootTypeLiteral(XAbstractFeatureCall featureCall) {
	if (featureCall.isTypeLiteral()) {
		return featureCall;
	}
	if (featureCall.isPackageFragment()) {
		return getRootTypeLiteral((XAbstractFeatureCall) featureCall.eContainer());
	}
	if (featureCall.getFeature() == null || featureCall.getFeature().eIsProxy()) {
		// syntactic check
		if (featureCall instanceof XFeatureCall || featureCall instanceof XMemberFeatureCall) {
			if (!isPotentialTypeLiteral(featureCall, null)) {
				return null;
			}
			if (featureCall instanceof XMemberFeatureCall) {
				return doGetRootTypeLiteral((XMemberFeatureCall) featureCall);
			}
			if (featureCall instanceof XFeatureCall) {
				if (featureCall.eContainingFeature() == XbasePackage.Literals.XMEMBER_FEATURE_CALL__MEMBER_CALL_TARGET) {
					return doGetRootTypeLiteral((XMemberFeatureCall) featureCall.eContainer());
				}
			}
		}
	}
	return null;
}
 
Example 4
Source File: FeatureCallCompiler.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void _toJavaExpression(XAbstractFeatureCall call, ITreeAppendable b) {
	if (call.isTypeLiteral()) {
		b.append((JvmType) call.getFeature()).append(".class");
	} else if (isPrimitiveVoid(call)) {
		throw new IllegalArgumentException("feature yields 'void'");
	} else {
		final String referenceName = getReferenceName(call, b);
		if (referenceName != null) {
			if (call instanceof XFeatureCall || call instanceof XMemberFeatureCall) {
				b.trace(call, XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, 0).append(referenceName);
			} else {
				b.trace(call, false).append(referenceName);
			}
		} else {
			featureCalltoJavaExpression(call, b, true);
		}
	}
}
 
Example 5
Source File: SARLOperationHelper.java    From sarl with Apache License 2.0 6 votes vote down vote up
private static boolean isLocalExpression(XAbstractFeatureCall expression, ISideEffectContext context, boolean dereference) {
	if (expression.isTypeLiteral() || expression.isPackageFragment()) {
		return false;
	}
	final JvmIdentifiableElement feature = expression.getFeature();
	if (feature != null && (feature.eIsProxy() || isExternalFeature(feature))) {
		return false;
	}
	if (feature instanceof XVariableDeclaration) {
		if (dereference) {
			final XVariableDeclaration variable = (XVariableDeclaration) feature;
			for (final XExpression value : context.getVariableValues(variable.getIdentifier())) {
				if (!isLocalExpression(value, context, dereference)) {
					return false;
				}
			}
		}
	}
	return true;
}
 
Example 6
Source File: XExpressionHelper.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public boolean hasSideEffects(XAbstractFeatureCall featureCall, boolean inspectContents) {
	if (featureCall instanceof XBinaryOperation) {
		XBinaryOperation binaryOperation = (XBinaryOperation) featureCall;
		if (binaryOperation.isReassignFirstArgument()) {
			return true;
		}
	}
	if (featureCall instanceof XAssignment) {
		return true;
	}
	if (featureCall.isPackageFragment() || featureCall.isTypeLiteral()) {
		return false;
	}
	final JvmIdentifiableElement feature = featureCall.getFeature();
	if (feature == null || feature.eIsProxy())
		return true; // linking problems ... could be anything
	if (feature instanceof JvmConstructor) { //super() and this()
		return true;
	}
	if (feature instanceof JvmOperation) {
		JvmOperation jvmOperation = (JvmOperation) feature;
		if (findPureAnnotation(jvmOperation) == null) {
			return true;
		} else {
			if(inspectContents) {
				for (XExpression param : featureCall.getActualArguments()) {
					if (hasSideEffects(param))
						return true;
				}
			}
		}
	}
	return false;
}
 
Example 7
Source File: XbaseHighlightingCalculator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void highlightFeatureCall(XAbstractFeatureCall featureCall, IHighlightedPositionAcceptor acceptor, String id) {
//		highlightDeprecation(acceptor, featureCall, null, featureCall.getFeature());
		if (featureCall.isTypeLiteral()) {
			ICompositeNode node = NodeModelUtils.findActualNodeFor(featureCall);
			highlightNode(acceptor, node, id);
		} else {
			highlightFeature(acceptor, featureCall, XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, id);
		}
	}
 
Example 8
Source File: CreateMemberQuickfixes.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected boolean isThis(XAssignment assigment) {
	XExpression assignable = assigment.getAssignable();
	if (!(assignable instanceof XAbstractFeatureCall)) {
		return false;
	}
	XAbstractFeatureCall featureCall = (XAbstractFeatureCall) assignable;
	return featureCall.getFeature() instanceof JvmDeclaredType
			&& !featureCall.isExplicitOperationCallOrBuilderSyntax() && !featureCall.isTypeLiteral();
}
 
Example 9
Source File: CreateMemberQuickfixes.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected boolean isStaticAccess(XAbstractFeatureCall call) {
	if (call instanceof XMemberFeatureCall) {
		XMemberFeatureCall featureCall = (XMemberFeatureCall) call;
		if (featureCall.isExplicitStatic()) {
			return true;
		}
		if (featureCall.getMemberCallTarget() instanceof XAbstractFeatureCall) {
			XAbstractFeatureCall targetCall = (XAbstractFeatureCall) featureCall.getMemberCallTarget();
			if ( targetCall.isTypeLiteral()) {
				return true;
			}
		}
	}
	return isStatic(logicalContainerProvider.getNearestLogicalContainer(call)); 
}
 
Example 10
Source File: AbstractExpressionGenerator.java    From sarl with Apache License 2.0 5 votes vote down vote up
/**  Generate a feature call.
 *
 * @param expr the call expression.
 */
public void generate(XAbstractFeatureCall expr) {
	if (expr.isTypeLiteral()) {
		final JvmType type = (JvmType) expr.getFeature();
		this.codeReceiver.append(type);
	//} else if (getExpressionHelper().isShortCircuitOperation(expr)) {
	//	generateShortCircuitInvocation(expr);
	} else {
		if (expr instanceof XMemberFeatureCall && ((XMemberFeatureCall) expr).isNullSafe()) {
			featureCalltoJavaExpression(expr, () -> expr);
		} else {
			featureCalltoJavaExpression(expr, null);
		}
	}
}
 
Example 11
Source File: ResolvedFeature.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public boolean isTypeLiteral() {
	XAbstractFeatureCall featureCall = getFeatureCall();
	return featureCall.isTypeLiteral();
}
 
Example 12
Source File: SerializerScopeProvider.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected IScope getTypeScope(XAbstractFeatureCall call, JvmType type) {
	if (call.isTypeLiteral() || call.isPackageFragment()) {
		return doGetTypeScope(call, type);
	}
	return getThisOrSuperScope(call, type);
}
 
Example 13
Source File: AnnotationValueValidator.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected boolean _isValidAnnotationValue(XAbstractFeatureCall expression) {
	if (expression.isTypeLiteral()) {
		return true;
	}
	return super.isConstant(expression);
}