@Override public ITextRegion getSignificantTextRegion(EObject element) { if (element instanceof XSwitchExpression && ((XSwitchExpression) element).getLocalVarName() != null) { return getLocationOfAttribute( element, XbasePackage.Literals.XSWITCH_EXPRESSION__LOCAL_VAR_NAME, -1, true); } if (element instanceof XAbstractFeatureCall) { XAbstractFeatureCall typeLiteral = typeLiteralHelper.getRootTypeLiteral((XAbstractFeatureCall) element); if (typeLiteral != null) { if (typeLiteral instanceof XMemberFeatureCall) { XAbstractFeatureCall target = (XAbstractFeatureCall) ((XMemberFeatureCall) typeLiteral).getMemberCallTarget(); if (target.isTypeLiteral()) { return super.getSignificantTextRegion(typeLiteral); } } INode node = NodeModelUtils.findActualNodeFor(typeLiteral); if (node != null) { return toZeroBasedRegion(node.getTextRegionWithLineInformation()); } } } return super.getSignificantTextRegion(element); }
// 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; }
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); } } } }
protected IScope getExecutableScope(XAbstractFeatureCall call, JvmIdentifiableElement feature) { QualifiedName name = QualifiedName.create(feature.getSimpleName()); 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) { String propertyName = Strings.toFirstLower(feature.getSimpleName().substring(3)); return new SingletonScope(EObjectDescription.create(propertyName, feature), IScope.NULLSCOPE); } if (call.isExplicitOperationCallOrBuilderSyntax() || ((JvmExecutable) feature).getParameters().size() > 1 || (!call.isExtension() && ((JvmExecutable) feature).getParameters().size() == 1)) { return new SingletonScope(EObjectDescription.create(name, feature), IScope.NULLSCOPE); } if (feature.getSimpleName().startsWith("get") || feature.getSimpleName().startsWith("is")) { List<IEObjectDescription> result = Lists.newArrayListWithCapacity(2); result.add(EObjectDescription.create(name, feature)); if (feature.getSimpleName().startsWith("get")) { String propertyName = Strings.toFirstLower(feature.getSimpleName().substring(3)); result.add(EObjectDescription.create(propertyName, feature)); } else { String propertyName = Strings.toFirstLower(feature.getSimpleName().substring(2)); result.add(EObjectDescription.create(propertyName, feature)); } return new SimpleScope(result); } return new SingletonScope(EObjectDescription.create(name, feature), IScope.NULLSCOPE); }
protected void computeFeatureCallHighlighting( XAbstractFeatureCall featureCall, IHighlightedPositionAcceptor acceptor) { JvmIdentifiableElement feature = featureCall.getFeature(); if (feature != null && !feature.eIsProxy()) { if (feature instanceof JvmField) { if (((JvmField) feature).isStatic()) { highlightFeatureCall(featureCall, acceptor, STATIC_FIELD); } else { highlightFeatureCall(featureCall, acceptor, FIELD); } } else if (feature instanceof JvmOperation && !featureCall.isOperation()) { JvmOperation jvmOperation = (JvmOperation) feature; if (jvmOperation.isStatic()) highlightFeatureCall(featureCall, acceptor, STATIC_METHOD_INVOCATION); } if (!(featureCall instanceof XBinaryOperation || featureCall instanceof XUnaryOperation || featureCall instanceof XPostfixOperation)) { if (featureCall.isExtension()) { highlightFeatureCall(featureCall, acceptor, EXTENSION_METHOD_INVOCATION); } else { // Extensions without implicit first argument XExpression implicitReceiver = featureCall.getImplicitReceiver(); if (implicitReceiver != null && implicitReceiver instanceof XAbstractFeatureCall) { if (isExtension(((XAbstractFeatureCall) implicitReceiver).getFeature())) highlightFeatureCall(featureCall, acceptor, EXTENSION_METHOD_INVOCATION); } } } if (feature instanceof JvmAnnotationTarget && DeprecationUtil.isDeprecated((JvmAnnotationTarget) feature)) { highlightFeatureCall(featureCall, acceptor, DEPRECATED_MEMBERS); } } }
private void addTypeCastToExplicitReceiver( XAbstractFeatureCall featureCall, IModificationContext context, JvmType declaringType, EReference structuralFeature) throws BadLocationException { List<INode> nodes = NodeModelUtils.findNodesForFeature(featureCall, structuralFeature); if (nodes.isEmpty()) return; INode firstNode = IterableExtensions.head(nodes); INode lastNode = IterableExtensions.last(nodes); int offset = firstNode.getOffset(); int length = lastNode.getEndOffset() - offset; ReplacingAppendable appendable = appendableFactory.create( context.getXtextDocument(), (XtextResource) featureCall.eResource(), offset, length); appendable.append("("); ListIterator<INode> nodeIter = nodes.listIterator(); while (nodeIter.hasNext()) { String text = nodeIter.next().getText(); if (nodeIter.previousIndex() == 0) appendable.append(Strings.removeLeadingWhitespace(text)); else if (nodeIter.nextIndex() == nodes.size()) appendable.append(Strings.trimTrailingLineBreak(text)); else appendable.append(text); } appendable.append(" as "); appendable.append(declaringType); appendable.append(")"); appendable.commitChanges(); }
/** * creates the feature scope for {@link XAbstractFeatureCall}, including the local variables in * case it is a feature call without receiver (XFeatureCall). */ protected IScope createFeatureCallScope(final XAbstractFeatureCall call, EReference reference) { if (call instanceof XFeatureCall || ((call instanceof XAssignment) && ((XAssignment) call).getAssignable() == null)) { IScope result = createSimpleFeatureCallScope(call, reference, call.eResource(), false, -1); return result; } final XExpression syntacticalReceiver = getSyntacticalReceiver(call); IScope result = createFeatureCallScopeForReceiver(call, syntacticalReceiver, reference); return result; }
protected void highlightFeatureCall( XAbstractFeatureCall featureCall, IHighlightedPositionAcceptor acceptor, String id) { // highlightDeprecation(acceptor, featureCall, null, featureCall.getFeature()); if (featureCall.isTypeLiteral()) { ICompositeNode node = NodeModelUtils.findActualNodeFor(featureCall); highlightNode(acceptor, node, id); } else { highlightFeature( acceptor, featureCall, XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, id); } }
protected String checkJvmOperation( JvmOperation input, XAbstractFeatureCall context, boolean isExplicitOperationCall, JvmFeatureDescription jvmFeatureDescription, EList<XExpression> arguments) { List<XExpression> actualArguments = featureCall2JavaMapping.getActualArguments( context, input, jvmFeatureDescription.getImplicitReceiver()); if (!isValidNumberOfArguments(input, actualArguments)) return INVALID_NUMBER_OF_ARGUMENTS; if (!isExplicitOperationCall && !isSugaredMethodInvocationWithoutParanthesis(jvmFeatureDescription)) return METHOD_ACCESS_WITHOUT_PARENTHESES; if (!context.getTypeArguments().isEmpty() // raw type or type inference && input.getTypeParameters().size() != context.getTypeArguments().size()) return INVALID_NUMBER_OF_TYPE_ARGUMENTS; // TODO check type parameter bounds against type arguments if (!areArgumentTypesValid(input, actualArguments)) return INVALID_ARGUMENT_TYPES; return null; }
protected IScope createFeatureScopeForTypeRef( JvmTypeReference type, XAbstractFeatureCall context, IScope parent, Predicate<JvmMember> isAccept) { if (type instanceof JvmWildcardTypeReference) { JvmWildcardTypeReference wildcard = (JvmWildcardTypeReference) type; for (JvmTypeConstraint constraint : wildcard.getConstraints()) { if (constraint instanceof JvmUpperBound) { JvmTypeReference upperBound = constraint.getTypeReference(); parent = createFeatureScopeForTypeRef( upperBound, context, getContextType(context), context.getImplicitReceiver()); } } return parent; } else { return super.createFeatureScopeForTypeRef( type, context, getContextType(context), context.getImplicitReceiver()); } }
protected IScope getTypeScope(XAbstractFeatureCall call, JvmType type) { if (call.isTypeLiteral() || call.isPackageFragment()) { return doGetTypeScope(call, type); } return getThisOrSuperScope(call, type); }
public LightweightTypeReference resolvesTo(final String expression, final String type) { try { final XExpression xExpression = this.expression(expression, false); Resource _eResource = xExpression.eResource(); EList<Diagnostic> _errors = _eResource.getErrors(); String _string = _errors.toString(); Resource _eResource_1 = xExpression.eResource(); EList<Diagnostic> _errors_1 = _eResource_1.getErrors(); boolean _isEmpty = _errors_1.isEmpty(); Assert.assertTrue(_string, _isEmpty); Resource _eResource_2 = xExpression.eResource(); EList<Diagnostic> _warnings = _eResource_2.getWarnings(); String _string_1 = _warnings.toString(); Resource _eResource_3 = xExpression.eResource(); EList<Diagnostic> _warnings_1 = _eResource_3.getWarnings(); boolean _isEmpty_1 = _warnings_1.isEmpty(); Assert.assertTrue(_string_1, _isEmpty_1); IBatchTypeResolver _typeResolver = this.getTypeResolver(); final IResolvedTypes resolvedTypes = _typeResolver.resolveTypes(xExpression); final LightweightTypeReference resolvedType = resolvedTypes.getActualType(xExpression); String _simpleName = resolvedType.getSimpleName(); Assert.assertEquals(type, _simpleName); TreeIterator<EObject> _eAllContents = xExpression.eAllContents(); Iterable<EObject> _iterable = IteratorExtensions.<EObject>toIterable(_eAllContents); for (final EObject content : _iterable) { boolean _matched = false; if (!_matched) { if (content instanceof XSwitchExpression) { final XSwitchExpression _xSwitchExpression = (XSwitchExpression) content; _matched = true; this.assertExpressionTypeIsResolved(_xSwitchExpression, resolvedTypes); String _localVarName = _xSwitchExpression.getLocalVarName(); boolean _notEquals = (!Objects.equal(_localVarName, null)); if (_notEquals) { this.assertIdentifiableTypeIsResolved(_xSwitchExpression, resolvedTypes); } } } if (!_matched) { if (content instanceof XAbstractFeatureCall) { final XAbstractFeatureCall _xAbstractFeatureCall = (XAbstractFeatureCall) content; _matched = true; this.assertExpressionTypeIsResolved(_xAbstractFeatureCall, resolvedTypes); XExpression _implicitReceiver = _xAbstractFeatureCall.getImplicitReceiver(); boolean _notEquals = (!Objects.equal(_implicitReceiver, null)); if (_notEquals) { XExpression _implicitReceiver_1 = _xAbstractFeatureCall.getImplicitReceiver(); this.assertExpressionTypeIsResolved(_implicitReceiver_1, resolvedTypes); } } } if (!_matched) { if (content instanceof XExpression) { final XExpression _xExpression = (XExpression) content; _matched = true; this.assertExpressionTypeIsResolved(_xExpression, resolvedTypes); } } if (!_matched) { if (content instanceof JvmIdentifiableElement) { final JvmIdentifiableElement _jvmIdentifiableElement = (JvmIdentifiableElement) content; _matched = true; this.assertIdentifiableTypeIsResolved(_jvmIdentifiableElement, resolvedTypes); } } } TreeIterator<EObject> _eAllContents_1 = xExpression.eAllContents(); Iterable<EObject> _iterable_1 = IteratorExtensions.<EObject>toIterable(_eAllContents_1); for (final EObject content_1 : _iterable_1) { boolean _matched_1 = false; if (!_matched_1) { if (content_1 instanceof XConstructorCall) { final XConstructorCall _xConstructorCall = (XConstructorCall) content_1; _matched_1 = true; Object _eGet = _xConstructorCall.eGet(Literals.XCONSTRUCTOR_CALL__CONSTRUCTOR, false); final InternalEObject constructor = ((InternalEObject) _eGet); String _string_2 = _xConstructorCall.toString(); Assert.assertNotNull(_string_2, constructor); String _string_3 = _xConstructorCall.toString(); boolean _eIsProxy = constructor.eIsProxy(); Assert.assertFalse(_string_3, _eIsProxy); } } if (!_matched_1) { if (content_1 instanceof XAbstractFeatureCall) { final XAbstractFeatureCall _xAbstractFeatureCall = (XAbstractFeatureCall) content_1; _matched_1 = true; Object _eGet = _xAbstractFeatureCall.eGet(Literals.XABSTRACT_FEATURE_CALL__FEATURE, false); final InternalEObject feature = ((InternalEObject) _eGet); String _string_2 = _xAbstractFeatureCall.toString(); Assert.assertNotNull(_string_2, feature); String _string_3 = _xAbstractFeatureCall.toString(); boolean _eIsProxy = feature.eIsProxy(); Assert.assertFalse(_string_3, _eIsProxy); XExpression _implicitReceiver = _xAbstractFeatureCall.getImplicitReceiver(); boolean _notEquals = (!Objects.equal(_implicitReceiver, null)); if (_notEquals) { XExpression _implicitReceiver_1 = _xAbstractFeatureCall.getImplicitReceiver(); Object _eGet_1 = _implicitReceiver_1.eGet(Literals.XABSTRACT_FEATURE_CALL__FEATURE, false); final InternalEObject implicitFeature = ((InternalEObject) _eGet_1); String _string_4 = implicitFeature.toString(); Assert.assertNotNull(_string_4, feature); String _string_5 = implicitFeature.toString(); boolean _eIsProxy_1 = feature.eIsProxy(); Assert.assertFalse(_string_5, _eIsProxy_1); } } } } Resource _eResource_4 = xExpression.eResource(); Iterable<Diagnostic> _linkingAndSyntaxErrors = this.getLinkingAndSyntaxErrors(_eResource_4); String _string_2 = _linkingAndSyntaxErrors.toString(); Resource _eResource_5 = xExpression.eResource(); Iterable<Diagnostic> _linkingAndSyntaxErrors_1 = this.getLinkingAndSyntaxErrors(_eResource_5); boolean _isEmpty_2 = IterableExtensions.isEmpty(_linkingAndSyntaxErrors_1); Assert.assertTrue(_string_2, _isEmpty_2); Resource _eResource_6 = xExpression.eResource(); EList<Diagnostic> _warnings_2 = _eResource_6.getWarnings(); String _string_3 = _warnings_2.toString(); Resource _eResource_7 = xExpression.eResource(); EList<Diagnostic> _warnings_3 = _eResource_7.getWarnings(); boolean _isEmpty_3 = _warnings_3.isEmpty(); Assert.assertTrue(_string_3, _isEmpty_3); return resolvedType; } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }