org.eclipse.xtext.xbase.XMemberFeatureCall Java Examples

The following examples show how to use org.eclipse.xtext.xbase.XMemberFeatureCall. 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: LinkingTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testOverloadedMethods_03() throws Exception {
	XtendFile file = file(
			"import java.util.List\n" +
			"class X {\n" +
			"  def foo() {\n" +
			"    var List<String> strings = null\n" +
			"    var testdata.OverloadedMethods<Object> receiver = null\n" +
			"    receiver.overloaded(strings, strings)\n" +
			"  }\n" +
			"}");
	XtendClass clazz = (XtendClass) file.getXtendTypes().get(0);
	XtendFunction func  = (XtendFunction) clazz.getMembers().get(0);
	XMemberFeatureCall featureCall = (XMemberFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(2);
	JvmIdentifiableElement overloaded = featureCall.getFeature();
	assertNotNull(overloaded);
	assertFalse(overloaded.eIsProxy());
	assertEquals("testdata.OverloadedMethods.overloaded(java.util.List,java.util.List)", overloaded.getIdentifier());
}
 
Example #2
Source File: TypeProviderTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testExpectationRelevantExpressionType_05() throws Exception {
	String clazzString = 
			"class C<T> {\n" +
			"  def String m(String s, Class<? super T>[] types) {\n" + 
			"    this.m('', newArrayList)\n" +  
			"  }\n" +
			"}";
	XtendClass clazz = (XtendClass) file(clazzString, false).getXtendTypes().get(0);
	XtendFunction function = (XtendFunction) clazz.getMembers().get(0);
	XBlockExpression body = (XBlockExpression) function.getExpression();
	XMemberFeatureCall invocation = (XMemberFeatureCall) body.getExpressions().get(0);
	XFeatureCall newArrayList = (XFeatureCall) invocation.getActualArguments().get(1);
	assertEquals("newArrayList", newArrayList.getFeature().getSimpleName());
	assertEquals("Class<? super T>[]", getExpectedType(newArrayList).getSimpleName());
	assertEquals("ArrayList<Class<? super T>>", getType(newArrayList).getSimpleName());
}
 
Example #3
Source File: LinkingTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testOverloadedMethods_02() throws Exception {
	XtendFile file = file(
			"import java.util.List\n" +
			"class X {\n" +
			"  def foo() {\n" +
			"    var List<CharSequence> chars = null\n" +
			"    var List<String> strings = null\n" +
			"    var testdata.OverloadedMethods<Object> receiver = null\n" +
			"    receiver.overloaded(strings, chars)\n" +
			"  }\n" +
			"}");
	XtendClass clazz = (XtendClass) file.getXtendTypes().get(0);
	XtendFunction func  = (XtendFunction) clazz.getMembers().get(0);
	XMemberFeatureCall featureCall = (XMemberFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(3);
	JvmIdentifiableElement overloaded = featureCall.getFeature();
	assertNotNull(overloaded);
	assertFalse(overloaded.eIsProxy());
	assertEquals("testdata.OverloadedMethods.overloaded(java.lang.Iterable,java.util.Collection)", overloaded.getIdentifier());
}
 
Example #4
Source File: LinkingTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testOverloadedMethods_21() throws Exception {
	XtendFile file = file(
			"import java.util.Collection\n" +
			"class X {\n" +
			"  def <T> foo(Collection<T> collection, Iterable<? extends T> elements) {\n" +
			"    val t = elements.head\n" +
			"    collection.addAll(t)\n" +
			"  }\n" +
			"}");
	XtendClass clazz = (XtendClass) file.getXtendTypes().get(0);
	XtendFunction func  = (XtendFunction) clazz.getMembers().get(0);
	XMemberFeatureCall featureCall = (XMemberFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(1);
	JvmIdentifiableElement addAll = featureCall.getFeature();
	assertNotNull(addAll);
	assertFalse(addAll.eIsProxy());
	assertEquals("org.eclipse.xtext.xbase.lib.CollectionExtensions.addAll(java.util.Collection,T[])", addAll.getIdentifier());
}
 
Example #5
Source File: ScopeProviderAccess.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Returns the node that best describes the error, e.g. if there is an expression
 * <code>com::foo::DoesNotExist::method()</code> the error will be rooted at <code>com</code>, but
 * the real problem is <code>com::foo::DoesNotExist</code>.
 */
private INode getErrorNode(XExpression expression, INode node) {
	if (expression instanceof XFeatureCall) {
		XFeatureCall featureCall = (XFeatureCall) expression;
		if (!canBeTypeLiteral(featureCall)) {
			return node;
		}
		if (featureCall.eContainingFeature() == XbasePackage.Literals.XMEMBER_FEATURE_CALL__MEMBER_CALL_TARGET) {
			XMemberFeatureCall container = (XMemberFeatureCall) featureCall.eContainer();
			if (canBeTypeLiteral(container)) {
				boolean explicitStatic = container.isExplicitStatic();
				XMemberFeatureCall outerMost = getLongestTypeLiteralCandidate(container, explicitStatic);
				if (outerMost != null)
					return NodeModelUtils.getNode(outerMost);
			}
		}
	}
	return node;
}
 
Example #6
Source File: XbaseProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected void createReceiverProposals(XExpression receiver, CrossReference crossReference, ContentAssistContext contentAssistContext, ICompletionProposalAcceptor acceptor) {
//		long time = System.currentTimeMillis();
		String ruleName = getConcreteSyntaxRuleName(crossReference);
		Function<IEObjectDescription, ICompletionProposal> proposalFactory = getProposalFactory(ruleName, contentAssistContext);
		IResolvedTypes resolvedTypes = typeResolver.resolveTypes(receiver);
		LightweightTypeReference receiverType = resolvedTypes.getActualType(receiver);
		if (receiverType == null || receiverType.isPrimitiveVoid()) {
			return;
		}
		IExpressionScope expressionScope = resolvedTypes.getExpressionScope(receiver, IExpressionScope.Anchor.RECEIVER);
		// TODO exploit the type name information
		IScope scope;
		if (contentAssistContext.getCurrentModel() != receiver) {
			EObject currentModel = contentAssistContext.getCurrentModel();
			if (currentModel instanceof XMemberFeatureCall && ((XMemberFeatureCall) currentModel).getMemberCallTarget() == receiver) {
				scope = filterByConcreteSyntax(expressionScope.getFeatureScope((XAbstractFeatureCall) currentModel), crossReference);
			} else {
				scope = filterByConcreteSyntax(expressionScope.getFeatureScope(), crossReference);
			}
		} else {
			scope = filterByConcreteSyntax(expressionScope.getFeatureScope(), crossReference);
		}
		getCrossReferenceProposalCreator().lookupCrossReference(scope, receiver, XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, acceptor, getFeatureDescriptionPredicate(contentAssistContext), proposalFactory);
//		System.out.printf("XbaseProposalProvider.createReceiverProposals = %d\n", System.currentTimeMillis() - time);
	}
 
Example #7
Source File: XbaseValidator.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void checkNoJavaStyleTypeCasting(INode node) {
	BidiTreeIterator<INode> iterator = node.getAsTreeIterable().reverse().iterator();
	ILeafNode child = getFirstLeafNode(iterator);
	if (child != null && child.getGrammarElement() == grammarAccess.getXParenthesizedExpressionAccess().getRightParenthesisKeyword_2()) {
		INode expressionNode = getNode(iterator, grammarAccess.getXParenthesizedExpressionAccess().getXExpressionParserRuleCall_1());
		EObject semanticObject = NodeModelUtils.findActualSemanticObjectFor(expressionNode);
		if (semanticObject instanceof XFeatureCall || semanticObject instanceof XMemberFeatureCall) {
			XAbstractFeatureCall featureCall = (XAbstractFeatureCall) semanticObject;
			if (featureCall.isTypeLiteral()) {
				ICompositeNode parenthesizedNode = child.getParent();
				ITextRegion parenthesizedRegion = parenthesizedNode.getTextRegion();
				addIssue("Use 'as' keyword for type casting.", featureCall, parenthesizedRegion.getOffset(), parenthesizedRegion.getLength(), JAVA_STYLE_TYPE_CAST);
			}
		}
	}
}
 
Example #8
Source File: LinkingTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testSugarOverTypeLiteral_02() throws Exception {
	XtendFile file = file(
			"import org.eclipse.emf.ecore.resource.Resource\n" +
			"import org.eclipse.emf.common.util.URI\n" +
			"class C {\n" +
			"	def m(Resource Resource, URI unused) {\n" +
			"		Resource.URI" +
			"	}\n" +
			"}\n"); 
	XtendClass c = (XtendClass) file.getXtendTypes().get(0);
	XtendFunction m = (XtendFunction) c.getMembers().get(0);
	XBlockExpression body = (XBlockExpression) m.getExpression();
	XMemberFeatureCall featureCall = (XMemberFeatureCall) body.getExpressions().get(0);
	JvmIdentifiableElement method = featureCall.getFeature();
	assertEquals("org.eclipse.emf.ecore.resource.Resource.getURI()", method.getIdentifier());
}
 
Example #9
Source File: Bug409780Test.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testConstraintsInfluenceFeatureScope() throws Exception {
	XtendFile file = file(
			"class C {\n" + 
			"	def private a(Iterable<CharSequence> it) {\n" + 
			"		map[ b ].map[ append('') ]\n" + 
			"	}\n" + 
			"	def private <T extends Appendable> T b(CharSequence c) {}\n" + 
			"}"); 
	XtendClass c = (XtendClass) file.getXtendTypes().get(0);
	XtendFunction m = (XtendFunction) c.getMembers().get(0);
	XBlockExpression body = (XBlockExpression) m.getExpression();
	XMemberFeatureCall featureCall = (XMemberFeatureCall) body.getExpressions().get(0);
	JvmIdentifiableElement method = featureCall.getFeature();
	assertEquals("org.eclipse.xtext.xbase.lib.IterableExtensions.map(java.lang.Iterable,org.eclipse.xtext.xbase.lib.Functions$Function1)", method.getIdentifier());
	assertTrue(featureCall.isStatic());
	assertTrue(featureCall.isExtension());
	assertFalse(featureCall.isTypeLiteral());
	LightweightTypeReference type = getType(featureCall);
	assertEquals("java.lang.Iterable<java.lang.Appendable>", type.getIdentifier());
}
 
Example #10
Source File: ImplicitReceiver.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void applyToComputationState() {
	super.applyToComputationState();
	XAbstractFeatureCall featureCall = getFeatureCall();
	if (featureCall instanceof XMemberFeatureCall) {
		XExpression target = ((XMemberFeatureCall) featureCall).getMemberCallTarget();
		if (target == null || !(target instanceof XAbstractFeatureCall))
			throw new IllegalStateException();
		XAbstractFeatureCall targetFeatureCall = (XAbstractFeatureCall) target;
		ResolvedTypes resolvedTypes = getState().getResolvedTypes();
		LightweightTypeReference targetType = resolvedTypes.getActualType(targetFeatureCall.getFeature());
		if (targetType == null) {
			throw new IllegalStateException();
		}
		TypeExpectation expectation = new TypeExpectation(null, getState(), false);
		resolvedTypes.acceptType(targetFeatureCall, expectation, targetType.copyInto(resolvedTypes.getReferenceOwner()), false, ConformanceFlags.UNCHECKED);
	}
}
 
Example #11
Source File: XbaseLocationInFileProvider.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public ITextRegion getSignificantTextRegion(EObject element) {
	if (element instanceof XAbstractFeatureCall) {
		XAbstractFeatureCall typeLiteral = typeLiteralHelper.getRootTypeLiteral((XAbstractFeatureCall) element);
		if (typeLiteral != null) {
			if (typeLiteral instanceof XMemberFeatureCall) {
				XAbstractFeatureCall target = (XAbstractFeatureCall) ((XMemberFeatureCall) typeLiteral).getMemberCallTarget();
				if (target.isTypeLiteral()) {
					return super.getSignificantTextRegion(typeLiteral);
				}
			}
			INode node = NodeModelUtils.findActualNodeFor(typeLiteral);
			if (node != null) {
				return toZeroBasedRegion(node.getTextRegionWithLineInformation());
			}
		}
	}
	return super.getSignificantTextRegion(element);
}
 
Example #12
Source File: Utils.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Replies the root feature call into a sequence of feature calls that has
 * not reference to elements declared within the container, and that are
 * not one of the container's parameters.
 *
 * @param featureCall the leaf feature call.
 * @param container the container of the feature call.
 * @param containerParameters the parameters of the container.
 * @return the root feature call, or {@code null} if there is no root feature call.
 * @since 0.8.6
 * @see #getRootFeatureCall(XAbstractFeatureCall)
 */
public static XAbstractFeatureCall getRootFeatureCall(XAbstractFeatureCall featureCall,
		XExpression container, List<JvmFormalParameter> containerParameters) {
	if (hasLocalParameters(featureCall, container, containerParameters)
			|| !(featureCall instanceof XMemberFeatureCall || featureCall instanceof XFeatureCall)) {
		return null;
	}
	XAbstractFeatureCall current = featureCall;
	EObject currentContainer = current.eContainer();
	while (currentContainer != null) {
		if (currentContainer instanceof XMemberFeatureCall || currentContainer instanceof XFeatureCall) {
			final XAbstractFeatureCall c = (XAbstractFeatureCall) currentContainer;
			if (hasLocalParameters(c, container, containerParameters)) {
				return current;
			}
			current = c;
			currentContainer = current.eContainer();
		} else {
			return current;
		}
	}
	return current;
}
 
Example #13
Source File: LinkingTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testOverloadedMethods_04() throws Exception {
	XtendFile file = file(
			"import java.util.List\n" +
			"class X {\n" +
			"  def foo() {\n" +
			"    var List<? extends Object> objects = null\n" +
			"    var testdata.OverloadedMethods<Object> receiver = null\n" +
			"    receiver.overloaded(objects, objects)\n" +
			"  }\n" +
			"}");
	XtendClass clazz = (XtendClass) file.getXtendTypes().get(0);
	XtendFunction func  = (XtendFunction) clazz.getMembers().get(0);
	XMemberFeatureCall featureCall = (XMemberFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(2);
	JvmIdentifiableElement overloaded = featureCall.getFeature();
	assertNotNull(overloaded);
	assertFalse(overloaded.eIsProxy());
	assertEquals("testdata.OverloadedMethods.overloaded(java.lang.Iterable,java.lang.Iterable)", overloaded.getIdentifier());
}
 
Example #14
Source File: TypeComputationStateTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testTypeOnlyRegisteredOnce_02() throws Exception {
	XMemberFeatureCall expression = ((XMemberFeatureCall) expression("1.toString"));
	resolver.initializeFrom(expression);
	PublicResolvedTypes resolution = new PublicResolvedTypes(resolver);
	AnyTypeReference any = resolution.getReferenceOwner().newAnyTypeReference();
	new ExpressionBasedRootTypeComputationState(resolution, resolver.getBatchScopeProvider().newSession(expression.eResource()),
			expression, any).computeTypes();
	Map<XExpression, List<TypeData>> expressionTypes = resolution.basicGetExpressionTypes();
	TreeIterator<EObject> allContents = expression.eAllContents();
	while (allContents.hasNext()) {
		EObject o = allContents.next();
		List<TypeData> types = expressionTypes.get(o);
		assertEquals(types.toString(), 1, size(filter(types, it -> !it.isReturnType())));
	}
}
 
Example #15
Source File: LinkingTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testOverloadedMethods_11() throws Exception {
	XtendFile file = file(
			"import java.util.List\n" +
			"class X {\n" +
			"  def foo() {\n" +
			"    var Integer i = 0\n" +
			"    var testdata.OverloadedMethods<Object> receiver = null\n" +
			"    receiver.overloadedInt(i)\n" +
			"  }\n" +
			"}");
	XtendClass clazz = (XtendClass) file.getXtendTypes().get(0);
	XtendFunction func  = (XtendFunction) clazz.getMembers().get(0);
	XMemberFeatureCall featureCall = (XMemberFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(2);
	JvmIdentifiableElement overloaded = featureCall.getFeature();
	assertNotNull(overloaded);
	assertFalse(overloaded.eIsProxy());
	assertEquals("testdata.OverloadedMethods.overloadedInt(java.lang.Integer)", overloaded.getIdentifier());
}
 
Example #16
Source File: LinkingTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testExplicitTypeOverSugar_02() throws Exception {
	XtendFile file = file(
			"import static extension org.eclipse.emf.ecore.util.EcoreUtil.*\n" + 
			"import org.eclipse.emf.ecore.EObject\n" + 
			"import org.eclipse.emf.common.util.URI\n" + 
			"\n" + 
			"class C {\n" + 
			"  def m(EObject it) {\n" + 
			"    URI.appendFragment(\"someString\")\n" + 
			"  }\n" + 
			"}"); 
	XtendClass c = (XtendClass) file.getXtendTypes().get(0);
	XtendFunction m = (XtendFunction) c.getMembers().get(0);
	XBlockExpression body = (XBlockExpression) m.getExpression();
	XMemberFeatureCall featureCall = (XMemberFeatureCall) body.getExpressions().get(0);
	JvmIdentifiableElement method = featureCall.getFeature();
	assertEquals("org.eclipse.emf.common.util.URI.appendFragment(java.lang.String)", method.getIdentifier());
	assertFalse(featureCall.isStaticWithDeclaringType());
	XFeatureCall target = (XFeatureCall) featureCall.getMemberCallTarget();
	assertFalse(target.isTypeLiteral());
	assertEquals("org.eclipse.emf.ecore.util.EcoreUtil.getURI(org.eclipse.emf.ecore.EObject)", target.getFeature().getIdentifier());
}
 
Example #17
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 #18
Source File: LinkingTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testOverloadedMethods_17() throws Exception {
	XtendFile file = file(
			"import java.util.Collection\n" +
			"class X {\n" +
			"  def <T> foo(Collection<? super T> collection, Iterable<? extends T> elements) {\n" +
			"    collection.addAll(elements.head)\n" +
			"  }\n" +
			"}");
	XtendClass clazz = (XtendClass) file.getXtendTypes().get(0);
	XtendFunction func  = (XtendFunction) clazz.getMembers().get(0);
	XMemberFeatureCall featureCall = (XMemberFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(0);
	JvmIdentifiableElement addAll = featureCall.getFeature();
	assertNotNull(addAll);
	assertFalse(addAll.eIsProxy());
	assertEquals("org.eclipse.xtext.xbase.lib.CollectionExtensions.addAll(java.util.Collection,T[])", addAll.getIdentifier());
}
 
Example #19
Source File: LinkingTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testOverloadedMethods_06() throws Exception {
	XtendFile file = file(
			"import java.util.List\n" +
			"class X {\n" +
			"  def foo() {\n" +
			"    var List<CharSequence> chars = null\n" +
			"    var List<String> strings = null\n" +
			"    var testdata.OverloadedMethods<CharSequence> receiver = null\n" +
			"    receiver.overloaded2(strings, chars)\n" +
			"  }\n" +
			"}");
	XtendClass clazz = (XtendClass) file.getXtendTypes().get(0);
	XtendFunction func  = (XtendFunction) clazz.getMembers().get(0);
	XMemberFeatureCall featureCall = (XMemberFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(3);
	JvmIdentifiableElement overloaded = featureCall.getFeature();
	assertNotNull(overloaded);
	assertFalse(overloaded.eIsProxy());
	assertEquals("testdata.OverloadedMethods.overloaded2(java.lang.Iterable,java.util.Collection)", overloaded.getIdentifier());
}
 
Example #20
Source File: XbaseIdentifiableTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
	public void testClosureParameter() throws Exception {
//		List<? super String> list = Lists.newArrayList();
//		ListExtensions.map(list, new Functions.Function1<CharSequence, String>() {
//			public String apply(CharSequence p) {
//				return null;
//			}
//		});
//		ListExtensions.map(list, new Functions.Function1<Object, String>() {
//			public String apply(Object p) {
//				return null;
//			}
//		});
		XBlockExpression block = (XBlockExpression) expression(
				"{\n" + 
				"  var java.util.List<? super String> list = null;\n" + 
				"  list.map(e|e)\n" +
				"}");
		XMemberFeatureCall featureCall = (XMemberFeatureCall) block.getExpressions().get(1);
		XClosure closure = (XClosure) featureCall.getMemberCallArguments().get(0);
		JvmFormalParameter e = closure.getDeclaredFormalParameters().get(0);
		LightweightTypeReference typeRef = typeResolver.resolveTypes(closure).getActualType(e);
		assertEquals("java.lang.Object", typeRef.getIdentifier());
	}
 
Example #21
Source File: LinkingTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testOverloadedMethods_15() throws Exception {
	XtendFile file = file(
			"import java.util.Collection\n" +
			"class X {\n" +
			"  def <T> foo(Collection<T> collection, Iterable<? extends T> elements) {\n" +
			"    collection.addAll(elements)\n" +
			"  }\n" +
			"}");
	XtendClass clazz = (XtendClass) file.getXtendTypes().get(0);
	XtendFunction func  = (XtendFunction) clazz.getMembers().get(0);
	XMemberFeatureCall featureCall = (XMemberFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(0);
	JvmIdentifiableElement addAll = featureCall.getFeature();
	assertNotNull(addAll);
	assertFalse(addAll.eIsProxy());
	assertEquals("org.eclipse.xtext.xbase.lib.CollectionExtensions.addAll(java.util.Collection,java.lang.Iterable)", addAll.getIdentifier());
}
 
Example #22
Source File: LinkingTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testImplicitFirstArgument_00_a() throws Exception {
	XtendClass clazz = clazz(
			"class MyXtendClass {\n" + 
			"  def prependHello(String myString) {\n" + 
			"    'Hello '+myString\n" + 
			"  }\n" + 
			"  def testExtensionMethods(String it) {\n" + 
			"    it.prependHello\n" + 
			"  }\n" + 
			"}");
	XtendFunction func= (XtendFunction) clazz.getMembers().get(1);
	XMemberFeatureCall first = (XMemberFeatureCall) ((XBlockExpression)func.getExpression()).getExpressions().get(0);
	JvmOperation firstFeature = (JvmOperation) first.getFeature();
	assertEquals("prependHello", firstFeature.getSimpleName());
	assertNull(first.getInvalidFeatureIssueCode(), first.getInvalidFeatureIssueCode());
	XFeatureCall firstReceiver = (XFeatureCall) first.getImplicitReceiver();
	assertEquals("MyXtendClass", firstReceiver.getFeature().getSimpleName());
}
 
Example #23
Source File: FeatureCallCompiler.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected boolean inlineCallNeedsParenthesis(XAbstractFeatureCall call, String formatString) {
	String trimmedFormatString = formatString.trim();
	if (trimmedFormatString.startsWith("(")) {
		return false;
	}
	if (call.eContainer() instanceof XMemberFeatureCall && call.eContainingFeature() == XbasePackage.Literals.XMEMBER_FEATURE_CALL__MEMBER_CALL_TARGET) {
		XMemberFeatureCall mfc = (XMemberFeatureCall) call.eContainer();
		JvmAnnotationReference inlineAnnotation = expressionHelper.findInlineAnnotation(mfc);
		if (inlineAnnotation != null) {
			return true;
		}
		if (mfc.isExtension()) {
			return false;
		}
		return !trimmedFormatString.endsWith(")");
	}
	return false;
}
 
Example #24
Source File: SARLReentrantTypeResolver.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Create the extension provider dedicated to the access to the used capacity functions.
 *
 * @param thisFeature the current object.
 * @param field the extension field.
 * @return the SARL capacity extension provider, or {@code null}.
 */
protected XAbstractFeatureCall createSarlCapacityExtensionProvider(JvmIdentifiableElement thisFeature, JvmField field) {
	// For capacity call redirection
	if (thisFeature instanceof JvmDeclaredType) {
		final JvmAnnotationReference capacityAnnotation = this.annotationLookup.findAnnotation(field,
				ImportedCapacityFeature.class);
		if (capacityAnnotation != null) {
			final String methodName = Utils.createNameForHiddenCapacityImplementationCallingMethodFromFieldName(
					field.getSimpleName());
			final JvmOperation callerOperation = findOperation((JvmDeclaredType) thisFeature, methodName);
			if (callerOperation != null) {
				final XbaseFactory baseFactory = getXbaseFactory();
				final XMemberFeatureCall extensionProvider = baseFactory.createXMemberFeatureCall();
				extensionProvider.setFeature(callerOperation);
				final XFeatureCall thisAccess = baseFactory.createXFeatureCall();
				thisAccess.setFeature(thisFeature);
				extensionProvider.setMemberCallTarget(thisAccess);
				return extensionProvider;
			}
		}
	}
	return null;
}
 
Example #25
Source File: LinkingTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testInjectedExtensionMethodCall() throws Exception {
	XtendClass clazz = clazz("" +
			"class Foo {" +
			"  @com.google.inject.Inject extension String string" +
			"  def foo() " +
			"    {(1 as int).indexOf()}" +
			"}");
	XtendFunction func = (XtendFunction) clazz.getMembers().get(1);
	final XMemberFeatureCall call = (XMemberFeatureCall)((XBlockExpression)func.getExpression()).getExpressions().get(0);
	assertEquals("java.lang.String.indexOf(int)", call.getFeature().getIdentifier());
	assertEquals("Foo.string", ((XMemberFeatureCall)call.getImplicitReceiver()).getFeature().getIdentifier());
}
 
Example #26
Source File: ErrorTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testErrorModel_020() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("package x");
  _builder.newLine();
  _builder.append("class Y {");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("@com.google.inject.Inject extension test.GenericExtensionMethods<String,Integer> x");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("def foo(String arg) {");
  _builder.newLine();
  _builder.append("\t\t");
  _builder.append("arg.method");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("}");
  _builder.newLine();
  _builder.append("}");
  _builder.newLine();
  final XtendFile file = this.processWithoutException(_builder);
  final XtendTypeDeclaration y = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
  XtendMember _last = IterableExtensions.<XtendMember>last(y.getMembers());
  final XtendFunction function = ((XtendFunction) _last);
  XExpression _expression = function.getExpression();
  final XBlockExpression body = ((XBlockExpression) _expression);
  XExpression _head = IterableExtensions.<XExpression>head(body.getExpressions());
  final XMemberFeatureCall featureCall = ((XMemberFeatureCall) _head);
  XExpression _implicitReceiver = featureCall.getImplicitReceiver();
  final XMemberFeatureCall implicitReceiver = ((XMemberFeatureCall) _implicitReceiver);
  final XExpression this_ = implicitReceiver.getMemberCallTarget();
  final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(this_);
  Assert.assertNotNull(resolvedTypes.getActualType(this_));
}
 
Example #27
Source File: LinkingTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testQualifiedThis() throws Exception {
	XtendFile file = file(
			"class C {\n" + 
			"  def void m() { C.this.m2() }\n" +
			"  def void m2() {}\n" +
			"}");
	XtendClass c = (XtendClass) file.getXtendTypes().get(0);
	XtendFunction n = (XtendFunction) c.getMembers().get(0);
	XBlockExpression body = (XBlockExpression) n.getExpression();
	XMemberFeatureCall featureCall = (XMemberFeatureCall) body.getExpressions().get(0);
	JvmIdentifiableElement feature = featureCall.getFeature();
	assertEquals("C.m2()", feature.getIdentifier());
}
 
Example #28
Source File: XbaseLocationInFileProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testStaticFeatureCall_06() throws Exception {
	String text = "java::util::UnknownThing::emptyList";
	XMemberFeatureCall featureCall = castedExpression(text);
	ITextRegion region = locationInFileProvider.getFullTextRegion(featureCall, XbasePackage.Literals.XMEMBER_FEATURE_CALL__MEMBER_CALL_TARGET, 0);
	String significant = text.substring(region.getOffset(), region.getOffset() + region.getLength());
	assertEquals("java::util::UnknownThing", significant);
}
 
Example #29
Source File: SerializerTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testSerialize_ExtrasIssue164() throws Exception {
	DerivedStateAwareResource resource = (DerivedStateAwareResource) newResource("org.eclipse.xtext.xbase.tests.serializer.SerializerTest.Demo.demo");
	XMemberFeatureCall call = (XMemberFeatureCall) resource.getContents().get(0);
	ISerializer serializer = get(ISerializer.class);
	call.eAdapters().clear();
	String string = serializer.serialize(call);
	assertEquals("org.eclipse.xtext.xbase.tests.serializer.SerializerTest.Demo.demo", string);
}
 
Example #30
Source File: ParameterContextInformationProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected JvmIdentifiableElement getCalledFeature(XExpression call) {
	if (call instanceof XConstructorCall)
		return ((XConstructorCall) call).getConstructor();
	else if (call instanceof XFeatureCall || call instanceof XMemberFeatureCall)
		return ((XAbstractFeatureCall) call).getFeature();
	else
		return null;
}