Example usage for org.eclipse.jdt.internal.compiler.problem DefaultProblem getCategoryID

List of usage examples for org.eclipse.jdt.internal.compiler.problem DefaultProblem getCategoryID

Introduction

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

Prototype

@Override
public int getCategoryID() 

Source Link

Usage

From source file:org.eclim.plugin.jdt.command.include.ImportMissingCommand.java

License:Open Source License

/**
 * {@inheritDoc}//from   w w w .j av  a  2  s. c  o m
 * @see org.eclim.command.Command#execute(CommandLine)
 */
public String execute(CommandLine commandLine) throws Exception {
    String file = commandLine.getValue(Options.FILE_OPTION);
    String projectName = commandLine.getValue(Options.PROJECT_OPTION);

    IJavaProject project = JavaUtils.getJavaProject(projectName);

    ICompilationUnit src = JavaUtils.getCompilationUnit(project, file);
    IProblem[] problems = JavaUtils.getProblems(src);
    ArrayList<String> missing = new ArrayList<String>();
    for (IProblem problem : problems) {
        if (problem instanceof DefaultProblem) {
            DefaultProblem p = (DefaultProblem) problem;
            if (p.getCategoryID() == DefaultProblem.CAT_TYPE
                    || p.getCategoryID() == DefaultProblem.CAT_MEMBER) {
                String[] args = p.getArguments();
                if (args.length == 1) {
                    String cls = args[0];
                    Matcher matcher = GENERIC.matcher(cls);
                    if (matcher.matches()) {
                        cls = matcher.replaceFirst("$1");
                    }
                    if (!missing.contains(cls)) {
                        missing.add(cls);
                    }
                }
            }
        }
    }

    ArrayList<ImportMissingResult> results = new ArrayList<ImportMissingResult>();
    for (String type : missing) {
        results.add(new ImportMissingResult(type, findImport(project, type)));
    }

    return ImportMissingFilter.instance.filter(commandLine, results);
}