Java 类org.eclipse.xtext.diagnostics.Severity 实例源码

项目:n4js    文件:QuickFixXpectMethod.java   
/**
 * Example: {@code // XPECT quickFixList  at 'a.<|>method' --> 'import A','do other things' }
 *
 * @param expectation
 *            comma separated strings, which are proposed as quick fix
 * @param resource
 *            injected xtext-file
 * @param offset
 *            cursor position at '<|>'
 * @param checkType
 *            'display': verify list of provided proposals comparing their user-displayed strings.
 * @param selected
 *            which proposal to pick
 * @param mode
 *            modus of operation
 * @param offset2issue
 *            mapping of offset(!) to issues.
 * @throws Exception
 *             if failing
 */
@Xpect
@ParameterParser(syntax = "('at' (arg2=STRING (arg3=ID  (arg4=STRING)?  (arg5=ID)? )? )? )?")
@ConsumedIssues({ Severity.INFO, Severity.ERROR, Severity.WARNING })
public void quickFixList(
        @CommaSeparatedValuesExpectation(quoted = true, ordered = true) ICommaSeparatedValuesExpectation expectation, // arg0
        @ThisResource XtextResource resource, // arg1
        RegionWithCursor offset, // arg2
        String checkType, // arg3
        String selected, // arg4
        String mode, // arg5
        @IssuesByLine Multimap<Integer, Issue> offset2issue) throws Exception {

    List<IssueResolution> resolutions = collectAllResolutions(resource, offset, offset2issue);

    List<String> resolutionNames = Lists.newArrayList();
    for (IssueResolution resolution : resolutions) {
        resolutionNames.add(resolution.getLabel());
    }

    expectation.assertEquals(resolutionNames);
}
项目:n4js    文件:XpectN4JSES5TranspilerHelper.java   
private boolean registerErrors(Resource dep, StringBuilder errorResult) {
    boolean hasErrors = false;
    List<Issue> issues = resourceValidator.validate(dep, CheckMode.ALL, CancelIndicator.NullImpl);
    List<Issue> errorIssues = new ArrayList<>();
    for (Issue issue : issues) {
        if (Severity.ERROR == issue.getSeverity()) {
            errorIssues.add(issue);
        }
    }
    hasErrors = !errorIssues.isEmpty();
    if (hasErrors) {
        errorResult.append("Couldn't compile resource " + dep.getURI() + " because it contains errors: ");
        for (Issue errorIssue : errorIssues) {
            errorResult
                    .append(nl + errorIssue.getMessage() + " at line " + errorIssue.getLineNumber());
        }
    }
    return hasErrors;
}
项目:solidity-ide    文件:SolidityMarkerCreator.java   
private void createInfoMarkers(CompiledContract contract, IFile file) {
    if (contract.getEvm() == null || contract.getEvm().getGasEstimates() == null) {
        return;
    }
    GasEstimates gasEstimates = contract.getEvm().getGasEstimates();

    SolcIssue solcIssue = new SolcIssue();
    solcIssue.setIFile(file);
    solcIssue.setLineNumber(1);
    solcIssue.setSeverity(Severity.INFO);
    String message = prettyPrint(gasEstimates);
    solcIssue.setMessage(message);
    solcIssue.setErrorCode(createErrorCodeFromMessage(Severity.INFO, message));
    EObject element = getEObject(file, 0);
    solcIssue.setUriToProblem(EcoreUtil.getURI(element));

    try {
        super.createMarker(solcIssue, file, NORMAL_VALIDATION);
    } catch (CoreException e) {
        e.printStackTrace();
    }

}
项目:solidity-ide    文件:SolidityMarkerCreator.java   
private SolcIssue createSolcIssue(CompileError error, Set<IResource> filesToCompile) {
    String[] parts = error.getFormattedMessage().split(":");
    String fileName = partAtIndex(parts, 0);
    IFile errorFile = findFileForName(filesToCompile, fileName);
    int lineNumber = extractNumber(partAtIndex(parts, 1));
    int columnNumber = extractNumber(partAtIndex(parts, 2));
    Map<Integer, String> fileContent = getFileContent(errorFile);
    int offset = calculateOffset(fileContent, columnNumber, lineNumber);
    int length = calculateIssueLength(fileContent.get(lineNumber), partAtIndex(parts, 4));

    Severity severity = calculateSeverity(error.getSeverity());
    String message = error.getMessage();
    SolcIssue solcIssue = new SolcIssue();
    solcIssue.setIFile(errorFile);
    solcIssue.setLineNumber(lineNumber);
    solcIssue.setColumnNumber(columnNumber);
    solcIssue.setSeverity(severity);
    solcIssue.setMessage(message);
    solcIssue.setOffset(offset);
    solcIssue.setLength(length);
    solcIssue.setErrorCode(createErrorCodeFromMessage(severity, message));
    EObject element = getEObject(errorFile, offset);
    solcIssue.setUriToProblem(EcoreUtil.getURI(element));
    return solcIssue;
}
项目:solidity-ide    文件:SolidityMarkerCreator.java   
private Severity calculateSeverity(String severety) {
    switch (severety) {
        case "warning" :
            return Severity.WARNING;
        case "error" :
            return Severity.ERROR;
        default :
            return Severity.INFO;
    }
}
项目:xtext-extras    文件:XbaseTypeComputer.java   
protected void checkValidReturn(XReturnExpression object, ITypeComputationState state) {
    // if the expectation comes from a method's return type
    // then it is legal, thus we must check if the return is
    // contained in a throw expression
    if (hasThrowableExpectation(state) &&
            EcoreUtil2.getContainerOfType(object, XThrowExpression.class) != null) {
        state.addDiagnostic(new EObjectDiagnosticImpl(
                Severity.ERROR,
                IssueCodes.INVALID_RETURN,
                "Invalid return inside throw.",
                object,
                null,
                -1,
                new String[] { 
                }));
    }
}
项目:xtext-extras    文件:XbaseTypeComputer.java   
protected void checkValidReturnExpression(XExpression returnValue, ITypeComputationState expressionState) {
    ITypeComputationResult result = expressionState.computeTypes(returnValue);
    LightweightTypeReference actualType = result.getActualExpressionType();
    int conformanceFlags = result.getConformanceFlags();
    if (actualType.isPrimitiveVoid() && (conformanceFlags & ConformanceFlags.NO_IMPLICIT_RETURN) != 0) {
        String message = "Invalid return's expression.";
        if (returnValue instanceof XReturnExpression) {
            // when the return's expression is directory a return
            // we provide a more detailed error
            message = "Return cannot be nested.";
        }
        expressionState.addDiagnostic(new EObjectDiagnosticImpl(
                Severity.ERROR,
                IssueCodes.INVALID_RETURN,
                message,
                returnValue,
                null,
                -1,
                new String[] { 
                }));
    }
}
项目:xtext-extras    文件:XbaseTypeComputer.java   
protected void _computeTypes(XSynchronizedExpression expr, ITypeComputationState state) {
    ITypeComputationState paramState = state.withExpectation(state.getReferenceOwner().newReferenceToObject());
    ITypeComputationResult paramType = paramState.computeTypes(expr.getParam());
    LightweightTypeReference actualParamType = paramType.getActualExpressionType();
    if (actualParamType != null && (actualParamType.isPrimitive() || actualParamType.isAny())) {
        state.addDiagnostic(new EObjectDiagnosticImpl(
                Severity.ERROR,
                IssueCodes.INCOMPATIBLE_TYPES,
                actualParamType.getHumanReadableName() +  " is not a valid type's argument for the synchronized expression.",
                expr.getParam(),
                null,
                -1,
                new String[] { 
                }));
    }
    state.computeTypes(expr.getExpression());
}
项目:dsl-devkit    文件:DefaultCheckImpl.java   
/**
 * Gets a numeric value mapped to a given {@link Severity}. Severities are mapped to
 * <ul>
 * <li>{@link Diagnostic#ERROR}
 * <li>{@link Diagnostic#WARNING}
 * <li>{@link Diagnostic#INFO}
 * </ul>
 *
 * @param severity
 *          the issue severity
 * @return the numeric value representing a severity
 */
protected int toDiagnosticSeverity(final Severity severity) {
  int diagnosticSeverity = -1;
  switch (severity) {
  case ERROR:
    diagnosticSeverity = Diagnostic.ERROR;
    break;
  case WARNING:
    diagnosticSeverity = Diagnostic.WARNING;
    break;
  case INFO:
    diagnosticSeverity = Diagnostic.INFO;
    break;
  default:
    throw new IllegalArgumentException("Unknow severity " + severity); //$NON-NLS-1$
  }
  return diagnosticSeverity;
}
项目:xtext-extras    文件:ConstructorLinkingCandidate.java   
@Override
public boolean validate(IAcceptor<? super AbstractDiagnostic> result) {
    JvmDeclaredType declaringType = getConstructor().getDeclaringType();
    if (declaringType.isAbstract()) {
        String message = "Cannot instantiate the abstract type " + declaringType.getSimpleName();
        AbstractDiagnostic diagnostic = new EObjectDiagnosticImpl(
                Severity.ERROR, 
                IssueCodes.ABSTRACT_CLASS_INSTANTIATION, 
                message, 
                getExpression(), 
                getDefaultValidationFeature(), -1, null);
        result.accept(diagnostic);
        return false;
    }
    return super.validate(result);
}
项目:xtext-extras    文件:ImplicitFirstArgument.java   
@Override
public boolean validate(IAcceptor<? super AbstractDiagnostic> result) {
    if (!getState().isInstanceContext()) {
        JvmIdentifiableElement implicitFeature = getFeature();
        if (implicitFeature instanceof JvmType) {
            JvmIdentifiableElement feature = getState().getResolvedTypes().getLinkedFeature(getOwner());
            if (feature == null || feature.eIsProxy() || !(feature instanceof JvmFeature))
                return true;
            String message = "Cannot make an implicit reference to this from a static context";
            AbstractDiagnostic diagnostic = new EObjectDiagnosticImpl(Severity.ERROR,
                    IssueCodes.STATIC_ACCESS_TO_INSTANCE_MEMBER, message, getOwner(),
                    XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, -1, null);
            result.accept(diagnostic);
            return false;
        }
    }
    return super.validate(result);
}
项目:xtext-extras    文件:RootResolvedTypes.java   
protected AbstractDiagnostic createTypeDiagnostic(XExpression expression, LightweightTypeReference actualType, LightweightTypeReference expectedType) {
    if (!expectedType.isAny()) {
        String actualName = actualType.getSimpleName();
        String expectedName = expectedType.getSimpleName();
        if (actualName.equals(expectedName)) {
            if (expectedType.isAssignableFrom(actualType)) {
                return null;
            }
        }
        if (expression.eContainingFeature() == XbasePackage.Literals.XABSTRACT_FEATURE_CALL__IMPLICIT_FIRST_ARGUMENT) {
            return new EObjectDiagnosticImpl(Severity.ERROR, IssueCodes.INCOMPATIBLE_TYPES, String.format(
                    "Type mismatch: cannot convert implicit first argument from %s to %s", actualType.getHumanReadableName(), expectedType.getHumanReadableName()),
                    expression, null, -1, null);
        } else {
            return new EObjectDiagnosticImpl(Severity.ERROR, IssueCodes.INCOMPATIBLE_TYPES, String.format(
                    "Type mismatch: cannot convert from %s to %s", actualType.getHumanReadableName(), expectedType.getHumanReadableName()),
                    expression, null, -1, null);
        }
    } else {
        return new EObjectDiagnosticImpl(Severity.ERROR, IssueCodes.INCOMPATIBLE_TYPES, String.format(
                "Type mismatch: type %s is not applicable at this location", actualType.getHumanReadableName()), expression, null, -1,
                null);
    }
}
项目:xtext-extras    文件:AbstractPendingLinkingCandidate.java   
protected boolean validateVisibility(IAcceptor<? super AbstractDiagnostic> result) {
    if (!isVisible()) {
        String message = String.format("The %1$s %2$s%3$s is not visible", 
                getFeatureTypeName(),
                getSimpleFeatureName(),
                getFeatureParameterTypesAsString());
        AbstractDiagnostic diagnostic = new EObjectDiagnosticImpl(
                Severity.ERROR, 
                IssueCodes.FEATURE_NOT_VISIBLE, 
                message, 
                getExpression(), 
                getDefaultValidationFeature(), -1, null);
        result.accept(diagnostic);
        return false;
    }
    return true;
}
项目:xtext-extras    文件:AbstractPendingLinkingCandidate.java   
protected boolean validateArity(IAcceptor<? super AbstractDiagnostic> result) {
    if (getArityMismatch() != 0) {
        String message; 
        if (getArguments().isEmpty()) {
            message = String.format("Invalid number of arguments. The %1$s %2$s%3$s is not applicable without arguments" , 
                    getFeatureTypeName(), 
                    getSimpleFeatureName(), 
                    getFeatureParameterTypesAsString());
        } else {
            message = String.format("Invalid number of arguments. The %1$s %2$s%3$s is not applicable for the arguments %4$s" , 
                    getFeatureTypeName(), 
                    getSimpleFeatureName(), 
                    getFeatureParameterTypesAsString(), 
                    getArgumentTypesAsString());
        }
        AbstractDiagnostic diagnostic = new EObjectDiagnosticImpl(
                Severity.ERROR, 
                IssueCodes.INVALID_NUMBER_OF_ARGUMENTS, 
                message, 
                getExpression(), 
                getInvalidArgumentsValidationFeature(), -1, null);
        result.accept(diagnostic);
        return false;
    }
    return true;
}
项目:xtext-extras    文件:TypeInsteadOfConstructorLinkingCandidate.java   
@Override
public boolean validate(IAcceptor<? super AbstractDiagnostic> result) {
    JvmType type = (JvmType) description.getElementOrProxy();
    String typeKind = "";
    if (type instanceof JvmPrimitiveType || type instanceof JvmVoid) {
        typeKind = "primitive type";
    } else if (type instanceof JvmAnnotationType) {
        typeKind = "annotation type";
    } else if (type instanceof JvmEnumerationType) {
        typeKind = "enum type";
    } else if (type instanceof JvmGenericType && ((JvmGenericType) type).isInterface()) {
        typeKind = "interface type";
    } else if (type instanceof JvmTypeParameter) {
        typeKind = "type parameter";
    }
    String message = String.format("Cannot instantiate the %s %s", typeKind, type.getSimpleName());
    AbstractDiagnostic diagnostic = new EObjectDiagnosticImpl(Severity.ERROR,
            IssueCodes.ILLEGAL_CLASS_INSTANTIATION, message, getExpression(),
            XbasePackage.Literals.XCONSTRUCTOR_CALL__CONSTRUCTOR, -1, null);
    result.accept(diagnostic);
    return false;
}
项目:xtext-extras    文件:BatchLinkableResource.java   
@Override
protected EObject handleCyclicResolution(Triple<EObject, EReference, INode> triple) throws AssertionError {
    if (!isValidationDisabled()) {
        EObject context = triple.getFirst();
        if (context.eClass() == TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE) {
            // here we may end up with cyclic resolution requests in rare situations, e.g. for input types
            // like :
            /*
             * package p;
             * class C extends p.C.Bogus {}
             */
            return null;
        }
        DiagnosticMessage message = new DiagnosticMessage("Cyclic linking detected : " + getReferences(triple, resolving), Severity.ERROR, "cyclic-resolution");
        List<Diagnostic> list = getDiagnosticList(message);
        Diagnostic diagnostic = createDiagnostic(triple, message);
        if (!list.contains(diagnostic))
            list.add(diagnostic);
    }
    return null;
}
项目:xtext-core    文件:AbstractDeclarativeValidator.java   
/**
 * @since 2.4
 */
protected void addIssue(String message, EObject source, EStructuralFeature feature, int index, String issueCode,
        String... issueData) {
    Severity severity = getIssueSeverities(getContext(), getCurrentObject()).getSeverity(issueCode);
    if (severity != null) {
        switch (severity) {
            case WARNING:
                getMessageAcceptor().acceptWarning(message, source, feature, index, issueCode, issueData);
                break;
            case INFO:
                getMessageAcceptor().acceptInfo(message, source, feature, index, issueCode, issueData);
                break;
            case ERROR:
                getMessageAcceptor().acceptError(message, source, feature, index, issueCode, issueData);
                break;
            default:
                break;
        }
    }
}
项目:xtext-core    文件:AbstractDeclarativeValidator.java   
/**
 * @since 2.4
 */
protected void addIssue(String message, EObject source, int offset,  int length, String issueCode, String... issueData) {
    Severity severity = getIssueSeverities(getContext(), getCurrentObject()).getSeverity(issueCode);
    if (severity != null) {
        switch (severity) {
            case WARNING:
                getMessageAcceptor().acceptWarning(message, source, offset, length, issueCode, issueData);
                break;
            case INFO:
                getMessageAcceptor().acceptInfo(message, source,  offset, length, issueCode, issueData);
                break;
            case ERROR:
                getMessageAcceptor().acceptError(message, source, offset, length, issueCode, issueData);
                break;
            default:
                break;
        }
    }
}
项目:xtext-core    文件:SeverityConverter.java   
public Severity stringToSeverity(String severityAsString) {
    if (severityAsString == null)
        throw new IllegalArgumentException("Severity as string was null");
    if (severityAsString.equals(SEVERITY_ERROR)) {
        return Severity.ERROR;
    }
    if (severityAsString.equals(SEVERITY_WARNING)) {
        return Severity.WARNING;
    }
    if (severityAsString.equals(SEVERITY_INFO)) {
        return Severity.INFO;
    }
    if (severityAsString.equals(SEVERITY_IGNORE)) {
        return Severity.IGNORE;
    }
    throw new IllegalArgumentException("Unknown severity '"+severityAsString+"'.");
}
项目:dsl-devkit    文件:ModelValidator.java   
/**
 * Log issue.
 *
 * @param resource
 *          the resource
 * @param issue
 *          the issue
 * @param logger
 *          the logger
 */
private void logIssue(final Resource resource, final Issue issue, final Logger logger) {
  final String message = NLS.bind(MESSAGE_TEMPLATE, new Object[] {resource.getURI().lastSegment(), issue.getLineNumber(), issue.getMessage()});
  final Severity severity = issue.getSeverity();
  switch (severity) {
  case ERROR:
    logger.error(message);
    break;
  case WARNING:
    logger.warn(message);
    break;
  case INFO:
    if (logger.isInfoEnabled()) {
      logger.info(message);
    }
    break;

  default:
    break;
  }
}
项目:xtext-core    文件:DiagnosticConverterImpl.java   
@Override
public void convertResourceDiagnostic(Diagnostic diagnostic, Severity severity, IAcceptor<Issue> acceptor) {
    IssueImpl issue = new Issue.IssueImpl();
    issue.setSyntaxError(diagnostic instanceof XtextSyntaxDiagnostic);
    issue.setSeverity(severity);
    issue.setLineNumber(diagnostic.getLine());
    issue.setColumn(diagnostic.getColumn());
    issue.setMessage(diagnostic.getMessage());

    if (diagnostic instanceof org.eclipse.xtext.diagnostics.Diagnostic) {
        org.eclipse.xtext.diagnostics.Diagnostic xtextDiagnostic = (org.eclipse.xtext.diagnostics.Diagnostic) diagnostic;
        issue.setOffset(xtextDiagnostic.getOffset());
        issue.setLength(xtextDiagnostic.getLength());
    }
    if (diagnostic instanceof AbstractDiagnostic) {
        AbstractDiagnostic castedDiagnostic = (AbstractDiagnostic)diagnostic;
        issue.setUriToProblem(castedDiagnostic.getUriToProblem());
        issue.setCode(castedDiagnostic.getCode());
        issue.setData(castedDiagnostic.getData());
    }
    issue.setType(CheckType.FAST);
    acceptor.accept(issue);
}
项目:xtext-core    文件:XtextLinker.java   
@Override
public void linkModel(EObject model, IDiagnosticConsumer consumer) {
    if (model instanceof Grammar) {
        final Xtext2EcoreTransformer transformer = createTransformer((Grammar) model, consumer);
        //TODO duplicate
        transformer.removeGeneratedPackages();
        super.linkModel(model, consumer);
        updateOverriddenRules((Grammar) model);
        try {
            transformer.transform();
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            consumer.consume(new ExceptionDiagnostic(e), Severity.ERROR);
        }
        if (!model.eResource().eAdapters().contains(packageRemover))
            model.eResource().eAdapters().add(packageRemover);
    } else {
        super.linkModel(model, consumer);
    }
}
项目:xtext-core    文件:XtextDiagnosticConverter.java   
@Override
protected Severity getSeverity(Diagnostic diagnostic) {
    Severity result = super.getSeverity(diagnostic);
    String issueCode = getIssueCode(diagnostic);
    if (result == Severity.WARNING && issueCode != null) {
        // only warnings can be suppressed
        EObject causer = getCauser(diagnostic);
        if (causer != null) {
            if (isMarkedAsIgnored(causer, issueCode)) {
                return null;
            }
            if (!(causer instanceof AbstractRule)) {
                AbstractRule rule = GrammarUtil.containingRule(causer);
                if (rule != null && isMarkedAsIgnored(rule, issueCode)) {
                    return null;
                }
            }
            Grammar grammar = GrammarUtil.getGrammar(causer);
            if (grammar != null && isMarkedAsIgnored(grammar, issueCode)) {
                return null;
            }
        }
    }
    return result;
}
项目:xtext-core    文件:XtextValidator.java   
@Check
public void checkOppositeReferenceUsed(Assignment assignment) {
    Severity severity = getIssueSeverities(getContext(), getCurrentObject()).getSeverity(BIDIRECTIONAL_REFERENCE);
    if (severity == null || severity == Severity.IGNORE) {
        // Don't perform any check if the result is ignored
        return;
    }
    EClassifier classifier = GrammarUtil.findCurrentType(assignment);
    if (classifier instanceof EClass) {
        EStructuralFeature feature = ((EClass) classifier).getEStructuralFeature(assignment.getFeature());
        if (feature instanceof EReference) {
            EReference reference = (EReference) feature;
            if (reference.getEOpposite() != null && !(reference.isContainment() || reference.isContainer())) {
                addIssue("The feature '" + assignment.getFeature() + "' is a bidirectional reference."
                        + " This may cause problems in the linking process.",
                        assignment, XtextPackage.eINSTANCE.getAssignment_Feature(), BIDIRECTIONAL_REFERENCE);
            }
        }
    }
}
项目:xtext-core    文件:ListBasedDiagnosticConsumer.java   
private Internal getInternal(Severity severity) {
    if (severity == null)
        throw new NullPointerException("Severity may not be null");
    switch(severity) {
        case ERROR: 
            if (errors == null) {
                errors = new Internal();
            }
            return errors;
        case WARNING:
            if (warnings == null) {
                warnings = new Internal();
            }
            return warnings;
        default:
            throw new IllegalArgumentException("Illegal severity: INFO. Diagnostics may either be warnings or errors");
    }
}
项目:xtext-core    文件:ValidationTestHelper.java   
protected Iterable<Issue> doMatchIssues(final Resource resource, final EClass objectType, final String code,
        final int offset, final int length, final Severity severity, final List<Issue> validate,
        final String... messageParts) {
    return Iterables.filter(validate, new Predicate<Issue>() {
        @Override
        public boolean apply(Issue input) {
            if (Strings.equal(input.getCode(), code) && input.getSeverity()==severity) {
                if ((offset < 0 || offset == input.getOffset()) && (length < 0 || length == input.getLength())) {
                    EObject object = resource.getResourceSet().getEObject(input.getUriToProblem(), true);
                    if (objectType.isInstance(object)) {
                        for (String messagePart : messageParts) {
                            if(!isValidationMessagePartMatches(input.getMessage(), messagePart)){
                                return false;
                            }
                        }
                        return true;
                    }
                }
            }
            return false;
        }
    });
}
项目:n4js    文件:N4HeadlessCompiler.java   
/**
 * Validates all non-external Xtext resources of the given project. Prints issues and adds them to the given issue
 * acceptor.
 *
 * @param markedProject
 *            the project to validate
 * @param recorder
 *            the progress recorder
 * @param issueAcceptor
 *            the issue acceptor
 * @throws N4JSCompileErrorException
 *             if an error occurs during validation
 */
private void validateProject(MarkedProject markedProject, N4ProgressStateRecorder recorder,
        IssueAcceptor issueAcceptor) throws N4JSCompileErrorException {

    if (logger.isVerbose())
        logger.info(" Validating project " + markedProject);
    IssueCollector issueCollector = new IssueCollector();
    IssueFilter issueFilter = new IssueFilter(issueCollector, issue -> issue.getSeverity() == Severity.ERROR);
    issueAcceptor = new IssueAcceptorTee(issueAcceptor, issueFilter);

    // validation TODO see IDE-1426 redesign validation calls with generators
    for (Resource resource : markedProject.resources) {
        if (resource instanceof XtextResource && // is Xtext resource
                (!n4jsCore.isNoValidate(resource.getURI())) && // is validating
                (!markedProject.externalResources.contains(resource)) // not in external folder
        ) {
            if (logger.isCreateDebugOutput())
                logger.debug("   Validating resource " + resource.getURI());
            XtextResource xtextResource = (XtextResource) resource;
            IResourceValidator validator = xtextResource.getResourceServiceProvider().getResourceValidator();
            List<Issue> issues = validator.validate(xtextResource, CheckMode.ALL, CancelIndicator.NullImpl);

            if (!issues.isEmpty()) {
                recorder.markResourceIssues(resource, issues);
                issueAcceptor.acceptAll(issues);
                issues.stream().forEach(logger::issue);
            }
        }
    }

    // Projects should not compile if there are severe errors:
    if (!isKeepOnCompiling()) {
        failOnErrors(issueCollector.getCollectedIssues(), markedProject.project.getProjectId());
    }
}
项目:n4js    文件:N4JSIssueSeverities.java   
/**
 * @return the Severity for the given severity code. If no configured severity could be found in the configurable
 *         issue codes, the default severity configured in messages.properties (contained in this package) will be
 *         returned.
 */
@Override
public Severity getSeverity(String code) {
    if (!configurableIssueCodes.containsKey(code)) {
        Severity severity = IssueCodes.getDefaultSeverity(code);
        if (severity != null) {
            return severity;
        }
    }
    return super.getSeverity(code);
}
项目:n4js    文件:N4MFIssueSeverities.java   
/**
 * @return the Severity for the given severity code. If no configured severity could be found in the configurable
 *         issue codes, the default severity configured in messages.properties (contained in this package) will be
 *         returned.
 */
@Override
public Severity getSeverity(String code) {
    if (!configurableIssueCodes.containsKey(code)) {
        Severity severity = IssueCodes.getDefaultSeverity(code);
        if (severity != null) {
            return severity;
        }
    }
    return super.getSeverity(code);
}
项目:solidity-ide    文件:SolidityMarkerCreator.java   
private String createErrorCodeFromMessage(Severity severity, String message) {
    switch (severity) {
        case ERROR :
            return "error";
        case WARNING :
            return SolidityWarning.getCodeForMessage(message);
        default :
            return "info";
    }
}
项目:xtext-extras    文件:XbaseSeverityConverter.java   
@Override
public Severity stringToSeverity(final String severityAsString) {
    String valueToConvert = severityAsString;
    if (severityAsString.startsWith(XbaseConfigurableIssueCodes.JDT_CORE_PLUGIN_ID)) {
        valueToConvert = delegatedValue(decodeDelegationKey(severityAsString));
    }
    return super.stringToSeverity(valueToConvert);
}
项目:xtext-extras    文件:DiagnosticOnFirstKeyword.java   
public DiagnosticOnFirstKeyword(
        Severity severity,
        String problemCode,
        String message,
        EObject problematicObject,
        String[] data) {
    super(severity, problemCode, message, problematicObject, null, -1, data);
}
项目:xtext-extras    文件:XbaseTypeComputer.java   
private void checkTypeParameterNotAllowedAsLiteral(EObject ctx, JvmType type, ITypeComputationState state) {
    if (type instanceof JvmTypeParameter) {
        state.addDiagnostic(new EObjectDiagnosticImpl(
                Severity.ERROR,
                IssueCodes.INVALID_USE_OF_TYPE_PARAMETER,
                "Illegal class literal for the type parameter " + type.getSimpleName()+".",
                ctx,
                null,
                -1,
                new String[] { 
                }));
    }
}
项目:xtext-core    文件:ProjectManager.java   
public void reportProjectIssue(final String message, final String code, final Severity severity) {
  Issue.IssueImpl _issueImpl = new Issue.IssueImpl();
  final Procedure1<Issue.IssueImpl> _function = (Issue.IssueImpl it) -> {
    it.setMessage(message);
    it.setCode(code);
    it.setSeverity(severity);
    it.setUriToProblem(this.baseDir);
  };
  Issue.IssueImpl _doubleArrow = ObjectExtensions.<Issue.IssueImpl>operator_doubleArrow(_issueImpl, _function);
  this.issueAcceptor.apply(this.baseDir, Collections.<Issue>unmodifiableList(CollectionLiterals.<Issue>newArrayList(_doubleArrow)));
}
项目:xtext-extras    文件:AbstractTypeComputationState.java   
protected void addLocalToCurrentScope(QualifiedName elementName, JvmIdentifiableElement element, boolean raiseIssueIfShadowing) {
    if (getResolver().isDisallowedName(elementName)) {
        resolvedTypes.addDiagnostic(new EObjectDiagnosticImpl(
                Severity.ERROR,
                IssueCodes.VARIABLE_NAME_DISALLOWED, 
                "'" + elementName + "' is not a valid name", 
                getResolver().getSourceElement(element),
                element.eClass().getEStructuralFeature("name"),
                -1,
                null));
        return;
    }
    if (getResolver().isDiscouragedName(elementName)) {
        if (!isIgnored(IssueCodes.VARIABLE_NAME_DISCOURAGED)) {
            resolvedTypes.addDiagnostic(new EObjectDiagnosticImpl(
                    getSeverity(IssueCodes.VARIABLE_NAME_DISCOURAGED),
                    IssueCodes.VARIABLE_NAME_DISCOURAGED, 
                    "'" + elementName + "' is a discouraged name", 
                    getResolver().getSourceElement(element),
                    element.eClass().getEStructuralFeature("name"),
                    -1,
                    null));
        }
    }
    if (raiseIssueIfShadowing) {
        IEObjectDescription existingElement = featureScopeSession.getLocalElement(elementName);
        if (existingElement != null) {
            resolvedTypes.addDiagnostic(new EObjectDiagnosticImpl(
                    Severity.ERROR,
                    IssueCodes.VARIABLE_NAME_SHADOWING, 
                    "Duplicate local variable " + elementName, 
                    getResolver().getSourceElement(element),
                    element.eClass().getEStructuralFeature("name"),
                    -1,
                    null));
        }
    }
    featureScopeSession = featureScopeSession.addLocalElement(elementName, element, getReferenceOwner());
}
项目:xtext-extras    文件:RootResolvedTypes.java   
public void addDiagnostics(final Resource resource) {
    if (resource instanceof XtextResource) {
        if (((XtextResource) resource).isValidationDisabled())
            return;
    }
    class DiagnosticAcceptor implements IAcceptor<AbstractDiagnostic> {

        @Override
        public void accept(/* @Nullable */ AbstractDiagnostic diagnostic) {
            if (diagnostic instanceof EObjectDiagnosticImpl) {
                Severity severity = ((EObjectDiagnosticImpl) diagnostic).getSeverity();
                if (severity == Severity.ERROR) {
                    resource.getErrors().add(diagnostic);
                } else if (severity == Severity.WARNING) {
                    resource.getWarnings().add(diagnostic);
                }
            } else {
                resource.getErrors().add(diagnostic);
            }
        }

    }
    DiagnosticAcceptor acceptor = new DiagnosticAcceptor();
    addQueuedDiagnostics(acceptor);
    addLinkingDiagnostics(acceptor);
    addTypeDiagnostics(acceptor);
}
项目:xtext-extras    文件:FeatureLinkingCandidate.java   
@Override
protected Severity getUnhandledExceptionSeverity(JvmExecutable executable) {
    if (getFeature() instanceof JvmConstructor) {
        return Severity.ERROR;
    }
    return super.getUnhandledExceptionSeverity(executable);
}
项目:dsl-devkit    文件:ValidValidatorFragment.java   
/**
 * Gets the valid model.
 *
 * @param grammar
 *          the grammar
 * @return the valid model
 */
private ValidModel getValidModel(final Grammar grammar) {
  if (model != null) {
    return model;
  }

  Resource resource = null;
  final String name = GrammarUtil.getName(grammar) + '.' + XTEXT_EXTENSION;
  URI uri;
  for (final Resource res : grammar.eResource().getResourceSet().getResources()) {
    if (res.getURI() != null && name.equals(EmfResourceUtil.getFileName(res.getURI()))) {
      resource = res;
      break;
    }
  }
  if (getValidURI() == null) {
    Assert.isNotNull(resource, NLS.bind(Messages.RESOURCE_NOT_FOUND, name));
    uri = resource.getURI().trimFileExtension().appendFileExtension(VALID_EXTENSION);
  } else {
    uri = URI.createURI(getValidURI());
  }

  resource = resource.getResourceSet().getResource(uri, true);

  final List<Issue> issues = VALIDATOR.validate(resource, LOGGER);
  for (final Issue issue : issues) {
    if (issue.isSyntaxError() || issue.getSeverity() == Severity.ERROR) {
      throw new WorkflowInterruptedException(NLS.bind(Messages.ERROR_FOUND, uri.toString()));
    }
  }
  model = (ValidModel) resource.getContents().get(0);
  return model;
}
项目:xtext-extras    文件:AbstractPendingLinkingCandidate.java   
protected boolean validateTypeArgumentConformance(IAcceptor<? super AbstractDiagnostic> result) {
    if (getTypeArgumentConformanceFailures(result) == 0) {
        // TODO use early exit computation
        List<XExpression> arguments = getSyntacticArguments();
        for(int i = 0; i < arguments.size(); i++) {
            XExpression argument = arguments.get(i);
            if (isDefiniteEarlyExit(argument)) {
                XExpression errorOn = getExpression();
                String message = "Unreachable code.";
                EStructuralFeature errorFeature = null;
                if (i < arguments.size() - 1) {
                    errorOn = arguments.get(i + 1);
                } else {
                    errorFeature = getDefaultValidationFeature();
                    if (errorOn instanceof XBinaryOperation) {
                        message = "Unreachable code. The right argument expression does not complete normally.";
                    } else {
                        message = "Unreachable code. The last argument expression does not complete normally.";
                    }
                }
                AbstractDiagnostic diagnostic = new EObjectDiagnosticImpl(
                        Severity.ERROR, 
                        IssueCodes.UNREACHABLE_CODE, 
                        message, 
                        errorOn, 
                        errorFeature, 
                        -1, null);
                result.accept(diagnostic);
                return false;
            }
        }
    } else {
        return false;
    }
    return true;
}
项目:xtext-extras    文件:ErrorSafeExtensions.java   
public Iterable<Issue> getErrors(final EObject element) {
  Iterable<Issue> _xblockexpression = null;
  {
    final IElementIssueProvider issueProvider = this.issueProviderFactory.get(element.eResource());
    final Function1<Issue, Boolean> _function = (Issue it) -> {
      Severity _severity = it.getSeverity();
      return Boolean.valueOf(Objects.equal(_severity, Severity.ERROR));
    };
    _xblockexpression = IterableExtensions.<Issue>filter(issueProvider.getIssues(element), _function);
  }
  return _xblockexpression;
}