Example usage for org.eclipse.jdt.core.compiler IProblem ParsingError

List of usage examples for org.eclipse.jdt.core.compiler IProblem ParsingError

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.compiler IProblem ParsingError.

Prototype

int ParsingError

To view the source code for org.eclipse.jdt.core.compiler IProblem ParsingError.

Click Source Link

Usage

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

License:Open Source License

public boolean hasCorrections(ICompilationUnit cu, int problemId) {
    switch (problemId) {
    case IProblem.ImportNotFound:
    case IProblem.UndefinedMethod:
    case IProblem.UndefinedField:
    case IProblem.UndefinedType:
    case IProblem.ParsingError:
        return true;
    default://from w  w  w .  j  a va 2s .  c o  m
        return false;
    }
}

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

License:Open Source License

public IJavaCompletionProposal[] getCorrections(IInvocationContext context, IProblemLocation[] locations)
        throws CoreException {
    if (locations == null || locations.length == 0) {
        return null;
    }/*from w  w  w. jav a 2s  . com*/

    final IProject project = context.getCompilationUnit().getJavaProject().getProject();

    if (AspectJPlugin.isAJProject(project)) {
        // We're looking at a problem in an AspectJ Project
        IEditorPart ed = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
        if ((ed instanceof AspectJEditor)) {
            // Only apply to the Java editor
            return null;
        }
    } else {
        // We're looking at a problem in a Java Project
        boolean relevantError = false;
        for (int i = 0; i < locations.length && !relevantError; i++) {
            int problemId = locations[i].getProblemId();
            switch (problemId) {
            case IProblem.ParsingError:
                String[] args = locations[i].getProblemArguments();
                if (args[0].equals("aspect")) { //$NON-NLS-1$
                    relevantError = true;
                    break;
                }
                relevantError = false;
            default:
                relevantError = false;
            }
        }
        if (!relevantError) {
            // Only apply to relevant appearances of the problem
            return null;
        }
    }

    HashSet handledProblems = new HashSet(locations.length);
    ArrayList resultingCollections = new ArrayList();
    for (int i = 0; i < locations.length; i++) {
        IProblemLocation curr = locations[i];
        Integer id = new Integer(curr.getProblemId());
        if (handledProblems.add(id)) {
            process(context, curr, resultingCollections);
        }
    }
    return (IJavaCompletionProposal[]) resultingCollections
            .toArray(new IJavaCompletionProposal[resultingCollections.size()]);
}

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

License:Open Source License

private void process(IInvocationContext context, IProblemLocation problem, Collection proposals)
        throws CoreException {
    int id = problem.getProblemId();
    if (id == 0) { // no proposals for none-problem locations
        return;//from w  ww  .j a va2  s  .  co  m
    }
    switch (id) {
    case IProblem.ImportNotFound:
    case IProblem.UndefinedMethod:
    case IProblem.UndefinedField:
    case IProblem.UndefinedType:
        AspectsProcessor.switchToAJEditorProposal(context, problem, proposals);
        break;
    case IProblem.ParsingError:
        final IProject project = context.getCompilationUnit().getJavaProject().getProject();
        if (AspectJPlugin.isAJProject(project)) {
            AspectsProcessor.switchToAJEditorProposal(context, problem, proposals);
        } else {
            AspectsProcessor.convertToAJProjectProposal(context, problem, proposals);
        }
        break;
    default:
    }
}

From source file:processing.mode.java.pdex.CompileErrorMessageSimplifier.java

License:Open Source License

/**
 * Tones down the jargon in the ecj reported errors.
 */// w w w  .  java 2 s  . c o  m
public static String getSimplifiedErrorMessage(IProblem iprob, String badCode) {
    if (iprob == null)
        return null;

    String args[] = iprob.getArguments();

    if (DEBUG) {
        Messages.log("Simplifying message: " + iprob.getMessage() + " ID: " + getIDName(iprob.getID()));
        Messages.log("Arg count: " + args.length);
        for (String arg : args) {
            Messages.log("Arg " + arg);
        }
        Messages.log("Bad code: " + badCode);
    }

    String result = null;

    switch (iprob.getID()) {

    case IProblem.ParsingError:
        if (args.length > 0) {
            result = Language.interpolate("editor.status.error_on", args[0]);
        }
        break;

    case IProblem.ParsingErrorDeleteToken:
        if (args.length > 0) {
            if (args[0].equalsIgnoreCase("Invalid Character")) {
                result = getErrorMessageForCurlyQuote(badCode);
            }
        }
        break;

    case IProblem.ParsingErrorDeleteTokens:
        result = getErrorMessageForCurlyQuote(badCode);
        if (result == null) {
            result = Language.interpolate("editor.status.error_on", args[0]);
        }
        break;

    case IProblem.ParsingErrorInsertToComplete:
        if (args.length > 0) {
            if (args[0].length() == 1) {
                result = getErrorMessageForBracket(args[0].charAt(0));

            } else {
                if (args[0].equals("AssignmentOperator Expression")) {
                    result = Language.interpolate("editor.status.missing.add", "=");

                } else if (args[0].equalsIgnoreCase(") Statement")) {
                    result = getErrorMessageForBracket(args[0].charAt(0));

                } else {
                    result = Language.interpolate("editor.status.error_on", args[0]);
                }
            }
        }
        break;

    case IProblem.ParsingErrorInvalidToken:
        if (args.length > 0) {
            if (args[0].equals("int")) {
                if (args[1].equals("VariableDeclaratorId")) {
                    result = Language.text("editor.status.reserved_words");
                } else {
                    result = Language.interpolate("editor.status.error_on", args[0]);
                }
            } else if (args[0].equalsIgnoreCase("Invalid Character")) {
                result = getErrorMessageForCurlyQuote(badCode);
            }
            if (result == null) {
                result = Language.interpolate("editor.status.error_on", args[0]);
            }
        }
        break;

    case IProblem.ParsingErrorInsertTokenAfter:
        if (args.length > 0) {
            if (args[1].length() == 1) {
                result = getErrorMessageForBracket(args[1].charAt(0));
            } else {
                // https://github.com/processing/processing/issues/3104
                if (args[1].equalsIgnoreCase("Statement")) {
                    result = Language.interpolate("editor.status.error_on", args[0]);
                } else {
                    result = Language.interpolate("editor.status.error_on", args[0]) + " "
                            + Language.interpolate("editor.status.missing.add", args[1]);
                }
            }
        }
        break;

    case IProblem.ParsingErrorReplaceTokens:
        result = getErrorMessageForCurlyQuote(badCode);

    case IProblem.UndefinedConstructor:
        if (args.length == 2) {
            String constructorName = args[0];
            // For messages such as "contructor sketch_name.ClassXYZ() is undefined", change
            // constructor name to "ClassXYZ()". See #3434
            if (constructorName.contains(".")) {
                // arg[0] contains sketch name twice: sketch_150705a.sketch_150705a.Thing
                constructorName = constructorName.substring(constructorName.indexOf('.') + 1);
                constructorName = constructorName.substring(constructorName.indexOf('.') + 1);
            }
            String constructorArgs = removePackagePrefixes(args[args.length - 1]);
            result = Language.interpolate("editor.status.undefined_constructor", constructorName,
                    constructorArgs);
        }
        break;

    case IProblem.UndefinedMethod:
        if (args.length > 2) {
            String methodName = args[args.length - 2];
            String methodArgs = removePackagePrefixes(args[args.length - 1]);
            result = Language.interpolate("editor.status.undefined_method", methodName, methodArgs);
        }
        break;

    case IProblem.ParameterMismatch:
        if (args.length > 3) {
            // 2nd arg is method name, 3rd arg is correct param list
            if (args[2].trim().length() == 0) {
                // the case where no params are needed.
                result = Language.interpolate("editor.status.empty_param", args[1]);

            } else {
                result = Language.interpolate("editor.status.wrong_param", args[1], args[1],
                        removePackagePrefixes(args[2]));
                //          String method = q(args[1]);
                //          String methodDef = " \"" + args[1] + "(" + getSimpleName(args[2]) + ")\"";
                //          result = result.replace("method", method);
                //          result += methodDef;
            }
        }
        break;

    case IProblem.UndefinedField:
        if (args.length > 0) {
            result = Language.interpolate("editor.status.undef_global_var", args[0]);
        }
        break;

    case IProblem.UndefinedType:
        if (args.length > 0) {
            result = Language.interpolate("editor.status.undef_class", args[0]);
        }
        break;

    case IProblem.UnresolvedVariable:
        if (args.length > 0) {
            result = Language.interpolate("editor.status.undef_var", args[0]);
        }
        break;

    case IProblem.UndefinedName:
        if (args.length > 0) {
            result = Language.interpolate("editor.status.undef_name", args[0]);
        }
        break;

    case IProblem.UnterminatedString:
        if (badCode.contains("") || badCode.contains("?")) {
            result = Language.interpolate("editor.status.unterm_string_curly",
                    badCode.replaceAll("[^?]", ""));
        }
        break;

    case IProblem.TypeMismatch:
        if (args.length > 1) {
            result = Language.interpolate("editor.status.type_mismatch", args[0], args[1]);
            //        result = result.replace("typeA", q(args[0]));
            //        result = result.replace("typeB", q(args[1]));
        }
        break;

    case IProblem.LocalVariableIsNeverUsed:
        if (args.length > 0) {
            result = Language.interpolate("editor.status.unused_variable", args[0]);
        }
        break;

    case IProblem.UninitializedLocalVariable:
        if (args.length > 0) {
            result = Language.interpolate("editor.status.uninitialized_variable", args[0]);
        }
        break;

    case IProblem.AssignmentHasNoEffect:
        if (args.length > 0) {
            result = Language.interpolate("editor.status.no_effect_assignment", args[0]);
        }
        break;

    case IProblem.HidingEnclosingType:
        if (args.length > 0) {
            result = Language.interpolate("editor.status.hiding_enclosing_type", args[0]);
        }
        break;
    }

    if (result == null) {
        String message = iprob.getMessage();
        if (message != null) {
            // Remove all instances of token
            // "Syntax error on token 'blah', delete this token"
            Matcher matcher = tokenRegExp.matcher(message);
            message = matcher.replaceAll("");
            result = message;
        }
    }

    if (DEBUG) {
        Messages.log("Simplified Error Msg: " + result);
    }

    return result;
}

From source file:processing.mode.java.pdex.ErrorMessageSimplifier.java

License:Open Source License

/**
 * Tones down the jargon in the ecj reported errors.
 *///from  w  ww.  j a v  a2  s .c o m
public static String getSimplifiedErrorMessage(JavaProblem problem) {
    if (problem == null)
        return null;

    IProblem iprob = problem.getIProblem();
    String args[] = iprob.getArguments();
    //    Base.log("Simplifying message: " + problem.getMessage() + " ID: "
    //        + getIDName(iprob.getID()));
    //    Base.log("Arg count: " + args.length);
    //    for (int i = 0; i < args.length; i++) {
    //      Base.log("Arg " + args[i]);
    //    }

    String result = null;

    switch (iprob.getID()) {

    case IProblem.ParsingError:
        if (args.length > 0) {
            result = Language.interpolate("editor.status.error_on", args[0]);
        }
        break;

    case IProblem.ParsingErrorDeleteToken:
        if (args.length > 0) {
            result = Language.interpolate("editor.status.error_on", args[0]);
        }
        break;

    case IProblem.ParsingErrorInsertToComplete:
        if (args.length > 0) {
            if (args[0].length() == 1) {
                result = getErrorMessageForBracket(args[0].charAt(0));

            } else {
                if (args[0].equals("AssignmentOperator Expression")) {
                    result = Language.interpolate("editor.status.missing.add", "=");

                } else if (args[0].equalsIgnoreCase(") Statement")) {
                    result = getErrorMessageForBracket(args[0].charAt(0));

                } else {
                    result = Language.interpolate("editor.status.error_on", args[0]);
                }
            }
        }
        break;

    case IProblem.ParsingErrorInvalidToken:
        if (args.length > 0) {
            if (args[1].equals("VariableDeclaratorId")) {
                if (args[0].equals("int")) {
                    result = Language.text("editor.status.reserved_words");
                } else {
                    result = Language.interpolate("editor.status.error_on", args[0]);
                }
            } else {
                result = Language.interpolate("editor.status.error_on", args[0]);
            }
        }
        break;

    case IProblem.ParsingErrorInsertTokenAfter:
        if (args.length > 0) {
            if (args[1].length() == 1) {
                result = getErrorMessageForBracket(args[1].charAt(0));
            } else {
                // https://github.com/processing/processing/issues/3104
                if (args[1].equalsIgnoreCase("Statement")) {
                    result = Language.interpolate("editor.status.error_on", args[0]);
                } else {
                    result = Language.interpolate("editor.status.error_on", args[0]) + " "
                            + Language.interpolate("editor.status.missing.add", args[1]);
                }
            }
        }
        break;

    case IProblem.UndefinedConstructor:
        if (args.length == 2) {
            String constructorName = args[0];
            // For messages such as "contructor sketch_name.ClassXYZ() is undefined", change
            // constructor name to "ClassXYZ()". See #3434
            if (constructorName.contains(".")) {
                // arg[0] contains sketch name twice: sketch_150705a.sketch_150705a.Thing
                constructorName = constructorName.substring(constructorName.indexOf('.') + 1);
                constructorName = constructorName.substring(constructorName.indexOf('.') + 1);
            }
            String constructorArgs = removePackagePrefixes(args[args.length - 1]);
            result = Language.interpolate("editor.status.undefined_constructor", constructorName,
                    constructorArgs);
        }
        break;

    case IProblem.UndefinedMethod:
        if (args.length > 2) {
            String methodName = args[args.length - 2];
            String methodArgs = removePackagePrefixes(args[args.length - 1]);
            result = Language.interpolate("editor.status.undefined_method", methodName, methodArgs);
        }
        break;

    case IProblem.ParameterMismatch:
        if (args.length > 3) {
            // 2nd arg is method name, 3rd arg is correct param list
            if (args[2].trim().length() == 0) {
                // the case where no params are needed.
                result = Language.interpolate("editor.status.empty_param", args[1]);

            } else {
                result = Language.interpolate("editor.status.wrong_param", args[1], args[1],
                        removePackagePrefixes(args[2]));
                //          String method = q(args[1]);
                //          String methodDef = " \"" + args[1] + "(" + getSimpleName(args[2]) + ")\"";
                //          result = result.replace("method", method);
                //          result += methodDef;
            }
        }
        break;

    case IProblem.UndefinedField:
        if (args.length > 0) {
            result = Language.interpolate("editor.status.undef_global_var", args[0]);
        }
        break;

    case IProblem.UndefinedType:
        if (args.length > 0) {
            result = Language.interpolate("editor.status.undef_class", args[0]);
        }
        break;

    case IProblem.UnresolvedVariable:
        if (args.length > 0) {
            result = Language.interpolate("editor.status.undef_var", args[0]);
        }
        break;

    case IProblem.UndefinedName:
        if (args.length > 0) {
            result = Language.interpolate("editor.status.undef_name", args[0]);
        }
        break;

    case IProblem.TypeMismatch:
        if (args.length > 1) {
            result = Language.interpolate("editor.status.type_mismatch", args[0], args[1]);
            //        result = result.replace("typeA", q(args[0]));
            //        result = result.replace("typeB", q(args[1]));
        }
        break;

    case IProblem.LocalVariableIsNeverUsed:
        if (args.length > 0) {
            result = Language.interpolate("editor.status.unused_variable", args[0]);
        }
        break;

    case IProblem.UninitializedLocalVariable:
        if (args.length > 0) {
            result = Language.interpolate("editor.status.uninitialized_variable", args[0]);
        }
        break;

    case IProblem.AssignmentHasNoEffect:
        if (args.length > 0) {
            result = Language.interpolate("editor.status.no_effect_assignment", args[0]);
        }
        break;

    case IProblem.HidingEnclosingType:
        if (args.length > 0) {
            result = Language.interpolate("editor.status.hiding_enclosing_type", args[0]);
        }
    }

    //log("Simplified Error Msg: " + result);
    return (result == null) ? problem.getMessage() : result;
}