use of org.eclipse.xtext.xbase.XConstructorCall in project xtext-xtend by eclipse.
the class XtendHoverSignatureProviderTest method testSignatureForXtendDefaultConstructor.
@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);
}
}
use of org.eclipse.xtext.xbase.XConstructorCall in project xtext-xtend by eclipse.
the class XtendEObjectAtOffsetHelper method resolveCrossReferencedElement.
@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;
}
use of org.eclipse.xtext.xbase.XConstructorCall in project xtext-xtend by eclipse.
the class XtendSyntacticSequencer method emit_XParenthesizedExpression_LeftParenthesisKeyword_0_a.
/**
* 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);
}
use of org.eclipse.xtext.xbase.XConstructorCall in project xtext-xtend by eclipse.
the class XtendReentrantTypeResolver method doPrepareLocalTypes.
protected void doPrepareLocalTypes(final ResolvedTypes resolvedTypes, IFeatureScopeSession featureScopeSession, JvmFeature container, Map<JvmIdentifiableElement, ResolvedTypes> resolvedTypesByContext) {
List<JvmGenericType> localClasses = container.getLocalClasses();
for (final JvmGenericType localClass : localClasses) {
JvmTypeReference superType = localClass.getSuperTypes().get(0);
final IFeatureScopeSession nestedSession = featureScopeSession;
if (InferredTypeIndicator.isInferred(superType)) {
final XComputedTypeReference casted = (XComputedTypeReference) superType;
InferredTypeIndicator typeProvider = (InferredTypeIndicator) casted.getTypeProvider();
final AnonymousClass anonymousClass = (AnonymousClass) typeProvider.getExpression();
XConstructorCall constructorCall = anonymousClass.getConstructorCall();
IScope typeScope = featureScopeSession.getScope(constructorCall, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE, resolvedTypes);
final JvmDeclaredType type = anonymousClassUtil.getSuperTypeNonResolving(anonymousClass, typeScope);
if (type == null) {
JvmUnknownTypeReference superTypeReference = TypesFactory.eINSTANCE.createJvmUnknownTypeReference();
requestCapturedLocalVariables(superTypeReference, localClass, resolvedTypes, resolvedTypesByContext, new IAcceptor<JvmTypeReference>() {
@Override
public void accept(JvmTypeReference capturingTypeReference) {
casted.setEquivalent(capturingTypeReference);
inferAnonymousClassConstructor(anonymousClass, localClass);
}
});
} else {
final JvmParameterizedTypeReference superTypeReference = createSuperTypeReference(type, constructorCall);
requestCapturedLocalVariables(superTypeReference, localClass, resolvedTypes, resolvedTypesByContext, new IAcceptor<JvmTypeReference>() {
@Override
@SuppressWarnings("deprecation")
public void accept(JvmTypeReference capturingTypeReference) {
casted.setEquivalent(capturingTypeReference);
IFeatureScopeSession mySession = addThisAndSuper(nestedSession, resolvedTypes.getReferenceOwner(), localClass, superTypeReference, false);
if (type.eClass() == TypesPackage.Literals.JVM_GENERIC_TYPE && ((JvmGenericType) type).isInterface()) {
localClass.getSuperTypes().add(0, typesBuilder.newTypeRef(localClass, Object.class));
inferAnonymousClassConstructor(anonymousClass, localClass);
} else {
for (JvmMember superMember : type.getMembers()) {
if (superMember instanceof JvmConstructor) {
JvmConstructor superTypeConstructor = (JvmConstructor) superMember;
boolean visible = mySession.isVisible(superTypeConstructor);
inferAnonymousClassConstructor(anonymousClass, localClass, superTypeConstructor, visible);
}
}
}
}
});
}
}
}
}
use of org.eclipse.xtext.xbase.XConstructorCall in project xtext-xtend by eclipse.
the class XtendCompiler method _toJavaExpression.
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);
}
}
Aggregations