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

The following examples show how to use org.eclipse.xtext.xbase.XAbstractFeatureCall#getImplicitReceiver() . 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: XbaseUsageCrossReferencer.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected TreeIterator<Notifier> newContentsIterator() {
	return new ContentTreeIterator<Notifier>(emfObjects) {
		private static final long serialVersionUID = 1L;

		@Override
		protected Iterator<? extends EObject> getEObjectChildren(EObject eObject) {
			if(eObject instanceof XAbstractFeatureCall){
				Iterable<EObject> result = eObject.eContents();
				XAbstractFeatureCall featureCall = (XAbstractFeatureCall) eObject;
				XExpression implicitReceiver = featureCall.getImplicitReceiver();
				if(implicitReceiver != null) 
					result = Iterables.concat(result, Collections.singleton(implicitReceiver));
				XExpression implicitFirstArgument = featureCall.getImplicitFirstArgument();
				if(implicitFirstArgument != null)
					result = Iterables.concat(result, Collections.singleton(implicitFirstArgument));
				return result.iterator();
			} else 
				return super.getEObjectChildren(eObject);
		}
	};
}
 
Example 2
Source File: Oven.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public void fireproof(String input) throws Exception {
	try {
		EObject file = parseHelper.parse(input);
		IResolvedTypes resolvedTypes = typeResolver.resolveTypes(file);
		Assert.assertNotNull(resolvedTypes);
		if (file != null) {
			TreeIterator<EObject> allContents = file.eAllContents();
			while (allContents.hasNext()) {
				EObject content = allContents.next();
				if (content instanceof XAbstractFeatureCall) {
					assertExpressionTypeIsResolved(((XExpression) content), resolvedTypes);
					XAbstractFeatureCall abstractFeatureCall = (XAbstractFeatureCall) content;
					if (abstractFeatureCall.getImplicitReceiver() != null) {
						assertExpressionTypeIsResolved(abstractFeatureCall.getImplicitReceiver(),
								resolvedTypes);
					}
					if (abstractFeatureCall.getImplicitFirstArgument() != null) {
						assertExpressionTypeIsResolved(abstractFeatureCall.getImplicitFirstArgument(),
								resolvedTypes);
					}
				} else if (content instanceof XClosure) {
					assertExpressionTypeIsResolved(((XExpression) content), resolvedTypes);
					for (JvmFormalParameter it : ((XClosure) content).getImplicitFormalParameters()) {
						assertIdentifiableTypeIsResolved(it, resolvedTypes);
					}
				} else if (content instanceof XExpression) {
					assertExpressionTypeIsResolved(((XExpression) content), resolvedTypes);
				} else if (content instanceof JvmIdentifiableElement) {
					assertIdentifiableTypeIsResolved(((JvmIdentifiableElement) content), resolvedTypes);
				}
			}
		}
	} catch (Throwable e) {
		ComparisonFailure error = new ComparisonFailure(e.getMessage(), input, "");
		error.setStackTrace(e.getStackTrace());
		throw error;
	}
}
 
Example 3
Source File: Oven.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public void fireproof(String input) throws Exception {
	try {
		EObject file = parseHelper.parse(input);
		IResolvedTypes resolvedTypes = typeResolver.resolveTypes(file);
		Assert.assertNotNull(resolvedTypes);
		if (file != null) {
			TreeIterator<EObject> allContents = file.eAllContents();
			while (allContents.hasNext()) {
				EObject content = allContents.next();
				if (content instanceof XAbstractFeatureCall) {
					assertExpressionTypeIsResolved((XExpression) content, resolvedTypes);
					XAbstractFeatureCall abstractFeatureCall = (XAbstractFeatureCall) content;
					if (abstractFeatureCall.getImplicitReceiver() != null) {
						assertExpressionTypeIsResolved(abstractFeatureCall.getImplicitReceiver(), resolvedTypes);
					}
					if (abstractFeatureCall.getImplicitFirstArgument() != null) {
						assertExpressionTypeIsResolved(abstractFeatureCall.getImplicitFirstArgument(), resolvedTypes);
					}
				} else if (content instanceof XClosure) {
					assertExpressionTypeIsResolved((XExpression) content, resolvedTypes);
					for (JvmFormalParameter p : ((XClosure) content).getImplicitFormalParameters()) {
						assertIdentifiableTypeIsResolved(p, resolvedTypes);
					}
				} else if (content instanceof XExpression) {
					assertExpressionTypeIsResolved((XExpression) content, resolvedTypes);
				} else if (content instanceof JvmIdentifiableElement) {
					assertIdentifiableTypeIsResolved((JvmIdentifiableElement) content, resolvedTypes);
				}
			}
		}
	} catch (Throwable e) {
		ComparisonFailure error = new ComparisonFailure(e.getMessage(), input, "");
		error.setStackTrace(e.getStackTrace());
		throw error;
	}
}
 
Example 4
Source File: Oven.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public void fireproof(String input) throws Exception {
	try {
		EObject file = parseHelper.parse(input);
		IResolvedTypes resolvedTypes = typeResolver.resolveTypes(file);
		Assert.assertNotNull(resolvedTypes);
		if (file == null) {
			return;
		}
		for (EObject content : IteratorExtensions.toIterable(file.eAllContents())) {
			if (content instanceof XAbstractFeatureCall) {
				assertExpressionTypeIsResolved(((XExpression) content), resolvedTypes);
				XAbstractFeatureCall abstractFeatureCall = (XAbstractFeatureCall) content;
				if (abstractFeatureCall.getImplicitReceiver() != null) {
					assertExpressionTypeIsResolved(abstractFeatureCall.getImplicitReceiver(), resolvedTypes);
				}
				if (abstractFeatureCall.getImplicitFirstArgument() != null) {
					assertExpressionTypeIsResolved(abstractFeatureCall.getImplicitFirstArgument(), resolvedTypes);
				}
			} else if (content instanceof XClosure) {
				assertExpressionTypeIsResolved(((XExpression) content), resolvedTypes);
				((XClosure) content).getImplicitFormalParameters()
						.forEach((JvmFormalParameter it) -> assertIdentifiableTypeIsResolved(it, resolvedTypes));
			} else if (content instanceof XExpression) {
				assertExpressionTypeIsResolved(((XExpression) content), resolvedTypes);
			} else if (content instanceof JvmIdentifiableElement) {
				assertIdentifiableTypeIsResolved(((JvmIdentifiableElement) content), resolvedTypes);
			}
		}
	} catch (Throwable e) {
		ComparisonFailure error = new ComparisonFailure(e.getMessage(), input, "");
		error.setStackTrace(e.getStackTrace());
		throw error;
	}
}
 
Example 5
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 6
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 7
Source File: XbaseHighlightingCalculator.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected boolean isExtensionWithImplicitFirstArgument(XAbstractFeatureCall featureCall) {
	XExpression implicitReceiver = featureCall.getImplicitReceiver();
	return implicitReceiver instanceof XAbstractFeatureCall
			&& isExtension(((XAbstractFeatureCall) implicitReceiver).getFeature());
}
 
Example 8
Source File: AbstractExpressionGenerator.java    From sarl with Apache License 2.0 4 votes vote down vote up
/** Compute the list of object that serve as the receiver for the given call.
 *
 * @param call the feature call to analyze.
 * @param output the objects that constitute the call's receiver.
 * @param thisKeyword the "this" keyword.
 * @param referenceNameDefinition replies the name of the expression, if defined.
 * @return {@code true} if a receiver was found; otherwise {@code false}.
 */
public static boolean buildCallReceiver(XAbstractFeatureCall call, Function0<? extends String> thisKeyword,
		Function1<? super XExpression, ? extends String> referenceNameDefinition, List<Object> output) {
	if (call.isStatic()) {
		if (call instanceof XMemberFeatureCall) {
			final XMemberFeatureCall memberFeatureCall = (XMemberFeatureCall) call;
			if (memberFeatureCall.isStaticWithDeclaringType()) {
				final XAbstractFeatureCall target = (XAbstractFeatureCall) memberFeatureCall.getMemberCallTarget();
				final JvmType declaringType = (JvmType) target.getFeature();
				output.add(declaringType);
				return true;
			}
		}
		output.add(((JvmFeature) call.getFeature()).getDeclaringType());
		return true;
	}
	final XExpression receiver = call.getActualReceiver();
	if (receiver == null) {
		return false;
	}
	final XExpression implicit = call.getImplicitReceiver();
	if (receiver == implicit) {
		output.add(thisKeyword.apply());
	} else {
		output.add(receiver);
		if (receiver instanceof XAbstractFeatureCall) {
			// some local types have a reference name bound to the empty string
			// which is the reason why we have to check for an empty string as a valid
			// reference name here
			// see AnonymousClassCompilerTest.testCapturedLocalVar_04
			// if it turns out that we have to deal with generics there too, we may
			// have to create a field in the synthesized local class with a unique
			// name that points to 'this'
			if (((XAbstractFeatureCall) receiver).getFeature() instanceof JvmType) {
				final String referenceName = referenceNameDefinition.apply(receiver);
				if (referenceName != null && referenceName.length() == 0) {
					return false;
				}
			}
		}
	}
	return true;
}