use of org.eclipse.xtext.common.types.JvmDeclaredType 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.JvmDeclaredType 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.JvmDeclaredType in project xtext-xtend by eclipse.
the class XtendImportsConfiguration method getLocallyDefinedTypes.
@Override
public Iterable<JvmDeclaredType> getLocallyDefinedTypes(XtextResource resource) {
XtendFile xtendFile = getXtendFile(resource);
if (xtendFile == null)
return emptyList();
final List<JvmDeclaredType> locallyDefinedTypes = newArrayList();
for (XtendTypeDeclaration xtendType : xtendFile.getXtendTypes()) {
for (EObject inferredElement : associations.getJvmElements(xtendType)) {
if (inferredElement instanceof JvmDeclaredType) {
JvmDeclaredType declaredType = (JvmDeclaredType) inferredElement;
locallyDefinedTypes.add(declaredType);
addInnerTypes(declaredType, new IAcceptor<JvmDeclaredType>() {
@Override
public void accept(JvmDeclaredType t) {
locallyDefinedTypes.add(t);
}
});
}
}
}
return locallyDefinedTypes;
}
use of org.eclipse.xtext.common.types.JvmDeclaredType 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.JvmDeclaredType in project xtext-xtend by eclipse.
the class AnonymousClassUtil method getSuperTypeNonResolving.
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;
}
Aggregations