org.eclipse.xtext.common.types.JvmExecutable Java Examples

The following examples show how to use org.eclipse.xtext.common.types.JvmExecutable. 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: XtypeProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected void appendParameters(StyledString result, JvmExecutable executable, int insignificantParameters, LightweightTypeReferenceFactory ownedConverter) {
	List<JvmFormalParameter> declaredParameters = executable.getParameters();
	List<JvmFormalParameter> relevantParameters = declaredParameters.subList(Math.min(insignificantParameters, declaredParameters.size()), declaredParameters.size());
	for(int i = 0; i < relevantParameters.size(); i++) {
		JvmFormalParameter parameter = relevantParameters.get(i);
		if (i != 0)
			result.append(", ");
		if (i == relevantParameters.size() - 1 && executable.isVarArgs() && parameter.getParameterType() instanceof JvmGenericArrayTypeReference) {
			JvmGenericArrayTypeReference parameterType = (JvmGenericArrayTypeReference) parameter.getParameterType();
			result.append(ownedConverter.toLightweightReference(parameterType.getComponentType()).getHumanReadableName());
			result.append("...");
		} else {
			if (parameter.getParameterType()!= null) {
				String simpleName = ownedConverter.toLightweightReference(parameter.getParameterType()).getHumanReadableName();
				if (simpleName != null) // is null if the file is not on the class path
					result.append(simpleName);
			}
		}
		result.append(' ');
		result.append(notNull(parameter.getName()));
	}
}
 
Example #2
Source File: SARLJvmModelInferrer.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Copy and clean the given documentation by removing any unecessary <code>@param</code>.
 *
 * @param sourceOperation the source for the documentation.
 * @param targetOperation the target for the documentation.
 * @return <code>true</code> if a documentation was added.
 */
protected boolean copyAndCleanDocumentationTo(XtendExecutable sourceOperation, JvmExecutable targetOperation) {
	assert sourceOperation != null;
	assert targetOperation != null;

	String comment = SARLJvmModelInferrer.this.typeBuilder.getDocumentation(sourceOperation);
	if (Strings.isNullOrEmpty(comment)) {
		return false;
	}

	comment = cleanDocumentation(comment,
			Iterables.transform(sourceOperation.getParameters(), it -> it.getName()),
			Iterables.transform(targetOperation.getParameters(), it -> it.getSimpleName()));

	SARLJvmModelInferrer.this.typeBuilder.setDocumentation(targetOperation, comment);
	return true;
}
 
Example #3
Source File: CrySLParser.java    From CogniCrypt with Eclipse Public License 2.0 6 votes vote down vote up
private List<CrySLForbiddenMethod> getForbiddenMethods(final EList<ForbMethod> methods) {
	final List<CrySLForbiddenMethod> methodSignatures = new ArrayList<>();
	for (final ForbMethod fm : methods) {
		final JvmExecutable meth = fm.getJavaMeth();
		final List<Entry<String, String>> pars = new ArrayList<>();
		for (final JvmFormalParameter par : meth.getParameters()) {
			pars.add(new SimpleEntry<>(par.getSimpleName(), par.getParameterType().getSimpleName()));
		}
		final List<CrySLMethod> crysl = new ArrayList<>();

		final Event alternative = fm.getRep();
		if (alternative != null) {
			crysl.addAll(CrySLParserUtils.resolveAggregateToMethodeNames(alternative));
		}
		methodSignatures.add(new CrySLForbiddenMethod(
				new CrySLMethod(meth.getDeclaringType().getIdentifier() + "." + meth.getSimpleName(), pars, null, new SimpleEntry<>(UNDERSCORE, ANY_TYPE)), false, crysl));
	}
	return methodSignatures;
}
 
Example #4
Source File: SARLValidator.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Retrieve the types of the formal parameters of the given JVM executable object.
 *
 * @param jvmExecutable the JVM executable.
 * @param wrapFromPrimitives indicates if the primitive types must be wrapped to object type equivalent.
 * @param wrapToPrimitives indicates if the object types must be wrapped to primitive type equivalent.
 * @return the list of types.
 * @since 0.8
 * @see #getParamTypes(JvmOperation, boolean)
 */
protected List<LightweightTypeReference> getParamTypeReferences(JvmExecutable jvmExecutable,
		boolean wrapFromPrimitives, boolean wrapToPrimitives) {
	assert (wrapFromPrimitives && !wrapToPrimitives) || (wrapToPrimitives && !wrapFromPrimitives);
	final List<LightweightTypeReference> types = newArrayList();
	for (final JvmFormalParameter parameter : jvmExecutable.getParameters()) {
		LightweightTypeReference typeReference = toLightweightTypeReference(parameter.getParameterType());
		if (wrapFromPrimitives) {
			typeReference = typeReference.getWrapperTypeIfPrimitive();
		} else if (wrapToPrimitives) {
			typeReference = typeReference.getPrimitiveIfWrapperType();
		}
		types.add(typeReference);
	}
	return types;
}
 
Example #5
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
private boolean hasExecutableWithException(Iterable<? extends JvmExecutable> executables, final String... exceptions) {
	return tryFind(executables, new Predicate<JvmExecutable>() {
		@Override
		public boolean apply(JvmExecutable executable) {
			EList<JvmTypeReference> declrExceptions = executable.getExceptions();
			if (declrExceptions.size() != exceptions.length) {
				return false;
			}
			Iterable<String> asStrings = transform(declrExceptions, new Function<JvmTypeReference, String>() {

				@Override
				public String apply(JvmTypeReference input) {
					return input.getIdentifier();
				}
			});
			for (String ex : exceptions) {
				if (!contains(asStrings, ex)) {
					return false;
				}
			}
			return true;
		}
	}).isPresent();
}
 
Example #6
Source File: JavaElementFinder.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
private boolean doParametersMatch(JvmExecutable object, IMethod method, IType declaringType)
		throws JavaModelException {
	int numberOfParameters = method.getNumberOfParameters();
	String[] parameterTypes = method.getParameterTypes();
	boolean match = true;
	for (int i = 0; i < numberOfParameters && match; i++) {
		JvmFormalParameter formalParameter = object.getParameters().get(i);
		String parameterType = parameterTypes[i];
		String readable = toQualifiedRawTypeName(parameterType, declaringType);
		String qualifiedParameterType = getQualifiedParameterType(formalParameter);
		if (!readable.equals(qualifiedParameterType)) {
			// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=387576
			if (qualifiedParameterType != null && qualifiedParameterType.endsWith("$") && qualifiedParameterType.startsWith(readable)) {
				for(int c = readable.length(); c < qualifiedParameterType.length() && match; c++) {
					if (qualifiedParameterType.charAt(c) != '$') {
						match = false;
					}
				}
			} else {
				match = false;
			}
		}
	}
	return match;
}
 
Example #7
Source File: XtendJvmModelInferrer.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
protected void translateParameter(JvmExecutable executable, XtendParameter parameter) {
	JvmFormalParameter jvmParam = typesFactory.createJvmFormalParameter();
	jvmParam.setName(parameter.getName());
	if (parameter.isVarArg()) {
		executable.setVarArgs(true);
		JvmGenericArrayTypeReference arrayType = typeReferences.createArrayType(jvmTypesBuilder
				.cloneWithProxies(parameter.getParameterType()));
		jvmParam.setParameterType(arrayType);
	} else {
		jvmParam.setParameterType(jvmTypesBuilder.cloneWithProxies(parameter.getParameterType()));
	}
	associator.associate(parameter, jvmParam);
	translateAnnotationsTo(parameter.getAnnotations(), jvmParam);
	if (parameter.isExtension() && typeReferences.findDeclaredType(Extension.class, parameter) != null) {
		jvmParam.getAnnotations().add(_annotationTypesBuilder.annotationRef(Extension.class));
	}
	executable.getParameters().add(jvmParam);
}
 
Example #8
Source File: AbstractResolvedExecutable.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public String getResolvedSignature() {
	JvmExecutable declaration = getDeclaration();
	List<LightweightTypeReference> parameterTypes = getResolvedParameterTypes();
	StringBuilder result = new StringBuilder(declaration.getSimpleName().length() + 2 + 30 * parameterTypes.size());
	result.append(declaration.getSimpleName());
	result.append('(');
	for(int i = 0; i < parameterTypes.size(); i++) {
		if (i != 0) {
			result.append(',');
		}
		result.append(parameterTypes.get(i).getJavaIdentifier());
	}
	result.append(')');
	return result.toString();
}
 
Example #9
Source File: SerializerScopeProvider.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected IScope getExecutableScope(XAbstractFeatureCall call, JvmIdentifiableElement feature) {
	final String simpleName = feature.getSimpleName();
	QualifiedName name = QualifiedName.create(simpleName);
	if (call.isOperation()) {
		QualifiedName operator = getOperator(call, name);
		if (operator == null) {
			return IScope.NULLSCOPE;
		}
		return new SingletonScope(EObjectDescription.create(operator, feature), IScope.NULLSCOPE);
	}
	if (call instanceof XAssignment) {
		return getAccessorScope(simpleName, name, feature);
	}
	if (call.isExplicitOperationCallOrBuilderSyntax() || ((JvmExecutable) feature).getParameters().size() > 1
			|| (!call.isExtension() && ((JvmExecutable) feature).getParameters().size() == 1)) {
		return new SingletonScope(EObjectDescription.create(name, feature), IScope.NULLSCOPE);
	}

	return getAccessorScope(simpleName, name, feature);
}
 
Example #10
Source File: JdtBasedTypeFactory.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
private void setParameterNamesAndAnnotations(IMethodBinding method, ITypeBinding[] parameterTypes,
		String[] parameterNames, JvmExecutable result) {
	InternalEList<JvmFormalParameter> parameters = (InternalEList<JvmFormalParameter>)result.getParameters();
	for (int i = 0; i < parameterTypes.length; i++) {
		IAnnotationBinding[] parameterAnnotations;
		try {
			parameterAnnotations = method.getParameterAnnotations(i);
		} catch(AbortCompilation aborted) {
			parameterAnnotations = null;
		}
		ITypeBinding parameterType = parameterTypes[i];
		String parameterName = parameterNames == null ? null /* lazy */ : i < parameterNames.length ? parameterNames[i] : "arg" + i;
		JvmFormalParameter formalParameter = createFormalParameter(parameterType, parameterName, parameterAnnotations);
		parameters.addUnique(formalParameter);
	}
}
 
Example #11
Source File: JdtBasedTypeFactory.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
ParameterNameInitializer createParameterNameInitializer(
		IMethodBinding method,
		WorkingCopyOwner workingCopyOwner,
		JvmExecutable result,
		String handleIdentifier,
		String[] path,
		String name,
		SegmentSequence signaturex) {
	if (method.isConstructor() && method.getDeclaringClass().isEnum()) {
		String syntheticParams = "Ljava/lang/String;I";
		String withoutSyntheticArgs = signaturex.toString();
		// sometimes (don't really know when... JDT bug?) an enum constructor comes without synthetic arguments
		// this solution might wrongly strip off a (String,int) signature, but I don't see how this can be done differently here.
		if (withoutSyntheticArgs.startsWith(syntheticParams)) {
			withoutSyntheticArgs = withoutSyntheticArgs.substring(syntheticParams.length());
		}
		return new EnumConstructorParameterNameInitializer(workingCopyOwner, result, handleIdentifier, path, name, withoutSyntheticArgs);
	}
	return new ParameterNameInitializer(workingCopyOwner, result, handleIdentifier, path, name, signaturex);
}
 
Example #12
Source File: XbaseIdeContentProposalPriorities.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public int getCrossRefPriority(IEObjectDescription objectDesc, ContentAssistEntry entry) {
	if (entry != null) {
		if (objectDesc instanceof SimpleIdentifiableElementDescription) {
			if (!"this".equals(entry.getProposal()) && !"super".equals(entry.getProposal())) {
				return adjustPriority(entry, getCrossRefPriority() + 70);
			}
		} else if (objectDesc instanceof StaticFeatureDescriptionWithTypeLiteralReceiver) {
			return adjustPriority(entry, getCrossRefPriority() + 60);
		} else if (objectDesc instanceof IIdentifiableElementDescription) {
			JvmIdentifiableElement element = ((IIdentifiableElementDescription) objectDesc).getElementOrProxy();
			if (element instanceof JvmField) {
				return adjustPriority(entry, getCrossRefPriority() + 50);
			} else if (element instanceof JvmExecutable) {
				return adjustPriority(entry, getCrossRefPriority() + 20);
			}
		}
	}
	return super.getCrossRefPriority(objectDesc, entry);
}
 
Example #13
Source File: SARLJvmModelInferrer.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc}.
 *
 * <p>Overridden for: removing the existing associated body, and delaying the local type inference.
 */
@Override
protected void setBody(JvmExecutable executable, XExpression expression) {
	final GenerationContext context = getContext(
			EcoreUtil2.getContainerOfType(executable, JvmType.class));
	this.typeBuilder.removeExistingBody(executable);
	this.associator.associateLogicalContainer(expression, executable);
	if (expression != null) {
		if (context.getParentContext() == null) {
			context.getPostFinalizationElements().add(() -> {
				initializeLocalTypes(context, executable, expression);
			});
		} else {
			initializeLocalTypes(context, executable, expression);
		}
	} else {
		initializeLocalTypes(context, executable, expression);
	}
}
 
Example #14
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
private boolean hasExecutableWithException(Iterable<? extends JvmExecutable> executables, final String... exceptions) {
	return tryFind(executables, new Predicate<JvmExecutable>() {
		@Override
		public boolean apply(JvmExecutable executable) {
			EList<JvmTypeReference> declrExceptions = executable.getExceptions();
			if (declrExceptions.size() != exceptions.length) {
				return false;
			}
			Iterable<String> asStrings = transform(declrExceptions, new Function<JvmTypeReference, String>() {

				@Override
				public String apply(JvmTypeReference input) {
					return input.getIdentifier();
				}
			});
			for (String ex : exceptions) {
				if (!contains(asStrings, ex)) {
					return false;
				}
			}
			return true;
		}
	}).isPresent();
}
 
Example #15
Source File: XbaseCopyQualifiedNameService.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public String getQualifiedName(EObject constructor, EObject constructorCall) {
	if (constructor instanceof JvmConstructor && constructorCall instanceof XConstructorCall) {
		return _getQualifiedName((JvmConstructor) constructor, (XConstructorCall) constructorCall);
	} else if (constructor instanceof JvmExecutable && constructorCall instanceof XAbstractFeatureCall) {
		return _getQualifiedName((JvmExecutable) constructor, (XAbstractFeatureCall) constructorCall);
	} else if (constructor instanceof JvmExecutable && constructorCall != null) {
		return _getQualifiedName((JvmExecutable) constructor, constructorCall);
	} else if (constructor instanceof JvmExecutable && constructorCall == null) {
		return _getQualifiedName((JvmExecutable) constructor, (Void) null);
	} else if (constructor != null && constructorCall != null) {
		return _getQualifiedName(constructor, constructorCall);
	} else if (constructor != null && constructorCall == null) {
		return _getQualifiedName(constructor, (Void) null);
	} else if (constructor == null && constructorCall != null) {
		return _getQualifiedName((Void) null, constructorCall);
	} else {
		return _getQualifiedName((Void) null, (Void) null);
	}
}
 
Example #16
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
private boolean hasExecutableWithException(Iterable<? extends JvmExecutable> executables, final String... exceptions) {
	return tryFind(executables, new Predicate<JvmExecutable>() {
		@Override
		public boolean apply(JvmExecutable executable) {
			EList<JvmTypeReference> declrExceptions = executable.getExceptions();
			if (declrExceptions.size() != exceptions.length) {
				return false;
			}
			Iterable<String> asStrings = transform(declrExceptions, new Function<JvmTypeReference, String>() {

				@Override
				public String apply(JvmTypeReference input) {
					return input.getIdentifier();
				}
			});
			for (String ex : exceptions) {
				if (!contains(asStrings, ex)) {
					return false;
				}
			}
			return true;
		}
	}).isPresent();
}
 
Example #17
Source File: XbaseDeclarativeHoverSignatureProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected String getThrowsDeclaration(JvmExecutable executable) {
	String result = "";
	EList<JvmTypeReference> exceptions = executable.getExceptions();
	if (exceptions.size() > 0) {
		result += " throws ";
		Iterator<JvmTypeReference> iterator = exceptions.iterator();
		while (iterator.hasNext()) {
			JvmTypeReference next = iterator.next();
			result += next.getSimpleName();
			if (iterator.hasNext())
				result += ", ";
		}
	}
	return result;
}
 
Example #18
Source File: XtendValidator.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected String typeLabel(JvmExecutable executable) {
	if (executable instanceof JvmOperation) 
		return "method";
	else if(executable instanceof JvmConstructor) 
		return "constructor";
	else 
		return "?";
}
 
Example #19
Source File: JdtBasedTypeFactory.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
ParameterNameInitializer createParameterNameInitializer(
		IMethodBinding method,
		WorkingCopyOwner workingCopyOwner,
		JvmExecutable result,
		String handleIdentifier,
		String[] path,
		String name,
		SegmentSequence signaturex) {
	if (method.isConstructor()) {
		ITypeBinding declarator = method.getDeclaringClass();
		if (declarator.isEnum()) {
			return new EnumConstructorParameterNameInitializer(workingCopyOwner, result, handleIdentifier, path, name, signaturex);
		}
		if (declarator.isMember()) {
			return new ParameterNameInitializer(workingCopyOwner, result, handleIdentifier, path, name, signaturex) {
				@Override
				protected void setParameterNames(IMethod javaMethod, java.util.List<JvmFormalParameter> parameters) throws JavaModelException {
					String[] parameterNames = javaMethod.getParameterNames();
					int size = parameters.size();
					if (size == parameterNames.length) {
						super.setParameterNames(javaMethod, parameters);
					} else if (size == parameterNames.length - 1) {
						for (int i = 1; i < parameterNames.length; i++) {
							String string = parameterNames[i];
							parameters.get(i - 1).setName(string);
						}
					} else {
						throw new IllegalStateException("unmatching arity for java method "+javaMethod.toString()+" and "+getExecutable().getIdentifier());
					}
				}
			};
		}
	}
	return new ParameterNameInitializer(workingCopyOwner, result, handleIdentifier, path, name, signaturex);
}
 
Example #20
Source File: ExpressionArgumentFactory.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public IFeatureCallArguments createExpressionArguments(XExpression expression, AbstractLinkingCandidate<?> candidate) {
	JvmIdentifiableElement feature = candidate.getFeature();
	if (feature instanceof JvmExecutable) {
		JvmExecutable executable = (JvmExecutable) feature;
		return createArgumentsForExecutable(executable.isVarArgs(), candidate.getArguments(), executable.getParameters(), candidate.hasReceiver(), candidate.getState().getReferenceOwner());
	} else {
		if (expression instanceof XAssignment) {
			XAssignment assignment = (XAssignment) expression;
			LightweightTypeReference featureType = candidate.getActualType(candidate.getFeature(), true);
			return new AssignmentFeatureCallArguments(assignment.getValue(), featureType);
		} else {
			return new StandardFeatureCallArguments(candidate.getArguments(), Collections.<JvmFormalParameter>emptyList(), candidate.hasReceiver(), candidate.getState().getReferenceOwner());
		}
	}
}
 
Example #21
Source File: XbaseDispatchingEObjectTextHover.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected Pair<EObject, IRegion> getXtextElementAt(XtextResource resource, int offset) {
	Pair<EObject, IRegion> original = super.getXtextElementAt(resource, offset);
	if (original != null) {
		EObject object = eObjectAtOffsetHelper.resolveContainedElementAt(resource, offset);
		if (object instanceof XAbstractFeatureCall){
			JvmIdentifiableElement feature = ((XAbstractFeatureCall) object).getFeature();
			if(feature instanceof JvmExecutable 
					|| feature instanceof JvmField 
					|| feature instanceof JvmConstructor 
					|| feature instanceof XVariableDeclaration 
					|| feature instanceof JvmFormalParameter)
				return Tuples.create(object, original.getSecond());
		} else if (object instanceof XConstructorCall){
				return Tuples.create(object, original.getSecond());
		}
	}
	
	EObjectInComment eObjectReferencedInComment = javaDocTypeReferenceProvider.computeEObjectReferencedInComment(resource, offset);
	if(eObjectReferencedInComment != null) {
		EObject eObject = eObjectReferencedInComment.getEObject();
		ITextRegion region = eObjectReferencedInComment.getRegion();
		return Tuples.create(eObject, new Region(region.getOffset(), region.getLength()));
	}
	
	return original;
}
 
Example #22
Source File: XbaseCopyQualifiedNameService.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected String _getQualifiedName(JvmExecutable executable, XAbstractFeatureCall featureCall) {
	IResolvedTypes resolvedTypes = typeResolver.resolveTypes(featureCall);
	IResolvedExecutable resolvedExecutable = resolveExecutable(executable, featureCall, resolvedTypes);
	return toFullyQualifiedName(executable) //
			+ "(" + toQualifiedNames(featureCall.getActualArguments(), //
					(argument) -> toQualifiedName(argument, resolvedExecutable, executable, resolvedTypes,
							featureCall.getActualArguments()))
			+ ")";
}
 
Example #23
Source File: SARLUIStrings.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Replies the styled parameters.
 *
 * @param element the element from which the parameters are extracted.
 * @return the styled parameters
 * @since 0.6
 */
public StyledString styledParameters(JvmIdentifiableElement element) {
	final StyledString str = new StyledString();
	if (element instanceof JvmExecutable) {
		final JvmExecutable executable = (JvmExecutable) element;
		str.append(this.keywords.getLeftParenthesisKeyword());
		str.append(parametersToStyledString(
				executable.getParameters(),
				executable.isVarArgs(),
				false));
		str.append(this.keywords.getRightParenthesisKeyword());
	}
	return str;
}
 
Example #24
Source File: XtendHoverSerializer.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public String computeUnsugaredExpression(EObject object) {
	if (object instanceof XAbstractFeatureCall) {
		StringBuilder stringBuilder = new StringBuilder();
		XAbstractFeatureCall featureCall = (XAbstractFeatureCall) object;
		JvmIdentifiableElement feature = featureCall.getFeature();
		if (feature != null && !feature.eIsProxy()) {
			// Static extensions which are no expliciteOperationCalls
			if (featureCall instanceof XMemberFeatureCall && feature instanceof JvmOperation && !((XMemberFeatureCall) featureCall).isExplicitOperationCall()) {
				JvmOperation jvmOperation = (JvmOperation) feature;
				if (jvmOperation.isStatic()) {
					return stringBuilder.append(getStaticCallDesugaredVersion(featureCall, jvmOperation)).toString();
				}
			}
			// Static calls with implicit receiver or implicit first argument
			if (featureCall.getImplicitReceiver() != null || featureCall.getImplicitFirstArgument() != null) {
				if (featureCall.isStatic()) {
					return stringBuilder.append(getStaticCallDesugaredVersion(featureCall, (JvmMember) feature)).toString();
				}
				XExpression receiver = featureCall.getActualReceiver();
				if (receiver instanceof XMemberFeatureCall) {
					stringBuilder.append(THIS).append(DELIMITER);
					stringBuilder.append(((XMemberFeatureCall) receiver).getFeature().getSimpleName()).append(DELIMITER);
				} else if (receiver instanceof XAbstractFeatureCall) {
					JvmIdentifiableElement receiverFeature = ((XAbstractFeatureCall) receiver).getFeature();
					if (receiverFeature == feature.eContainer()) {
						stringBuilder.append(THIS).append(DELIMITER);
					} else {
						stringBuilder.append(receiverFeature.getSimpleName()).append(DELIMITER);
					}
				}
				stringBuilder.append(feature.getSimpleName());
				if (feature instanceof JvmExecutable)
					stringBuilder.append(computeArguments(featureCall));
				return stringBuilder.toString();
			}
		}
	}
	return "";
}
 
Example #25
Source File: JdtBasedTypeFactory.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @noreference This constructor is not intended to be referenced by clients.
 */
protected ParameterNameInitializer(WorkingCopyOwner workingCopyOwner, JvmExecutable executable, String handleIdentifier, String[] path, String name, CharSequence signature) {
	super();
	this.workingCopyOwner = workingCopyOwner;
	this.executable = executable;
	this.handleIdentifier = handleIdentifier;
	this.path = path;
	this.name = name;
	this.signature = signature;
}
 
Example #26
Source File: JvmExecutableItemProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * This returns the label text for the adapted class.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public String getText(Object object)
{
	String label = ((JvmExecutable)object).getSimpleName();
	return label == null || label.length() == 0 ?
		getString("_UI_JvmExecutable_type") :
		getString("_UI_JvmExecutable_type") + " " + label;
}
 
Example #27
Source File: ExtensionScopeHelper.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Features that are valid extensions are all {@link JvmOperation operations}
 * with at least one {@link JvmExecutable#getParameters() parameter}.
 */
protected boolean isPossibleExtension(JvmFeature feature) {
	if (!(feature instanceof JvmOperation)) {
		return false;
	}
	List<JvmFormalParameter> parameters = ((JvmExecutable) feature).getParameters();
	if (parameters.isEmpty()) {
		return false;
	}
	return true;
}
 
Example #28
Source File: LogicalContainerAwareReentrantTypeResolver.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void _recordExpressions(JvmExecutable executable) {
	List<JvmGenericType> localClasses = executable.getLocalClasses();
	for(int i = 0, size = localClasses.size(); i < size; i++) {
		recordExpressions(localClasses.get(i));
	}
	recordAnnotationExpressions(executable);
}
 
Example #29
Source File: BucketedEObjectDescription.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void computeShadowingKey(JvmIdentifiableElement identifiable, StringBuilder result) {
	if (identifiable instanceof JvmExecutable) {
		JvmExecutable executable = (JvmExecutable) identifiable;
		result.append('(');
		boolean first = true;
		for(JvmFormalParameter parameter: executable.getParameters()) {
			if (!first) {
				result.append(',');
			} else {
				first = false;
			}
			if (parameter.getParameterType() != null && parameter.getParameterType().getType() != null)
				result.append(parameter.getParameterType().getType().getIdentifier());
			else
				result.append("null");
		}
		result.append(')');
	}
	if (getImplicitFirstArgument() != null) {
		result.append(":implicitFirstArgument");
	}
	if (getImplicitReceiver() != null) {
		result.append(":implicitReceiver");
	}
	if (isTypeLiteral()) {
		result.append(":typeLiteral");
	}
	if (isVisible()) {
		result.append('+');
	} else {
		result.append('-');
	}
}
 
Example #30
Source File: ExpressionScope.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected String getSignature(IIdentifiableElementDescription desc) {
	String descName = desc.getName().getFirstSegment();
	StringBuilder builder = new StringBuilder(64).append(descName);
	JvmIdentifiableElement elementOrProxy = desc.getElementOrProxy();
	if (elementOrProxy instanceof JvmExecutable) {
		JvmExecutable executable = (JvmExecutable) desc.getElementOrProxy();
		String opName = executable.getSimpleName();
		if (opName.length() - 3 == descName.length() && opName.startsWith("set")) {
			builder.append("=");
		}
		appendParameters(executable, builder, desc.isExtension());
	}
	return builder.toString();
}