Search in sources :

Example 1 with SingletonScope

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;
}
Also used : XVariableDeclaration(org.eclipse.xtext.xbase.XVariableDeclaration) SingletonScope(org.eclipse.xtext.scoping.impl.SingletonScope) JvmExecutable(org.eclipse.xtext.common.types.JvmExecutable) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) XSwitchExpression(org.eclipse.xtext.xbase.XSwitchExpression) JvmType(org.eclipse.xtext.common.types.JvmType) JvmField(org.eclipse.xtext.common.types.JvmField) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall)

Example 2 with SingletonScope

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);
}
Also used : SingletonScope(org.eclipse.xtext.scoping.impl.SingletonScope) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) QualifiedName(org.eclipse.xtext.naming.QualifiedName) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmMember(org.eclipse.xtext.common.types.JvmMember)

Example 3 with SingletonScope

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);
}
Also used : SingletonScope(org.eclipse.xtext.scoping.impl.SingletonScope) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) QualifiedName(org.eclipse.xtext.naming.QualifiedName) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType)

Example 4 with SingletonScope

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);
            }
        }
    }
}
Also used : SingletonScope(org.eclipse.xtext.scoping.impl.SingletonScope) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall)

Example 5 with SingletonScope

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);
}
Also used : SingletonScope(org.eclipse.xtext.scoping.impl.SingletonScope) JvmExecutable(org.eclipse.xtext.common.types.JvmExecutable) QualifiedName(org.eclipse.xtext.naming.QualifiedName) XAssignment(org.eclipse.xtext.xbase.XAssignment)

Aggregations

SingletonScope (org.eclipse.xtext.scoping.impl.SingletonScope)6 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)4 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)3 QualifiedName (org.eclipse.xtext.naming.QualifiedName)3 JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)2 JvmExecutable (org.eclipse.xtext.common.types.JvmExecutable)2 JvmType (org.eclipse.xtext.common.types.JvmType)2 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)2 Resource (org.eclipse.emf.ecore.resource.Resource)1 JvmField (org.eclipse.xtext.common.types.JvmField)1 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)1 JvmMember (org.eclipse.xtext.common.types.JvmMember)1 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1 SimpleScope (org.eclipse.xtext.scoping.impl.SimpleScope)1 XAssignment (org.eclipse.xtext.xbase.XAssignment)1 XSwitchExpression (org.eclipse.xtext.xbase.XSwitchExpression)1 XVariableDeclaration (org.eclipse.xtext.xbase.XVariableDeclaration)1 XImportDeclaration (org.eclipse.xtext.xtype.XImportDeclaration)1 XImportSection (org.eclipse.xtext.xtype.XImportSection)1