Search in sources :

Example 41 with IProblem

use of org.eclipse.jdt.core.compiler.IProblem in project che by eclipse.

the class PotentialProgrammingProblemsFix method createCleanUp.

public static ICleanUpFix createCleanUp(CompilationUnit compilationUnit, boolean addSerialVersionIds) {
    IProblem[] problems = compilationUnit.getProblems();
    IProblemLocation[] locations = new IProblemLocation[problems.length];
    for (int i = 0; i < problems.length; i++) {
        locations[i] = new ProblemLocation(problems[i]);
    }
    return createCleanUp(compilationUnit, locations, addSerialVersionIds);
}
Also used : IProblemLocation(org.eclipse.jdt.ui.text.java.IProblemLocation) ProblemLocation(org.eclipse.jdt.internal.ui.text.correction.ProblemLocation) IProblemLocation(org.eclipse.jdt.ui.text.java.IProblemLocation) IProblem(org.eclipse.jdt.core.compiler.IProblem)

Example 42 with IProblem

use of org.eclipse.jdt.core.compiler.IProblem in project che by eclipse.

the class ASTNodes method getProblems.

public static IProblem[] getProblems(ASTNode node, int scope, int severity) {
    ASTNode root = node.getRoot();
    if (!(root instanceof CompilationUnit))
        return EMPTY_PROBLEMS;
    IProblem[] problems = ((CompilationUnit) root).getProblems();
    if (root == node)
        return problems;
    final int iterations = computeIterations(scope);
    List<IProblem> result = new ArrayList<IProblem>(5);
    for (int i = 0; i < problems.length; i++) {
        IProblem problem = problems[i];
        boolean consider = false;
        if ((severity & PROBLEMS) == PROBLEMS)
            consider = true;
        else if ((severity & WARNING) != 0)
            consider = problem.isWarning();
        else if ((severity & ERROR) != 0)
            consider = problem.isError();
        if (consider) {
            ASTNode temp = node;
            int count = iterations;
            do {
                int nodeOffset = temp.getStartPosition();
                int problemOffset = problem.getSourceStart();
                if (nodeOffset <= problemOffset && problemOffset < nodeOffset + temp.getLength()) {
                    result.add(problem);
                    count = 0;
                } else {
                    count--;
                }
            } while ((temp = temp.getParent()) != null && count > 0);
        }
    }
    return result.toArray(new IProblem[result.size()]);
}
Also used : ArrayList(java.util.ArrayList) IProblem(org.eclipse.jdt.core.compiler.IProblem)

Example 43 with IProblem

use of org.eclipse.jdt.core.compiler.IProblem in project che by eclipse.

the class RenameAnalyzeUtil method analyzeCompileErrors.

private static RefactoringStatus analyzeCompileErrors(String newCuSource, CompilationUnit newCUNode, CompilationUnit oldCUNode) {
    RefactoringStatus result = new RefactoringStatus();
    IProblem[] newProblems = RefactoringAnalyzeUtil.getIntroducedCompileProblems(newCUNode, oldCUNode);
    for (int i = 0; i < newProblems.length; i++) {
        IProblem problem = newProblems[i];
        if (problem.isError())
            result.addEntry(new RefactoringStatusEntry((problem.isError() ? RefactoringStatus.ERROR : RefactoringStatus.WARNING), problem.getMessage(), new JavaStringStatusContext(newCuSource, SourceRangeFactory.create(problem))));
    }
    return result;
}
Also used : RefactoringStatusEntry(org.eclipse.ltk.core.refactoring.RefactoringStatusEntry) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) JavaStringStatusContext(org.eclipse.jdt.internal.corext.refactoring.base.JavaStringStatusContext) IProblem(org.eclipse.jdt.core.compiler.IProblem)

Example 44 with IProblem

use of org.eclipse.jdt.core.compiler.IProblem in project che by eclipse.

the class StringCleanUp method computeNumberOfFixes.

/**
	 * {@inheritDoc}
	 */
@Override
public int computeNumberOfFixes(CompilationUnit compilationUnit) {
    try {
        ICompilationUnit cu = (ICompilationUnit) compilationUnit.getJavaElement();
        if (!cu.isStructureKnown())
            //[clean up] 'Remove unnecessary $NLS-TAGS$' removes necessary ones in case of syntax errors: https://bugs.eclipse.org/bugs/show_bug.cgi?id=285814 : 
            return 0;
    } catch (JavaModelException e) {
        return 0;
    }
    int result = 0;
    IProblem[] problems = compilationUnit.getProblems();
    if (isEnabled(CleanUpConstants.ADD_MISSING_NLS_TAGS))
        result += getNumberOfProblems(problems, IProblem.NonExternalizedStringLiteral);
    if (isEnabled(CleanUpConstants.REMOVE_UNNECESSARY_NLS_TAGS))
        result += getNumberOfProblems(problems, IProblem.UnnecessaryNLSTag);
    return result;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) JavaModelException(org.eclipse.jdt.core.JavaModelException) IProblem(org.eclipse.jdt.core.compiler.IProblem)

Example 45 with IProblem

use of org.eclipse.jdt.core.compiler.IProblem in project che by eclipse.

the class JavaReconciler method convertProblem.

private Problem convertProblem(IProblem problem) {
    Problem result = DtoFactory.getInstance().createDto(Problem.class);
    result.setArguments(Arrays.asList(problem.getArguments()));
    result.setID(problem.getID());
    result.setMessage(problem.getMessage());
    result.setOriginatingFileName(new String(problem.getOriginatingFileName()));
    result.setError(problem.isError());
    result.setWarning(problem.isWarning());
    result.setSourceEnd(problem.getSourceEnd());
    result.setSourceStart(problem.getSourceStart());
    result.setSourceLineNumber(problem.getSourceLineNumber());
    return result;
}
Also used : Problem(org.eclipse.che.ide.ext.java.shared.dto.Problem) IProblem(org.eclipse.jdt.core.compiler.IProblem)

Aggregations

IProblem (org.eclipse.jdt.core.compiler.IProblem)62 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)28 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)25 ArrayList (java.util.ArrayList)21 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)10 File (java.io.File)9 ASTParser (org.eclipse.jdt.core.dom.ASTParser)9 ClassFile (org.eclipse.jdt.internal.compiler.ClassFile)7 IProblemLocation (org.eclipse.jdt.ui.text.java.IProblemLocation)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 IOException (java.io.IOException)5 InputStream (java.io.InputStream)5 HashMap (java.util.HashMap)5 ASTNode (org.eclipse.jdt.core.dom.ASTNode)5 RefactoringStatusEntry (org.eclipse.ltk.core.refactoring.RefactoringStatusEntry)5 URI (java.net.URI)4 HashSet (java.util.HashSet)4 StringTokenizer (java.util.StringTokenizer)4 IJavaProject (org.eclipse.jdt.core.IJavaProject)4 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)4