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

The following examples show how to use org.eclipse.xtext.xbase.XAbstractFeatureCall#getFeature() . 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 checkIsValidConstructorArgument(XExpression argument, JvmType containerType) {
	TreeIterator<EObject> iterator = EcoreUtil2.eAll(argument);
	while(iterator.hasNext()) {
		EObject partOfArgumentExpression = iterator.next();
		if (partOfArgumentExpression instanceof XFeatureCall || partOfArgumentExpression instanceof XMemberFeatureCall) {				
			XAbstractFeatureCall featureCall = (XAbstractFeatureCall) partOfArgumentExpression;
			XExpression actualReceiver = featureCall.getActualReceiver();
			if(actualReceiver instanceof XFeatureCall && ((XFeatureCall)actualReceiver).getFeature() == containerType) {
				JvmIdentifiableElement feature = featureCall.getFeature();
				if (feature != null && !feature.eIsProxy()) {
					if (feature instanceof JvmField) {
						if (!((JvmField) feature).isStatic())
							error("Cannot refer to an instance field " + feature.getSimpleName() + " while explicitly invoking a constructor", 
									partOfArgumentExpression, null, INVALID_CONSTRUCTOR_ARGUMENT);
					} else if (feature instanceof JvmOperation) {
						if (!((JvmOperation) feature).isStatic())
							error("Cannot refer to an instance method while explicitly invoking a constructor", 
									partOfArgumentExpression, null, INVALID_CONSTRUCTOR_ARGUMENT);	
					}
				}
			}
		} else if(isLocalClassSemantics(partOfArgumentExpression)) {
			iterator.prune();
		}
	}
}
 
Example 2
Source File: AbstractExpressionGenerator.java    From sarl with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("checkstyle:npathcomplexity")
private void featureCalltoJavaExpression(XAbstractFeatureCall call, Function0<? extends XExpression> beginOfBlock) {
	final List<Object> leftOperand = new ArrayList<>();
	if (needMultiAssignment(call)) {
		buildLeftOperand(call, leftOperand);
	}
	final List<Object> receiver = new ArrayList<>();
	buildCallReceiver(call, getExtraLanguageKeywordProvider().getThisKeywordLambda(),
			this.referenceNameLambda, receiver);
	final JvmIdentifiableElement feature = call.getFeature();
	List<XExpression> args = null;
	if (feature instanceof JvmExecutable) {
		args = getActualArguments(call);
	}
	final String name = getCallSimpleName(
			call,
			getLogicalContainerProvider(),
			getFeatureNameProvider(),
			getExtraLanguageKeywordProvider().getNullKeywordLambda(),
			getExtraLanguageKeywordProvider().getThisKeywordLambda(),
			getExtraLanguageKeywordProvider().getSuperKeywordLambda(),
			this.referenceNameLambda2);
	internalAppendCall(feature, leftOperand, receiver, name, args, beginOfBlock);
}
 
Example 3
Source File: DefaultFeatureCallValidator.java    From sarl with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isDisallowedCall(XAbstractFeatureCall call) {
	if (call != null && call.getFeature() != null) {
		final JvmIdentifiableElement feature = call.getFeature();
		final String id = feature.getQualifiedName();
		// Exit is forbidden on a agent-based system
		if ("java.lang.System.exit".equals(id)) { //$NON-NLS-1$
			return !isInsideOOTypeDeclaration(call);
		}
		// Avoid any call to the hidden functions (function name contains "$" character).
		final String simpleName = feature.getSimpleName();
		if (Utils.isHiddenMember(simpleName)
			&& !Utils.isNameForHiddenCapacityImplementationCallingMethod(simpleName)
			&& (!Utils.isImplicitLambdaParameterName(simpleName) || !isInsideClosure(call))) {
			return true;
		}
		// Avoid any reference to private API.
		if (isPrivateAPI(feature) && !isPrivateAPI(call)) {
			return true;
		}
	}
	return false;
}
 
Example 4
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 5
Source File: XbaseValidator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected boolean isLocallyUsed(EObject target, EObject containerToFindUsage) {
	if (readAndWriteTracking.isRead(target)) {
		return true;
	}
	Collection<Setting> usages = XbaseUsageCrossReferencer.find(target, containerToFindUsage);
	// field and local variables are used when they are not used as the left operand of an assignment operator.
	if (target instanceof XVariableDeclaration || target instanceof JvmField) {
		for (final Setting usage : usages) {
			final EObject object = usage.getEObject();
			if (object instanceof XAssignment) {
				final XAssignment assignment = (XAssignment) object;
				if (assignment.getFeature() != target) {
					return true;
				}
			} else {
				return true;
			}
		}
		return false;
	}
	// for non-private members it is enough to check that there are usages
	if (!(target instanceof JvmOperation) || ((JvmOperation)target).getVisibility()!=JvmVisibility.PRIVATE) {
		return !usages.isEmpty();
	} else {
		// for private members it has to be checked if all usages are within the operation
		EObject targetSourceElem = associations.getPrimarySourceElement(target);
		for (Setting s : usages) {
			if (s.getEObject() instanceof XAbstractFeatureCall) {
				XAbstractFeatureCall fc = (XAbstractFeatureCall) s.getEObject();
				// when the feature call does not call itself or the call is
				// from another function, then it is locally used
				if (fc.getFeature() != target || !EcoreUtil.isAncestor(targetSourceElem, fc))
					return true;
			} else {
				return true;
			}
		}
		return false;
	}
}
 
Example 6
Source File: SARLHoverSignatureProvider.java    From sarl with Apache License 2.0 5 votes vote down vote up
@Override
protected String _signature(XAbstractFeatureCall featureCall, boolean typeAtEnd) {
	final JvmIdentifiableElement feature = featureCall.getFeature();
	if (feature != null) {
		return internalGetSignature(feature, typeAtEnd);
	}
	return ""; //$NON-NLS-1$
}
 
Example 7
Source File: FeatureCallCompiler.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected ITreeAppendable appendLeftOperand(final XAbstractFeatureCall expr, ITreeAppendable appendable, boolean isExpressionContext) {
	XBinaryOperation binaryOperation = (XBinaryOperation) expr;
	XAbstractFeatureCall leftOperand = (XAbstractFeatureCall) binaryOperation.getLeftOperand();
	JvmIdentifiableElement feature = leftOperand.getFeature();
	if (appendable.hasName(feature)) {
		return appendable.append(appendable.getName(feature));
	}
	boolean hasReceiver = appendReceiver(leftOperand, appendable, isExpressionContext);
	if (hasReceiver) {
		appendable.append(".");
	}
	return appendable.append(feature.getSimpleName());
}
 
Example 8
Source File: TypeConvertingCompiler.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
/** Convert a wrapper expression (number, char, boolean) to its primitive equivalent.
 *
 * @param wrapper unused in this context but useful for inheritors.
 * @param primitive the primitive type to convert to.
 * @param context the context of the convertion, i.e. the containing expression.
 * @param appendable the receiver of the convertion.
 * @param expression the expression to convert.
 */
protected void convertWrapperToPrimitive(
		final LightweightTypeReference wrapper, 
		final LightweightTypeReference primitive, 
		XExpression context, 
		final ITreeAppendable appendable,
		final Later expression) {
	XExpression normalized = normalizeBlockExpression(context);
	if (normalized instanceof XAbstractFeatureCall && !(context.eContainer() instanceof XAbstractFeatureCall)) {
		// Avoid javac bug
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=410797
		// TODO make that dependent on the compiler version (javac 1.7 fixed that bug)
		XAbstractFeatureCall featureCall = (XAbstractFeatureCall) normalized;
		if (featureCall.isStatic()) {
			JvmIdentifiableElement feature = featureCall.getFeature();
			if (feature instanceof JvmOperation) {
				if (!((JvmOperation) feature).getTypeParameters().isEmpty()) {
					appendable.append("(");
					appendable.append(primitive);
					appendable.append(") ");
					expression.exec(appendable);
					return;
				}
			}
		}
	}
	appendable.append("(");
	if (mustInsertTypeCast(context, wrapper)) {
		appendable.append("(");
		appendable.append(wrapper);
		appendable.append(") ");
	} 
	expression.exec(appendable);
	appendable.append(")");
	appendable.append(".");
	appendable.append(primitive);
	appendable.append("Value()");
}
 
Example 9
Source File: OrderSensitivityTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void doTestOverloadedAndExpect(final String declarator, final String invocation, final String expectation) {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("{");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("var java.util.List<CharSequence> chars = null");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("var java.util.List<String> strings = null");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("var ");
    _builder.append(declarator, "\t");
    _builder.append(" receiver = null");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("receiver.");
    _builder.append(invocation, "\t");
    _builder.newLineIfNotEmpty();
    _builder.append("}");
    _builder.newLine();
    XExpression _expression = this.expression(_builder);
    final XBlockExpression block = ((XBlockExpression) _expression);
    XExpression _last = IterableExtensions.<XExpression>last(block.getExpressions());
    final XAbstractFeatureCall featureCall = ((XAbstractFeatureCall) _last);
    final JvmIdentifiableElement feature = featureCall.getFeature();
    Assert.assertNotNull("feature is not null", feature);
    Assert.assertFalse("feature is resolved", feature.eIsProxy());
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append(declarator);
    _builder_1.append(".");
    _builder_1.append(expectation);
    Assert.assertEquals(_builder_1.toString(), feature.getIdentifier());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 10
Source File: ConstantExpressionValidator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected boolean _isConstantExpression(final XAbstractFeatureCall it) {
  boolean _switchResult = false;
  JvmIdentifiableElement _feature = it.getFeature();
  boolean _matched = false;
  if (_feature instanceof JvmEnumerationLiteral) {
    _matched=true;
    _switchResult = false;
  }
  if (!_matched) {
    _switchResult = this.isConstant(it);
  }
  return _switchResult;
}
 
Example 11
Source File: AbstractExpressionGenerator.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Compute the simple name for the called feature.
 *
 * @param featureCall the feature call.
 * @param logicalContainerProvider the provider of logicial container.
 * @param featureNameProvider the provider of feature name.
 * @param nullKeyword the null-equivalent keyword.
 * @param thisKeyword the this-equivalent keyword.
 * @param superKeyword the super-equivalent keyword.
 * @param referenceNameLambda replies the reference name or {@code null} if none.
 * @return the simple name.
 */
public static String getCallSimpleName(XAbstractFeatureCall featureCall,
		ILogicalContainerProvider logicalContainerProvider,
		IdentifiableSimpleNameProvider featureNameProvider,
		Function0<? extends String> nullKeyword,
		Function0<? extends String> thisKeyword,
		Function0<? extends String> superKeyword,
		Function1<? super JvmIdentifiableElement, ? extends String> referenceNameLambda) {
	String name = null;
	final JvmIdentifiableElement calledFeature = featureCall.getFeature();
	if (calledFeature instanceof JvmConstructor) {
		final JvmDeclaredType constructorContainer = ((JvmConstructor) calledFeature).getDeclaringType();
		final JvmIdentifiableElement logicalContainer = logicalContainerProvider.getNearestLogicalContainer(featureCall);
		final JvmDeclaredType contextType = ((JvmMember) logicalContainer).getDeclaringType();
		if (contextType == constructorContainer) {
			name = thisKeyword.apply();
		} else {
			name = superKeyword.apply();
		}
	} else if (calledFeature != null) {
		final String referenceName = referenceNameLambda.apply(calledFeature);
		if (referenceName != null) {
			name = referenceName;
		} else if (calledFeature instanceof JvmOperation) {
			name = featureNameProvider.getSimpleName(calledFeature);
		} else {
			name = featureCall.getConcreteSyntaxFeatureName();
		}
	}
	if (name == null) {
		return nullKeyword.apply();
	}
	return name;
}
 
Example 12
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 13
Source File: AbstractExtraLanguageValidator.java    From sarl with Apache License 2.0 5 votes vote down vote up
private boolean internalCheckMemberFeaturCallMapping(XAbstractFeatureCall featureCall,
		Procedure3<? super EObject, ? super JvmType, ? super String> typeErrorHandler,
		Function2<? super EObject, ? super JvmIdentifiableElement, ? extends Boolean> featureErrorHandler) {
	final ExtraLanguageFeatureNameConverter converter = getFeatureNameConverter();
	if (converter != null) {
		final ConversionType conversionType = converter.getConversionTypeFor(featureCall);
		switch (conversionType) {
		case EXPLICIT:
			return true;
		case IMPLICIT:
			final JvmIdentifiableElement element = featureCall.getFeature();
			if (element instanceof JvmType) {
				return doTypeMappingCheck(featureCall, (JvmType) element, typeErrorHandler);
			}
			if (featureCall instanceof XMemberFeatureCall) {
				final XMemberFeatureCall memberFeatureCall = (XMemberFeatureCall) featureCall;
				final XExpression receiver = memberFeatureCall.getMemberCallTarget();
				if (receiver instanceof XMemberFeatureCall || receiver instanceof XFeatureCall) {
					internalCheckMemberFeaturCallMapping(
							(XAbstractFeatureCall) receiver,
							typeErrorHandler,
							featureErrorHandler);
				}
			}
			break;
		case FORBIDDEN_CONVERSION:
		default:
			if (featureErrorHandler != null) {
				return !featureErrorHandler.apply(featureCall, featureCall.getFeature());
			}
			return false;
		}
	}
	return true;
}
 
Example 14
Source File: InvokedResolvedOperation.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected LightweightTypeReference getReceiverType(XAbstractFeatureCall featureCall, IResolvedTypes resolvedTypes, ITypeReferenceOwner owner) {
	XExpression receiver = featureCall.getActualReceiver();
	if (receiver == null) {
		// static feature call
		JvmOperation operation = (JvmOperation) featureCall.getFeature();
		JvmDeclaredType declaringType = operation.getDeclaringType();
		return owner.newParameterizedTypeReference(declaringType);
	}
	return resolvedTypes.getActualType(receiver);
}
 
Example 15
Source File: InvokedResolvedOperation.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected InvokedResolvedOperation resolve(XAbstractFeatureCall featureCall, IResolvedTypes resolvedTypes, ITypeReferenceOwner owner) {
	JvmIdentifiableElement feature = featureCall.getFeature();
	if (feature instanceof JvmOperation) {
		LightweightTypeReference contextType = getReceiverType(featureCall, resolvedTypes, owner);
		return new InvokedResolvedOperation((JvmOperation) feature, contextType, resolvedTypes.getActualTypeArguments(featureCall), overrideTester);
	} else {
		throw new IllegalArgumentException();
	}
}
 
Example 16
Source File: SARLHoverSerializer.java    From sarl with Apache License 2.0 5 votes vote down vote up
@Override
public String computeUnsugaredExpression(EObject object) {
	if (object instanceof XAbstractFeatureCall) {
		final XAbstractFeatureCall featureCall = (XAbstractFeatureCall) object;
		final JvmIdentifiableElement feature = featureCall.getFeature();
		if (feature instanceof JvmExecutable && !feature.eIsProxy()
				&& (featureCall.getImplicitReceiver() != null || featureCall.getImplicitFirstArgument() != null)
				&& !featureCall.isStatic()) {
			final XExpression receiver = featureCall.getActualReceiver();
			if (receiver instanceof XMemberFeatureCall) {
				final JvmIdentifiableElement memberFeature = ((XMemberFeatureCall) receiver).getFeature();
				final String name = memberFeature.getSimpleName();
				if (Utils.isNameForHiddenCapacityImplementationCallingMethod(name)) {
					final JvmOperation op = (JvmOperation) memberFeature;
					final StringBuilder result = new StringBuilder();
					result.append("getSkill(typeof("); //$NON-NLS-1$
					result.append(op.getReturnType().getSimpleName());
					result.append("))."); //$NON-NLS-1$
					result.append(feature.getSimpleName());
					result.append(computeArguments(featureCall));
					return result.toString();
				}
			}
		}
	}
	return super.computeUnsugaredExpression(object);
}
 
Example 17
Source File: SARLEarlyExitComputer.java    From sarl with Apache License 2.0 5 votes vote down vote up
@Override
protected Collection<ExitPoint> _exitPoints(XAbstractFeatureCall expression) {
	final Collection<ExitPoint> exitPoints = super._exitPoints(expression);
	if (isNotEmpty(exitPoints)) {
		return exitPoints;
	}
	final JvmIdentifiableElement element = expression.getFeature();
	if (isEarlyExitAnnotatedElement(element)) {
		return Collections.<ExitPoint>singletonList(new SarlExitPoint(expression, false));
	}
	return Collections.emptyList();
}
 
Example 18
Source File: SarlCompiler.java    From sarl with Apache License 2.0 4 votes vote down vote up
private void convertNullSafeWrapperToPrimitive(
		LightweightTypeReference wrapper,
		LightweightTypeReference primitive,
		XExpression context,
		ITreeAppendable appendable,
		Later expression) {
	// BEGIN Specific
	final String defaultValue = primitive.isType(boolean.class) ? "false" : "0"; //$NON-NLS-1$ //$NON-NLS-2$
	// END Specific
	final XExpression normalized = normalizeBlockExpression(context);
	if (normalized instanceof XAbstractFeatureCall && !(context.eContainer() instanceof XAbstractFeatureCall)) {
		// Avoid javac bug
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=410797
		// TODO make that dependent on the compiler version (javac 1.7 fixed that bug)
		final XAbstractFeatureCall featureCall = (XAbstractFeatureCall) normalized;
		if (featureCall.isStatic()) {
			final JvmIdentifiableElement feature = featureCall.getFeature();
			if (feature instanceof JvmOperation) {
				if (!((JvmOperation) feature).getTypeParameters().isEmpty()) {
					// BEGIN Specific
					appendable.append("(("); //$NON-NLS-1$
					expression.exec(appendable);
					appendable.append(") == null ? "); //$NON-NLS-1$
					appendable.append(defaultValue);
					appendable.append(" : "); //$NON-NLS-1$
					// END Specific
					appendable.append("("); //$NON-NLS-1$
					appendable.append(primitive);
					appendable.append(") "); //$NON-NLS-1$
					expression.exec(appendable);
					// BEGIN Specific
					appendable.append(") "); //$NON-NLS-1$
					// END Specific
					return;
				}
			}
		}
	}

	// BEGIN Specific
	appendable.append("(("); //$NON-NLS-1$
	expression.exec(appendable);
	appendable.append(") == null ? "); //$NON-NLS-1$
	appendable.append(defaultValue);
	appendable.append(" : "); //$NON-NLS-1$
	// END Specific
	final boolean mustInsertTypeCast;
	try {
		mustInsertTypeCast = (Boolean) this.reflect.invoke(this, "mustInsertTypeCast", context, wrapper); //$NON-NLS-1$
	} catch (Exception exception) {
		throw new Error(exception);
	}
	if (mustInsertTypeCast) {
		appendable.append("("); //$NON-NLS-1$
		appendable.append(wrapper);
		appendable.append(") "); //$NON-NLS-1$
	}
	// BEGIN Specific
	appendable.append("("); //$NON-NLS-1$
	expression.exec(appendable);
	appendable.append(")"); //$NON-NLS-1$
	// END Specific
	appendable.append("."); //$NON-NLS-1$
	appendable.append(primitive);
	appendable.append("Value())"); //$NON-NLS-1$
}
 
Example 19
Source File: XbaseHighlightingCalculator.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected void computeFeatureCallHighlighting(XAbstractFeatureCall featureCall, IHighlightedPositionAcceptor acceptor) {
	JvmIdentifiableElement feature = featureCall.getFeature();
	if (feature != null && !feature.eIsProxy()) {
		
		if (feature instanceof XVariableDeclaration) {
			if (!SPECIAL_FEATURE_NAMES.contains(((XVariableDeclaration) feature).getName())) {
				// highlighting of special identifiers is done separately, so it's omitted here 
				highlightFeatureCall(featureCall, acceptor, LOCAL_VARIABLE);
				
				if (!((XVariableDeclaration) feature).isWriteable()) {
					highlightFeatureCall(featureCall, acceptor, LOCAL_FINAL_VARIABLE);
				}
			}
			
		} else if (feature instanceof JvmFormalParameter) {
			if (!SPECIAL_FEATURE_NAMES.contains(((JvmFormalParameter) feature).getName())) {
				// highlighting of special identifiers is done separately, so it's omitted here 
				final EObject eContainingFeature = feature.eContainingFeature();
				
				if (eContainingFeature == TypesPackage.Literals.JVM_EXECUTABLE__PARAMETERS
						|| eContainingFeature == XbasePackage.Literals.XCLOSURE__DECLARED_FORMAL_PARAMETERS) {
					// which is the case for constructors and methods
					highlightFeatureCall(featureCall, acceptor, PARAMETER_VARIABLE);
				} else {
					// covers parameters of for and template expr FOR loops, as well as switch statements
					highlightFeatureCall(featureCall, acceptor, LOCAL_VARIABLE);
					highlightFeatureCall(featureCall, acceptor, LOCAL_FINAL_VARIABLE);
				}
			}
			
		} else if (feature instanceof JvmTypeParameter) {
			highlightFeatureCall(featureCall, acceptor, TYPE_VARIABLE);
			
		} else if (feature instanceof JvmField) {
			highlightFeatureCall(featureCall, acceptor, FIELD);
			
			if (((JvmField) feature).isStatic()) {
				highlightFeatureCall(featureCall, acceptor, STATIC_FIELD);
				
				if (((JvmField) feature).isFinal()) {
					highlightFeatureCall(featureCall, acceptor, STATIC_FINAL_FIELD);
				}
			}
			
		} else if (feature instanceof JvmOperation && !featureCall.isOperation()) {
			JvmOperation jvmOperation = (JvmOperation) feature;
			
			highlightFeatureCall(featureCall, acceptor, METHOD);
			
			if (jvmOperation.isAbstract()) {
				highlightFeatureCall(featureCall, acceptor, ABSTRACT_METHOD_INVOCATION);
			}
			
			if (jvmOperation.isStatic()) {
				highlightFeatureCall(featureCall, acceptor, STATIC_METHOD_INVOCATION);
			}
			
			if (featureCall.isExtension() || isExtensionWithImplicitFirstArgument(featureCall)) {
				highlightFeatureCall(featureCall, acceptor, EXTENSION_METHOD_INVOCATION);
			}
			
		} else if (feature instanceof JvmDeclaredType) {
			highlightReferenceJvmType(acceptor, featureCall, XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, feature);
		}
		
		if(feature instanceof JvmAnnotationTarget && DeprecationUtil.isTransitivelyDeprecated((JvmAnnotationTarget)feature)){
			highlightFeatureCall(featureCall, acceptor, DEPRECATED_MEMBERS);
		}
	}
}
 
Example 20
Source File: FeatureCallCompiler.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected void appendFeatureCall(XAbstractFeatureCall call, ITreeAppendable b) {
	if (expressionHelper.isInlined(call)) {
		appendInlineFeatureCall(call, b);
		return;
	}
	JvmIdentifiableElement feature = call.getFeature();
	String name = null;
	if (feature instanceof JvmConstructor) {
		JvmDeclaredType constructorContainer = ((JvmConstructor) feature).getDeclaringType();
		JvmIdentifiableElement logicalContainer = contextProvider.getNearestLogicalContainer(call);
		JvmDeclaredType contextType = ((JvmMember) logicalContainer).getDeclaringType();
		if (contextType == constructorContainer)
			name = "this";
		else
			name = "super";
	} else if(feature != null) {
		if (b.hasName(feature)) {
			name = b.getName(feature);
		} else {
			name = featureNameProvider.getSimpleName(feature);
		}
	}
	if(name == null)
		name = "/* name is null */";
	b.trace(call, XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, 0).append(name);
	if (feature instanceof JvmExecutable) {
		b.append("(");
		List<XExpression> arguments = getActualArguments(call);
		if (!arguments.isEmpty()) {
			XExpression receiver = null;
			if (call instanceof XMemberFeatureCall) {
				receiver = ((XMemberFeatureCall) call).getMemberCallTarget();
			} else if (call instanceof XAssignment) {
				receiver = ((XAssignment) call).getAssignable();
			}
			boolean shouldBreakFirstArgument = receiver == null || arguments.get(0) != receiver;
			appendArguments(arguments, b, shouldBreakFirstArgument);
		}
		b.append(")");
	}
}