Example usage for org.eclipse.jdt.internal.compiler.problem ProblemSeverities Error

List of usage examples for org.eclipse.jdt.internal.compiler.problem ProblemSeverities Error

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.problem ProblemSeverities Error.

Prototype

int Error

To view the source code for org.eclipse.jdt.internal.compiler.problem ProblemSeverities Error.

Click Source Link

Usage

From source file:com.codenvy.ide.ext.java.server.internal.codeassist.impl.Engine.java

License:Open Source License

public Engine(Map settings) {
    this.options = new AssistOptions(settings);
    this.compilerOptions = new CompilerOptions(settings);
    this.forbiddenReferenceIsError = (this.compilerOptions.getSeverity(CompilerOptions.ForbiddenReference)
            & ProblemSeverities.Error) != 0;
    this.discouragedReferenceIsError = (this.compilerOptions.getSeverity(CompilerOptions.DiscouragedReference)
            & ProblemSeverities.Error) != 0;
}

From source file:com.google.gwt.dev.javac.GWTProblem.java

License:Open Source License

public static void recordError(ASTNode node, CompilationUnitDeclaration cud, String message,
        HelpInfo helpInfo) {/* w  ww  .ja  v  a2  s.  c o  m*/
    recordProblem(node, cud.compilationResult(), message, helpInfo, ProblemSeverities.Error);
}

From source file:com.google.gwt.dev.javac.GWTProblem.java

License:Open Source License

public static void recordError(SourceInfo info, int startColumn, CompilationResult compResult, String message,
        HelpInfo helpInfo) {//from   ww w .ja v a 2 s .  c  o m
    recordProblem(info, startColumn, compResult, message, helpInfo, ProblemSeverities.Error);
}

From source file:com.google.gwt.dev.javac.JsniCollector.java

License:Open Source License

public static void reportJsniError(SourceInfo info, AbstractMethodDeclaration method, String msg) {
    reportJsniProblem(info, method, msg, ProblemSeverities.Error);
}

From source file:jmockit.assist.MockASTVisitor.java

License:Open Source License

private void addMarker(final ASTNode node, final String msg, final boolean isError) {
    try {/*from  w  ww. ja v a 2 s. c  o  m*/
        int start = node.getStartPosition();
        int endChar = start + node.getLength();
        int line = cu.getLineNumber(start);
        int col = cu.getColumnNumber(start);
        int id = IProblem.TypeRelated;
        String filePath = icunit.getPath().toOSString();
        String[] args = new String[] {};

        int severity = isError ? ProblemSeverities.Error : ProblemSeverities.Warning;

        CategorizedProblem problem = new DefaultProblem(filePath.toCharArray(), msg, id, args, severity, start,
                endChar, line, col) {
            @Override
            public String getMarkerType() {
                return JMockitCompilationParticipant.MARKER;
            }
        };

        probs.add(problem);
    } catch (Exception e) {
        Activator.log(e);
    }
}

From source file:org.ant4eclipse.ant.jdt.ecj.JavacCompilerAdapter.java

License:Open Source License

/**
 * Creates the problem instances which can be used to report some issues.
 * /*from   w ww . jav  a2s .  c  om*/
 * @param problems
 *          The receiving list for the problems. Not <code>null</code>.
 * @param sourcefilename
 *          The filename these problems are related to. Not <code>null</code>.
 * @param text
 *          The content of the javac outcome. Not <code>null</code>.
 */
private void createProblems(List<CategorizedProblem> problems, String sourcefilename, String text) {
    List<String> lines = Utilities.splitText(text);
    Collections.reverse(lines);
    for (int i = 0; i < lines.size() - 2; i++) {
        int col = lines.get(i).indexOf('^');
        if (col != -1) {
            // we've got a marker for the issue which usually looks like in the following example
            //
            // mysource.java:12 : there's an error
            // public class mysource- {
            // ^
            //
            String line = lines.get(i + 2);
            int suffix = line.indexOf(SUFFIX_JAVA);
            if (suffix != -1) {
                line = line.substring(suffix + SUFFIX_JAVA.length() + 1); // +1 to skip a ':' before the line number
                int colon = line.indexOf(':');
                if (colon != -1) {
                    int lineno = Integer.parseInt(line.substring(0, colon));
                    String error = line.substring(colon + 1).trim();
                    problems.add(this._problemfactory.createProblem(sourcefilename.toCharArray(),
                            IProblem.Unclassified, new String[] { error }, new String[] { error },
                            ProblemSeverities.Error, -1, -1, lineno, problems.size()));
                }
            }
        }
    }
}

From source file:org.codehaus.jdt.groovy.internal.compiler.ast.GroovyCompilationUnitDeclaration.java

License:Open Source License

private void recordProblems(List<?> errors) {
    // FIXASC look at this error situation (described below), surely we need to do it?
    // Due to the nature of driving all groovy entities through compilation together, we can accumulate messages for other
    // compilation units whilst processing the one we wanted to. Per GRE396 this can manifest as recording the wrong thing
    // against the wrong type. That is the only case I have seen of it, so I'm not putting in the general mechanism for all
    // errors yet, I'm just dealing with RuntimeParserExceptions. The general strategy would be to compare the ModuleNode
    // for each message with the ModuleNode currently being processed - if they differ then this isn't a message for this
    // unit and so we ignore it. If we do deal with it then we remember that we did (in errorsRecorded) and remove it from
    // the list of those to process.

    List errorsRecorded = new ArrayList();
    // FIXASC poor way to get the errors attached to the files
    // FIXASC does groovy ever produce warnings? How are they treated here?
    for (Iterator<?> iterator = errors.iterator(); iterator.hasNext();) {
        SyntaxException syntaxException = null;
        Message message = (Message) iterator.next();
        StringWriter sw = new StringWriter();
        message.write(new PrintWriter(sw));
        String msg = sw.toString();
        CategorizedProblem p = null;/*  ww w  . j a v  a 2s  .co m*/
        int line = 0;
        int sev = 0;
        int scol = 0;
        int ecol = 0;
        // LocatedMessage instances are produced sometimes, e.g. by grails ast transforms, use the context for position
        if (message instanceof LocatedMessage) {
            CSTNode context = ((LocatedMessage) message).getContext();
            if (context instanceof Token) {
                line = context.getStartLine();
                scol = context.getStartColumn();
                String text = ((Token) context).getText();
                ecol = scol + (text == null ? 1 : (text.length() - 1));
            }
        }
        if (message instanceof SimpleMessage) {
            SimpleMessage simpleMessage = (SimpleMessage) message;
            sev |= ProblemSeverities.Error;
            String simpleText = simpleMessage.getMessage();
            if (simpleText.length() > 1 && simpleText.charAt(0) == '\n') {
                simpleText = simpleText.substring(1);
            }
            msg = "Groovy:" + simpleText;
            if (msg.indexOf("\n") != -1) {
                msg = msg.substring(0, msg.indexOf("\n"));
            }
        }
        if (message instanceof SyntaxErrorMessage) {
            SyntaxErrorMessage errorMessage = (SyntaxErrorMessage) message;
            syntaxException = errorMessage.getCause();
            sev |= ProblemSeverities.Error;
            // FIXASC in the short term, prefixed groovy to indicate
            // where it came from
            String actualMessage = syntaxException.getMessage();
            if (actualMessage.length() > 1 && actualMessage.charAt(0) == '\n') {
                actualMessage = actualMessage.substring(1);
            }
            msg = "Groovy:" + actualMessage;
            if (msg.indexOf("\n") != -1) {
                msg = msg.substring(0, msg.indexOf("\n"));
            }
            line = syntaxException.getLine();
            scol = errorMessage.getCause().getStartColumn();
            ecol = errorMessage.getCause().getEndColumn() - 1;
        }
        int soffset = -1;
        int eoffset = -1;
        if (message instanceof ExceptionMessage) {
            ExceptionMessage em = (ExceptionMessage) message;
            sev |= ProblemSeverities.Error;
            if (em.getCause() instanceof RuntimeParserException) {
                RuntimeParserException rpe = (RuntimeParserException) em.getCause();
                sev |= ProblemSeverities.Error;
                msg = "Groovy:" + rpe.getMessage();
                if (msg.indexOf("\n") != -1) {
                    msg = msg.substring(0, msg.indexOf("\n"));
                }
                ModuleNode errorModuleNode = rpe.getModule();
                ModuleNode thisModuleNode = this.getModuleNode();
                if (!errorModuleNode.equals(thisModuleNode)) {
                    continue;
                }
                soffset = rpe.getNode().getStart();
                eoffset = rpe.getNode().getEnd() - 1;
                // need to work out the line again as it may be wrong
                line = 0;
                while (compilationResult.lineSeparatorPositions[line] < soffset
                        && line < compilationResult.lineSeparatorPositions.length) {
                    line++;
                }

                line++; // from an array index to a real 'line number'
            }
        }
        if (syntaxException instanceof PreciseSyntaxException) {
            soffset = ((PreciseSyntaxException) syntaxException).getStartOffset();
            eoffset = ((PreciseSyntaxException) syntaxException).getEndOffset();
            // need to work out the line again as it may be wrong
            line = 0;
            while (line < compilationResult.lineSeparatorPositions.length
                    && compilationResult.lineSeparatorPositions[line] < soffset) {
                line++;
            }
            ;
            line++; // from an array index to a real 'line number'
        } else {
            if (soffset == -1) {
                soffset = getOffset(compilationResult.lineSeparatorPositions, line, scol);
            }
            if (eoffset == -1) {
                eoffset = getOffset(compilationResult.lineSeparatorPositions, line, ecol);
            }
        }
        if (soffset > eoffset) {
            eoffset = soffset;
        }
        if (soffset > sourceEnd) {
            soffset = sourceEnd;
            eoffset = sourceEnd;
        }

        char[] filename = getFileName();
        p = new DefaultProblemFactory().createProblem(filename, 0, new String[] { msg }, 0,
                new String[] { msg }, sev, soffset, eoffset, line, scol);
        this.problemReporter.record(p, compilationResult, this, false);
        errorsRecorded.add(message);
        System.err.println(new String(compilationResult.getFileName()) + ": " + line + " " + msg);
    }
    errors.removeAll(errorsRecorded);
}

From source file:org.codehaus.jdt.groovy.internal.compiler.ScriptFolderCompilationParticipant.java

License:Open Source License

/**
 * @param buildContext/*w ww  . ja v  a  2s  .  co m*/
 * @return
 */
private CategorizedProblem[] createProblem(BuildContext buildContext) {
    DefaultProblem problem = new DefaultProblem(buildContext.getFile().getFullPath().toOSString().toCharArray(),
            "Error compiling Groovy project.  Either the Groovy-JDT patch is not installed or JavaBuilder is not being used.",
            0, new String[0], ProblemSeverities.Error, 0, 0, 1, 0);
    return new CategorizedProblem[] { problem };
}

From source file:org.eclipse.ajdt.internal.ui.editor.CompilationUnitAnnotationModelWrapper.java

License:Open Source License

public void beginReporting() {
    if (delegate != null) {
        ((IProblemRequestor) delegate).beginReporting();

        IJavaProject project = unit.getJavaProject();

        AJCompilationUnitStructureRequestor requestor = new AJCompilationUnitStructureRequestor(unit,
                new AJCompilationUnitInfo(), new HashMap());
        JavaModelManager.PerWorkingCopyInfo perWorkingCopyInfo = ((CompilationUnit) unit)
                .getPerWorkingCopyInfo();
        boolean computeProblems = JavaProject.hasJavaNature(project.getProject()) && perWorkingCopyInfo != null
                && perWorkingCopyInfo.isActive();
        IProblemFactory problemFactory = new DefaultProblemFactory();
        Map options = project.getOptions(true);
        IBuffer buffer;/*from w  ww  . j  a v  a2 s .  c om*/
        try {
            buffer = unit.getBuffer();

            final char[] contents = buffer == null ? null : buffer.getCharacters();

            AJSourceElementParser parser = new AJSourceElementParser(requestor, problemFactory,
                    new CompilerOptions(options), true/*report local declarations*/, false);
            parser.reportOnlyOneSyntaxError = !computeProblems;

            parser.scanner.source = contents;
            requestor.setParser(parser);

            CompilationUnitDeclaration unitDec = parser.parseCompilationUnit(
                    new org.aspectj.org.eclipse.jdt.internal.compiler.env.ICompilationUnit() {
                        public char[] getContents() {
                            return contents;
                        }

                        public char[] getMainTypeName() {
                            return ((CompilationUnit) unit).getMainTypeName();
                        }

                        public char[][] getPackageName() {
                            return ((CompilationUnit) unit).getPackageName();
                        }

                        public char[] getFileName() {
                            return ((CompilationUnit) unit).getFileName();
                        }

                        public boolean ignoreOptionalProblems() {
                            return false;
                        }
                    }, true /*full parse to find local elements*/);
            org.aspectj.org.eclipse.jdt.core.compiler.IProblem[] problems = unitDec.compilationResult.problems;
            if (problems != null) {
                for (int i = 0; i < problems.length; i++) {
                    org.aspectj.org.eclipse.jdt.core.compiler.IProblem problem = problems[i];
                    if (problem == null)
                        continue;
                    ((IProblemRequestor) delegate)
                            .acceptProblem(
                                    new DefaultProblem(problem.getOriginatingFileName(), problem.getMessage(),
                                            problem.getID(), problem.getArguments(),
                                            problem.isError() ? ProblemSeverities.Error
                                                    : ProblemSeverities.Warning,
                                            problem.getSourceStart(), problem.getSourceEnd(),
                                            problem.getSourceLineNumber(), 0)); // unknown column
                }
            }
        } catch (JavaModelException e) {
        }
    }
}

From source file:org.eclipse.jdt.internal.compiler.lookup.MethodVerifier15.java

License:Open Source License

void checkForBridgeMethod(MethodBinding currentMethod, MethodBinding inheritedMethod,
        MethodBinding[] allInheritedMethods) {
    if (currentMethod.isVarargs() != inheritedMethod.isVarargs())
        problemReporter(currentMethod).varargsConflict(currentMethod, inheritedMethod, this.type);

    // so the parameters are equal and the return type is compatible b/w the currentMethod & the substituted inheritedMethod
    MethodBinding originalInherited = inheritedMethod.original();
    if (originalInherited.returnType != currentMethod.returnType)
        if (!isAcceptableReturnTypeOverride(currentMethod, inheritedMethod))
            problemReporter(currentMethod).unsafeReturnTypeOverride(currentMethod, originalInherited,
                    this.type);

    MethodBinding bridge = this.type.addSyntheticBridgeMethod(originalInherited, currentMethod.original());
    if (bridge != null) {
        for (int i = 0, l = allInheritedMethods == null ? 0 : allInheritedMethods.length; i < l; i++) {
            if (allInheritedMethods[i] != null
                    && detectInheritedNameClash(originalInherited, allInheritedMethods[i].original()))
                return;
        }//w ww. ja  va 2  s. co m
        // See if the new bridge clashes with any of the user methods of the class. For this check
        // we should check for "method descriptor clash" and not just "method signature clash". Really
        // what we are checking is whether there is a contention for the method dispatch table slot.
        // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=293615.
        MethodBinding[] current = (MethodBinding[]) this.currentMethods.get(bridge.selector);
        for (int i = current.length - 1; i >= 0; --i) {
            final MethodBinding thisMethod = current[i];
            if (thisMethod.areParameterErasuresEqual(bridge)
                    && thisMethod.returnType.erasure() == bridge.returnType.erasure()) {
                // use inherited method for problem reporting.
                problemReporter(thisMethod).methodNameClash(thisMethod,
                        inheritedMethod.declaringClass.isRawType() ? inheritedMethod
                                : inheritedMethod.original(),
                        ProblemSeverities.Error);
                return;
            }
        }
    }
}