/** override to add any other implicit feature calls. */ protected IScope createImplicitFeatureCallScope( final EObject call, final IScope parent, IScope localVariableScope) { IScope result = parent; IEObjectDescription thisVariable = localVariableScope.getSingleElement(THIS); if (thisVariable != null) { EObject implicitReceiver = thisVariable.getEObjectOrProxy(); JvmTypeReference implicitReceiverType = typeProvider.getTypeForIdentifiable((JvmIdentifiableElement) implicitReceiver); if (implicitReceiverType != null && implicitReceiver instanceof JvmIdentifiableElement) { XFeatureCall receiver = XbaseFactory.eINSTANCE.createXFeatureCall(); receiver.setFeature((JvmIdentifiableElement) implicitReceiver); result = createFeatureScopeForTypeRef( implicitReceiverType, call, getContextType(call), receiver, result); } } IEObjectDescription itVariable = localVariableScope.getSingleElement(IT); if (itVariable != null) { EObject implicitReceiver = itVariable.getEObjectOrProxy(); JvmTypeReference implicitReceiverType = typeProvider.getTypeForIdentifiable((JvmIdentifiableElement) implicitReceiver); if (implicitReceiverType != null && implicitReceiver instanceof JvmIdentifiableElement) { XFeatureCall receiver = XbaseFactory.eINSTANCE.createXFeatureCall(); receiver.setFeature((JvmIdentifiableElement) implicitReceiver); result = createFeatureScopeForTypeRef( implicitReceiverType, call, getContextType(call), receiver, result); } } return result; }
protected IScope doGetTypeScope(XFeatureCall call, JvmType type) { if (call.isPackageFragment()) { if (type instanceof JvmDeclaredType) { String packageName = ((JvmDeclaredType) type).getPackageName(); int dot = packageName.indexOf('.'); if (dot == -1) { return new SingletonScope(EObjectDescription.create(packageName, type), IScope.NULLSCOPE); } else { String firstSegment = packageName.substring(0, dot); return new SingletonScope( EObjectDescription.create(firstSegment, type), IScope.NULLSCOPE); } } return IScope.NULLSCOPE; } else { if (type instanceof JvmDeclaredType && ((JvmDeclaredType) type).getDeclaringType() != null) { Resource resource = call.eResource(); if (resource instanceof XtextResource) { XImportSection importSection = importsConfiguration.getImportSection((XtextResource) resource); if (importSection != null) { List<XImportDeclaration> importDeclarations = importSection.getImportDeclarations(); List<IEObjectDescription> descriptions = Lists.newArrayList(); for (XImportDeclaration importDeclaration : importDeclarations) { if (!importDeclaration.isStatic() && !importDeclaration.isWildcard() && !importDeclaration.isExtension()) { JvmDeclaredType importedType = importDeclaration.getImportedType(); if (importedType == type) { String syntax = importsConfiguration.getLegacyImportSyntax(importDeclaration); if (syntax != null /* no node model attached */ && syntax.equals(type.getQualifiedName())) { String packageName = importedType.getPackageName(); descriptions.add( EObjectDescription.create( syntax.substring(packageName.length() + 1), type)); } } if (EcoreUtil.isAncestor(importedType, type)) { String name = type.getSimpleName(); JvmType worker = type; while (worker != importedType) { worker = (JvmType) worker.eContainer(); name = worker.getSimpleName() + "$" + name; } descriptions.add(EObjectDescription.create(name, type)); } } } return new SimpleScope(descriptions); } } return new SingletonScope( EObjectDescription.create(type.getSimpleName(), type), IScope.NULLSCOPE); } else { return new SingletonScope( EObjectDescription.create(type.getSimpleName(), type), IScope.NULLSCOPE); } } }
/** * This method serves as an entry point for the content assist scoping for simple feature calls. * * @param context the context e.g. a for loop expression, a block or a catch clause * @param reference the reference who's value shall be scoped. Not necessarily a feature of the * context. * @param includeCurrentBlock <code>false</code> in the context of scoping but content assist will * not have the actual value holder of the reference at hand so it passes its container to * this method and expects the declared variables to be exposed in the scope. * @param idx the index in an expression list of a block. Otherwise to be ignored. */ public IScope createSimpleFeatureCallScope( final EObject context, EReference reference, Resource resource, boolean includeCurrentBlock, int idx) { if (context instanceof XFeatureCall) { XFeatureCall featureCall = (XFeatureCall) context; if (featureCall.getDeclaringType() != null) { JvmParameterizedTypeReference typeReference = typeReferences.createTypeRef(featureCall.getDeclaringType()); JvmFeatureScope result = createFeatureScopeForTypeRef( typeReference, context, getContextType(context), null, IScope.NULLSCOPE); return result; } } IScope staticScope = createStaticScope(context, resource, IScope.NULLSCOPE); DelegatingScope delegatingStaticScope = new DelegatingScope(IScope.NULLSCOPE); DelegatingScope implicitThis = new DelegatingScope(delegatingStaticScope); LocalVariableScopeContext scopeContext = createLocalVariableScopeContext(context, reference, includeCurrentBlock, idx); IScope localVariableScope = createLocalVarScope(implicitThis, scopeContext); IScope scopeForImplicitFeatures = createImplicitFeatureCallScope(context, IScope.NULLSCOPE, localVariableScope); implicitThis.setDelegate(scopeForImplicitFeatures); delegatingStaticScope.setDelegate(staticScope); return localVariableScope; }
protected String _case( JvmField input, XFeatureCall context, EReference reference, JvmFeatureDescription jvmFeatureDescription) { if (context.getDeclaringType() == null) { if (input.isStatic()) return INSTANCE_ACCESS_TO_STATIC_MEMBER; } else { if (!input.isStatic()) return STATIC_ACCESS_TO_INSTANCE_MEMBER; } if (context.isExplicitOperationCall()) return FIELD_ACCESS_WITH_PARENTHESES; return null; }
protected String _case( JvmOperation input, XFeatureCall context, EReference reference, JvmFeatureDescription jvmFeatureDescription) { if (context.getDeclaringType() != null) { if (!input.isStatic()) return STATIC_ACCESS_TO_INSTANCE_MEMBER; } return checkJvmOperation( input, context, context.isExplicitOperationCall(), jvmFeatureDescription, context.getFeatureCallArguments()); }
protected String _case( JvmIdentifiableElement input, XFeatureCall context, EReference ref, LocalVarDescription description) { if (context.isExplicitOperationCall()) return LOCAL_VAR_ACCESS_WITH_PARENTHESES; return null; }
protected IFeatureCallArguments toArguments( final String signature, final String invocation, final boolean receiver) { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("def void m("); _builder.append(signature, ""); _builder.append(") {"); _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.append("m("); _builder.append(invocation, "\t"); _builder.append(")"); _builder.newLineIfNotEmpty(); _builder.append("}"); _builder.newLine(); final String functionString = _builder.toString(); final XtendFunction function = this.function(functionString); XExpression _expression = function.getExpression(); final XBlockExpression body = ((XBlockExpression) _expression); EList<XExpression> _expressions = body.getExpressions(); XExpression _head = IterableExtensions.<XExpression>head(_expressions); final XFeatureCall featureCall = ((XFeatureCall) _head); final EList<XExpression> arguments = featureCall.getFeatureCallArguments(); final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function); EList<JvmFormalParameter> _parameters = operation.getParameters(); ITypeReferenceOwner _owner = this.getOwner(); final IFeatureCallArguments result = this.factory.createVarArgArguments(arguments, _parameters, receiver, _owner); Class<? extends IFeatureCallArguments> _class = result.getClass(); boolean _equals = Objects.equal(_class, VarArgFeatureCallArguments.class); Assert.assertTrue(_equals); return result; } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
private void addTypeCastToImplicitReceiver( XFeatureCall featureCall, IModificationContext context, JvmType declaringType) throws BadLocationException { String receiver; if (featureCall.getImplicitReceiver() instanceof XAbstractFeatureCall) receiver = ((XAbstractFeatureCall) featureCall.getImplicitReceiver()).getFeature().getSimpleName(); else return; List<INode> nodes = NodeModelUtils.findNodesForFeature( featureCall, XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE); if (nodes.isEmpty()) return; INode firstNode = IterableExtensions.head(nodes); int offset = firstNode.getOffset(); ReplacingAppendable appendable = appendableFactory.create( context.getXtextDocument(), (XtextResource) featureCall.eResource(), offset, 0); appendable.append("("); appendable.append(receiver); appendable.append(" as "); appendable.append(declaringType); appendable.append(")."); appendable.commitChanges(); }