use of org.eclipse.xtend.core.xtend.XtendMember in project xtext-xtend by eclipse.
the class CompilationUnitImpl method toXtendMemberDeclaration.
public MemberDeclaration toXtendMemberDeclaration(final XtendMember delegate) {
final Function1<XtendMember, XtendMemberDeclarationImpl<? extends XtendMember>> _function = (XtendMember it) -> {
XtendMemberDeclarationImpl<? extends XtendMember> _switchResult = null;
boolean _matched = false;
if (delegate instanceof XtendTypeDeclaration) {
_matched = true;
_switchResult = this.toXtendTypeDeclaration(((XtendTypeDeclaration) delegate));
}
if (!_matched) {
if (delegate instanceof XtendFunction) {
_matched = true;
XtendMethodDeclarationImpl _xtendMethodDeclarationImpl = new XtendMethodDeclarationImpl();
final Procedure1<XtendMethodDeclarationImpl> _function_1 = (XtendMethodDeclarationImpl it_1) -> {
it_1.setDelegate(((XtendFunction) delegate));
it_1.setCompilationUnit(this);
};
_switchResult = ObjectExtensions.<XtendMethodDeclarationImpl>operator_doubleArrow(_xtendMethodDeclarationImpl, _function_1);
}
}
if (!_matched) {
if (delegate instanceof XtendConstructor) {
_matched = true;
XtendConstructorDeclarationImpl _xtendConstructorDeclarationImpl = new XtendConstructorDeclarationImpl();
final Procedure1<XtendConstructorDeclarationImpl> _function_1 = (XtendConstructorDeclarationImpl it_1) -> {
it_1.setDelegate(((XtendConstructor) delegate));
it_1.setCompilationUnit(this);
};
_switchResult = ObjectExtensions.<XtendConstructorDeclarationImpl>operator_doubleArrow(_xtendConstructorDeclarationImpl, _function_1);
}
}
if (!_matched) {
if (delegate instanceof XtendField) {
_matched = true;
XtendMemberDeclarationImpl<XtendField> _xifexpression = null;
EObject _eContainer = ((XtendField) delegate).eContainer();
if ((_eContainer instanceof XtendAnnotationType)) {
XtendAnnotationTypeElementDeclarationImpl _xtendAnnotationTypeElementDeclarationImpl = new XtendAnnotationTypeElementDeclarationImpl();
final Procedure1<XtendAnnotationTypeElementDeclarationImpl> _function_1 = (XtendAnnotationTypeElementDeclarationImpl it_1) -> {
it_1.setDelegate(((XtendField) delegate));
it_1.setCompilationUnit(this);
};
_xifexpression = ObjectExtensions.<XtendAnnotationTypeElementDeclarationImpl>operator_doubleArrow(_xtendAnnotationTypeElementDeclarationImpl, _function_1);
} else {
XtendFieldDeclarationImpl _xtendFieldDeclarationImpl = new XtendFieldDeclarationImpl();
final Procedure1<XtendFieldDeclarationImpl> _function_2 = (XtendFieldDeclarationImpl it_1) -> {
it_1.setDelegate(((XtendField) delegate));
it_1.setCompilationUnit(this);
};
_xifexpression = ObjectExtensions.<XtendFieldDeclarationImpl>operator_doubleArrow(_xtendFieldDeclarationImpl, _function_2);
}
_switchResult = _xifexpression;
}
}
if (!_matched) {
if (delegate instanceof XtendEnumLiteral) {
_matched = true;
XtendEnumerationValueDeclarationImpl _xtendEnumerationValueDeclarationImpl = new XtendEnumerationValueDeclarationImpl();
final Procedure1<XtendEnumerationValueDeclarationImpl> _function_1 = (XtendEnumerationValueDeclarationImpl it_1) -> {
it_1.setDelegate(((XtendEnumLiteral) delegate));
it_1.setCompilationUnit(this);
};
_switchResult = ObjectExtensions.<XtendEnumerationValueDeclarationImpl>operator_doubleArrow(_xtendEnumerationValueDeclarationImpl, _function_1);
}
}
return _switchResult;
};
return this.<XtendMember, XtendMemberDeclarationImpl<? extends XtendMember>>getOrCreate(delegate, _function);
}
use of org.eclipse.xtend.core.xtend.XtendMember in project xtext-xtend by eclipse.
the class XtendJvmModelInferrer method initialize.
protected void initialize(XtendAnnotationType source, JvmAnnotationType inferredJvmType) {
inferredJvmType.setVisibility(source.getVisibility());
inferredJvmType.setStatic(source.isStatic() && !isTopLevel(source));
inferredJvmType.setAbstract(true);
translateAnnotationsTo(source.getAnnotations(), inferredJvmType);
jvmTypesBuilder.copyDocumentationTo(source, inferredJvmType);
for (XtendMember member : source.getMembers()) {
if (member instanceof XtendField) {
XtendField field = (XtendField) member;
if (!Strings.isEmpty(field.getName())) {
JvmOperation operation = typesFactory.createJvmOperation();
associator.associatePrimary(member, operation);
operation.setSimpleName(field.getName());
JvmTypeReference returnType = null;
XExpression initialValue = field.getInitialValue();
if (field.getType() != null) {
returnType = jvmTypesBuilder.cloneWithProxies(field.getType());
} else if (initialValue != null) {
returnType = jvmTypesBuilder.inferredType(initialValue);
}
operation.setReturnType(returnType);
if (initialValue != null) {
JvmAnnotationValue jvmAnnotationValue = jvmTypesBuilder.toJvmAnnotationValue(initialValue);
if (jvmAnnotationValue != null) {
operation.setDefaultValue(jvmAnnotationValue);
jvmAnnotationValue.setOperation(operation);
}
jvmTypesBuilder.setBody(operation, initialValue);
}
operation.setVisibility(JvmVisibility.PUBLIC);
translateAnnotationsTo(member.getAnnotations(), operation);
jvmTypesBuilder.copyDocumentationTo(member, operation);
inferredJvmType.getMembers().add(operation);
}
}
}
}
use of org.eclipse.xtend.core.xtend.XtendMember in project xtext-xtend by eclipse.
the class XtendImportedNamespaceScopeProvider method getContainerScope.
private AbstractScope getContainerScope(XtendMember syntacticContainer, AbstractScope result) {
JvmDeclaredType innermost = null;
List<List<JvmTypeParameter>> typeParameters = null;
XtendMember workWithMe = syntacticContainer;
while (workWithMe != null) {
EObject derivedJvmElement = getAssociations().getPrimaryJvmElement(workWithMe);
// scope for JvmTypeParameterDeclarator
if (derivedJvmElement instanceof JvmTypeParameterDeclarator) {
JvmTypeParameterDeclarator parameterDeclarator = (JvmTypeParameterDeclarator) derivedJvmElement;
List<JvmTypeParameter> current = parameterDeclarator.getTypeParameters();
if (!current.isEmpty()) {
if (typeParameters == null) {
typeParameters = Lists.newArrayListWithCapacity(3);
}
typeParameters.add(current);
}
}
if (innermost == null && derivedJvmElement instanceof JvmDeclaredType) {
if (syntacticContainer != workWithMe) {
// prevent stackoverflow / cyclic resolution
innermost = (JvmDeclaredType) derivedJvmElement;
}
}
EObject container = workWithMe;
do {
container = container.eContainer();
if (container == null) {
if (typeParameters == null) {
if (innermost == null)
return result;
return new NestedTypesScope(innermost, this, result);
}
TypeParameterScope typeParameterScope = new TypeParameterScope(typeParameters, result);
if (innermost == null) {
return typeParameterScope;
}
return new NestedTypesScope(innermost, this, typeParameterScope);
}
} while (!(container instanceof XtendMember));
workWithMe = (XtendMember) container;
}
return result;
}
use of org.eclipse.xtend.core.xtend.XtendMember 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.XtendMember in project xtext-xtend by eclipse.
the class TypeDeclarationAwareBatchTypeResolver method addXtendTypes.
/**
* Collects all Xtend type declarations and adds them to the list. The types are added
* from the innermost to the outermost type declaration. That is, nested classes are
* added before their declarators are added. This greatly simplifies the implementation of
* {@code isHandled} in the concrete {@link org.eclipse.xtext.xbase.typesystem.internal.AbstractRootedReentrantTypeResolver}.
*/
private void addXtendTypes(XtendTypeDeclaration declaration, List<EObject> result) {
for (XtendMember member : declaration.getMembers()) {
TreeIterator<EObject> iterator = EcoreUtil2.getAllNonDerivedContents(member, true);
while (iterator.hasNext()) {
EObject next = iterator.next();
if (next instanceof XtendTypeDeclaration) {
addXtendTypes((XtendTypeDeclaration) next, result);
iterator.prune();
}
}
}
result.add(declaration);
}
Aggregations