org.eclipse.xtext.xbase.XFeatureCall Java Examples

The following examples show how to use org.eclipse.xtext.xbase.XFeatureCall. 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: TypeProviderTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testExpectationRelevantExpressionType_01() throws Exception {
	String clazzString = "import java.util.Set\n" +
		"import org.eclipse.xtext.xbase.typesystem.util.TypeParameterSubstitutor\n" +
		"import org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference\n" +
		"class C extends TypeParameterSubstitutor<Set<String>> {\n" +
		"  override substitute(LightweightTypeReference original) {\n" + 
		"    original.accept(this, newHashSet)\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 newHashSet = (XFeatureCall) invocation.getActualArguments().get(1);
	assertEquals("newHashSet", newHashSet.getFeature().getSimpleName());
	assertEquals("Set<String>", getExpectedType(newHashSet).getSimpleName());
	assertEquals("HashSet<String>", getType(newHashSet).getSimpleName());
}
 
Example #2
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 #3
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 #4
Source File: AbstractTypeComputationState.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void addExtensionsToCurrentScope(List<? extends JvmIdentifiableElement> extensionProviders) {
	if (extensionProviders.isEmpty())
		return;
	if (extensionProviders.size() == 1) {
		addExtensionToCurrentScope(extensionProviders.get(0));
		return;
	}
	Map<XExpression, LightweightTypeReference> prototypeToType = Maps2.newLinkedHashMapWithExpectedSize(extensionProviders.size());
	for(JvmIdentifiableElement extensionProvider: extensionProviders) {
		LightweightTypeReference knownType = getResolvedTypes().getActualType(extensionProvider);
		if (knownType != null && !knownType.isAny() && !knownType.isUnknown()) {
			XFeatureCall prototype = getResolver().getXbaseFactory().createXFeatureCall();
			prototype.setFeature(extensionProvider);
			prototypeToType.put(prototype, knownType);
		}
	}
	if (!prototypeToType.isEmpty())
		featureScopeSession = featureScopeSession.addToExtensionScope(prototypeToType);
}
 
Example #5
Source File: XbaseValidator.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Check
public void checkDelegateConstructorIsFirst(XFeatureCall featureCall) {
	JvmIdentifiableElement feature = featureCall.getFeature();
	if (feature != null && !feature.eIsProxy() && feature instanceof JvmConstructor) {
		JvmIdentifiableElement container = logicalContainerProvider.getNearestLogicalContainer(featureCall);
		if (container != null) {
			if (container instanceof JvmConstructor) {
				XExpression body = logicalContainerProvider.getAssociatedExpression(container);
				if (body == featureCall)
					return;
				if (body instanceof XBlockExpression) {
					List<XExpression> expressions = ((XBlockExpression) body).getExpressions();
					if (expressions.isEmpty() || expressions.get(0) != featureCall) {
						error("Constructor call must be the first expression in a constructor", null, INVALID_CONSTRUCTOR_INVOCATION);
					}
				}
			} else {
				error("Constructor call must be the first expression in a constructor", null, INVALID_CONSTRUCTOR_INVOCATION);
			}
		}
	}
}
 
Example #6
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 #7
Source File: SarlCompiler.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Replies all the variables that are referenced into the given expression.
 *
 * @param expression the expression.
 * @param onlyWritable if {@code true} only the writable variables are replied. Otherwise, all variables are replied.
 * @return the referenced variables.
 */
@SuppressWarnings("static-method")
protected Map<XVariableDeclaration, XFeatureCall> getReferencedLocalVariable(XExpression expression, boolean onlyWritable) {
	final Map<XVariableDeclaration, XFeatureCall> localVariables = new TreeMap<>((k1, k2) -> {
		return k1.getIdentifier().compareTo(k2.getIdentifier());
	});
	for (final XFeatureCall featureCall : EcoreUtil2.getAllContentsOfType(expression, XFeatureCall.class)) {
		if (featureCall.getFeature() instanceof XVariableDeclaration) {
			final XVariableDeclaration localVariable = (XVariableDeclaration) featureCall.getFeature();
			if ((!onlyWritable || localVariable.isWriteable()) && !localVariables.containsKey(localVariable)) {
				localVariables.put(localVariable, featureCall);
			}
		}
	}
	return localVariables;
}
 
Example #8
Source File: LinkingTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testImplicitFirstArgument_02() throws Exception {
	XtendClass clazz = clazz(
			"import static extension test.ImplicitFirstArgumentStatics.*\n" +
			"class MyXtendClass {\n" + 
			"  def testExtensionMethods(CharSequence it) {\n" + 
			"    toUpperCase\n" +
			"  }\n" +
			"  extension String" +
			"  def toUpperCase() { null }\n" + 
			"}");
	XtendFunction func= (XtendFunction) clazz.getMembers().get(0);
	
	XFeatureCall second = (XFeatureCall) ((XBlockExpression)func.getExpression()).getExpressions().get(0);
	JvmOperation secondFeature = (JvmOperation) second.getFeature();
	assertEquals("MyXtendClass.toUpperCase()", secondFeature.getIdentifier());
	assertEquals(0, secondFeature.getParameters().size());
	assertNull(second.getImplicitFirstArgument());
	XFeatureCall secondReceiver = (XFeatureCall) second.getImplicitReceiver();
	assertTrue(secondReceiver.getFeature() instanceof JvmGenericType);
	assertNull(second.getInvalidFeatureIssueCode());
}
 
Example #9
Source File: FeatureLinkHelper.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
public XExpression getSyntacticReceiver(XExpression expression) {
	if (expression instanceof XAbstractFeatureCall) {
		if (expression instanceof XFeatureCall) {
			return null;
		}
		if (expression instanceof XMemberFeatureCall) {
			return ((XMemberFeatureCall) expression).getMemberCallTarget();
		}
		if (expression instanceof XAssignment) {
			return ((XAssignment) expression).getAssignable();
		}
		if (expression instanceof XBinaryOperation) {
			return ((XBinaryOperation) expression).getLeftOperand();
		}
		if (expression instanceof XUnaryOperation) {
			return ((XUnaryOperation) expression).getOperand();
		}
		if (expression instanceof XPostfixOperation) {
			return ((XPostfixOperation) expression).getOperand();
		}
	}
	return null;
}
 
Example #10
Source File: FeatureLinkHelper.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
public List<XExpression> getSyntacticArguments(XAbstractFeatureCall expression) {
	if (expression instanceof XFeatureCall) {
		return ((XFeatureCall) expression).getFeatureCallArguments();
	}
	if (expression instanceof XMemberFeatureCall) {
		return ((XMemberFeatureCall) expression).getMemberCallArguments();
	}
	if (expression instanceof XAssignment) {
		return Collections.singletonList(((XAssignment) expression).getValue());
	}
	if (expression instanceof XBinaryOperation) {
		return Collections.singletonList(((XBinaryOperation) expression).getRightOperand());
	}
	// explicit condition to make sure we thought about it
	if (expression instanceof XUnaryOperation) {
		return Collections.emptyList();
	}
	if (expression instanceof XPostfixOperation) {
		return Collections.emptyList();
	}
	return Collections.emptyList();
}
 
Example #11
Source File: XtendCompiler.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected boolean needSyntheticSelfVariable(XClosure closure, LightweightTypeReference typeRef) {
	JvmType jvmType = typeRef.getType();
	TreeIterator<EObject> closureIterator = closure.eAllContents();
	while (closureIterator.hasNext()) {
		EObject obj1 = closureIterator.next();
		if (obj1 instanceof XClosure) {
			closureIterator.prune();
		} else if (obj1 instanceof XtendTypeDeclaration) {
			TreeIterator<EObject> typeIterator = obj1.eAllContents();
			while (typeIterator.hasNext()) {
				EObject obj2 = typeIterator.next();
				if (obj2 instanceof XClosure) {
					typeIterator.prune();
				} else if (obj2 instanceof XFeatureCall && isReferenceToSelf((XFeatureCall) obj2, jvmType)) {
					return true;
				}
			}
			closureIterator.prune();
		}
	}
	return false;
}
 
Example #12
Source File: LinkingTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testBug403580_03() throws Exception {
	XtendFile file = file(
			"abstract class C {\n" +
			"	def void m() {\n" +
			"		overloaded [ String s | s ]\n" +
			"	}\n" +
			"	def void overloaded((String)=>String s)" +
			"	def <T> void overloaded(Comparable<T> c)" + 
			"}\n"); 
	XtendClass c = (XtendClass) file.getXtendTypes().get(0);
	XtendFunction m = (XtendFunction) c.getMembers().get(0);
	XBlockExpression body = (XBlockExpression) m.getExpression();
	XFeatureCall featureCall = (XFeatureCall) body.getExpressions().get(0);
	JvmIdentifiableElement method = featureCall.getFeature();
	assertEquals("C.overloaded(org.eclipse.xtext.xbase.lib.Functions$Function1)", method.getIdentifier());
}
 
Example #13
Source File: LinkingTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testTypeOfSuper() throws Exception {
	String classAsString = 
		"class Foo extends java.util.ArrayList<String> {" +
		"	def m() {\n" + 
		"		super.add(null)\n" + 
		"	}\n" +
		"}";
	XtendClass clazz = clazz(classAsString);
	XtendFunction function = (XtendFunction) clazz.getMembers().get(0);
	XExpression body = function.getExpression();
	XBlockExpression block = (XBlockExpression) body;
	XMemberFeatureCall featureCall = (XMemberFeatureCall) block.getExpressions().get(0);
	XFeatureCall superCall = (XFeatureCall) featureCall.getMemberCallTarget();
	LightweightTypeReference type = getType(superCall);
	assertEquals("java.util.ArrayList<java.lang.String>", type.getIdentifier());
}
 
Example #14
Source File: XbaseFormatter.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void _format(final XFeatureCall expr, @Extension final IFormattableDocument format) {
  this.formatFeatureCallTypeParameters(expr, format);
  boolean _isExplicitOperationCall = expr.isExplicitOperationCall();
  if (_isExplicitOperationCall) {
    final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
      it.noSpace();
    };
    final ISemanticRegion open = format.prepend(this.textRegionExtensions.regionFor(expr).keyword(this.grammar.getXFeatureCallAccess().getExplicitOperationCallLeftParenthesisKeyword_3_0_0()), _function);
    final ISemanticRegion close = this.textRegionExtensions.regionFor(expr).keyword(this.grammar.getXFeatureCallAccess().getRightParenthesisKeyword_3_2());
    this.formatFeatureCallParams(expr.getFeatureCallArguments(), open, close, format);
  } else {
    EList<XExpression> _featureCallArguments = expr.getFeatureCallArguments();
    for (final XExpression arg : _featureCallArguments) {
      this.format(arg, format);
    }
  }
}
 
Example #15
Source File: XbaseFormatter2.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void _format(final XFeatureCall expr, final FormattableDocument format) {
  this.formatFeatureCallTypeParameters(expr, format);
  boolean _isExplicitOperationCall = expr.isExplicitOperationCall();
  if (_isExplicitOperationCall) {
    final ILeafNode open = this._nodeModelAccess.nodeForKeyword(expr, "(");
    final Procedure1<FormattingDataInit> _function = (FormattingDataInit it) -> {
      it.noSpace();
    };
    Function1<? super FormattableDocument, ? extends Iterable<FormattingData>> _prepend = this._formattingDataFactory.prepend(open, _function);
    format.operator_add(_prepend);
    boolean _isMultiParamInOwnLine = this.isMultiParamInOwnLine(expr, format);
    if (_isMultiParamInOwnLine) {
      this.formatFeatureCallParamsMultiline(open, expr.getFeatureCallArguments(), format);
    } else {
      this.formatFeatureCallParamsWrapIfNeeded(open, expr.getFeatureCallArguments(), format);
    }
  } else {
    EList<XExpression> _featureCallArguments = expr.getFeatureCallArguments();
    for (final XExpression arg : _featureCallArguments) {
      this.format(arg, format);
    }
  }
}
 
Example #16
Source File: AbstractXbaseCompiler.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected boolean hasJvmConstructorCall(XExpression obj) {
	if (!(obj instanceof XBlockExpression)) {
		return false;
	}
	XBlockExpression blockExpression = (XBlockExpression) obj;
	EList<XExpression> expressions = blockExpression.getExpressions();
	if (expressions.isEmpty()) {
		return false;
	}
	XExpression expr = expressions.get(0);
	if (!(expr instanceof XFeatureCall)) {
		return false;
	}
	XFeatureCall featureCall = (XFeatureCall) expr;
	return featureCall.getFeature() instanceof JvmConstructor;
}
 
Example #17
Source File: LinkingTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testBug403580_04() throws Exception {
	XtendFile file = file(
			"abstract class C {\n" +
			"	def void m() {\n" +
			"		overloaded [ String s | s.length ]\n" +
			"	}\n" +
			"	def void overloaded((String)=>String s)" +
			"	def <T> void overloaded(Comparable<T> c)" + 
			"}\n"); 
	XtendClass c = (XtendClass) file.getXtendTypes().get(0);
	XtendFunction m = (XtendFunction) c.getMembers().get(0);
	XBlockExpression body = (XBlockExpression) m.getExpression();
	XFeatureCall featureCall = (XFeatureCall) body.getExpressions().get(0);
	JvmIdentifiableElement method = featureCall.getFeature();
	assertEquals("C.overloaded(java.lang.Comparable)", method.getIdentifier());
}
 
Example #18
Source File: LinkingTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testDeclaredConstructor_01() throws Exception {
	XtendClass clazz = clazz(
			"class Foo { " +
			"  int i" +
			"  new(int i) { this.i = i }" +
			"}");
	assertEquals(2, clazz.getMembers().size());
	
	XtendConstructor constructor = (XtendConstructor) clazz.getMembers().get(1);
	XAssignment assignment = (XAssignment) ((XBlockExpression)constructor.getExpression()).getExpressions().get(0);
	JvmField field = (JvmField) assignment.getFeature();
	assertEquals("i", field.getSimpleName());
	XFeatureCall target = (XFeatureCall) assignment.getAssignable();
	JvmDeclaredType identifiableElement = (JvmDeclaredType) target.getFeature();
	assertEquals("Foo", identifiableElement.getSimpleName());
	XFeatureCall value = (XFeatureCall) assignment.getValue();
	JvmFormalParameter parameter = (JvmFormalParameter) value.getFeature();
	assertEquals("i", parameter.getSimpleName());
}
 
Example #19
Source File: LinkingTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Ignore("Depends on the order of the overloaded methods")
@Test public void testBug403580_07() throws Exception {
	XtendFile file = file(
			"abstract class C {\n" +
			"	def void m() {\n" +
			"		overloaded [ String s | s.length ]\n" +
			"	}\n" +
			"	def <T> void overloaded(Comparable<T> c)" + 
			"	def void overloaded((String)=>int s)" +
			"}\n"); 
	XtendClass c = (XtendClass) file.getXtendTypes().get(0);
	XtendFunction m = (XtendFunction) c.getMembers().get(0);
	XBlockExpression body = (XBlockExpression) m.getExpression();
	XFeatureCall featureCall = (XFeatureCall) body.getExpressions().get(0);
	JvmIdentifiableElement method = featureCall.getFeature();
	assertEquals("C.overloaded(java.lang.Comparable)", method.getIdentifier());
}
 
Example #20
Source File: LinkingTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testSugarOverTypeLiteral_03() throws Exception {
	XtendFile file = file(
			"import org.eclipse.emf.ecore.EPackage\n" +
			"class C {\n" +
			"	def m(Object it) {\n" +
			"		EPackage" +
			"	}" +
			"	def void getEPackage(Object o) {}\n" +
			"}\n"); 
	XtendClass c = (XtendClass) file.getXtendTypes().get(0);
	XtendFunction m = (XtendFunction) c.getMembers().get(0);
	XBlockExpression body = (XBlockExpression) m.getExpression();
	XFeatureCall featureCall = (XFeatureCall) body.getExpressions().get(0);
	JvmIdentifiableElement method = featureCall.getFeature();
	assertEquals("C.getEPackage(java.lang.Object)", method.getIdentifier());
}
 
Example #21
Source File: SARLExpressionHelper.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Convert the boolean constant to the object equivalent if possible.
 *
 * @param expression the expression to convert.
 * @return one of the boolean constants {@link Boolean#TRUE} or {@link Boolean#FALSE},
 *     or {@code null} if the expression is not a constant boolean expression.
 */
@SuppressWarnings("static-method")
public Boolean toBooleanPrimitiveWrapperConstant(XExpression expression) {
	if (expression instanceof XBooleanLiteral) {
		return ((XBooleanLiteral) expression).isIsTrue() ? Boolean.TRUE : Boolean.FALSE;
	}
	if (expression instanceof XMemberFeatureCall) {
		final XMemberFeatureCall call = (XMemberFeatureCall) expression;
		final XExpression receiver = call.getMemberCallTarget();
		if (receiver instanceof XFeatureCall) {
			final XFeatureCall call2 = (XFeatureCall) receiver;
			final String call2Identifier = call2.getConcreteSyntaxFeatureName();
			if (Boolean.class.getSimpleName().equals(call2Identifier) || Boolean.class.getName().equals(call2Identifier)) {
				final String callIdentifier = call.getConcreteSyntaxFeatureName();
				if ("TRUE".equals(callIdentifier)) { //$NON-NLS-1$
					return Boolean.TRUE;
				} else if ("FALSE".equals(callIdentifier)) { //$NON-NLS-1$
					return Boolean.FALSE;
				}
			}
		}
	}
	return null;
}
 
Example #22
Source File: UnresolvedFeatureCallTypeAwareMessageProvider.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected boolean isStaticMemberCallTarget(final EObject contextObject) {
  boolean candidate = ((contextObject instanceof XFeatureCall) && (contextObject.eContainingFeature() == 
    XbasePackage.Literals.XMEMBER_FEATURE_CALL__MEMBER_CALL_TARGET));
  if (candidate) {
    EObject _eContainer = contextObject.eContainer();
    XMemberFeatureCall memberFeatureCall = ((XMemberFeatureCall) _eContainer);
    boolean _isExplicitStatic = memberFeatureCall.isExplicitStatic();
    if (_isExplicitStatic) {
      return true;
    }
  }
  return false;
}
 
Example #23
Source File: LinkingErrorTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testFieldsAreNotSugared() throws Exception {
	XtendClass clazz = clazz("class A {\n"
			+ " String getFoo\n"
			+ " def String doStuff() {\n" + 
			"	    foo\n" + 
			"	}");
	XFeatureCall call = (XFeatureCall) ((XBlockExpression)((XtendFunction)clazz.getMembers().get(1)).getExpression()).getExpressions().get(0);
	JvmIdentifiableElement feature = call.getFeature();
	assertTrue(feature.eIsProxy());
}
 
Example #24
Source File: JvmModelBasedLinkingTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testLinkToField() throws Exception {
	XFeatureCall expr = (XFeatureCall) expression("x", false);
	Resource resource = expr.eResource();
	resource.eSetDeliver(false);
	resource.getContents().add(jvmTypesBuilder.toClass(expr, "Foo", cls -> {
		cls.getMembers().add(jvmTypesBuilder.toField(expr, "x", stringType(expr)));
		cls.getMembers().add(jvmTypesBuilder.toMethod(expr, "doStuff", stringType(expr), (JvmOperation o) -> {
			o.getParameters().add(jvmTypesBuilder.toParameter(expr, "y", stringType(expr)));
			jvmTypesBuilder.setBody(o, expr);
		}));
	}));
	validationTestHelper.assertNoErrors(expr);
	Assert.assertTrue(expr.getFeature() instanceof JvmField);
}
 
Example #25
Source File: ImportsCollector.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void _visit(final XFeatureCall semanticObj, final INode originNode, final ImportsAcceptor acceptor) {
  if (((semanticObj.getFeature() instanceof JvmType) && semanticObj.isTypeLiteral())) {
    JvmIdentifiableElement _feature = semanticObj.getFeature();
    this.visit(((JvmType) _feature), originNode, acceptor);
  } else {
    this.collectStaticImportsFrom(semanticObj, acceptor);
  }
}
 
Example #26
Source File: ParameterContextInformationProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected Keyword getParameterListOpenParenthesis(XExpression call) {
	if (call instanceof XFeatureCall)
		return grammarAccess.getXFeatureCallAccess().findKeywords("(").get(0);
	else if (call instanceof XMemberFeatureCall)
		return grammarAccess.getXMemberFeatureCallAccess().findKeywords("(").get(0);
	else if (call instanceof XConstructorCall)
		return grammarAccess.getXConstructorCallAccess().findKeywords("(").get(0);
	else
		return null;
}
 
Example #27
Source File: XbaseExpectedTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testTypeParamInference_07() throws Exception {
	XBlockExpression block = (XBlockExpression) expression("{ var this = new testdata.ClosureClient() invoke1([ String e|e.length],'foo') }");
	XFeatureCall fc = (XFeatureCall) block.getExpressions().get(1);
	final XExpression closure = fc.getFeatureCallArguments().get(0);
	assertExpected(Functions.class.getCanonicalName()+"$Function1<java.lang.String, java.lang.Integer>", closure);
}
 
Example #28
Source File: AbstractBatchReturnTypeTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testProxy() throws Exception {
  final XFeatureCall proxy = XbaseFactory.eINSTANCE.createXFeatureCall();
  ((InternalEObject) proxy).eSetProxyURI(URI.createURI("path#fragment"));
  final IResolvedTypes typeResolution = this.getTypeResolver().resolveTypes(proxy);
  Assert.assertNotNull(typeResolution);
  Assert.assertEquals(IResolvedTypes.NULL, typeResolution);
}
 
Example #29
Source File: LinkingErrorTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testResourceVisibleInTry() throws Exception {
	XtendFunction function = function("def tryCatch() {\n" + 
			"	    try(val a = []) a" + 
			"	}");
	XTryCatchFinallyExpression tryCatch = (XTryCatchFinallyExpression) ((XBlockExpression) function.getExpression()).getExpressions().get(0);
	XFeatureCall call = (XFeatureCall) tryCatch.getExpression();
	JvmIdentifiableElement feature = call.getFeature();
	assertFalse(feature.eIsProxy());
}
 
Example #30
Source File: XbaseParserTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testFeatureCall_4() throws Exception {
	XFeatureCall call = (XFeatureCall) expression("bar(0,1,2)");
	assertNotNull(call);
	assertEquals("bar",call.getConcreteSyntaxFeatureName());
	assertEquals(3, call.getExplicitArguments().size());
	for (int i = 0; i < 3; i++)
		assertEquals(""+ i, ((XNumberLiteral) call.getExplicitArguments().get(i)).getValue());
}