org.eclipse.xtext.xbase.XConstructorCall Java Examples

The following examples show how to use org.eclipse.xtext.xbase.XConstructorCall. 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: XtendEObjectAtOffsetHelper.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected EObject resolveCrossReferencedElement(INode node) {
	EObject referencedElement = super.resolveCrossReferencedElement(node);
	EObject referenceOwner = NodeModelUtils.findActualSemanticObjectFor(node);
	if(referenceOwner instanceof XConstructorCall) {
		if (referenceOwner.eContainer() instanceof AnonymousClass) {
			AnonymousClass anon = (AnonymousClass) referenceOwner.eContainer();
			JvmGenericType superType = anonymousClassUtil.getSuperType(anon);
			if(superType != null) {
				if (referencedElement instanceof JvmGenericType)  
					return superType;
				else if(referencedElement instanceof JvmConstructor) {
					if(superType.isInterface())
						return superType;
					JvmConstructor superConstructor = anonymousClassUtil.getSuperTypeConstructor(anon);
					if(superConstructor != null)
						return superConstructor;
				}
			}
		}
	}
	return referencedElement;
}
 
Example #2
Source File: AnonymousClassUtil.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
public JvmDeclaredType getSuperTypeNonResolving(AnonymousClass anonymousClass, IScope typeScope) {
	XConstructorCall constructorCall = anonymousClass.getConstructorCall();
	EObject constructorProxy = (EObject) constructorCall.eGet(XbasePackage.Literals.XCONSTRUCTOR_CALL__CONSTRUCTOR, false);
	IEObjectDescription description = null;
	if (constructorProxy != null) {
		if (!constructorProxy.eIsProxy()) {
			return getSuperType(anonymousClass);
		}
		String fragment = EcoreUtil.getURI(constructorProxy).fragment();
		INode node = uriEncoder.getNode(constructorCall, fragment);
		String name = linkingHelper.getCrossRefNodeAsString(node, true);
		QualifiedName superTypeName = qualifiedNameConverter.toQualifiedName(name);
		description = typeScope.getSingleElement(superTypeName);
	}
	if (description == null || !EcoreUtil2.isAssignableFrom(TypesPackage.Literals.JVM_DECLARED_TYPE, description.getEClass())) {
		description = typeScope.getSingleElement(QualifiedName.create("java", "lang", "Object"));
	}
	if (description != null && EcoreUtil2.isAssignableFrom(TypesPackage.Literals.JVM_DECLARED_TYPE, description.getEClass())) {
		JvmDeclaredType type = (JvmDeclaredType) description.getEObjectOrProxy();
		if (!type.eIsProxy())
			return type;
		return (JvmDeclaredType) EcoreUtil.resolve(type, anonymousClass);
	}
	return null;
}
 
Example #3
Source File: XbaseInterpreter.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected Object _doEvaluate(XConstructorCall constructorCall, IEvaluationContext context, CancelIndicator indicator) {
	JvmConstructor jvmConstructor = constructorCall.getConstructor();
	List<Object> arguments = evaluateArgumentExpressions(jvmConstructor, constructorCall.getArguments(), context, indicator);
	Constructor<?> constructor = javaReflectAccess.getConstructor(jvmConstructor);
	try {
		if (constructor == null)
			throw new NoSuchMethodException("Could not find constructor " + jvmConstructor.getIdentifier());
		constructor.setAccessible(true);
		Object result = constructor.newInstance(arguments.toArray(new Object[arguments.size()]));
		return result;
	} catch (InvocationTargetException targetException) {
		throw new EvaluationException(targetException.getTargetException());
	} catch (Exception e) {
		throw new IllegalStateException("Could not invoke constructor: " + jvmConstructor.getIdentifier(), e);
	}
}
 
Example #4
Source File: UIStringsTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
/** Only the simple name of the type is specified.
 * The JvmTypeReference is not a proxy.
 */
@Test
public void testReferenceToString_0() throws Exception {
	XtendFile file = file(
			  "package org.eclipse.xtend.core.tests.validation.uistrings\n"
			+ "public interface InterfaceA { }\n"
			+ "public class ClassB implements InterfaceA { }\n"
			+ "public class ClassC extends ClassB {\n"
			+ "}\n"
			+ "class XtendClass1 {\n"
			+ "  def test() {\n"
			+ "    val x = new List<ClassC>\n"
			+ "  }\n"
			+ "}\n");
	XtendClass clazz = (XtendClass) file.getXtendTypes().get(3);
	XBlockExpression block = (XBlockExpression) ((XtendFunction) clazz.getMembers().get(0)).getExpression();
	XVariableDeclaration declaration = (XVariableDeclaration) block.getExpressions().get(0);
	XConstructorCall cons = (XConstructorCall) declaration.getRight();
	JvmTypeReference reference = cons.getTypeArguments().get(0);
	assertNotNull(reference);
	assertNotNull(reference.getType());
	assertFalse(reference.getType().eIsProxy());
	assertNotNull(reference.eResource());
	assertEquals("ClassC", this.uiStrings.referenceToString(reference, "the-default-label"));
}
 
Example #5
Source File: XbaseCompiler.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void _toJavaStatement(final XConstructorCall expr, ITreeAppendable b, final boolean isReferenced) {
	for (XExpression arg : expr.getArguments()) {
		prepareExpression(arg, b);
	}
	
	if (!isReferenced) {
		b.newLine();
		constructorCallToJavaExpression(expr, b);
		b.append(";");
	} else if (isVariableDeclarationRequired(expr, b, true)) {
		Later later = new Later() {
			@Override
			public void exec(ITreeAppendable appendable) {
				constructorCallToJavaExpression(expr, appendable);
			}
		};
		declareFreshLocalVariable(expr, b, later);
	}
}
 
Example #6
Source File: BrokenConstructorCallAwareEObjectAtOffsetHelper.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected EObject resolveCrossReferencedElement(INode node) {
	EObject referenceOwner = NodeModelUtils.findActualSemanticObjectFor(node);
	if (referenceOwner != null) {
		EReference crossReference = GrammarUtil.getReference((CrossReference) node.getGrammarElement(),
				referenceOwner.eClass());
		if (!crossReference.isMany()) {
			EObject resultOrProxy = (EObject) referenceOwner.eGet(crossReference);
			if (resultOrProxy != null && resultOrProxy.eIsProxy() && crossReference == XbasePackage.Literals.XCONSTRUCTOR_CALL__CONSTRUCTOR) {
				if (referenceOwner instanceof XConstructorCall) {
					JvmIdentifiableElement linkedType = batchTypeResolver.resolveTypes(referenceOwner).getLinkedFeature((XConstructorCall)referenceOwner);
					if (linkedType != null)
						return linkedType;
				}
			} 
			return resultOrProxy;
		} else {
			return super.resolveCrossReferencedElement(node);
		}
	}
	return null;
}
 
Example #7
Source File: XtendCompiler.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected boolean isVariableDeclarationRequired(XExpression expr, ITreeAppendable b, boolean recursive) {
	boolean result = super.isVariableDeclarationRequired(expr, b, recursive);
	if (result && expr instanceof XConstructorCall) {
		EObject container = expr.eContainer();
		if (container instanceof AnonymousClass) {
			AnonymousClass anonymousClass = (AnonymousClass) container;
			result = isVariableDeclarationRequired(anonymousClass, b, recursive);
			if (result) {
				JvmConstructor constructor = anonymousClass.getConstructorCall().getConstructor();
				JvmDeclaredType type = constructor.getDeclaringType();
				if (((JvmGenericType) type).isAnonymous()) {
					return false;
				}
			}
		}
	}
	return result;
}
 
Example #8
Source File: AbstractTypeComputationState.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public List<IConstructorLinkingCandidate> getLinkingCandidates(XConstructorCall constructorCall) {
	IConstructorLinkingCandidate result = reentrantTypeResolver.getScopeProviderAccess().getKnownConstructor(constructorCall, this, resolvedTypes);
	if(result != null) {
		return Collections.singletonList(result);
	}
	EObject proxyOrResolved = (EObject) constructorCall.eGet(XbasePackage.Literals.XCONSTRUCTOR_CALL__CONSTRUCTOR, false);
	Iterable<IEObjectDescription> descriptions = reentrantTypeResolver.getScopeProviderAccess().getCandidateDescriptions(
			constructorCall, XbasePackage.Literals.XCONSTRUCTOR_CALL__CONSTRUCTOR, proxyOrResolved, featureScopeSession, resolvedTypes);
	List<IConstructorLinkingCandidate> resultList = Lists.newArrayList();
	for(IEObjectDescription description: descriptions) {
		resultList.add(createCandidate(constructorCall, toIdentifiableDescription(description)));
	}
	if (resultList.isEmpty()) {
		resultList.add(new NullConstructorLinkingCandidate(constructorCall, this));
	}
	return resultList;
}
 
Example #9
Source File: XbaseSyntacticSequencer.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Syntax: '('*
 */
@Override
protected void emit_XParenthesizedExpression_LeftParenthesisKeyword_0_a(EObject semanticObject,
		ISynNavigable transition, List<INode> nodes) {

	Keyword kw = grammarAccess.getXParenthesizedExpressionAccess().getLeftParenthesisKeyword_0();

	if (nodes == null) {
		if (semanticObject instanceof XIfExpression || semanticObject instanceof XTryCatchFinallyExpression) {
			EObject cnt = semanticObject.eContainer();
			if (cnt instanceof XExpression && !(cnt instanceof XBlockExpression)
					&& !(cnt instanceof XForLoopExpression))
				acceptUnassignedKeyword(kw, kw.getValue(), null);
		}
		if (semanticObject instanceof XConstructorCall) {
			XConstructorCall call = (XConstructorCall) semanticObject;
			if (!call.isExplicitConstructorCall() && call.getArguments().isEmpty()) {
				acceptUnassignedKeyword(kw, kw.getValue(), null);
			}
		}
	}
	acceptNodes(transition, nodes);
}
 
Example #10
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 #11
Source File: XExpressionHelper.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @return whether the expression itself (not its children) possibly causes a side-effect
 */
public boolean hasSideEffects(XExpression expr) {
	if (expr instanceof XClosure
		|| expr instanceof XStringLiteral
		|| expr instanceof XTypeLiteral
		|| expr instanceof XBooleanLiteral
		|| expr instanceof XNumberLiteral
		|| expr instanceof XNullLiteral
		|| expr instanceof XAnnotation
		)
		return false;
	if(expr instanceof XCollectionLiteral) {
		for(XExpression element: ((XCollectionLiteral)expr).getElements()) {
			if(hasSideEffects(element))
				return true;
		}
		return false;
	}
	if (expr instanceof XAbstractFeatureCall) {
		XAbstractFeatureCall featureCall = (XAbstractFeatureCall) expr;
		return hasSideEffects(featureCall, true);
	}
	if (expr instanceof XConstructorCall) {
		XConstructorCall constrCall = (XConstructorCall) expr;
		return findPureAnnotation(constrCall.getConstructor()) == null;
	}
	return true;
}
 
Example #12
Source File: XbaseCompiler.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected ILocationData getLocationWithNewKeyword(XConstructorCall call) {
	final ICompositeNode startNode = NodeModelUtils.getNode(call);
	if (startNode != null) {
		List<INode> resultNodes = Lists.newArrayList();
		for (INode child : startNode.getChildren()) {
			if (child.getGrammarElement() instanceof Keyword && "(".equals(child.getText()))
				break;
			resultNodes.add(child);
		}
		return toLocationData(resultNodes);
	}
	return null;
}
 
Example #13
Source File: ImportsCollector.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public void visit(final EObject jvmType, final INode originNode, final ImportsAcceptor acceptor) {
  if (jvmType instanceof JvmGenericType) {
    _visit((JvmGenericType)jvmType, originNode, acceptor);
    return;
  } else if (jvmType instanceof JvmDeclaredType) {
    _visit((JvmDeclaredType)jvmType, originNode, acceptor);
    return;
  } else if (jvmType instanceof XFeatureCall) {
    _visit((XFeatureCall)jvmType, originNode, acceptor);
    return;
  } else if (jvmType instanceof XMemberFeatureCall) {
    _visit((XMemberFeatureCall)jvmType, originNode, acceptor);
    return;
  } else if (jvmType instanceof XAbstractFeatureCall) {
    _visit((XAbstractFeatureCall)jvmType, originNode, acceptor);
    return;
  } else if (jvmType instanceof XConstructorCall) {
    _visit((XConstructorCall)jvmType, originNode, acceptor);
    return;
  } else if (jvmType instanceof XTypeLiteral) {
    _visit((XTypeLiteral)jvmType, originNode, acceptor);
    return;
  } else if (jvmType instanceof XAnnotation) {
    _visit((XAnnotation)jvmType, originNode, acceptor);
    return;
  } else if (jvmType instanceof JvmTypeReference) {
    _visit((JvmTypeReference)jvmType, originNode, acceptor);
    return;
  } else if (jvmType != null) {
    _visit(jvmType, originNode, acceptor);
    return;
  } else if (jvmType == null) {
    _visit((Void)null, originNode, acceptor);
    return;
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(jvmType, originNode, acceptor).toString());
  }
}
 
Example #14
Source File: AnonymousClassImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@SuppressWarnings("unchecked")
@Override
public void eSet(int featureID, Object newValue)
{
	switch (featureID)
	{
		case XtendPackage.ANONYMOUS_CLASS__ANNOTATIONS:
			getAnnotations().clear();
			getAnnotations().addAll((Collection<? extends XAnnotation>)newValue);
			return;
		case XtendPackage.ANONYMOUS_CLASS__ANNOTATION_INFO:
			setAnnotationInfo((XtendAnnotationTarget)newValue);
			return;
		case XtendPackage.ANONYMOUS_CLASS__MODIFIERS:
			getModifiers().clear();
			getModifiers().addAll((Collection<? extends String>)newValue);
			return;
		case XtendPackage.ANONYMOUS_CLASS__DECLARING_TYPE:
			setDeclaringType((XtendTypeDeclaration)newValue);
			return;
		case XtendPackage.ANONYMOUS_CLASS__NAME:
			setName((String)newValue);
			return;
		case XtendPackage.ANONYMOUS_CLASS__MEMBERS:
			getMembers().clear();
			getMembers().addAll((Collection<? extends XtendMember>)newValue);
			return;
		case XtendPackage.ANONYMOUS_CLASS__CONSTRUCTOR_CALL:
			setConstructorCall((XConstructorCall)newValue);
			return;
	}
	super.eSet(featureID, newValue);
}
 
Example #15
Source File: TypeUsageCollector.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected JvmIdentifiableElement getReferencedElement(EObject owner, EReference reference) {
	JvmIdentifiableElement referencedThing = (JvmIdentifiableElement) owner.eGet(reference);
	if (referencedThing != null && owner instanceof XConstructorCall && referencedThing.eIsProxy()) {
		JvmIdentifiableElement potentiallyLinkedType = batchTypeResolver.resolveTypes(owner).getLinkedFeature((XConstructorCall)owner);
		if (potentiallyLinkedType != null && !potentiallyLinkedType.eIsProxy()) {
			referencedThing = potentiallyLinkedType;
		}
	}
	return referencedThing;
}
 
Example #16
Source File: DefaultEarlyExitComputer.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected Collection<IEarlyExitComputer.ExitPoint> _exitPoints(final XConstructorCall expression) {
  EList<XExpression> _arguments = expression.getArguments();
  for (final XExpression argument : _arguments) {
    {
      Collection<IEarlyExitComputer.ExitPoint> argumentExitPoints = this.getExitPoints(argument);
      boolean _isNotEmpty = this.isNotEmpty(argumentExitPoints);
      if (_isNotEmpty) {
        return argumentExitPoints;
      }
    }
  }
  return Collections.<IEarlyExitComputer.ExitPoint>emptyList();
}
 
Example #17
Source File: XtendHoverSignatureProviderTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testSignatureConstructorCall_03() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("package testPackage");
    _builder.newLine();
    _builder.append("class Foo<S> {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def bar() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("new Foo<String>()");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet());
    final XtendClass clazz = IterableExtensions.<XtendClass>head(Iterables.<XtendClass>filter(xtendFile.getXtendTypes(), XtendClass.class));
    XtendMember _get = clazz.getMembers().get(0);
    final XtendFunction xtendFunction = ((XtendFunction) _get);
    XExpression _expression = xtendFunction.getExpression();
    XExpression _get_1 = ((XBlockExpression) _expression).getExpressions().get(0);
    final XConstructorCall constructorCall = ((XConstructorCall) _get_1);
    final String signature = this.signatureProvider.getSignature(constructorCall);
    Assert.assertEquals("Foo<String>()", signature);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #18
Source File: XbaseHoverProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.3
 */
protected EObject getObjectToView(EObject object) {
	if (object instanceof XAbstractFeatureCall) {
		return ((XAbstractFeatureCall) object).getFeature();
	} else if (object instanceof XConstructorCall)
		return ((XConstructorCall) object).getConstructor();
	return object;
}
 
Example #19
Source File: XbaseCopyQualifiedNameService.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected IResolvedExecutable resolveExecutable(JvmExecutable consturctor, XExpression expression, IResolvedTypes resolvedTypes) {
	if (consturctor instanceof JvmConstructor && expression instanceof XAbstractFeatureCall) {
		return _resolveExecutable((JvmConstructor) consturctor, (XAbstractFeatureCall) expression, resolvedTypes);
	} else if (consturctor instanceof JvmConstructor && expression instanceof XConstructorCall) {
		return _resolveExecutable((JvmConstructor) consturctor, (XConstructorCall) expression, resolvedTypes);
	} else if (consturctor instanceof JvmOperation && expression instanceof XAbstractFeatureCall) {
		return _resolveExecutable((JvmOperation) consturctor, (XAbstractFeatureCall) expression, resolvedTypes);
	} else {
		throw new IllegalArgumentException(
				"Unhandled parameter types: " + Arrays.asList(consturctor, expression, resolvedTypes).toString());
	}
}
 
Example #20
Source File: UIStringsTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
/** The qualified name of the type is specified.
 * The JvmTypeReference is proxy.
 */
@Test
public void testReferenceToString_3() throws Exception {
	XtendFile file1 = file(
			  "package org.eclipse.xtend.core.tests.validation.uistrings\n"
			+ "public interface InterfaceA { }\n"
			+ "public class ClassB implements InterfaceA { }\n"
			+ "public class ClassC extends ClassB {\n"
			+ "}\n");
	assertNotNull(file1);
	XtendFile file2 = file(
			  "package org.eclipse.xtend.core.tests.validation.uistrings\n"
			+ "class XtendClass1 {\n"
			+ "  def test() {\n"
			+ "    val x = new List<org.eclipse.xtend.core.tests.validation.uistrings.ClassC>\n"
			+ "  }\n"
			+ "}\n");
	XtendClass clazz = (XtendClass) file2.getXtendTypes().get(0);
	XBlockExpression block = (XBlockExpression) ((XtendFunction) clazz.getMembers().get(0)).getExpression();
	XVariableDeclaration declaration = (XVariableDeclaration) block.getExpressions().get(0);
	XConstructorCall cons = (XConstructorCall) declaration.getRight();
	JvmTypeReference reference = cons.getTypeArguments().get(0);
	assertNotNull(reference);
	assertNotNull(reference.getType());
	assertTrue(reference.getType().eIsProxy());
	assertNotNull(reference.eResource());
	assertEquals("ClassC", this.uiStrings.referenceToString(reference, "the-default-label"));
}
 
Example #21
Source File: UnresolvableConstructorCall.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public List<LightweightTypeReference> getTypeArguments() {
	XConstructorCall constructorCall = getConstructorCall();
	List<JvmTypeReference> typeArguments = constructorCall.getTypeArguments();
	if (typeArguments.isEmpty())
		return Collections.emptyList();
	List<LightweightTypeReference> result = Lists.newArrayList();
	for(JvmTypeReference typeArgument: typeArguments) {
		result.add(getState().getReferenceOwner().toLightweightTypeReference(typeArgument));
	}
	return result;
}
 
Example #22
Source File: XtendHighlightingCalculator.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void highlightConstructorCall(XConstructorCall constructorCall, IHighlightedPositionAcceptor acceptor) {
	if (constructorCall.eContainer() instanceof AnonymousClass) {
		final JvmGenericType superType = anonymousClassUtil.getSuperType((AnonymousClass) constructorCall.eContainer());
		if (superType != null) {
			highlightFeature(acceptor, constructorCall, XbasePackage.Literals.XCONSTRUCTOR_CALL__CONSTRUCTOR, getStyle(superType));
		}
	} else {
		super.highlightConstructorCall(constructorCall, acceptor);
	}
}
 
Example #23
Source File: XtendCompiler.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected void _toJavaExpression(AnonymousClass anonymousClass, ITreeAppendable b) {
	String varName = getReferenceName(anonymousClass, b);
	if (varName != null) {
		b.trace(anonymousClass, false).append(varName);
	} else {
		XConstructorCall constructorCall = anonymousClass.getConstructorCall();
		constructorCallToJavaExpression(constructorCall, b);
		JvmDeclaredType declaringType = constructorCall.getConstructor().getDeclaringType();
		compileAnonymousClassBody(anonymousClass, declaringType, b);
	}
}
 
Example #24
Source File: XtendHoverSignatureProviderTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testSignatureForXtendDefaultConstructor() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("package testPackage");
    _builder.newLine();
    _builder.append("class Foo {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def bar(){");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("new Foo()");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet());
    final XtendClass clazz = IterableExtensions.<XtendClass>head(Iterables.<XtendClass>filter(xtendFile.getXtendTypes(), XtendClass.class));
    XtendMember _get = clazz.getMembers().get(0);
    final XtendFunction xtendFunction = ((XtendFunction) _get);
    XExpression _expression = xtendFunction.getExpression();
    XExpression _get_1 = ((XBlockExpression) _expression).getExpressions().get(0);
    final XConstructorCall constructorCall = ((XConstructorCall) _get_1);
    final String signature = this.signatureProvider.getSignature(constructorCall.getConstructor());
    Assert.assertEquals("Foo()", signature);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #25
Source File: XtendCopyQualifiedNameServiceTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public void assertCopyQualifiedName(final EObject featureCall, final String expectedQualifiedName) {
  if (featureCall instanceof XAbstractFeatureCall) {
    _assertCopyQualifiedName((XAbstractFeatureCall)featureCall, expectedQualifiedName);
    return;
  } else if (featureCall instanceof XConstructorCall) {
    _assertCopyQualifiedName((XConstructorCall)featureCall, expectedQualifiedName);
    return;
  } else if (featureCall != null) {
    _assertCopyQualifiedName(featureCall, expectedQualifiedName);
    return;
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(featureCall, expectedQualifiedName).toString());
  }
}
 
Example #26
Source File: AbstractXbaseLinkingTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testOverloadedConstructors_08() throws Exception {
	XBlockExpression block = (XBlockExpression) expression(
			"{\n" +
			"    var java.util.List<CharSequence> chars = null\n" +
			"    var java.util.List<String> strings = null\n" +
			"    new testdata.OverloadedMethods<Object>(chars, strings)\n" +
			"}");
	XConstructorCall constructorCall = (XConstructorCall) block.getExpressions().get(2);
	JvmConstructor constructor = constructorCall.getConstructor();
	assertNotNull(constructor);
	assertFalse(constructor.eIsProxy());
	assertEquals("testdata.OverloadedMethods.OverloadedMethods(java.lang.Iterable,java.lang.Iterable)", constructor.getIdentifier());
}
 
Example #27
Source File: AbstractXbaseLinkingTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testOverloadedConstructors_03() throws Exception {
	XBlockExpression block = (XBlockExpression) expression(
			"{\n" +
			"    var java.util.List<CharSequence> chars = null\n" +
			"    var java.util.List<String> strings = null\n" +
			"    new testdata.OverloadedMethods<CharSequence>(strings, chars)\n" +
			"}");
	XConstructorCall constructorCall = (XConstructorCall) block.getExpressions().get(2);
	JvmConstructor constructor = constructorCall.getConstructor();
	assertNotNull(constructor);
	assertFalse(constructor.eIsProxy());
	assertEquals("testdata.OverloadedMethods.OverloadedMethods(java.lang.Iterable,java.util.Collection)", constructor.getIdentifier());
}
 
Example #28
Source File: ResolvedTypes.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public IConstructorLinkingCandidate getLinkingCandidate(/* @Nullable */ XConstructorCall constructorCall) {
	if (!shared.allLinking.contains(constructorCall)) {
		return null;
	}
	return (IConstructorLinkingCandidate) doGetCandidate(constructorCall);
}
 
Example #29
Source File: ResolvedTypes.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public JvmIdentifiableElement getLinkedFeature(/* @Nullable */ XConstructorCall constructorCall) {
	if (!shared.allLinking.contains(constructorCall)) {
		return null;
	}
	return doGetLinkedFeature(constructorCall);
}
 
Example #30
Source File: ConstructorScopes.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Creates the constructor scope for {@link XConstructorCall}.
 * The scope will likely contain descriptions for {@link JvmConstructor constructors}.
 * If there is not constructor declared, it may contain {@link JvmType types}.
 * 
 * @param session the currently available visibilityHelper data
 * @param reference the reference that will hold the resolved constructor
 * @param resolvedTypes the currently known resolved types
 */
public IScope createConstructorScope(EObject context, EReference reference, IFeatureScopeSession session, IResolvedTypes resolvedTypes) {
	if (!(context instanceof XConstructorCall)) {
		return IScope.NULLSCOPE;
	}
	/*
	 * We use a type scope here in order to provide better feedback for users,
	 * e.g. if the constructor call refers to an interface or a primitive.
	 */
	final IScope delegateScope = typeScopes.createTypeScope(context, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE, session, resolvedTypes);
	IScope result = new ConstructorTypeScopeWrapper(context, session, delegateScope);
	return result;
}