use of org.eclipse.xtend.core.xtend.AnonymousClass in project xtext-xtend by eclipse.
the class XtendGenerator method generateMembersInBody.
@Override
public ITreeAppendable generateMembersInBody(final JvmDeclaredType it, final ITreeAppendable appendable, final GeneratorConfig config) {
ITreeAppendable _xifexpression = null;
boolean _isLocal = it.isLocal();
if (_isLocal) {
ITreeAppendable _xblockexpression = null;
{
appendable.append("{").increaseIndentation();
EObject _head = IterableExtensions.<EObject>head(this.getSourceElements(it));
final AnonymousClass anonymousClass = ((AnonymousClass) _head);
if (((!appendable.hasName(Pair.<String, JvmDeclaredType>of("this", it))) && this.needSyntheticThisVariable(anonymousClass, it))) {
final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(anonymousClass);
final LightweightTypeReference actualType = resolvedTypes.getActualType(anonymousClass);
Pair<String, JvmDeclaredType> _mappedTo = Pair.<String, JvmDeclaredType>of("this", it);
final String thisName = appendable.declareSyntheticVariable(_mappedTo, "_this");
appendable.newLine().append("final ").append(actualType).append(" ").append(thisName).append(" = this;");
}
final Function1<JvmField, Boolean> _function = (JvmField it_1) -> {
boolean _xblockexpression_1 = false;
{
Procedure1<? super ITreeAppendable> _compilationStrategy = this._jvmTypeExtensions.getCompilationStrategy(it_1);
boolean _tripleNotEquals = (_compilationStrategy != null);
if (_tripleNotEquals) {
return Boolean.valueOf(true);
} else {
StringConcatenationClient _compilationTemplate = this._jvmTypeExtensions.getCompilationTemplate(it_1);
boolean _tripleNotEquals_1 = (_compilationTemplate != null);
if (_tripleNotEquals_1) {
return Boolean.valueOf(true);
} else {
boolean _not = (!(it_1.isFinal() && it_1.isStatic()));
if (_not) {
final XExpression expression = this._iLogicalContainerProvider.getAssociatedExpression(it_1);
if (((expression != null) && config.isGenerateExpressions())) {
return Boolean.valueOf(true);
}
}
}
}
_xblockexpression_1 = false;
}
return Boolean.valueOf(_xblockexpression_1);
};
final Iterable<JvmField> fieldsWithInitializer = IterableExtensions.<JvmField>filter(it.getDeclaredFields(), _function);
boolean _isEmpty = IterableExtensions.isEmpty(fieldsWithInitializer);
boolean _not = (!_isEmpty);
if (_not) {
appendable.newLine().append("{").increaseIndentation();
final Procedure1<LoopParams> _function_1 = (LoopParams it_1) -> {
final Function1<ITreeAppendable, ITreeAppendable> _function_2 = (ITreeAppendable it_2) -> {
return it_2.newLine();
};
it_1.setSeparator(_function_2);
};
final Procedure1<JvmField> _function_2 = (JvmField it_1) -> {
final ITreeAppendable memberAppendable = this._treeAppendableUtil.traceWithComments(appendable, it_1);
memberAppendable.openScope();
appendable.newLine();
final ITreeAppendable tracedAppendable = appendable.trace(it_1);
this._treeAppendableUtil.traceSignificant(tracedAppendable, it_1).append(it_1.getSimpleName());
this.generateInitialization(it_1, tracedAppendable, config);
tracedAppendable.append(";");
memberAppendable.closeScope();
};
this._loopExtensions.<JvmField>forEach(appendable, fieldsWithInitializer, _function_1, _function_2);
appendable.decreaseIndentation().newLine().append("}");
}
final Procedure1<LoopParams> _function_3 = (LoopParams it_1) -> {
final Function1<ITreeAppendable, ITreeAppendable> _function_4 = (ITreeAppendable it_2) -> {
return it_2.newLine();
};
it_1.setSeparator(_function_4);
};
final Procedure1<JvmMember> _function_4 = (JvmMember it_1) -> {
final ITreeAppendable memberAppendable = this._treeAppendableUtil.traceWithComments(appendable, it_1);
memberAppendable.openScope();
this.generateMember(it_1, memberAppendable, config);
memberAppendable.closeScope();
};
this._loopExtensions.<JvmMember>forEach(appendable, this.getMembersToBeCompiled(it), _function_3, _function_4);
_xblockexpression = appendable.decreaseIndentation().newLine().append("}");
}
_xifexpression = _xblockexpression;
} else {
_xifexpression = super.generateMembersInBody(it, appendable, config);
}
return _xifexpression;
}
use of org.eclipse.xtend.core.xtend.AnonymousClass in project xtext-xtend by eclipse.
the class XtendImportedNamespaceScopeProvider method getSuperTypeOfLocalTypeNonResolving.
protected JvmDeclaredType getSuperTypeOfLocalTypeNonResolving(JvmDeclaredType declarator) {
AnonymousClass anonymousClass = associations.getAnonymousClass(declarator);
if (anonymousClass != null) {
IScope typeScope = getScope(anonymousClass, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE);
JvmDeclaredType superType = anonymousClassUtil.getSuperTypeNonResolving(anonymousClass, typeScope);
if (superType != null) {
return superType;
}
}
return null;
}
use of org.eclipse.xtend.core.xtend.AnonymousClass in project xtext-xtend by eclipse.
the class XtendImportedNamespaceScopeProvider method getScope.
@Override
public IScope getScope(final EObject context, final EReference reference) {
EClass referenceType = reference.getEReferenceType();
if (TypesPackage.Literals.JVM_TYPE.isSuperTypeOf(referenceType)) {
if (context instanceof XImportDeclaration) {
Resource resource = context.eResource();
IJvmTypeProvider typeProvider = typeScopeProvider.getTypeProvider(resource.getResourceSet());
AbstractTypeScope typeScope = typeScopeProvider.createTypeScope(typeProvider, null);
IResourceDescriptions descriptions = resourceDescriptionsProvider.getResourceDescriptions(context.eResource().getResourceSet());
IResourceDescription resourceDescription = descriptions.getResourceDescription(resource.getURI());
if (resourceDescription != null) {
typeScope = new LocalResourceFilteringTypeScope(typeScope, resourceDescription);
}
RecordingTypeScope recordingTypeScope = new RecordingTypeScope(typeScope, getImportedNamesSet(resource), getQualifiedNameConverter());
// TODO this scope doesn't support binary syntax for inner types. It should be a KnownTypes scope which doesn't allow simple names
// Unfortunately I cannot use a RecordingTypeScope as a parent as it is not compatible...
IScope scope = SelectableBasedScope.createScope(recordingTypeScope, getAllDescriptions(resource), reference.getEReferenceType(), false);
return scope;
}
final XtendFile xtendFile = getXtendFile(context);
final Resource resource = xtendFile.eResource();
AbstractScope result = resourceScopeCache.get("type.scope", xtendFile.eResource(), new Provider<AbstractScope>() {
@Override
public AbstractScope get() {
IJvmTypeProvider typeProvider = typeScopeProvider.getTypeProvider(resource.getResourceSet());
AbstractTypeScope typeScope = typeScopeProvider.createTypeScope(typeProvider, null);
IResourceDescriptions descriptions = resourceDescriptionsProvider.getResourceDescriptions(context.eResource().getResourceSet());
IResourceDescription resourceDescription = descriptions.getResourceDescription(resource.getURI());
if (resourceDescription != null) {
typeScope = new LocalResourceFilteringTypeScope(typeScope, resourceDescription);
}
RecordingTypeScope recordingTypeScope = new RecordingTypeScope(typeScope, getImportedNamesSet(resource), getQualifiedNameConverter());
AbstractScope rootTypeScope = getRootTypeScope(xtendFile, recordingTypeScope);
AbstractScope importScope = getImportScope(xtendFile.getImportSection(), rootTypeScope, recordingTypeScope);
AbstractScope localTypes = getResourceTypeScope(xtendFile.eResource(), xtendFile.getPackage(), importScope);
AbstractScope primitiveAware = new PrimitiveAwareScope(localTypes, typeScope);
AbstractScope caching = new CachingTypeScope(primitiveAware);
return caching;
}
});
if (context instanceof AnonymousClass) {
// necessary for the super type of an anonymous class expression
JvmDeclaredType inferredAnonymousType = associations.getInferredType((AnonymousClass) context);
if (inferredAnonymousType != null)
result = new LocalTypeScope(singletonList(inferredAnonymousType), result);
}
XtendMember syntacticContainer = EcoreUtil2.getContainerOfType(context, XtendMember.class);
if (syntacticContainer != null) {
result = getContainerScope(syntacticContainer, result);
}
EObject logicalContainer = logicalContainerProvider.getNearestLogicalContainer(context);
if (logicalContainer != null) {
List<List<JvmTypeParameter>> typeParameters = new ArrayList<List<JvmTypeParameter>>();
while (logicalContainer instanceof JvmTypeParameterDeclarator) {
JvmTypeParameterDeclarator typeParamProvider = (JvmTypeParameterDeclarator) logicalContainer;
if (!typeParamProvider.getTypeParameters().isEmpty()) {
typeParameters.add(typeParamProvider.getTypeParameters());
}
logicalContainer = logicalContainer.eContainer();
}
if (!typeParameters.isEmpty())
result = new TypeParameterScope(typeParameters, result);
}
return result;
} else if (TypesPackage.Literals.JVM_CONSTRUCTOR.isSuperTypeOf(referenceType)) {
IScope typeScope = getScope(context, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE);
// this is not called from the type resolution where we want to allow constructors to link to interfaces
// in order to improve the error message, therefore we use a strict wrapper here
IScope result = new ConstructorTypeScopeWrapper(context, IVisibilityHelper.ALL, typeScope, true);
return result;
} else {
throw new IllegalArgumentException("Unexpected global request for " + reference);
}
}
use of org.eclipse.xtend.core.xtend.AnonymousClass 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.xtend.core.xtend.AnonymousClass 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);
}
}
Aggregations