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

The following examples show how to use org.eclipse.xtext.xbase.XAbstractFeatureCall#isPackageFragment() . 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: SerializerScopeProvider.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected IScope doGetTypeScope(XMemberFeatureCall call, JvmType type) {
	if (call.isPackageFragment()) {
		if (type instanceof JvmDeclaredType) {
			int segmentIndex = countSegments(call);
			String packageName = ((JvmDeclaredType) type).getPackageName();
			List<String> splitted = Strings.split(packageName, '.');
			String segment = splitted.get(segmentIndex);
			return new SingletonScope(EObjectDescription.create(segment, type), IScope.NULLSCOPE);
		}
		return IScope.NULLSCOPE;
	} else {
		if (type instanceof JvmDeclaredType && ((JvmDeclaredType) type).getDeclaringType() == null) {
			return new SingletonScope(EObjectDescription.create(type.getSimpleName(), type), IScope.NULLSCOPE);
		} else {
			XAbstractFeatureCall target = (XAbstractFeatureCall) call.getMemberCallTarget();
			if (target.isPackageFragment()) {
				String qualifiedName = type.getQualifiedName();
				int dot = qualifiedName.lastIndexOf('.');
				String simpleName = qualifiedName.substring(dot + 1);
				return new SingletonScope(EObjectDescription.create(simpleName, type), IScope.NULLSCOPE);
			} else {
				return new SingletonScope(EObjectDescription.create(type.getSimpleName(), type), IScope.NULLSCOPE);	
			}
		}
	}
}
 
Example 2
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 3
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 4
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 5
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);
}