use of org.eclipse.xtext.common.types.JvmConstructor in project xtext-xtend by eclipse.
the class XtendCompiler method isVariableDeclarationRequired.
@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;
}
use of org.eclipse.xtext.common.types.JvmConstructor in project xtext-xtend by eclipse.
the class XtendCompiler method _toJavaStatement.
@Override
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);
if (expr.eContainer() instanceof AnonymousClass) {
JvmConstructor constructor = expr.getConstructor();
JvmDeclaredType declaringType = constructor.getDeclaringType();
compileAnonymousClassBody((AnonymousClass) expr.eContainer(), declaringType, b);
}
b.append(";");
} else if (isVariableDeclarationRequired(expr, b, true)) {
Later later = new Later() {
@Override
public void exec(ITreeAppendable appendable) {
constructorCallToJavaExpression(expr, appendable);
if (expr.eContainer() instanceof AnonymousClass) {
JvmConstructor constructor = expr.getConstructor();
JvmDeclaredType declaringType = constructor.getDeclaringType();
compileAnonymousClassBody((AnonymousClass) expr.eContainer(), declaringType, appendable);
}
}
};
declareFreshLocalVariable(expr, b, later);
}
}
use of org.eclipse.xtext.common.types.JvmConstructor in project xtext-xtend by eclipse.
the class AnonymousClassUtil method getSuperType.
/* @Nullable */
public JvmGenericType getSuperType(AnonymousClass anonymousClass) {
JvmConstructor constructor = anonymousClass.getConstructorCall().getConstructor();
if (constructor != null && !constructor.eIsProxy()) {
JvmDeclaredType declaringType = constructor.getDeclaringType();
JvmType superType = Iterables.getLast(declaringType.getSuperTypes()).getType();
if (superType instanceof JvmGenericType)
return (JvmGenericType) superType;
}
return null;
}
use of org.eclipse.xtext.common.types.JvmConstructor in project xtext-xtend by eclipse.
the class XtendJvmModelInferrer method addDefaultConstructor.
protected void addDefaultConstructor(XtendClass source, JvmGenericType target) {
for (XtendMember member : source.getMembers()) {
if (member instanceof XtendConstructor)
return;
}
JvmConstructor constructor = typesFactory.createJvmConstructor();
target.getMembers().add(constructor);
associator.associate(source, constructor);
constructor.setSimpleName(source.getName());
constructor.setVisibility(JvmVisibility.PUBLIC);
typeExtensions.setSynthetic(constructor, true);
}
use of org.eclipse.xtext.common.types.JvmConstructor in project xtext-xtend by eclipse.
the class JvmModelTests method testAnonymousClass_01.
@Test
public void testAnonymousClass_01() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("def foo() {");
_builder.newLine();
_builder.append("\t");
_builder.append("new Runnable() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("int field");
_builder.newLine();
_builder.append("\t\t");
_builder.append("override run() {}");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(this.function(_builder.toString()));
this.typeResolver.resolveTypes(operation.eResource());
Assert.assertEquals(1, operation.getLocalClasses().size());
final JvmGenericType anonymous = IterableExtensions.<JvmGenericType>head(operation.getLocalClasses());
Assert.assertTrue(anonymous.isFinal());
Assert.assertFalse(anonymous.isStatic());
Assert.assertTrue(anonymous.isLocal());
Assert.assertFalse(anonymous.isAnonymous());
Assert.assertEquals(JvmVisibility.DEFAULT, anonymous.getVisibility());
Assert.assertEquals(2, anonymous.getSuperTypes().size());
Assert.assertEquals("java.lang.Runnable", IterableExtensions.<JvmTypeReference>last(anonymous.getSuperTypes()).getQualifiedName());
Assert.assertEquals(3, anonymous.getMembers().size());
final JvmMember constructor = IterableExtensions.<JvmMember>last(anonymous.getMembers());
Assert.assertTrue((constructor instanceof JvmConstructor));
Assert.assertEquals(0, ((JvmConstructor) constructor).getParameters().size());
JvmMember _head = IterableExtensions.<JvmMember>head(anonymous.getMembers());
Assert.assertTrue((_head instanceof JvmField));
final JvmMember overriding = anonymous.getMembers().get(1);
Assert.assertTrue((overriding instanceof JvmOperation));
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
Aggregations