Java 类org.eclipse.xtext.xbase.XAbstractFeatureCall 实例源码

项目:xtext-extras    文件:XbaseValidator.java   
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();
        }
    }
}
项目:xtext-extras    文件:XbaseValidator.java   
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);
            }
        }
    }
}
项目:xtext-extras    文件:AbstractConstantExpressionsInterpreter.java   
protected String getOperator(final XAbstractFeatureCall call) {
  String _switchResult = null;
  Resource _eResource = call.eResource();
  final Resource res = _eResource;
  boolean _matched = false;
  if (res instanceof StorageAwareResource) {
    boolean _isLoadedFromStorage = ((StorageAwareResource)res).isLoadedFromStorage();
    if (_isLoadedFromStorage) {
      _matched=true;
      QualifiedName _operator = this.operatorMapping.getOperator(QualifiedName.create(call.getFeature().getSimpleName()));
      String _string = null;
      if (_operator!=null) {
        _string=_operator.toString();
      }
      return _string;
    }
  }
  if (!_matched) {
    _switchResult = call.getConcreteSyntaxFeatureName();
  }
  return _switchResult;
}
项目:xtext-extras    文件:DynamicExtensionsScope.java   
public DynamicExtensionsScope(
        IScope parent,
        IFeatureScopeSession session, 
        XExpression firstArgument,
        LightweightTypeReference argumentType,
        boolean implicit,
        XAbstractFeatureCall context,
        OperatorMapping operatorMapping) {
    super(parent, session, context, operatorMapping);
    this.firstArgument = firstArgument;
    this.argumentType = argumentType;
    this.implicit = implicit;
    if (argumentType != null)
        this.helper = new ExtensionScopeHelper(argumentType);
    else
        this.helper = null;
}
项目:xtext-extras    文件:AbstractTypeComputationState.java   
protected IFeatureLinkingCandidate createCandidate(XAbstractFeatureCall featureCall, final StackedResolvedTypes demandComputedTypes, IIdentifiableElementDescription description) {
    if (description.getSyntacticReceiverType() != null) { 
        return createCandidateWithReceiverType(featureCall, demandComputedTypes, description);
    }
    // pretty much the same constraints as in #createCandidateWithReceiverType 
    ExpressionAwareStackedResolvedTypes resolvedTypes = this.resolvedTypes.pushTypes(featureCall);
    ExpressionTypeComputationState state = createExpressionComputationState(featureCall, resolvedTypes);
    if (description instanceof ScopeProviderAccess.ErrorDescription) {
        ScopeProviderAccess.ErrorDescription errorDescription = (ScopeProviderAccess.ErrorDescription) description;
        boolean followUpError = errorDescription.isFollowUpError();
        if (followUpError) {
            return new FollowUpError(featureCall, state);
        }
        return new UnresolvableFeatureCall(featureCall, errorDescription.getNode(), description.getName().toString(), state);
    } else if (description.isTypeLiteral()) {
        return new TypeLiteralLinkingCandidate(featureCall, description, getSingleExpectation(state), state);
    } else {
        return new FeatureLinkingCandidate(featureCall, description, getSingleExpectation(state), state);
    }
}
项目:xtext-extras    文件:AnnotationValueValidator.java   
protected boolean isValidAnnotationValue(final XExpression expression) {
  if (expression instanceof XListLiteral) {
    return _isValidAnnotationValue((XListLiteral)expression);
  } else if (expression instanceof XAbstractFeatureCall) {
    return _isValidAnnotationValue((XAbstractFeatureCall)expression);
  } else if (expression instanceof XAnnotation) {
    return _isValidAnnotationValue((XAnnotation)expression);
  } else if (expression != null) {
    return _isValidAnnotationValue(expression);
  } else if (expression == null) {
    return _isValidAnnotationValue((Void)null);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(expression).toString());
  }
}
项目:dsl-devkit    文件:CheckCompiler.java   
@Override
// CHECKSTYLE:OFF
protected void _toJavaExpression(final XAbstractFeatureCall expr, final ITreeAppendable b) {
  // CHECKSTYLE:ON
  FormalParameter parameter = getFormalParameter(expr);
  if (parameter != null) {
    // No Java entities are generated for this. Replace by a call to the getter function.
    b.append(generatorNaming.catalogInstanceName(parameter)).append(".").append(generatorNaming.formalParameterGetterName(parameter));
    b.append("(").append(getContextImplicitVariableName(expr)).append(")");
  } else {
    Member member = getMember(expr);
    if (member != null) {
      // Something isn't quite right in the Jvm model yet... or in the xbase compiler. Don't know what it is, but even if in an inner
      // class, it generates "this.foo" instead of either just "foo" or "OuterClass.this.foo". Force it to produce the latter.
      CheckCatalog catalog = EcoreUtil2.getContainerOfType(member, CheckCatalog.class);
      String catalogName = generatorNaming.validatorClassName(catalog);
      b.append(catalogName + ".this.").append(member.getName());
      return;
    }
    super._toJavaExpression(expr, b);
  }
}
项目:xtext-extras    文件:FeatureCallCompiler.java   
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);
        }
    }
}
项目:xtext-extras    文件:TypeLiteralScope.java   
@Override
protected List<IEObjectDescription> getLocalElementsByName(QualifiedName name) {
    XAbstractFeatureCall featureCall = getFeatureCall();
    if (featureCall.isExplicitOperationCallOrBuilderSyntax())
        return Collections.emptyList();
    QualifiedName fqn = parentSegments.append(name);
    IScope typeScope = getSession().getScope(getFeatureCall(), TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE, resolvedTypes);
    IEObjectDescription typeDescription = typeScope.getSingleElement(fqn);
    if (typeDescription != null) {
        EObject type = typeDescription.getEObjectOrProxy();
        if (type instanceof JvmType)
            return Collections.<IEObjectDescription>singletonList(new TypeLiteralDescription(
                    new AliasedEObjectDescription(name, typeDescription), isVisible((JvmType) type)));
    }
    return Collections.emptyList();
}
项目:xtext-extras    文件:ConstantConditionsInterpreter.java   
private boolean isFromXbaseLibrary(final XAbstractFeatureCall it, final EvaluationContext context) {
  boolean _xblockexpression = false;
  {
    final JvmIdentifiableElement feature = this.getFeature(it, context);
    boolean _switchResult = false;
    boolean _matched = false;
    if (feature instanceof JvmMember) {
      _matched=true;
      JvmDeclaredType _declaringType = null;
      if (((JvmMember)feature)!=null) {
        _declaringType=((JvmMember)feature).getDeclaringType();
      }
      String _packageName = null;
      if (_declaringType!=null) {
        _packageName=_declaringType.getPackageName();
      }
      String _string = XImportSectionNamespaceScopeProvider.XBASE_LIB.toString();
      _switchResult = Objects.equal(_packageName, _string);
    }
    if (!_matched) {
      _switchResult = false;
    }
    _xblockexpression = _switchResult;
  }
  return _xblockexpression;
}
项目:xtext-extras    文件:FeatureCallAsTypeLiteralHelper.java   
protected XAbstractFeatureCall doGetRootTypeLiteral(XMemberFeatureCall featureCall) {
    boolean staticNotation = featureCall.isExplicitStatic();
    XMemberFeatureCall current = featureCall;
    while(current.eContainingFeature() == XbasePackage.Literals.XMEMBER_FEATURE_CALL__MEMBER_CALL_TARGET) {
        XMemberFeatureCall container = (XMemberFeatureCall) current.eContainer();
        if (container.isExplicitStatic()) {
            if (staticNotation == false) {
                return current;
            }
            current = container;
        } else if (staticNotation) {
            return (XAbstractFeatureCall) current.getMemberCallTarget();
        } else {
            current = container;
        }
    }
    if (current != featureCall && staticNotation) {
        return (XAbstractFeatureCall) current.getMemberCallTarget();
    }
    return null;
}
项目:xtext-extras    文件:XbaseIdeContentProposalProvider.java   
protected void createReceiverProposals(final XExpression receiver, final CrossReference crossReference, final ContentAssistContext context, final IIdeContentProposalAcceptor acceptor) {
  final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(receiver);
  final LightweightTypeReference receiverType = resolvedTypes.getActualType(receiver);
  if (((receiverType == null) || receiverType.isPrimitiveVoid())) {
    return;
  }
  final IExpressionScope expressionScope = resolvedTypes.getExpressionScope(receiver, IExpressionScope.Anchor.RECEIVER);
  IScope scope = null;
  final EObject currentModel = context.getCurrentModel();
  if ((currentModel != receiver)) {
    if (((currentModel instanceof XMemberFeatureCall) && 
      (((XMemberFeatureCall) currentModel).getMemberCallTarget() == receiver))) {
      scope = this.syntaxFilteredScopes.create(expressionScope.getFeatureScope(((XAbstractFeatureCall) currentModel)), crossReference);
    } else {
      scope = this.syntaxFilteredScopes.create(expressionScope.getFeatureScope(), crossReference);
    }
  } else {
    scope = this.syntaxFilteredScopes.create(expressionScope.getFeatureScope(), crossReference);
  }
  this.getCrossrefProposalProvider().lookupCrossReference(scope, crossReference, context, acceptor, this.featureDescriptionPredicate);
}
项目:xtext-extras    文件:TypeLiteralLinkingCandidate.java   
@Override
protected void preApply() {
    XAbstractFeatureCall expression = getExpression();
    JvmType type = getType();
    if (expression instanceof XMemberFeatureCall) {
        if (type instanceof JvmDeclaredType) {
            JvmDeclaredType declaredType = (JvmDeclaredType) type;
            if (declaredType.getDeclaringType() == null) {
                helper.applyPackageFragment((XMemberFeatureCall) expression, declaredType);
            } else {
                String queriedName = description.getName().toString(); // may be Map$Entry
                String qualifiedName = declaredType.getIdentifier();
                String packageName = Strings.emptyIfNull(declaredType.getPackageName());
                if (packageName.length() + 1 + queriedName.length() == qualifiedName.length()) {
                    helper.applyPackageFragment((XMemberFeatureCall) expression, declaredType);
                }
            }
        }
    }
}
项目:xtext-extras    文件:XbaseInterpreter.java   
protected Object _assignValueTo(JvmField jvmField, XAbstractFeatureCall assignment, Object value,
        IEvaluationContext context, CancelIndicator indicator) {
    Object receiver = getReceiver(assignment, context, indicator);
    Field field = javaReflectAccess.getField(jvmField);
    try {
        if (field == null) {
            throw new NoSuchFieldException("Could not find field " + jvmField.getIdentifier());
        }
        if (!Modifier.isStatic(field.getModifiers()) && receiver == null)
            throw new EvaluationException(new NullPointerException("Cannot assign value to field: "
                    + jvmField.getIdentifier() + " on null instance"));
        JvmTypeReference type = jvmField.getType();
        Object coerced = coerceArgumentType(value, type);
        field.setAccessible(true);
        field.set(receiver, coerced);
        return value;
    } catch (Exception e) {
        throw new IllegalStateException("Could not access field: " + jvmField.getIdentifier()
                + " on instance: " + receiver, e);
    }
}
项目:xtext-extras    文件:ScopeProviderAccess.java   
protected IFeatureLinkingCandidate getKnownFeature(XAbstractFeatureCall featureCall, AbstractTypeComputationState state, ResolvedTypes resolvedTypes) {
    IFeatureLinkingCandidate result = resolvedTypes.getFeature(featureCall);
    if (result != null) {
        return new AppliedFeatureLinkingCandidate(result);
    }
    EObject proxyOrResolved = (EObject) featureCall.eGet(XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, false);
    if (proxyOrResolved == null) {
        return new NullFeatureLinkingCandidate(featureCall, state);
    }
    if (!proxyOrResolved.eIsProxy()) {
        return state.createResolvedLink(featureCall, (JvmIdentifiableElement) proxyOrResolved);
    }
    if (!encoder.isCrossLinkFragment(featureCall.eResource(), EcoreUtil.getURI(proxyOrResolved).fragment())) {
        JvmIdentifiableElement feature = featureCall.getFeature();
        if (!feature.eIsProxy()) {
            return state.createResolvedLink(featureCall, feature);
        }
    }
    return null;
}
项目:xtext-extras    文件:TypeConvertingCompiler.java   
private boolean mustInsertTypeCast(XExpression expression, LightweightTypeReference actualType) {
    IResolvedTypes resolvedTypes = getResolvedTypes(expression);
    if (mustCheckForMandatoryTypeCast(resolvedTypes, expression)) {
        if (expression instanceof XAbstractFeatureCall) {
            LightweightTypeReference featureType = resolvedTypes.getActualType(((XAbstractFeatureCall) expression).getFeature());
            if (featureType != null && !featureType.isMultiType() && actualType.isAssignableFrom(featureType)) {
                return false;
            }
        }
        if (expression.eContainer() instanceof XCastedExpression) {
            XCastedExpression castedExpression = (XCastedExpression) expression.eContainer();
            LightweightTypeReference castedExpressionType = getResolvedTypes(castedExpression).getActualType(castedExpression);
            if (castedExpressionType != null) {
                return actualType.getType() != castedExpressionType.getType();  
            }
        }
        return true;
    }
    return false;
}
项目:xtext-extras    文件:BatchFeatureCallTypeTest.java   
@Override
public void resolvesFeatureCallsTo(final String expression, final String... types) {
  final String expressionWithQualifiedNames = expression.replace("$$", "org::eclipse::xtext::xbase::lib::");
  final List<XAbstractFeatureCall> featureCalls = this.findFeatureCalls(expressionWithQualifiedNames);
  final IResolvedTypes resolvedTypes = this.getTypeResolver().resolveTypes(IterableExtensions.<XAbstractFeatureCall>head(featureCalls));
  final Iterable<XAbstractFeatureCall> actualFeatureCalls = this.filterTypeLiteralsAndPackageFragments(featureCalls);
  Assert.assertFalse(IterableExtensions.isEmpty(actualFeatureCalls));
  Assert.assertEquals(("" + actualFeatureCalls), ((List<String>)Conversions.doWrapArray(types)).size(), IterableExtensions.size(actualFeatureCalls));
  final Procedure2<XAbstractFeatureCall, Integer> _function = (XAbstractFeatureCall featureCall, Integer index) -> {
    final LightweightTypeReference type = resolvedTypes.getActualType(featureCall);
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("failed for feature call at ");
    _builder.append(index);
    Assert.assertEquals(_builder.toString(), types[(index).intValue()], type.getSimpleName());
  };
  IterableExtensions.<XAbstractFeatureCall>forEach(actualFeatureCalls, _function);
}
项目:xtext-extras    文件:FeatureLinkHelper.java   
public XExpression getSyntacticReceiver(XExpression expression) {
    if (expression instanceof XAbstractFeatureCall) {
        if (expression instanceof XFeatureCall) {
            return null;
        }
        if (expression instanceof XMemberFeatureCall) {
            return ((XMemberFeatureCall) expression).getMemberCallTarget();
        }
        if (expression instanceof XAssignment) {
            return ((XAssignment) expression).getAssignable();
        }
        if (expression instanceof XBinaryOperation) {
            return ((XBinaryOperation) expression).getLeftOperand();
        }
        if (expression instanceof XUnaryOperation) {
            return ((XUnaryOperation) expression).getOperand();
        }
        if (expression instanceof XPostfixOperation) {
            return ((XPostfixOperation) expression).getOperand();
        }
    }
    return null;
}
项目:xtext-extras    文件:FeatureLinkHelper.java   
public List<XExpression> getSyntacticArguments(XAbstractFeatureCall expression) {
    if (expression instanceof XFeatureCall) {
        return ((XFeatureCall) expression).getFeatureCallArguments();
    }
    if (expression instanceof XMemberFeatureCall) {
        return ((XMemberFeatureCall) expression).getMemberCallArguments();
    }
    if (expression instanceof XAssignment) {
        return Collections.singletonList(((XAssignment) expression).getValue());
    }
    if (expression instanceof XBinaryOperation) {
        return Collections.singletonList(((XBinaryOperation) expression).getRightOperand());
    }
    // explicit condition to make sure we thought about it
    if (expression instanceof XUnaryOperation) {
        return Collections.emptyList();
    }
    if (expression instanceof XPostfixOperation) {
        return Collections.emptyList();
    }
    return Collections.emptyList();
}
项目:xtext-extras    文件:ImplicitReceiver.java   
@Override
public void applyToComputationState() {
    super.applyToComputationState();
    XAbstractFeatureCall featureCall = getFeatureCall();
    if (featureCall instanceof XMemberFeatureCall) {
        XExpression target = ((XMemberFeatureCall) featureCall).getMemberCallTarget();
        if (target == null || !(target instanceof XAbstractFeatureCall))
            throw new IllegalStateException();
        XAbstractFeatureCall targetFeatureCall = (XAbstractFeatureCall) target;
        ResolvedTypes resolvedTypes = getState().getResolvedTypes();
        LightweightTypeReference targetType = resolvedTypes.getActualType(targetFeatureCall.getFeature());
        if (targetType == null) {
            throw new IllegalStateException();
        }
        TypeExpectation expectation = new TypeExpectation(null, getState(), false);
        resolvedTypes.acceptType(targetFeatureCall, expectation, targetType.copyInto(resolvedTypes.getReferenceOwner()), false, ConformanceFlags.UNCHECKED);
    }
}
项目:xtext-extras    文件:ReceiverFeatureScope.java   
public ReceiverFeatureScope(IScope parent, IFeatureScopeSession session, XExpression receiver, LightweightTypeReference receiverType, boolean implicit,
        XAbstractFeatureCall featureCall, TypeBucket bucket, JvmIdentifiableElement receiverFeature, OperatorMapping operatorMapping, boolean validStaticState) {
    super(parent, session, featureCall, operatorMapping);
    this.receiver = receiver;
    this.receiverType = receiverType;
    this.implicit = implicit;
    this.bucket = bucket;
    this.receiverFeature = receiverFeature;
    this.validStaticState = validStaticState;
}
项目:xtext-extras    文件:XbaseValidator.java   
protected void checkAssignment(XExpression expression, EStructuralFeature feature, boolean simpleAssignment) {
    if (!(expression instanceof XAbstractFeatureCall)) {
        error("The left-hand side of an assignment must be a variable", expression, null,
                ValidationMessageAcceptor.INSIGNIFICANT_INDEX, ASSIGNMENT_TO_NO_VARIABLE);
        return;
    }
    XAbstractFeatureCall assignment = (XAbstractFeatureCall) expression;
    JvmIdentifiableElement assignmentFeature = assignment.getFeature();
    if (assignmentFeature instanceof XVariableDeclaration) {
        XVariableDeclaration variableDeclaration = (XVariableDeclaration) assignmentFeature;
        if (variableDeclaration.isWriteable()) {
            return;
        }
        error("Assignment to final variable", expression, feature,
            ValidationMessageAcceptor.INSIGNIFICANT_INDEX, ASSIGNMENT_TO_FINAL);
    } else if (assignmentFeature instanceof JvmFormalParameter) {
        error("Assignment to final parameter", expression, feature,
                ValidationMessageAcceptor.INSIGNIFICANT_INDEX, ASSIGNMENT_TO_FINAL);
    } else if (assignmentFeature instanceof JvmField) {
        JvmField field = (JvmField) assignmentFeature;
        if (!field.isFinal()) {
            return;
        }
        if (simpleAssignment) {
            JvmIdentifiableElement container = logicalContainerProvider.getNearestLogicalContainer(assignment);

            // don't issue an error if it's an assignment of a local final field within a constructor.
            if (container != null && container instanceof JvmConstructor) {
                JvmConstructor constructor = (JvmConstructor) container;
                if (field.getDeclaringType() == constructor.getDeclaringType())
                    return;
            }
        }
        error("Assignment to final field", expression, feature,
                ValidationMessageAcceptor.INSIGNIFICANT_INDEX, ASSIGNMENT_TO_FINAL);
    } else if (!simpleAssignment) {
        error("The left-hand side of an assignment must be a variable", expression, null,
                ValidationMessageAcceptor.INSIGNIFICANT_INDEX, ASSIGNMENT_TO_NO_VARIABLE);
    }
}
项目:xtext-extras    文件:XbaseValidator.java   
@Check
public void checkDeprecated(XAbstractFeatureCall expression) {
    if (!isIgnored(DEPRECATED_MEMBER_REFERENCE)) {
        JvmIdentifiableElement feature = expression.getFeature();
        checkDeprecated(
                feature,
                expression,
                XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE);
    }
}
项目:xtext-extras    文件:EarlyExitValidator.java   
@Check
public void checkDeadCode(XBlockExpression block) {
    List<XExpression> expressions = block.getExpressions();
    for(int i = 0, size = expressions.size(); i < size - 1; i++) {
        XExpression expression = expressions.get(i);
        if (earlyExitComputer.isEarlyExit(expression)) {
            if (!(expression instanceof XAbstractFeatureCall)) {
                // XAbstractFeatureCall does already a decent job for its argument lists
                // no additional error necessary
                markAsDeadCode(expressions.get(i + 1));
            }
            return;
        }
    }
}
项目:xtext-extras    文件:LocalVariableScope.java   
protected boolean canBeLocalVariable() {
    XAbstractFeatureCall featureCall = getFeatureCall();
    if (featureCall != null) {
        return looksLikeLocalVariable(featureCall) || featureCall instanceof XAssignment;
    }
    return true;
}
项目:xtext-extras    文件:FeatureCallCompiler.java   
protected List<XExpression> getActualArguments(final XAbstractFeatureCall expr) {
    List<XExpression> actualArguments = expr.getActualArguments();
    return Lists.transform(actualArguments, new Function<XExpression, XExpression>() {
        @Override
        public XExpression apply(XExpression e) {
            return normalizeBlockExpression(e);
        }
    });
}
项目:xtext-extras    文件:SerializerScopeProvider.java   
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);
}
项目:xtext-extras    文件:FeatureScopes.java   
protected IScope createImplicitStaticScope(QualifiedName implicitName, XAbstractFeatureCall 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()) {
            TypeBucket receiverBucket = new TypeBucket(-1, Collections.singletonList(type.getType()), resolvedFeaturesProvider);
            return createStaticFeatureScope(featureCall, null, type, receiverBucket, parent, session);
        }
    }
    return parent;
}
项目:xtext-extras    文件:XbaseInterpreter.java   
/**
 * @param featureCall unused in this context but required for dispatching
 * @param indicator unused in this context but required for dispatching
 */
protected Object _invokeFeature(JvmIdentifiableElement identifiable, XAbstractFeatureCall featureCall, Object receiver,
        IEvaluationContext context, CancelIndicator indicator) {
    if (receiver != null)
        throw new IllegalStateException("feature was simple feature call but got receiver instead of null. Receiver: " + receiver);
    String localVarName = featureNameProvider.getSimpleName(identifiable);
    Object value = context.getValue(QualifiedName.create(localVarName));
    return value;
}
项目:xtext-extras    文件:ExpressionScope.java   
public IExpressionScope withAnchor(final Anchor anchor) {
    if (anchor == this.anchor)
        return this;
    return new IExpressionScope() {

        /* @NonNull */
        @Override
        public IScope getFeatureScope() {
            return ExpressionScope.this.getFeatureScope(anchor);
        }

        /* @NonNull */
        @Override
        public IScope getFeatureScope(/* @Nullable */ XAbstractFeatureCall currentFeatureCall) {
            return ExpressionScope.this.getFeatureScope(currentFeatureCall, anchor);
        }

        /* @NonNull */
        @Override
        public List<String> getTypeNamePrefix() {
            return ExpressionScope.this.getTypeNamePrefix();
        }

        @Override
        public boolean isPotentialTypeLiteral() {
            return ExpressionScope.this.isPotentialTypeLiteral();
        }

    };
}
项目:xtext-extras    文件:ExpressionScope.java   
public IScope getFeatureScope(/* @Nullable */ XAbstractFeatureCall currentFeatureCall, Anchor anchor) {
    if (anchor == Anchor.RECEIVER) {
        if (currentFeatureCall == requestedFeatureCall && cachedReceiverFeatureScope != null) {
            return cachedReceiverFeatureScope;
        }
        IScope result =  createFeatureCallScopeForReceiver(currentFeatureCall);
        this.requestedFeatureCall = currentFeatureCall;
        return cachedReceiverFeatureScope = result;
    }
    return getFeatureScope(anchor);
}
项目:xtext-extras    文件:TypeUsageCollector.java   
private boolean isOuterTypeLiteral(XAbstractFeatureCall featureCall) {
    if (featureCall.eContainingFeature() == XbasePackage.Literals.XMEMBER_FEATURE_CALL__MEMBER_CALL_TARGET) {
        XMemberFeatureCall container = (XMemberFeatureCall) featureCall.eContainer();
        if (container.isTypeLiteral()) {
            return true;
        }
    }
    return false;
}
项目:xtext-extras    文件:DefaultReentrantTypeResolver.java   
/**
 * Provide the error message for mutable variables that may not be captured in lambdas.
 * 
 * @param variable the writable variable declaration
 * @param featureCall the reference to the variable
 * @param resolvedTypes type information
 */
protected String getInvalidWritableVariableAccessMessage(XVariableDeclaration variable, XAbstractFeatureCall featureCall, IResolvedTypes resolvedTypes) {
    // TODO this should be part of a separate validation service
    XClosure containingClosure = EcoreUtil2.getContainerOfType(featureCall, XClosure.class);
    if (containingClosure != null && !EcoreUtil.isAncestor(containingClosure, variable)) {
        return String.format("Cannot %srefer to the non-final variable %s inside a lambda expression", getImplicitlyMessagePart(featureCall), variable.getSimpleName());
    }
    return null;
}
项目:xtext-extras    文件:XExpressionHelper.java   
public boolean hasSideEffects(XAbstractFeatureCall featureCall, boolean inspectContents) {
    if (featureCall instanceof XBinaryOperation) {
        XBinaryOperation binaryOperation = (XBinaryOperation) featureCall;
        if (binaryOperation.isReassignFirstArgument()) {
            return true;
        }
    }
    if (featureCall instanceof XAssignment) {
        return true;
    }
    if (featureCall.isPackageFragment() || featureCall.isTypeLiteral()) {
        return false;
    }
    final JvmIdentifiableElement feature = featureCall.getFeature();
    if (feature == null || feature.eIsProxy())
        return true; // linking problems ... could be anything
    if (feature instanceof JvmConstructor) { //super() and this()
        return true;
    }
    if (feature instanceof JvmOperation) {
        JvmOperation jvmOperation = (JvmOperation) feature;
        if (findPureAnnotation(jvmOperation) == null) {
            return true;
        } else {
            if(inspectContents) {
                for (XExpression param : featureCall.getActualArguments()) {
                    if (hasSideEffects(param))
                        return true;
                }
            }
        }
    }
    return false;
}
项目:xtext-extras    文件:XbaseHighlightingCalculator.java   
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);
        }
    }
项目:xtext-extras    文件:LocalVariableScope.java   
protected boolean looksLikeLocalVariable(XAbstractFeatureCall featureCall) {
    if (featureCall instanceof XFeatureCall) {
        boolean result = !featureCall.isExplicitOperationCallOrBuilderSyntax() && featureCall.getTypeArguments().isEmpty();
        return result;
    }
    return false;
}
项目:xtext-extras    文件:CompoundReentrantTypeResolver.java   
@Override
public IFeatureLinkingCandidate getLinkingCandidate(/* @Nullable */ XAbstractFeatureCall featureCall) {
    if (featureCall == null)
        return null;
    IResolvedTypes delegate = getDelegate(featureCall);
    return delegate.getLinkingCandidate(featureCall);
}
项目:xtext-extras    文件:LogicalContainerAwareReentrantTypeResolver.java   
protected IFeatureScopeSession addExtensionFieldsToMemberSession(
            ResolvedTypes resolvedTypes, 
            IFeatureScopeSession featureScopeSession, 
            JvmDeclaredType type, 
            JvmIdentifiableElement thisFeature,
            Set<String> seenNames,
            Set<JvmType> seenTypes) {
    if (seenTypes.add(type)) {
        Iterable<JvmField> fields = type.getDeclaredFields();
        // collect local fields first, to populate the set of names
        Map<XExpression, LightweightTypeReference> extensionProviders = null;
        for(JvmField field: fields) {
            if (featureScopeSession.isVisible(field) && seenNames.add(field.getSimpleName()) && isExtensionProvider(field)) {
                if (extensionProviders == null) {
                    extensionProviders = Maps2.newLinkedHashMapWithExpectedSize(3);
                }
                XAbstractFeatureCall extensionProvider = createExtensionProvider(thisFeature, field);
                LightweightTypeReference fieldType = resolvedTypes.getActualType(field);
                extensionProviders.put(extensionProvider, fieldType);
            }
        }
        // traverse the type hierarchy to create the feature scope sessions
        JvmTypeReference superType = getExtendedClass(type);
        IFeatureScopeSession result = featureScopeSession;
        if (superType != null) {
            result = addExtensionFieldsToMemberSession(resolvedTypes, featureScopeSession, (JvmDeclaredType) superType.getType(), thisFeature, seenNames, seenTypes);
        }
        if (extensionProviders != null) {
            result = result.addToExtensionScope(extensionProviders);
        }
        return result;
    }
    return featureScopeSession;
}
项目:xtext-extras    文件:ResolvedTypeLiteral.java   
protected ResolvedTypeLiteral(
        XAbstractFeatureCall featureCall,
        JvmIdentifiableElement resolvedElement,
        ITypeExpectation expectation,
        ExpressionTypeComputationState state) {
    super(featureCall, resolvedElement, expectation, state);
    this.helper = new TypeLiteralHelper(state);
}
项目:xtext-extras    文件:ResolvedTypeLiteral.java   
@Override
protected void preApply() {
    JvmType type = getType();
    XAbstractFeatureCall expression = getExpression();
    if (expression instanceof XMemberFeatureCall) {
        if (type instanceof JvmDeclaredType) {
            JvmDeclaredType declaredType = (JvmDeclaredType) type;
            if (declaredType.getDeclaringType() == null) {
                helper.applyPackageFragment((XMemberFeatureCall) expression, declaredType);
            }
        }
    }
}