use of org.eclipse.xtext.scoping.impl.SingletonScope in project xtext-extras by eclipse.
the class SerializerScopeProvider method createFeatureCallSerializationScope.
// TODO split this into smaller methods, investigate override / overload semantics
// This assumes that the model was linked properly and not changed in an incompatible way
// which is quite hard anyway ...
public IScope createFeatureCallSerializationScope(EObject context) {
if (!(context instanceof XAbstractFeatureCall)) {
return IScope.NULLSCOPE;
}
XAbstractFeatureCall call = (XAbstractFeatureCall) context;
JvmIdentifiableElement feature = call.getFeature();
// this and super - logical container aware FeatureScopes
if (feature instanceof JvmType) {
return getTypeScope(call, (JvmType) feature);
}
if (feature instanceof JvmConstructor) {
return getThisOrSuperScope(call, (JvmConstructor) feature);
}
if (feature instanceof JvmExecutable) {
return getExecutableScope(call, feature);
}
if (feature instanceof JvmFormalParameter || feature instanceof JvmField || feature instanceof XVariableDeclaration || feature instanceof XSwitchExpression) {
return new SingletonScope(EObjectDescription.create(feature.getSimpleName(), feature), IScope.NULLSCOPE);
}
return IScope.NULLSCOPE;
}
use of org.eclipse.xtext.scoping.impl.SingletonScope in project xtext-extras by eclipse.
the class SerializerScopeProvider method getThisOrSuperScope.
protected IScope getThisOrSuperScope(XAbstractFeatureCall call, JvmType thisOrSuper) {
QualifiedName name = THIS;
JvmIdentifiableElement logicalContainer = logicalContainerProvider.getNearestLogicalContainer(call);
if (logicalContainer instanceof JvmMember) {
JvmDeclaredType thisType = ((JvmMember) logicalContainer).getDeclaringType();
if (thisType != thisOrSuper) {
name = SUPER;
}
}
return new SingletonScope(EObjectDescription.create(name, thisOrSuper), IScope.NULLSCOPE);
}
use of org.eclipse.xtext.scoping.impl.SingletonScope in project xtext-extras by eclipse.
the class SerializerScopeProvider method getThisOrSuperScope.
protected IScope getThisOrSuperScope(XAbstractFeatureCall call, JvmConstructor constructor) {
QualifiedName name = THIS;
JvmIdentifiableElement logicalContainer = logicalContainerProvider.getNearestLogicalContainer(call);
if (logicalContainer instanceof JvmConstructor) {
JvmDeclaredType thisType = ((JvmConstructor) logicalContainer).getDeclaringType();
if (thisType != constructor.getDeclaringType()) {
name = SUPER;
}
}
return new SingletonScope(EObjectDescription.create(name, constructor), IScope.NULLSCOPE);
}
use of org.eclipse.xtext.scoping.impl.SingletonScope in project xtext-extras by eclipse.
the class SerializerScopeProvider method doGetTypeScope.
protected IScope doGetTypeScope(XMemberFeatureCall call, JvmType type) {
if (call.isPackageFragment()) {
if (type instanceof JvmDeclaredType) {
int segmentIndex = countSegments(call);
String packageName = ((JvmDeclaredType) type).getPackageName();
List<String> splitted = Strings.split(packageName, '.');
String segment = splitted.get(segmentIndex);
return new SingletonScope(EObjectDescription.create(segment, type), IScope.NULLSCOPE);
}
return IScope.NULLSCOPE;
} else {
if (type instanceof JvmDeclaredType && ((JvmDeclaredType) type).getDeclaringType() == null) {
return new SingletonScope(EObjectDescription.create(type.getSimpleName(), type), IScope.NULLSCOPE);
} else {
XAbstractFeatureCall target = (XAbstractFeatureCall) call.getMemberCallTarget();
if (target.isPackageFragment()) {
String qualifiedName = type.getQualifiedName();
int dot = qualifiedName.lastIndexOf('.');
String simpleName = qualifiedName.substring(dot + 1);
return new SingletonScope(EObjectDescription.create(simpleName, type), IScope.NULLSCOPE);
} else {
return new SingletonScope(EObjectDescription.create(type.getSimpleName(), type), IScope.NULLSCOPE);
}
}
}
}
use of org.eclipse.xtext.scoping.impl.SingletonScope in project xtext-extras by eclipse.
the class SerializerScopeProvider method getExecutableScope.
protected IScope getExecutableScope(XAbstractFeatureCall call, JvmIdentifiableElement feature) {
final String simpleName = feature.getSimpleName();
QualifiedName name = QualifiedName.create(simpleName);
if (call.isOperation()) {
QualifiedName operator = getOperator(call, name);
if (operator == null) {
return IScope.NULLSCOPE;
}
return new SingletonScope(EObjectDescription.create(operator, feature), IScope.NULLSCOPE);
}
if (call instanceof XAssignment) {
return getAccessorScope(simpleName, name, feature);
}
if (call.isExplicitOperationCallOrBuilderSyntax() || ((JvmExecutable) feature).getParameters().size() > 1 || (!call.isExtension() && ((JvmExecutable) feature).getParameters().size() == 1)) {
return new SingletonScope(EObjectDescription.create(name, feature), IScope.NULLSCOPE);
}
return getAccessorScope(simpleName, name, feature);
}
Aggregations