Java 类org.eclipse.xtext.validation.ValidationMessageAcceptor 实例源码

项目:xtext-extras    文件:XbaseWithAnnotationsValidator.java   
@Check
public void checkAllAttributesConfigured(XAnnotation annotation) {
    JvmType annotationType = annotation.getAnnotationType();
    if (annotationType == null || annotationType.eIsProxy() || !(annotationType instanceof JvmAnnotationType))
        return;
    Iterable<JvmOperation> attributes = ((JvmAnnotationType) annotationType).getDeclaredOperations();
    for (JvmOperation jvmOperation : attributes) {
        XExpression value = annotationUtil.findValue(annotation, jvmOperation);
        if(value == null) {
            if (jvmOperation.getDefaultValue() == null) {
                error("The annotation must define the attribute '"+jvmOperation.getSimpleName()+"'.", annotation, null, 
                        ValidationMessageAcceptor.INSIGNIFICANT_INDEX, ANNOTATIONS_MISSING_ATTRIBUTE_DEFINITION);
            }
        } else
            annotationValueValidator.validateAnnotationValue(value, this);
    }
}
项目:xtext-core    文件:XtextValidator.java   
@Check
public void checkFirstRule(Grammar g) {
    if (g.getRules().isEmpty())
        return;
    AbstractRule firstRule = g.getRules().get(0);
    if (!(firstRule instanceof ParserRule)) {
        if (!containsAnyParserRule(g, new HashSet<Grammar>()))
            return;
        error(
                "The first rule must be a parser rule.", 
                firstRule, 
                XtextPackage.Literals.ABSTRACT_RULE__NAME,
                ValidationMessageAcceptor.INSIGNIFICANT_INDEX);
    }
    else if (GrammarUtil.isDatatypeRule((ParserRule) firstRule)) {
        if (!containsAnyParserRule(g, new HashSet<Grammar>()))
            return;
        error(
                "The first rule must be a parser rule, but is a data type rule.", 
                firstRule,
                XtextPackage.Literals.ABSTRACT_RULE__NAME, 
                ValidationMessageAcceptor.INSIGNIFICANT_INDEX);
    }
}
项目:xtext-core    文件:XtextValidator.java   
private void doPropagateValidationResult(Diagnostic diagnostic,
        GeneratedMetamodel metamodel, ValidationMessageAcceptor acceptor) {
    boolean foundEObject = false;
    Object firstData = null;
    for(Object data: diagnostic.getData()) {
        if (firstData == null) {
            firstData = diagnostic.getData().get(0);
        }
        if (data instanceof EObject) {
            if (createMessageForSource(diagnostic, (EObject) data, acceptor)) {
                foundEObject = true;
            } 
            if (data instanceof EStructuralFeature && ((EStructuralFeature) data).getEContainingClass() != firstData) {
                EClass containingClass = ((EStructuralFeature) data).getEContainingClass();
                createMessageForSource(diagnostic, containingClass, acceptor);
            }
        }
    }
    if (!foundEObject) {
        doCreateMessage(
                diagnostic, 
                metamodel, 
                XtextPackage.Literals.ABSTRACT_METAMODEL_DECLARATION__EPACKAGE, 
                acceptor);
    }
}
项目:xtext-core    文件:XtextValidator.java   
public boolean checkCrossReferenceTerminal(RuleCall call) {
    if (call.getRule() != null && call.getRule().getType() != null) {
        EClassifier type = call.getRule().getType().getClassifier();
        EDataType dataType = GrammarUtil.findEString(GrammarUtil.getGrammar(call));
        if (dataType == null)
            dataType = EcorePackage.Literals.ESTRING;
        if (type != null && dataType != type) {
            error(
                    "The rule '" + call.getRule().getName() + "' is not valid for a cross reference since it does not return "+
                    "an EString. You'll have to wrap it in a data type rule.", 
                    call, null, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, null);
            return true;
        }
    }
    return false;
}
项目:xtext-core    文件:XtextValidator.java   
@Check
public void checkTerminalFragmentCalledFromTerminalRule(final RuleCall call) {
    if (call.getRule() != null && !call.getRule().eIsProxy()) {
        if (call.getRule() instanceof TerminalRule && ((TerminalRule) call.getRule()).isFragment()) {
            AbstractRule container = GrammarUtil.containingRule(call);
            if (!(container instanceof TerminalRule)) {
                getMessageAcceptor().acceptError(
                        "Only terminal rules may use terminal fragments.", 
                        call, 
                        XtextPackage.Literals.RULE_CALL__RULE,
                        ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
                        null);
            }
        }
    }
}
项目:xtext-core    文件:XtextValidator.java   
@Check
public void checkRuleCallInUnorderedGroup(final RuleCall call) {
    if (call.getRule() == null || call.getRule().eIsProxy() || !(call.getRule() instanceof ParserRule))
        return;
    if (GrammarUtil.isDatatypeRule((ParserRule) call.getRule()))
        return;
    if (GrammarUtil.isAssigned(call))
        return;
    if (EcoreUtil2.getContainerOfType(call, UnorderedGroup.class) != null)
        error(
                "Unassigned rule calls may not be used in unordered groups.", 
                call, 
                null,
                ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
                null);
}
项目:xtext-core    文件:PredicateUsesUnorderedGroupInspector.java   
public void createErrorMessages(UnorderedGroup object) {
    acceptError(
            "Cannot use unordered groups in syntactic predicates.", 
            object, 
            null,
            ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
            null);
    for(AbstractElement element: elementStack) {
        acceptError(
                "A predicate may not use an unordered group.", 
                element, 
                XtextPackage.Literals.ABSTRACT_ELEMENT__PREDICATED,
                ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
                null);
    }
    for(RuleCall ruleCall: callHierarchy) {
        if (!ruleCall.isPredicated())
            acceptError(
                    "The rule call is part of a call hierarchy that leads to a predicated unordered group.", 
                    ruleCall, 
                    XtextPackage.Literals.RULE_CALL__RULE,
                    ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
                    null);
    }
}
项目:xtext-core    文件:KeywordInspector.java   
public void inspectKeywordHidesTerminalRule(Keyword keyword) {
    AbstractRule container = GrammarUtil.containingRule(keyword);
    if (container instanceof TerminalRule)
        return;
    Grammar grammar = GrammarUtil.getGrammar(container);
    List<TerminalRule> rules = GrammarUtil.allTerminalRules(grammar);
    for(TerminalRule rule: rules) {
        if (!rule.isFragment()) {
            AbstractElement element = rule.getAlternatives();
            if (element instanceof Keyword && Strings.isEmpty(element.getCardinality())) {
                String value = ((Keyword) element).getValue();
                if (value.equals(keyword.getValue()))
                acceptor.acceptError(
                        "The keyword '" + value + "' hides the terminal rule " + rule.getName()+ ".", 
                        keyword,
                        XtextPackage.Literals.KEYWORD__VALUE,
                        ValidationMessageAcceptor.INSIGNIFICANT_INDEX, null);
            }
        }
    }
}
项目:dsl-devkit    文件:AbstractIssue.java   
/** {@inheritDoc} */
public void accept(final ValidationMessageAcceptor acceptor, final EObject object, final EStructuralFeature feature, final String message, final SeverityKind severityKind, final int index, final String issueCode, final String... issueData) {
  switch (severityKind) {
  case ERROR:
    acceptor.acceptError(message, object, feature, index, issueCode, issueData);
    return;
  case WARNING:
    acceptor.acceptWarning(message, object, feature, index, issueCode, issueData);
    return;
  case INFO:
    acceptor.acceptInfo(message, object, feature, index, issueCode, issueData);
    return;
  case IGNORE:
  default:
    return;
  }
}
项目:dsl-devkit    文件:CheckJavaValidator.java   
/**
 * Checks that a Check defines parameters with unique names.
 *
 * @param check
 *          the check to be checked
 */
@Check
public void checkFormalParameterNamesUnique(final com.avaloq.tools.ddk.check.check.Check check) {
  if (check.getFormalParameters().size() < 2) {
    return;
  }
  Function<FormalParameter, String> function = new Function<FormalParameter, String>() {
    @Override
    public String apply(final FormalParameter from) {
      return from.getName();
    }
  };
  for (final FormalParameter p : getDuplicates(Predicates.<FormalParameter> alwaysTrue(), function, check.getFormalParameters())) {
    error(Messages.CheckJavaValidator_DUPLICATE_PARAMETER_DEFINITION, p, XbasePackage.Literals.XVARIABLE_DECLARATION__NAME, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, IssueCodes.DUPLICATE_PARAMETER_DEFINITION);
  }

}
项目:dsl-devkit    文件:UniquenessJavaValidationHelper.java   
/**
 * Find duplicates in the given objects and mark them (on the given feature) as
 * warnings.
 *
 * @param possiblyDuplicateObjects
 *          an Iterable into which to look for duplicates
 * @param featureProvider
 *          provides the feature of the duplicate object on which to anchor the marker
 * @param issueCode
 *          the issue code
 */
public void warnOnDuplicates(final Iterable<T> possiblyDuplicateObjects, final Function<T, EStructuralFeature> featureProvider, final String issueCode) {
  if (acceptor == null) {
    throw new IllegalArgumentException(ACCEPTOR_CAN_T_BE_NULL);
  }
  if (possiblyDuplicateObjects == null) {
    return; // NO_ERROR
  }

  Set<T> duplicateEObjects = findDuplicates(possiblyDuplicateObjects);

  for (final T duplicate : duplicateEObjects) {
    final EStructuralFeature feature = featureProvider.apply(duplicate);
    acceptor.acceptWarning(getMessage(duplicate), duplicate, feature, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, issueCode);
  }
}
项目:dsl-devkit    文件:UniquenessJavaValidationHelper.java   
/**
 * Find duplicates in the given objects and mark them (on the given feature) as
 * errors.
 *
 * @param possiblyDuplicateObjects
 *          an Iterable into which to look for duplicates
 * @param featureProvider
 *          provides the feature of the duplicate object on which to anchor the marker
 * @param issueCode
 *          the issue code
 */
public void errorOnDuplicates(final Iterable<T> possiblyDuplicateObjects, final Function<T, EStructuralFeature> featureProvider, final String issueCode) {
  if (acceptor == null) {
    throw new IllegalArgumentException(ACCEPTOR_CAN_T_BE_NULL);
  }
  if (possiblyDuplicateObjects == null) {
    return; // NO_ERROR
  }

  Set<T> duplicateEObjects = findDuplicates(possiblyDuplicateObjects);

  for (final T duplicate : duplicateEObjects) {
    final EStructuralFeature feature = featureProvider.apply(duplicate);
    acceptor.acceptError(getMessage(duplicate), duplicate, feature, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, issueCode);
  }
}
项目:dsl-devkit    文件:CheckCfgJavaValidator.java   
/**
 * Checks whether a configured check's configuration equals the default. Emits an info if this is the case.
 *
 * @param configuredCheck
 *          the configured check
 */
@Check
public void checkConfigurationEqualsDefault(final ConfiguredCheck configuredCheck) {
  final com.avaloq.tools.ddk.check.check.Check check = configuredCheck.getCheck();
  if (!isParameterConfigured(configuredCheck) || check == null || check.eIsProxy()) {
    return; // only interesting if check configured and resolvable
  }

  Iterable<FormalParameter> formalParameters = check.getFormalParameters();
  for (final ConfiguredParameter configParam : configuredCheck.getParameterConfigurations()) {
    try {
      FormalParameter param = Iterables.find(formalParameters, new Predicate<FormalParameter>() {
        @Override
        public boolean apply(final FormalParameter input) {
          return input == configParam.getParameter();
        }
      });
      if (parameterValuesEqual(configParam.getNewValue(), param.getRight())) {
        info(NLS.bind(Messages.CheckCfgJavaValidator_CONFIGURED_PARAM_EQUALS_DEFAULT, param.getName()), configParam, CheckcfgPackage.Literals.CONFIGURED_PARAMETER__NEW_VALUE, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, IssueCodes.CONFIGURED_PARAM_EQUALS_DEFAULT);
      }
    } catch (NoSuchElementException e) {
      LOGGER.debug("Could not find referenced formal parameter");
    }
  }
}
项目:dsl-devkit    文件:CheckCfgJavaValidator.java   
/**
 * Checks that within a Check Configuration all Catalog Configurations are unique, meaning that a referenced
 * Check Catalog can only be configured in one place.
 *
 * @param configuration
 *          the configuration
 */
@Check
public void checkConfiguredCatalogUnique(final CheckConfiguration configuration) {
  if (configuration.getLegacyCatalogConfigurations().size() < 2) {
    return;
  }
  Predicate<ConfiguredCatalog> predicate = new Predicate<ConfiguredCatalog>() {
    @Override
    public boolean apply(final ConfiguredCatalog configuredCatalog) {
      final CheckCatalog catalog = configuredCatalog.getCatalog();
      return catalog != null && !catalog.eIsProxy();
    }
  };
  Function<ConfiguredCatalog, String> function = new Function<ConfiguredCatalog, String>() {
    @Override
    public String apply(final ConfiguredCatalog from) {
      return from.getCatalog().getName();
    }
  };
  for (final ConfiguredCatalog c : getDuplicates(predicate, function, configuration.getLegacyCatalogConfigurations())) {
    error(Messages.CheckCfgJavaValidator_DUPLICATE_CATALOG_CONFIGURATION, c, CheckcfgPackage.Literals.CONFIGURED_CATALOG__CATALOG, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, IssueCodes.DUPLICATE_CATALOG_CONFIGURATION);
  }

}
项目:dsl-devkit    文件:CheckCfgJavaValidator.java   
/**
 * Checks that Check Configurations are unique. A Configured Catalog may only contain one configuration for each referenced Check.
 *
 * @param configuration
 *          the configuration
 */
@Check
public void checkConfiguredCheckUnique(final ConfiguredCatalog configuration) {
  if (configuration.getCheckConfigurations().size() < 2) {
    return;
  }
  Predicate<ConfiguredCheck> predicate = new Predicate<ConfiguredCheck>() {
    @Override
    public boolean apply(final ConfiguredCheck configuredCheck) {
      return configuredCheck.getCheck() != null && !configuredCheck.getCheck().eIsProxy();
    }
  };
  Function<ConfiguredCheck, String> function = new Function<ConfiguredCheck, String>() {
    @Override
    public String apply(final ConfiguredCheck from) {
      return from.getCheck().getName();
    }
  };
  for (final ConfiguredCheck c : getDuplicates(predicate, function, configuration.getCheckConfigurations())) {
    error(Messages.CheckCfgJavaValidator_DUPLICATE_CHECK_CONFIGURATION, c, CheckcfgPackage.Literals.CONFIGURED_CHECK__CHECK, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, IssueCodes.DUPLICATE_CHECK_CONFIGURATION);
  }

}
项目:dsl-devkit    文件:CheckCfgJavaValidator.java   
/**
 * Checks that a Configured Check has unique Configured Parameters.
 *
 * @param configuredCheck
 *          the configured check
 */
@Check
public void checkConfiguredParameterUnique(final ConfiguredCheck configuredCheck) {
  if (configuredCheck.getParameterConfigurations().size() < 2) {
    return;
  }
  Predicate<ConfiguredParameter> predicate = new Predicate<ConfiguredParameter>() {
    @Override
    public boolean apply(final ConfiguredParameter configuredParameter) {
      return configuredParameter.getParameter() != null && !configuredParameter.getParameter().eIsProxy();
    }
  };
  Function<ConfiguredParameter, String> function = new Function<ConfiguredParameter, String>() {
    @Override
    public String apply(final ConfiguredParameter from) {
      return from.getParameter().getName();
    }
  };
  for (final ConfiguredParameter p : getDuplicates(predicate, function, configuredCheck.getParameterConfigurations())) {
    error(Messages.CheckCfgJavaValidator_DUPLICATE_PARAMETER_CONFIGURATION, p, CheckcfgPackage.Literals.CONFIGURED_PARAMETER__PARAMETER, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, IssueCodes.DUPLICATE_PARAMETER_CONFIGURATION);
  }

}
项目:RigidBodies    文件:RigidBodiesValidator.java   
@Check
public void massVectorSizes(final Mass m) {
  Matrix _position = m.getPosition();
  int _length = this.getLength(_position);
  boolean _notEquals = (_length != 3);
  if (_notEquals) {
    this.error("Mass position must be a 3D vector.", m, RigidBodiesPackage.Literals.MASS__POSITION, 
      ValidationMessageAcceptor.INSIGNIFICANT_INDEX, RigidBodiesValidator.MASS_POS_NO_3D);
  }
  Matrix _inertia = m.getInertia();
  int _length_1 = this.getLength(_inertia);
  boolean _notEquals_1 = (_length_1 != 9);
  if (_notEquals_1) {
    this.error("Mass inertia must be a 3 by 3 matrix.", m, RigidBodiesPackage.Literals.MASS__INERTIA, 
      ValidationMessageAcceptor.INSIGNIFICANT_INDEX, RigidBodiesValidator.MASS_INERTIA_NO_9D);
  }
}
项目:RigidBodies    文件:RigidBodiesValidator.java   
private void _checkIsValidLocking(final AdditiveLockedJointType aljt, final JointTypeExpression exp) {
  LockedJointTypeExpression _left = aljt.getLeft();
  JointTypeExpression _get = JointTypeHelper.get(exp, 0);
  this.checkIsValidLocking(_left, _get);
  EList<LockedJointTypeExpression> _right = aljt.getRight();
  final Procedure2<LockedJointTypeExpression, Integer> _function = new Procedure2<LockedJointTypeExpression, Integer>() {
    @Override
    public void apply(final LockedJointTypeExpression e, final Integer idx) {
      final JointTypeExpression jt = JointTypeHelper.get(exp, ((idx).intValue() + 1));
      boolean _notEquals = (!Objects.equal(jt, null));
      if (_notEquals) {
        RigidBodiesValidator.this.checkIsValidLocking(e, jt);
      } else {
        RigidBodiesValidator.this.error("No matching element in original joint type", e, null, 
          ValidationMessageAcceptor.INSIGNIFICANT_INDEX, RigidBodiesValidator.LOCKED_TYPE_NO_MATCH);
      }
    }
  };
  IterableExtensions.<LockedJointTypeExpression>forEach(_right, _function);
}
项目:RigidBodies    文件:RigidBodiesValidator.java   
private void _checkIsValidLocking(final LockedRevolute lr, final JointMovement jm) {
  boolean _and = false;
  if (!(jm instanceof Revolute)) {
    _and = false;
  } else {
    AXIS _axis = lr.getAxis();
    AXIS _axis_1 = ((Revolute) jm).getAxis();
    boolean _equals = Objects.equal(_axis, _axis_1);
    _and = _equals;
  }
  boolean _not = (!_and);
  if (_not) {
    this.error("No matching element in original joint type", lr, null, 
      ValidationMessageAcceptor.INSIGNIFICANT_INDEX, RigidBodiesValidator.LOCKED_TYPE_NO_MATCH);
  }
}
项目:RigidBodies    文件:RigidBodiesValidator.java   
private void _checkIsValidLocking(final LockedPlanar lp, final JointMovement jm) {
  boolean _and = false;
  if (!(jm instanceof Planar)) {
    _and = false;
  } else {
    AXIS _axis = lp.getAxis();
    AXIS _axis_1 = ((Planar) jm).getAxis();
    boolean _equals = Objects.equal(_axis, _axis_1);
    _and = _equals;
  }
  boolean _not = (!_and);
  if (_not) {
    this.error("No matching element in original joint type", lp, null, 
      ValidationMessageAcceptor.INSIGNIFICANT_INDEX, RigidBodiesValidator.LOCKED_TYPE_NO_MATCH);
  }
}
项目:xsemantics    文件:XsemanticsValidatorErrorGenerator.java   
protected void generateErrors(
        ValidationMessageAcceptor validationMessageAcceptor,
        RuleFailedException ruleFailedException, EObject originalSource) {
    if (ruleFailedException == null) {
        return;
    }
    Iterable<RuleFailedException> allFailures = filter
            .filterRuleFailedExceptions(ruleFailedException);
    // the last information about a model element with error
    ErrorInformation lastErrorInformationWithSource = null;
    // we will use it to print error messages which do not have
    // an associated model element
    for (RuleFailedException ruleFailedException2 : allFailures) {
        lastErrorInformationWithSource = generateErrors(
                validationMessageAcceptor,
                ruleFailedException2.getMessage(),
                ruleFailedException2.getIssue(),
                filter.filterErrorInformation(ruleFailedException2),
                lastErrorInformationWithSource, originalSource);
    }
}
项目:n4js    文件:N4JSValidatorErrorGenerator.java   
/**
 * Copied from super class to create error messages from RuleFailedExceptions via method
 * {@link TypeSystemErrorExtensions#compileMessage(RuleFailedException)}.
 */
@Override
protected void generateErrors(
        ValidationMessageAcceptor validationMessageAcceptor,
        RuleFailedException ruleFailedException, EObject originalSource) {
    if (ruleFailedException == null) {
        return;
    }
    Iterable<RuleFailedException> allFailures = filter
            .filterRuleFailedExceptions(ruleFailedException);
    // the last information about a model element with error
    ErrorInformation lastErrorInformationWithSource = null;
    // we will use it to print error messages which do not have
    // an associated model element
    for (RuleFailedException ruleFailedException2 : allFailures) {
        lastErrorInformationWithSource = generateErrors(
                validationMessageAcceptor,
                // ================================================================
                // only change w.r.t. super-class method:
                TypeSystemErrorExtensions.compileMessage(ruleFailedException2),
                // ruleFailedException2.getMessage(),
                // ================================================================
                ruleFailedException2.getIssue(),
                filter.filterErrorInformation(ruleFailedException2),
                lastErrorInformationWithSource, originalSource);
    }
}
项目:xtext-extras    文件:XbaseValidator.java   
@Check
public void checkReturn(XReturnExpression expr) {
    XExpression returnedExpression = expr.getExpression();
    IResolvedTypes resolvedTypes = typeResolver.resolveTypes(expr);
    LightweightTypeReference expectedReturnType = resolvedTypes.getExpectedReturnType(expr);
    if (expectedReturnType == null) {
        return;
    }
    if (expectedReturnType.isPrimitiveVoid()) {
        if (returnedExpression != null)
            error("Void functions cannot return a value.", expr, null,
                    ValidationMessageAcceptor.INSIGNIFICANT_INDEX, INVALID_RETURN);
    } else {
        if (returnedExpression == null)
            error("The function must return a result of type " + expectedReturnType.getHumanReadableName() + ".", expr, null,
                    ValidationMessageAcceptor.INSIGNIFICANT_INDEX, INVALID_RETURN);
        else {
            LightweightTypeReference expressionType = getActualType(returnedExpression);
            if (expressionType.isPrimitiveVoid()) {
                error("Incompatible types. Expected " + getNameOfTypes(expectedReturnType) + " but was "
                        + canonicalName(expressionType), returnedExpression, null,
                        ValidationMessageAcceptor.INSIGNIFICANT_INDEX, INCOMPATIBLE_TYPES);
            }
        }

    }
}
项目:xtext-extras    文件:XbaseValidator.java   
@Check
public void checkTypes(XCatchClause catchClause) {
    LightweightTypeReference parameterType = getActualType(catchClause, catchClause.getDeclaredParam());
    if (parameterType != null && !parameterType.isSubtypeOf(Throwable.class)) {
        error("No exception of type " + parameterType.getHumanReadableName()
                + " can be thrown; an exception type must be a subclass of Throwable",
                catchClause.getDeclaredParam(), TypesPackage.Literals.JVM_FORMAL_PARAMETER__PARAMETER_TYPE,
                ValidationMessageAcceptor.INSIGNIFICANT_INDEX, INCOMPATIBLE_TYPES);
    }
}
项目:xtext-extras    文件:XbaseValidator.java   
@Check
public void checkVariableDeclaration(XVariableDeclaration declaration) {
    if (declaration.getRight() == null) {
        if (!declaration.isWriteable())
            error("Value must be initialized", Literals.XVARIABLE_DECLARATION__WRITEABLE,
                    ValidationMessageAcceptor.INSIGNIFICANT_INDEX, MISSING_INITIALIZATION);
        if (declaration.getType() == null)
            error("Type cannot be derived", Literals.XVARIABLE_DECLARATION__NAME,
                    ValidationMessageAcceptor.INSIGNIFICANT_INDEX, MISSING_TYPE);
    }
}
项目:xtext-extras    文件:XbaseValidator.java   
@Check
public void checkInstanceOf(XInstanceOfExpression instanceOfExpression) {
    LightweightTypeReference leftType = getActualType(instanceOfExpression.getExpression());
    final LightweightTypeReference rightType = toLightweightTypeReference(instanceOfExpression.getType(), true);
    if (leftType == null || rightType == null || rightType.getType() == null || rightType.getType().eIsProxy()) {
        return;
    }
    if (containsTypeArgs(rightType)) {
        error("Cannot perform instanceof check against parameterized type " + getNameOfTypes(rightType), null, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, INVALID_INSTANCEOF);
        return;
    }
    if (leftType.isAny() || leftType.isUnknown()) {
        return; // null / unknown is ok
    }
    if (rightType.isPrimitive()) {
        error("Cannot perform instanceof check against primitive type " + this.getNameOfTypes(rightType), null, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, INVALID_INSTANCEOF);
        return;
    }
    if (leftType.isPrimitive() 
        || rightType.isArray() && !(leftType.isArray() || leftType.isType(Object.class) || leftType.isType(Cloneable.class) || leftType.isType(Serializable.class))
        || isFinal(rightType) && !memberOfTypeHierarchy(rightType, leftType)
        || isFinal(leftType) && !memberOfTypeHierarchy(leftType, rightType)) {
        error("Incompatible conditional operand types " + this.getNameOfTypes(leftType)+" and "+this.getNameOfTypes(rightType), null, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, INVALID_INSTANCEOF);
        return;
    }
    if (!isIgnored(OBSOLETE_INSTANCEOF) && rightType.isAssignableFrom(leftType, new TypeConformanceComputationArgument(false, false, true, true, false, false))) {
        addIssueToState(OBSOLETE_INSTANCEOF, "The expression of type " + getNameOfTypes(leftType)
                + " is already of type " + canonicalName(rightType), null);
    }
}
项目: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    文件:AnnotationValueValidator.java   
public void validateAnnotationValue(final XExpression value, final ValidationMessageAcceptor acceptor) {
  try {
    boolean _isValidAnnotationValue = this.isValidAnnotationValue(value);
    boolean _not = (!_isValidAnnotationValue);
    if (_not) {
      acceptor.acceptError("The value for an annotation attribute must be a constant expression", value, null, 
        ValidationMessageAcceptor.INSIGNIFICANT_INDEX, IssueCodes.ANNOTATIONS_ILLEGAL_ATTRIBUTE);
    }
  } catch (final Throwable _t) {
    if (_t instanceof NotResolvedFeatureException) {
    } else {
      throw Exceptions.sneakyThrow(_t);
    }
  }
}
项目:xtext-core    文件:GrammarWithoutLeftRecursionInspector.java   
public GrammarWithoutLeftRecursionInspector(ValidationMessageAcceptor validationMessageAcceptor) {
    this.validationMessageAcceptor = validationMessageAcceptor;
    this.validatedRules = Sets.newHashSet();
    this.callStack = Lists.newArrayList();
    this.ruleStack = Sets.newHashSet();
    this.usedRules = Sets.newHashSet();
    this.erroneousElements = Sets.newHashSet();
}
项目:xtext-core    文件:XtextValidator.java   
@Check
public void checkGeneratedPackageNotEmpty(GeneratedMetamodel metamodel) {
    EPackage pack = metamodel.getEPackage();
    if (pack != null && pack.getEClassifiers().isEmpty()) {
        getMessageAcceptor().acceptError(
                "Generated package '" + metamodel.getName() + "' may not be empty.",
                metamodel, 
                XtextPackage.Literals.ABSTRACT_METAMODEL_DECLARATION__EPACKAGE,
                ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
                EMPTY_GENERATED_PACKAGE);
    }
}
项目:xtext-core    文件:XtextValidator.java   
private void propageValidationResult(Diagnostic diagnostic, GeneratedMetamodel metamodel, ValidationMessageAcceptor acceptor) {
    if (diagnostic.getSeverity() != Diagnostic.OK) {
        if (diagnostic.getCode() != 0) {
            List<?> data = diagnostic.getData();
            if (!data.isEmpty() && data.get(0) instanceof EObject) {
                doPropagateValidationResult(diagnostic, metamodel, acceptor);
            }
        }
        for(Diagnostic child: diagnostic.getChildren())
            propageValidationResult(child, metamodel, acceptor);
    }
}
项目:xtext-core    文件:XtextValidator.java   
public boolean createMessageForSource(Diagnostic diagnostic, EObject object, ValidationMessageAcceptor acceptor) {
    String code = XtextValidator.class.getName() + ".PackageValidation." + diagnostic.getCode();
    int severity = diagnostic.getSeverity();
    if (diagnostic.getCode() == EcoreValidator.UNIQUE_CLASSIFIER_NAMES || diagnostic.getCode() == EcoreValidator.UNIQUE_FEATURE_NAMES)
        severity = Diagnostic.ERROR;
    String message = diagnostic.getMessage();
    return createMessageForSource(message, code, severity, object, acceptor);
}
项目:xtext-core    文件:XtextValidator.java   
public void doCreateMessage(Diagnostic diagnostic, EObject object, EStructuralFeature feature, ValidationMessageAcceptor acceptor) {
    String code = XtextValidator.class.getName() + ".PackageValidation." + diagnostic.getCode();
    int severity = diagnostic.getSeverity();
    if (diagnostic.getCode() == EcoreValidator.UNIQUE_CLASSIFIER_NAMES || diagnostic.getCode() == EcoreValidator.UNIQUE_FEATURE_NAMES)
        severity = Diagnostic.ERROR;
    String message = diagnostic.getMessage();
    doCreateMessage(message, code, severity, object, feature, acceptor);
}
项目:xtext-core    文件:XtextValidator.java   
public boolean createMessageForSource(String message, String code, int severity, EObject object, ValidationMessageAcceptor acceptor) {
    SourceAdapter sourceAdapter = SourceAdapter.find(object);
    boolean result = false;
    if (sourceAdapter != null) {
        for(EObject source: sourceAdapter.getSources()) {
            doCreateMessage(message, code, severity, source, null, acceptor);
            result = true;
        }
    }
    return result;
}
项目:xtext-core    文件:XtextValidator.java   
public void doCreateMessage(String message, String code, int severity, EObject context, EStructuralFeature feature, ValidationMessageAcceptor acceptor) {
    if (severity == Diagnostic.WARNING) {
        acceptor.acceptWarning(message, context, feature, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, code);
    } else if (severity == Diagnostic.ERROR) {
        acceptor.acceptError(message, context, feature, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, code);
    } else if (severity == Diagnostic.INFO) {
        acceptor.acceptInfo(message, context, feature, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, code);
    }
}
项目:xtext-core    文件:XtextValidator.java   
@Check
public void checkUnassignedRuleCallAllowed(final RuleCall call) {
    if (call.getRule() != null && !call.getRule().eIsProxy() && GrammarUtil.containingAssignment(call) == null) {
        AbstractRule container = GrammarUtil.containingRule(call);
        if (call.getRule() instanceof ParserRule) {
            if (container instanceof TerminalRule) {
                getMessageAcceptor().acceptError(
                        "Cannot call parser rule from terminal rule.", 
                        call, 
                        XtextPackage.Literals.RULE_CALL__RULE,
                        ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
                        null);
            } else {
                ParserRule parserRule = (ParserRule) call.getRule();
                if (!GrammarUtil.isDatatypeRule(parserRule) && !parserRule.isFragment()) {
                    checkCurrentMustBeUnassigned(call);
                }
            }
        }
        if (call.getRule() instanceof EnumRule) {
            if (container instanceof TerminalRule) {
                getMessageAcceptor().acceptError(
                        "Cannot call enum rule from terminal rule.", 
                        call, 
                        XtextPackage.Literals.RULE_CALL__RULE,
                        ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
                        null);
            }
        }
    }
}
项目:xtext-core    文件:XtextValidator.java   
@Check
public void checkCrossReferenceNotInAlternatives(Alternatives alternatives) {
    int numOfCrossRefs = IterableExtensions.size(IterableExtensions.filter(alternatives.getElements(), CrossReference.class));
    if (numOfCrossRefs > 1) {
        String errorMessage = "Cross references using the pattern 'feature=([SomeClass|ID] | [SomeClass|STRING])' are not allowed."
                + " Use the pattern '(feature=[SomeClass|ID] | feature=[SomeClass|STRING])' instead.";
        error(errorMessage, alternatives, null, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, CROSS_REFERENCE_IN_ALTERNATIVES);
    }
}
项目:xtext-core    文件:XtextValidator.java   
private void checkTypeIsEClass(TypeRef type) {
    if (type != null) {
        EClassifier classifier = type.getClassifier();
        if (classifier != null && !classifier.eIsProxy()) {
            if (!(classifier instanceof EClass)) {
                error(
                        "Type of cross reference must be an EClass.", 
                        type, 
                        null,
                        ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
                        null);
            }
        }
    }
}
项目:xtext-core    文件:PredicateUsesUnorderedGroupInspector.java   
public PredicateUsesUnorderedGroupInspector(ValidationMessageAcceptor validationMessageAcceptor) {
    this.validationMessageAcceptor = validationMessageAcceptor;
    this.validatedRules = Sets.newHashSet();
    this.callHierarchy = Sets.newHashSet();
    this.erroneousElements = Sets.newHashSet();
    this.alreadyChecked = Sets.newHashSet();
    this.elementStack = new Stack<AbstractElement>();
}
项目:dsl-devkit    文件:LibraryChecksCheckImpl.java   
/**
 * checkCatalogIsActiveGreeting.
 */
@Check(CheckType.FAST)
public void checkCatalogIsActiveGreeting(final Greeting it) {// Issue diagnostic
  libraryChecksCatalog.accept(getMessageAcceptor(), //
    it, // context EObject
    null, // EStructuralFeature
    libraryChecksCatalog.getCheckCatalogIsActiveMessage(), // Message
    libraryChecksCatalog.getCheckCatalogIsActiveSeverityKind(it), // Severity 
    ValidationMessageAcceptor.INSIGNIFICANT_INDEX, // Marker index
    LibraryChecksIssueCodes.CHECK_CATALOG_IS_ACTIVE // Issue code & data
  );
}