use of org.eclipse.xtext.common.types.JvmMember 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.xtext.common.types.JvmMember in project xtext-xtend by eclipse.
the class ConstantExpressionsInterpreter method findVisibleFeatures.
/**
* looks up the static final fields which are accessible in unqualified form for the given expression.
* That essentially includes static imports and the fields declared in the containing types
*/
protected Map<String, JvmIdentifiableElement> findVisibleFeatures(final XExpression expression) {
HashMap<String, JvmIdentifiableElement> _xblockexpression = null;
{
Resource _eResource = expression.eResource();
final Resource res = _eResource;
boolean _matched = false;
if (res instanceof StorageAwareResource) {
boolean _isLoadedFromStorage = ((StorageAwareResource) res).isLoadedFromStorage();
if (_isLoadedFromStorage) {
_matched = true;
return CollectionLiterals.<String, JvmIdentifiableElement>newHashMap();
}
}
JvmDeclaredType _switchResult_1 = null;
JvmIdentifiableElement _nearestLogicalContainer = this.containerProvider.getNearestLogicalContainer(expression);
final JvmIdentifiableElement cont = _nearestLogicalContainer;
boolean _matched_1 = false;
if (cont instanceof JvmGenericType) {
_matched_1 = true;
_switchResult_1 = ((JvmGenericType) cont);
}
if (!_matched_1) {
if (cont instanceof JvmMember) {
_matched_1 = true;
_switchResult_1 = ((JvmMember) cont).getDeclaringType();
}
}
final JvmDeclaredType container = _switchResult_1;
Pair<String, JvmDeclaredType> _mappedTo = Pair.<String, JvmDeclaredType>of("visibleFeaturesForAnnotationValues", container);
final Provider<HashMap<String, JvmIdentifiableElement>> _function = () -> {
final HashMap<String, JvmIdentifiableElement> result = CollectionLiterals.<String, JvmIdentifiableElement>newHashMap();
Resource _eResource_1 = expression.eResource();
final XImportSection section = this.importSectionLocator.getImportSection(((XtextResource) _eResource_1));
if ((section != null)) {
EList<XImportDeclaration> _importDeclarations = section.getImportDeclarations();
for (final XImportDeclaration imp : _importDeclarations) {
boolean _isStatic = imp.isStatic();
if (_isStatic) {
final String importedTypeName = imp.getImportedTypeName();
if ((importedTypeName != null)) {
final JvmType type = this.findTypeByName(imp, importedTypeName);
boolean _matched_2 = false;
if (type instanceof JvmGenericType) {
_matched_2 = true;
this.collectAllVisibleFields(((JvmDeclaredType) type), result);
}
if (!_matched_2) {
if (type instanceof JvmEnumerationType) {
_matched_2 = true;
EList<JvmEnumerationLiteral> _literals = ((JvmEnumerationType) type).getLiterals();
for (final JvmEnumerationLiteral feature : _literals) {
result.put(feature.getSimpleName(), feature);
}
}
}
}
}
}
}
this.collectAllVisibleFields(container, result);
return result;
};
_xblockexpression = this.cache.<HashMap<String, JvmIdentifiableElement>>get(_mappedTo, expression.eResource(), _function);
}
return _xblockexpression;
}
use of org.eclipse.xtext.common.types.JvmMember in project xtext-xtend by eclipse.
the class CompilationUnitImpl method toMemberDeclaration.
public MemberDeclaration toMemberDeclaration(final JvmMember delegate) {
final Function1<JvmMember, MemberDeclaration> _function = (JvmMember it) -> {
MemberDeclaration _switchResult = null;
boolean _matched = false;
if (delegate instanceof JvmDeclaredType) {
_matched = true;
_switchResult = this.toTypeDeclaration(((JvmDeclaredType) delegate));
}
if (!_matched) {
if (delegate instanceof JvmOperation) {
_matched = true;
MemberDeclaration _xifexpression = null;
JvmDeclaredType _declaringType = ((JvmOperation) delegate).getDeclaringType();
if ((_declaringType instanceof JvmAnnotationType)) {
JvmAnnotationTypeElementDeclarationImpl _xifexpression_1 = null;
boolean _isBelongedToCompilationUnit = this.isBelongedToCompilationUnit(delegate);
if (_isBelongedToCompilationUnit) {
MutableJvmAnnotationTypeElementDeclarationImpl _mutableJvmAnnotationTypeElementDeclarationImpl = new MutableJvmAnnotationTypeElementDeclarationImpl();
final Procedure1<MutableJvmAnnotationTypeElementDeclarationImpl> _function_1 = (MutableJvmAnnotationTypeElementDeclarationImpl it_1) -> {
it_1.setDelegate(((JvmOperation) delegate));
it_1.setCompilationUnit(this);
};
_xifexpression_1 = ObjectExtensions.<MutableJvmAnnotationTypeElementDeclarationImpl>operator_doubleArrow(_mutableJvmAnnotationTypeElementDeclarationImpl, _function_1);
} else {
JvmAnnotationTypeElementDeclarationImpl _jvmAnnotationTypeElementDeclarationImpl = new JvmAnnotationTypeElementDeclarationImpl();
final Procedure1<JvmAnnotationTypeElementDeclarationImpl> _function_2 = (JvmAnnotationTypeElementDeclarationImpl it_1) -> {
it_1.setDelegate(((JvmOperation) delegate));
it_1.setCompilationUnit(this);
};
_xifexpression_1 = ObjectExtensions.<JvmAnnotationTypeElementDeclarationImpl>operator_doubleArrow(_jvmAnnotationTypeElementDeclarationImpl, _function_2);
}
_xifexpression = _xifexpression_1;
} else {
JvmMethodDeclarationImpl _xifexpression_2 = null;
boolean _isBelongedToCompilationUnit_1 = this.isBelongedToCompilationUnit(delegate);
if (_isBelongedToCompilationUnit_1) {
MutableJvmMethodDeclarationImpl _mutableJvmMethodDeclarationImpl = new MutableJvmMethodDeclarationImpl();
final Procedure1<MutableJvmMethodDeclarationImpl> _function_3 = (MutableJvmMethodDeclarationImpl it_1) -> {
it_1.setDelegate(((JvmOperation) delegate));
it_1.setCompilationUnit(this);
};
_xifexpression_2 = ObjectExtensions.<MutableJvmMethodDeclarationImpl>operator_doubleArrow(_mutableJvmMethodDeclarationImpl, _function_3);
} else {
JvmMethodDeclarationImpl _jvmMethodDeclarationImpl = new JvmMethodDeclarationImpl();
final Procedure1<JvmMethodDeclarationImpl> _function_4 = (JvmMethodDeclarationImpl it_1) -> {
it_1.setDelegate(((JvmOperation) delegate));
it_1.setCompilationUnit(this);
};
_xifexpression_2 = ObjectExtensions.<JvmMethodDeclarationImpl>operator_doubleArrow(_jvmMethodDeclarationImpl, _function_4);
}
_xifexpression = ((MemberDeclaration) _xifexpression_2);
}
_switchResult = _xifexpression;
}
}
if (!_matched) {
if (delegate instanceof JvmConstructor) {
_matched = true;
JvmConstructorDeclarationImpl _xifexpression = null;
boolean _isBelongedToCompilationUnit = this.isBelongedToCompilationUnit(delegate);
if (_isBelongedToCompilationUnit) {
MutableJvmConstructorDeclarationImpl _mutableJvmConstructorDeclarationImpl = new MutableJvmConstructorDeclarationImpl();
final Procedure1<MutableJvmConstructorDeclarationImpl> _function_1 = (MutableJvmConstructorDeclarationImpl it_1) -> {
it_1.setDelegate(((JvmConstructor) delegate));
it_1.setCompilationUnit(this);
};
_xifexpression = ObjectExtensions.<MutableJvmConstructorDeclarationImpl>operator_doubleArrow(_mutableJvmConstructorDeclarationImpl, _function_1);
} else {
JvmConstructorDeclarationImpl _jvmConstructorDeclarationImpl = new JvmConstructorDeclarationImpl();
final Procedure1<JvmConstructorDeclarationImpl> _function_2 = (JvmConstructorDeclarationImpl it_1) -> {
it_1.setDelegate(((JvmConstructor) delegate));
it_1.setCompilationUnit(this);
};
_xifexpression = ObjectExtensions.<JvmConstructorDeclarationImpl>operator_doubleArrow(_jvmConstructorDeclarationImpl, _function_2);
}
_switchResult = _xifexpression;
}
}
if (!_matched) {
if (delegate instanceof JvmEnumerationLiteral) {
_matched = true;
JvmEnumerationValueDeclarationImpl _xifexpression = null;
boolean _isBelongedToCompilationUnit = this.isBelongedToCompilationUnit(delegate);
if (_isBelongedToCompilationUnit) {
MutableJvmEnumerationValueDeclarationImpl _mutableJvmEnumerationValueDeclarationImpl = new MutableJvmEnumerationValueDeclarationImpl();
final Procedure1<MutableJvmEnumerationValueDeclarationImpl> _function_1 = (MutableJvmEnumerationValueDeclarationImpl it_1) -> {
it_1.setDelegate(((JvmEnumerationLiteral) delegate));
it_1.setCompilationUnit(this);
};
_xifexpression = ObjectExtensions.<MutableJvmEnumerationValueDeclarationImpl>operator_doubleArrow(_mutableJvmEnumerationValueDeclarationImpl, _function_1);
} else {
JvmEnumerationValueDeclarationImpl _jvmEnumerationValueDeclarationImpl = new JvmEnumerationValueDeclarationImpl();
final Procedure1<JvmEnumerationValueDeclarationImpl> _function_2 = (JvmEnumerationValueDeclarationImpl it_1) -> {
it_1.setDelegate(((JvmEnumerationLiteral) delegate));
it_1.setCompilationUnit(this);
};
_xifexpression = ObjectExtensions.<JvmEnumerationValueDeclarationImpl>operator_doubleArrow(_jvmEnumerationValueDeclarationImpl, _function_2);
}
_switchResult = _xifexpression;
}
}
if (!_matched) {
if (delegate instanceof JvmField) {
_matched = true;
JvmFieldDeclarationImpl _xifexpression = null;
boolean _isBelongedToCompilationUnit = this.isBelongedToCompilationUnit(delegate);
if (_isBelongedToCompilationUnit) {
MutableJvmFieldDeclarationImpl _mutableJvmFieldDeclarationImpl = new MutableJvmFieldDeclarationImpl();
final Procedure1<MutableJvmFieldDeclarationImpl> _function_1 = (MutableJvmFieldDeclarationImpl it_1) -> {
it_1.setDelegate(((JvmField) delegate));
it_1.setCompilationUnit(this);
};
_xifexpression = ObjectExtensions.<MutableJvmFieldDeclarationImpl>operator_doubleArrow(_mutableJvmFieldDeclarationImpl, _function_1);
} else {
JvmFieldDeclarationImpl _jvmFieldDeclarationImpl = new JvmFieldDeclarationImpl();
final Procedure1<JvmFieldDeclarationImpl> _function_2 = (JvmFieldDeclarationImpl it_1) -> {
it_1.setDelegate(((JvmField) delegate));
it_1.setCompilationUnit(this);
};
_xifexpression = ObjectExtensions.<JvmFieldDeclarationImpl>operator_doubleArrow(_jvmFieldDeclarationImpl, _function_2);
}
_switchResult = _xifexpression;
}
}
return _switchResult;
};
return this.<JvmMember, MemberDeclaration>getOrCreate(delegate, _function);
}
use of org.eclipse.xtext.common.types.JvmMember in project xtext-xtend by eclipse.
the class JvmParameterDeclarationImpl method getDeclaringExecutable.
@Override
public ExecutableDeclaration getDeclaringExecutable() {
EObject _eContainer = this.getDelegate().eContainer();
MemberDeclaration _memberDeclaration = this.getCompilationUnit().toMemberDeclaration(((JvmMember) _eContainer));
return ((ExecutableDeclaration) _memberDeclaration);
}
use of org.eclipse.xtext.common.types.JvmMember in project xtext-xtend by eclipse.
the class JvmTypeParameterDeclarationImpl method getTypeParameterDeclarator.
@Override
public TypeParameterDeclarator getTypeParameterDeclarator() {
EObject _eContainer = this.getDelegate().eContainer();
MemberDeclaration _memberDeclaration = this.getCompilationUnit().toMemberDeclaration(((JvmMember) _eContainer));
return ((TypeParameterDeclarator) _memberDeclaration);
}
Aggregations