protected boolean hasConstructorCallWithThis(JvmConstructor constr) { XExpression associatedExpression = logicalContainerProvider.getAssociatedExpression(constr); if (associatedExpression == null) { return false; } TreeIterator<EObject> contents = associatedExpression.eAllContents(); while (contents.hasNext()) { EObject next = contents.next(); if (next instanceof XFeatureCall) { XFeatureCall featureCall = (XFeatureCall) next; if (featureCall.getFeature() instanceof JvmConstructor && featureCall.getConcreteSyntaxFeatureName().equals(IFeatureNames.THIS.toString())) { return true; } } } return false; }
@Check public void checkDelegateConstructorIsFirst(XFeatureCall featureCall) { JvmIdentifiableElement feature = featureCall.getFeature(); if (feature != null && !feature.eIsProxy() && feature instanceof JvmConstructor) { JvmIdentifiableElement container = logicalContainerProvider.getNearestLogicalContainer(featureCall); if (container != null) { if (container instanceof JvmConstructor) { XExpression body = logicalContainerProvider.getAssociatedExpression(container); if (body == featureCall) return; if (body instanceof XBlockExpression) { List<XExpression> expressions = ((XBlockExpression) body).getExpressions(); if (expressions.isEmpty() || expressions.get(0) != featureCall) { error("Constructor call must be the first expression in a constructor", null, INVALID_CONSTRUCTOR_INVOCATION); } } } else { error("Constructor call must be the first expression in a constructor", null, INVALID_CONSTRUCTOR_INVOCATION); } } } }
protected void checkIsValidConstructorArgument(XExpression argument, JvmType containerType) { TreeIterator<EObject> iterator = EcoreUtil2.eAll(argument); while(iterator.hasNext()) { EObject partOfArgumentExpression = iterator.next(); if (partOfArgumentExpression instanceof XFeatureCall || partOfArgumentExpression instanceof XMemberFeatureCall) { XAbstractFeatureCall featureCall = (XAbstractFeatureCall) partOfArgumentExpression; XExpression actualReceiver = featureCall.getActualReceiver(); if(actualReceiver instanceof XFeatureCall && ((XFeatureCall)actualReceiver).getFeature() == containerType) { JvmIdentifiableElement feature = featureCall.getFeature(); if (feature != null && !feature.eIsProxy()) { if (feature instanceof JvmField) { if (!((JvmField) feature).isStatic()) error("Cannot refer to an instance field " + feature.getSimpleName() + " while explicitly invoking a constructor", partOfArgumentExpression, null, INVALID_CONSTRUCTOR_ARGUMENT); } else if (feature instanceof JvmOperation) { if (!((JvmOperation) feature).isStatic()) error("Cannot refer to an instance method while explicitly invoking a constructor", partOfArgumentExpression, null, INVALID_CONSTRUCTOR_ARGUMENT); } } } } else if(isLocalClassSemantics(partOfArgumentExpression)) { iterator.prune(); } } }
protected void checkNoJavaStyleTypeCasting(INode node) { BidiTreeIterator<INode> iterator = node.getAsTreeIterable().reverse().iterator(); ILeafNode child = getFirstLeafNode(iterator); if (child != null && child.getGrammarElement() == grammarAccess.getXParenthesizedExpressionAccess().getRightParenthesisKeyword_2()) { INode expressionNode = getNode(iterator, grammarAccess.getXParenthesizedExpressionAccess().getXExpressionParserRuleCall_1()); EObject semanticObject = NodeModelUtils.findActualSemanticObjectFor(expressionNode); if (semanticObject instanceof XFeatureCall || semanticObject instanceof XMemberFeatureCall) { XAbstractFeatureCall featureCall = (XAbstractFeatureCall) semanticObject; if (featureCall.isTypeLiteral()) { ICompositeNode parenthesizedNode = child.getParent(); ITextRegion parenthesizedRegion = parenthesizedNode.getTextRegion(); addIssue("Use 'as' keyword for type casting.", featureCall, parenthesizedRegion.getOffset(), parenthesizedRegion.getLength(), JAVA_STYLE_TYPE_CAST); } } } }
@Override public void addExtensionsToCurrentScope(List<? extends JvmIdentifiableElement> extensionProviders) { if (extensionProviders.isEmpty()) return; if (extensionProviders.size() == 1) { addExtensionToCurrentScope(extensionProviders.get(0)); return; } Map<XExpression, LightweightTypeReference> prototypeToType = Maps2.newLinkedHashMapWithExpectedSize(extensionProviders.size()); for(JvmIdentifiableElement extensionProvider: extensionProviders) { LightweightTypeReference knownType = getResolvedTypes().getActualType(extensionProvider); if (knownType != null && !knownType.isAny() && !knownType.isUnknown()) { XFeatureCall prototype = getResolver().getXbaseFactory().createXFeatureCall(); prototype.setFeature(extensionProvider); prototypeToType.put(prototype, knownType); } } if (!prototypeToType.isEmpty()) featureScopeSession = featureScopeSession.addToExtensionScope(prototypeToType); }
/** * Returns the node that best describes the error, e.g. if there is an expression * <code>com::foo::DoesNotExist::method()</code> the error will be rooted at <code>com</code>, but * the real problem is <code>com::foo::DoesNotExist</code>. */ private INode getErrorNode(XExpression expression, INode node) { if (expression instanceof XFeatureCall) { XFeatureCall featureCall = (XFeatureCall) expression; if (!canBeTypeLiteral(featureCall)) { return node; } if (featureCall.eContainingFeature() == XbasePackage.Literals.XMEMBER_FEATURE_CALL__MEMBER_CALL_TARGET) { XMemberFeatureCall container = (XMemberFeatureCall) featureCall.eContainer(); if (canBeTypeLiteral(container)) { boolean explicitStatic = container.isExplicitStatic(); XMemberFeatureCall outerMost = getLongestTypeLiteralCandidate(container, explicitStatic); if (outerMost != null) return NodeModelUtils.getNode(outerMost); } } } return node; }
/** * 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 */ public IScope createSimpleFeatureCallScope(EObject context, IFeatureScopeSession session, IResolvedTypes resolvedTypes) { IScope root = IScope.NULLSCOPE; if (context instanceof XFeatureCall) { XFeatureCall featureCall = (XFeatureCall) context; if (!featureCall.isExplicitOperationCallOrBuilderSyntax()) { root = createTypeLiteralScope(context, QualifiedName.EMPTY, root, session, resolvedTypes); if (isDefiniteTypeLiteral(featureCall)) { return root; } } } IScope staticImports = createStaticFeaturesScope(context, root, session); IScope staticMembers = createStaticScope(asAbstractFeatureCall(context), null, null, staticImports, session, resolvedTypes); IScope staticExtensions = createStaticExtensionsScope(null, null, context, staticMembers, session, resolvedTypes); // we don't want to use captured instances of 'IT' as dynamic extension implicit argument // thus the dynamic extension scope only works for the *real* local variables IScope dynamicExtensions = createDynamicExtensionsScope(null, null, context, staticExtensions, session, resolvedTypes); IScope localVariables = createImplicitFeatureCallAndLocalVariableScope(context, dynamicExtensions, session, resolvedTypes); return localVariables; }
protected IScope createImplicitFeatureCallScope(QualifiedName implicitName, EObject featureCall, IFeatureScopeSession session, IResolvedTypes resolvedTypes, IScope parent) { IEObjectDescription thisDescription = session.getLocalElement(implicitName); if (thisDescription != null) { JvmIdentifiableElement thisElement = (JvmIdentifiableElement) thisDescription.getEObjectOrProxy(); boolean validStaticScope = true; if (thisElement instanceof JvmType && THIS.equals(implicitName) && !session.isInstanceContext()) { validStaticScope = false; } LightweightTypeReference type = resolvedTypes.getActualType(thisElement); if (type !=null && !type.isUnknown()) { XFeatureCall implicitReceiver = xbaseFactory.createXFeatureCall(); implicitReceiver.setFeature(thisElement); return createFeatureScopeForTypeRef(implicitReceiver, type, true, featureCall, session, thisElement, parent, validStaticScope); } } return parent; }
public XAbstractFeatureCall getRootTypeLiteral(XAbstractFeatureCall featureCall) { if (featureCall.isTypeLiteral()) { return featureCall; } if (featureCall.isPackageFragment()) { return getRootTypeLiteral((XAbstractFeatureCall) featureCall.eContainer()); } if (featureCall.getFeature() == null || featureCall.getFeature().eIsProxy()) { // syntactic check if (featureCall instanceof XFeatureCall || featureCall instanceof XMemberFeatureCall) { if (!isPotentialTypeLiteral(featureCall, null)) { return null; } if (featureCall instanceof XMemberFeatureCall) { return doGetRootTypeLiteral((XMemberFeatureCall) featureCall); } if (featureCall instanceof XFeatureCall) { if (featureCall.eContainingFeature() == XbasePackage.Literals.XMEMBER_FEATURE_CALL__MEMBER_CALL_TARGET) { return doGetRootTypeLiteral((XMemberFeatureCall) featureCall.eContainer()); } } } } return null; }
protected void _toJavaExpression(XAbstractFeatureCall call, ITreeAppendable b) { if (call.isTypeLiteral()) { b.append((JvmType) call.getFeature()).append(".class"); } else if (isPrimitiveVoid(call)) { throw new IllegalArgumentException("feature yields 'void'"); } else { final String referenceName = getReferenceName(call, b); if (referenceName != null) { if (call instanceof XFeatureCall || call instanceof XMemberFeatureCall) { b.trace(call, XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, 0).append(referenceName); } else { b.trace(call, false).append(referenceName); } } else { featureCalltoJavaExpression(call, b, true); } } }
protected ILocationData getLocationWithoutTypeArguments(XAbstractFeatureCall call) { final ICompositeNode startNode = NodeModelUtils.getNode(call); if (startNode != null) { List<INode> resultNodes = Lists.newArrayList(); if (call instanceof XFeatureCall || call instanceof XMemberFeatureCall) { boolean featureReferenceSeen = false; for (INode child : startNode.getChildren()) { if (featureReferenceSeen) { resultNodes.add(child); } else { EObject grammarElement = child.getGrammarElement(); if (grammarElement instanceof CrossReference) { Assignment assignment = GrammarUtil.containingAssignment(grammarElement); if (assignment != null && "feature".equals(assignment.getFeature())) { featureReferenceSeen = true; resultNodes.add(child); } } } } } return toLocationData(resultNodes); } return null; }
protected String getSwitchLocalVariableName(XSwitchExpression expr, ITreeAppendable b) { JvmFormalParameter declaredParam = expr.getDeclaredParam(); if (declaredParam != null) { if (b.hasName(declaredParam)) { return b.getName(declaredParam); } return null; } XExpression switchExpression = expr.getSwitch(); if (b.hasName(switchExpression)) { return b.getName(switchExpression); } if (switchExpression instanceof XFeatureCall) { XFeatureCall featureCall = (XFeatureCall) switchExpression; JvmIdentifiableElement feature = featureCall.getFeature(); if (b.hasName(feature)) { return b.getName(feature); } } return null; }
protected boolean canCompileToJavaLambda(XClosure closure, LightweightTypeReference typeRef, JvmOperation operation) { if (!typeRef.isInterfaceType()) return false; if (!operation.getTypeParameters().isEmpty()) return false; TreeIterator<EObject> iterator = closure.eAllContents(); JvmType jvmType = typeRef.getType(); while (iterator.hasNext()) { EObject obj = iterator.next(); if (obj instanceof XClosure) { iterator.prune(); } else if (obj instanceof XFeatureCall && isReferenceToSelf((XFeatureCall) obj, jvmType)) { return false; } } return true; }
protected boolean hasJvmConstructorCall(XExpression obj) { if (!(obj instanceof XBlockExpression)) { return false; } XBlockExpression blockExpression = (XBlockExpression) obj; EList<XExpression> expressions = blockExpression.getExpressions(); if (expressions.isEmpty()) { return false; } XExpression expr = expressions.get(0); if (!(expr instanceof XFeatureCall)) { return false; } XFeatureCall featureCall = (XFeatureCall) expr; return featureCall.getFeature() instanceof JvmConstructor; }
protected void collectStaticImportsFrom(XExpression expression, JvmIdentifiableElement feature) { if (expression instanceof XAbstractFeatureCall) { if (feature instanceof JvmEnumerationLiteral && expression instanceof XFeatureCall) { if (isEnumLiteralImplicitelyImported(expression, (JvmEnumerationLiteral) feature)) { return; } } XAbstractFeatureCall featureCall = (XAbstractFeatureCall) expression; if ((feature instanceof JvmOperation || feature instanceof JvmField) && featureCall.isStatic()) { if (featureCall.isExtension()) { acceptStaticExtensionImport((JvmMember) feature); } else { acceptStaticImport((JvmMember) feature); } } } }
protected void _format(final XFeatureCall expr, final FormattableDocument format) { this.formatFeatureCallTypeParameters(expr, format); boolean _isExplicitOperationCall = expr.isExplicitOperationCall(); if (_isExplicitOperationCall) { final ILeafNode open = this._nodeModelAccess.nodeForKeyword(expr, "("); final Procedure1<FormattingDataInit> _function = (FormattingDataInit it) -> { it.noSpace(); }; Function1<? super FormattableDocument, ? extends Iterable<FormattingData>> _prepend = this._formattingDataFactory.prepend(open, _function); format.operator_add(_prepend); boolean _isMultiParamInOwnLine = this.isMultiParamInOwnLine(expr, format); if (_isMultiParamInOwnLine) { this.formatFeatureCallParamsMultiline(open, expr.getFeatureCallArguments(), format); } else { this.formatFeatureCallParamsWrapIfNeeded(open, expr.getFeatureCallArguments(), format); } } else { EList<XExpression> _featureCallArguments = expr.getFeatureCallArguments(); for (final XExpression arg : _featureCallArguments) { this.format(arg, format); } } }
protected boolean _isMultiParamInOwnLine(final XFeatureCall fc, final FormattableDocument doc) { final ILeafNode closingBracket = this._nodeModelAccess.nodeForKeyword(fc, ")"); HiddenLeafs _hiddenLeafsBefore = null; if (closingBracket!=null) { _hiddenLeafsBefore=this._hiddenLeafAccess.getHiddenLeafsBefore(closingBracket); } boolean _tripleNotEquals = (_hiddenLeafsBefore != null); if (_tripleNotEquals) { int _newLines = this._hiddenLeafAccess.getHiddenLeafsBefore(closingBracket).getNewLines(); return (_newLines > 0); } final Iterable<XExpression> params = this.explicitParams(fc.getFeatureCallArguments()); return ((IterableExtensions.size(params) > 1) && this.isEachExpressionInOwnLine(params)); }
@Test public void testImplicitReceiver() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("{"); _builder.newLine(); _builder.append("\t"); _builder.append("val it = \'\'"); _builder.newLine(); _builder.append("\t"); _builder.append("toString"); _builder.newLine(); _builder.append("}"); _builder.newLine(); XExpression _parse = this._parseHelper.parse(_builder); final XBlockExpression block = ((XBlockExpression) _parse); Resource _eResource = block.eResource(); final BatchLinkableResource resource = ((BatchLinkableResource) _eResource); XExpression _last = IterableExtensions.<XExpression>last(block.getExpressions()); final XFeatureCall toString = ((XFeatureCall) _last); XExpression _implicitReceiver = toString.getImplicitReceiver(); final XFeatureCall implicitReceiver = ((XFeatureCall) _implicitReceiver); Assert.assertEquals("it", implicitReceiver.getFeature().getSimpleName()); resource.update(0, 0, ""); Assert.assertNull(this._reflectExtensions.<Object>get(toString, "implicitReceiver")); Assert.assertNotNull(toString.getImplicitReceiver()); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
@Check public void checkConstructorArgumentsAreValid(XFeatureCall featureCall) { JvmIdentifiableElement feature = featureCall.getFeature(); if (feature != null && !feature.eIsProxy() && feature instanceof JvmConstructor) { JvmType containerType = EcoreUtil2.getContainerOfType(logicalContainerProvider.getNearestLogicalContainer(featureCall), JvmType.class); for(XExpression argument: featureCall.getFeatureCallArguments()) { checkIsValidConstructorArgument(argument, containerType); } } }
@Check public void checkNoForwardReferences(XExpression fieldInitializer) { JvmIdentifiableElement container = logicalContainerProvider.getLogicalContainer(fieldInitializer); if (container instanceof JvmField) { JvmField field = (JvmField) container; boolean staticField = field.isStatic(); JvmDeclaredType declaredType = field.getDeclaringType(); if (declaredType == null) { return; } Collection<JvmField> illegalFields = Sets.newHashSet(); for(int i = declaredType.getMembers().size() - 1; i>=0; i--) { JvmMember member = declaredType.getMembers().get(i); if (member instanceof JvmField) { if (((JvmField) member).isStatic() == staticField) { illegalFields.add((JvmField) member); } } if (member == field) break; } TreeIterator<EObject> iterator = EcoreUtil2.eAll(fieldInitializer); while(iterator.hasNext()) { EObject object = iterator.next(); if (object instanceof XFeatureCall) { JvmIdentifiableElement feature = ((XFeatureCall) object).getFeature(); if (illegalFields.contains(((XFeatureCall) object).getFeature())) { error("Cannot reference the field '" + feature.getSimpleName() + "' before it is defined", object, null, INSIGNIFICANT_INDEX, ILLEGAL_FORWARD_REFERENCE); } } else if (isLocalClassSemantics(object)) { iterator.prune(); } } } }
@Check public void checkExplicitOperationCall(XFeatureCall featureCall) { if (featureCall.getFeature() instanceof JvmOperation && !featureCall.isExplicitOperationCallOrBuilderSyntax() && featureCall.getFeature().getSimpleName().equals(featureCall.getConcreteSyntaxFeatureName())) { addIssue("Method call without parentheses", featureCall, XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, OPERATION_WITHOUT_PARENTHESES); } }
@Override public void addExtensionToCurrentScope(JvmIdentifiableElement extensionProvider) { LightweightTypeReference knownType = getResolvedTypes().getActualType(extensionProvider); if (knownType != null && !knownType.isAny() && !knownType.isUnknown()) { XFeatureCall prototype = getResolver().getXbaseFactory().createXFeatureCall(); prototype.setFeature(extensionProvider); featureScopeSession = featureScopeSession.addToExtensionScope(Collections.<XExpression, LightweightTypeReference>singletonMap(prototype, knownType)); } }
protected IFeatureScopeSession addExtensionsToMemberSession(ResolvedTypes resolvedTypes, IFeatureScopeSession featureScopeSession, JvmDeclaredType type) { IEObjectDescription thisDescription = featureScopeSession.getLocalElement(IFeatureNames.THIS); if (thisDescription == null) { throw new IllegalStateException("Cannot find feature 'THIS'"); } JvmIdentifiableElement thisFeature = (JvmIdentifiableElement) thisDescription.getEObjectOrProxy(); IFeatureScopeSession childSession = addExtensionFieldsToMemberSession( resolvedTypes, featureScopeSession, type, thisFeature, Sets.<String>newHashSetWithExpectedSize(8), Sets.<JvmType>newHashSetWithExpectedSize(4)); XFeatureCall thisAccess = getXbaseFactory().createXFeatureCall(); thisAccess.setFeature(thisFeature); LightweightTypeReference thisType = resolvedTypes.getActualType(thisFeature); childSession = childSession.addToExtensionScope(Collections.<XExpression, LightweightTypeReference>singletonMap(thisAccess, thisType)); return childSession; }
public boolean isPackageFragment() { XAbstractFeatureCall featureCall = getFeatureCall(); if (featureCall instanceof XFeatureCall) return ((XFeatureCall) featureCall).isPackageFragment(); if (featureCall instanceof XMemberFeatureCall) return ((XMemberFeatureCall) featureCall).isPackageFragment(); return false; }
@Test public void testSwitchExpression_01() throws Exception { XSwitchExpression switchExpr = (XSwitchExpression) expression( "switch x : new Object() { " + " case x : x" + "}"); final XCasePart xCasePart = switchExpr.getCases().get(0); assertEquals(switchExpr.getDeclaredParam(), ((XFeatureCall) xCasePart.getThen()).getFeature()); assertEquals(switchExpr.getDeclaredParam(), ((XFeatureCall) xCasePart.getCase()).getFeature()); }
@Test public void testShadowing_4() throws Exception { XBlockExpression bop = (XBlockExpression) expression( "{" + " val size = 23;" + " {" + " val this = new java.util.ArrayList<String>(); " + " size();" + " };" + "}"); XBlockExpression innerBlock = (XBlockExpression)bop.getExpressions().get(1); assertEquals("java.util.ArrayList.size()",((XFeatureCall)innerBlock.getExpressions().get(1)).getFeature().getIdentifier()); }
@Test public void testShadowing_2() throws Exception { XBlockExpression bop = (XBlockExpression) expression( "{ " + " val size = 23;" + " val this = new java.util.ArrayList<String>(); " + " size;" + "}"); JvmIdentifiableElement feature = ((XFeatureCall)bop.getExpressions().get(2)).getFeature(); assertTrue(feature.toString(), feature instanceof XVariableDeclaration); }
protected IScope createDynamicExtensionsScope(QualifiedName implicitFirstArgumentName, IEObjectDescription firstArgumentDescription, EObject featureCall, IFeatureScopeSession captureLayer, IFeatureScopeSession session, IResolvedTypes resolvedTypes, IScope parent) { JvmIdentifiableElement feature = (JvmIdentifiableElement) firstArgumentDescription.getEObjectOrProxy(); if (feature instanceof JvmType && THIS.equals(implicitFirstArgumentName) && !session.isInstanceContext()) { return parent; } LightweightTypeReference type = resolvedTypes.getActualType(feature); if (type != null && !type.isUnknown()) { XFeatureCall implicitArgument = xbaseFactory.createXFeatureCall(); implicitArgument.setFeature(feature); return createDynamicExtensionsScope(featureCall, implicitArgument, type, true, parent, captureLayer); } return parent; }
protected IScope createImplicitExtensionScope(QualifiedName implicitName, EObject featureCall, IFeatureScopeSession session, IResolvedTypes resolvedTypes, IScope parent) { IEObjectDescription thisDescription = session.getLocalElement(implicitName); if (thisDescription != null) { JvmIdentifiableElement thisElement = (JvmIdentifiableElement) thisDescription.getEObjectOrProxy(); LightweightTypeReference type = resolvedTypes.getActualType(thisElement); if (type != null && !type.isUnknown()) { XFeatureCall implicitReceiver = xbaseFactory.createXFeatureCall(); implicitReceiver.setFeature(thisElement); return createStaticExtensionsScope(featureCall, implicitReceiver, type, true, parent, session); } } return parent; }
@Test public void testForLoop_01() throws Exception { final XBlockExpression block = (XBlockExpression) expression("{val s = null as Iterable<String>; for(String s: s) s}"); XForLoopExpression forLoop = (XForLoopExpression) block.getExpressions().get(1); XFeatureCall forFeatureCall = (XFeatureCall) forLoop.getForExpression(); assertEquals(block.getExpressions().get(0), forFeatureCall.getFeature()); XFeatureCall eachFeatureCall = (XFeatureCall) forLoop.getEachExpression(); assertFalse(eachFeatureCall.getFeature().eIsProxy()); assertSame(forLoop.getDeclaredParam(), eachFeatureCall.getFeature()); }
protected boolean looksLikeLocalVariable(XAbstractFeatureCall featureCall) { if (featureCall instanceof XFeatureCall) { boolean result = !featureCall.isExplicitOperationCallOrBuilderSyntax() && featureCall.getTypeArguments().isEmpty(); return result; } return false; }
@Override protected void doInternalToJavaStatement(XExpression obj, ITreeAppendable appendable, boolean isReferenced) { if (obj instanceof XFeatureCall) { _toJavaStatement((XFeatureCall) obj, appendable, isReferenced); } else if (obj instanceof XAbstractFeatureCall) { _toJavaStatement((XAbstractFeatureCall) obj, appendable, isReferenced); } else { super.doInternalToJavaStatement(obj, appendable, isReferenced); } }
protected void _toJavaStatement(final XFeatureCall expr, final ITreeAppendable b, boolean isReferenced) { // if it's a call to this() or super() make sure the arguments are forced to be compiled to expressions. if (expr.getFeature() instanceof JvmConstructor) { b.newLine(); featureCalltoJavaExpression(expr, b, false); b.append(";"); } else { _toJavaStatement((XAbstractFeatureCall) expr, b, isReferenced); } }
protected String getSwitchLocalVariableSimpleName(XSwitchExpression expr) { IdentifiableSimpleNameProvider nameProvider = getNameProvider(); String varName = nameProvider.getSimpleName(expr.getDeclaredParam()); if (varName != null) { return varName; } XExpression expression = expr.getSwitch(); if (!(expression instanceof XFeatureCall)) { return null; } XFeatureCall featureCall = (XFeatureCall) expression; JvmIdentifiableElement feature = featureCall.getFeature(); return nameProvider.getSimpleName(feature); }
protected boolean isSimpleFeatureCall(XExpression switch1) { if (switch1 instanceof XFeatureCall) { XFeatureCall featureCall = (XFeatureCall) switch1; return !(featureCall.getFeature() instanceof JvmOperation); } return false; }
/** * @return the variable name under which the result of the expression is stored. Returns <code>null</code> if the * expression hasn't been assigned to a local variable before. */ /* @Nullable */ protected String getReferenceName(XExpression expr, ITreeAppendable b) { if (b.hasName(expr)) return b.getName(expr); if (expr instanceof XFeatureCall) { XFeatureCall featureCall = (XFeatureCall) expr; if (b.hasName(featureCall.getFeature())) return b.getName(featureCall.getFeature()); } return null; }
protected Object _doEvaluate(XFeatureCall featureCall, IEvaluationContext context, CancelIndicator indicator) { if (featureCall.isTypeLiteral()) { JvmType type = (JvmType) featureCall.getFeature(); Object result = translateJvmTypeToResult(type, 0); return result; } else { return _doEvaluate((XAbstractFeatureCall) featureCall, context, indicator); } }
protected void acceptPreferredType(EObject owner, EReference referenceToTypeOrMember) { ITextRegion refRegion = locationInFileProvider.getFullTextRegion(owner, referenceToTypeOrMember, 0); if (refRegion.getLength() > 0) { IParseResult parseResult = resource.getParseResult(); if(parseResult != null) { String completeText = parseResult.getRootNode().getText(); String refText = completeText.substring(refRegion.getOffset(), refRegion.getOffset() + refRegion.getLength()); PreferredType preferredType = findPreferredType(owner, referenceToTypeOrMember, refText); if (preferredType != null) { if (preferredType.referencedType != null) { acceptType(preferredType.referencedType, preferredType.usedType, refRegion); } else { String suffix = refText.substring(preferredType.unresolvedTypeName.length()); if (owner instanceof XFeatureCall) { XFeatureCall featureCall = (XFeatureCall) owner; if (typeLiteralHelper.isPotentialTypeLiteral(featureCall, null)) { XAbstractFeatureCall root = typeLiteralHelper.getRootTypeLiteral(featureCall); if (root != null) { ITextRegion region = locationInFileProvider.getSignificantTextRegion(root); if (region.getOffset() == refRegion.getOffset()) { suffix = completeText.substring(region.getOffset(), region.getOffset() + region.getLength()); suffix = suffix.substring(preferredType.unresolvedTypeName.length()); refRegion = region; } } } } acceptUnresolvedType(preferredType.unresolvedTypeName, suffix, refRegion); } } } } }
@Test public void testImplicitThis_3() throws Exception { XBlockExpression bop = (XBlockExpression) expression( "{ " + " val java.util.List this = new java.util.ArrayList<String>(); " + " size;" + "}"); assertEquals("java.util.List.size()",((XFeatureCall)bop.getExpressions().get(1)).getFeature().getIdentifier()); }
protected boolean isStaticMemberCallTarget(final EObject contextObject) { boolean candidate = ((contextObject instanceof XFeatureCall) && (contextObject.eContainingFeature() == XbasePackage.Literals.XMEMBER_FEATURE_CALL__MEMBER_CALL_TARGET)); if (candidate) { EObject _eContainer = contextObject.eContainer(); XMemberFeatureCall memberFeatureCall = ((XMemberFeatureCall) _eContainer); boolean _isExplicitStatic = memberFeatureCall.isExplicitStatic(); if (_isExplicitStatic) { return true; } } return false; }