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

The following examples show how to use org.eclipse.xtext.xbase.XAbstractFeatureCall#getImplicitFirstArgument() . 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: XtendHoverSerializer.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
public String computeArguments(XAbstractFeatureCall featureCall) {
	StringBuilder stringBuilder = new StringBuilder("(");
	if (featureCall != null) {
		XExpression implicitFirstArgument = featureCall.getImplicitFirstArgument();
		List<XExpression> arguments = featureCall.getActualArguments();
		if (implicitFirstArgument != null) {
			XbaseSwitch<String> xbaseSwitch = new XtendHoverXbaseSwitch();
			String doSwitch = xbaseSwitch.doSwitch(implicitFirstArgument).trim();
			if (doSwitch != null)
				stringBuilder.append(doSwitch);
		}
		int start = implicitFirstArgument != null ? 1 : 0;
		for(int i = start; i < arguments.size(); i++) {
			if (i != 0) {
				stringBuilder.append(SEPARATOR);
			}
			XExpression expression = arguments.get(i);
			ICompositeNode node = NodeModelUtils.findActualNodeFor(expression);
			if (node != null)
				stringBuilder.append(node.getText().trim());
		}
	}
	stringBuilder.append(")");
	return stringBuilder.toString();
}
 
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 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 4
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 5
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 6
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 7
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);
}