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

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

Introduction

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

Prototype

int IsClassPathCorrect

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

Click Source Link

Usage

From source file:edu.uci.ics.sourcerer.extractor.ast.FeatureExtractor.java

License:Open Source License

public SourceExtractionReport extractSourceFiles(SourceExtractionReport report, Collection<IFile> sourceFiles,
        boolean force) {
    ReferenceExtractorVisitor visitor = new ReferenceExtractorVisitor(bundle);
    IMissingTypeWriter missingTypeWriter = bundle.getMissingTypeWriter();

    for (IFile source : sourceFiles) {
        ICompilationUnit icu = JavaCore.createCompilationUnitFrom(source);

        parser.setStatementsRecovery(true);
        parser.setResolveBindings(true);
        parser.setBindingsRecovery(true);
        parser.setSource(icu);//from w  w w. j  a  va2 s. c  om

        CompilationUnit unit = null;
        try {
            unit = (CompilationUnit) parser.createAST(null);
        } catch (Exception e) {
            logger.log(Level.SEVERE, "Error in creating AST for " + source.getName(), e);
            report.reportSourceExtractionException();
            continue;
        }

        boolean secondOrder = checkForMissingTypes(unit, report, missingTypeWriter);
        if (!report.hadMissingType() || force) {
            if (secondOrder) {
                logger.warning("Performing limited extraction of " + source.getName()
                        + " because of missing second order type.");
                for (IProblem problem : unit.getProblems()) {
                    if (problem.getID() == IProblem.IsClassPathCorrect) {
                        logger.warning("  " + problem.getArguments()[0]);
                    }
                }
                visitor.setBindingFreeMode(true);
            }
            try {
                visitor.setCompilationUnitSource(icu.getSource());
                unit.accept(visitor);
                report.reportSourceExtraction();
            } catch (Exception e) {
                logger.log(Level.SEVERE, "Error in extracting " + source.getName(), e);
                report.reportSourceExtractionException();
            }
            visitor.setBindingFreeMode(false);
        }
    }
    return report;
}

From source file:edu.uci.ics.sourcerer.extractor.ast.FeatureExtractor.java

License:Open Source License

@SuppressWarnings("unchecked")
private boolean checkForMissingTypes(CompilationUnit unit, SourceExtractionReport report,
        IMissingTypeWriter writer) {/*  w  w  w .j a va2 s  .c  o  m*/
    Set<String> onDemandImports = Helper.newHashSet();
    Map<String, String> singleTypeImports = Helper.newHashMap();
    Set<String> simpleNames = Helper.newHashSet();

    boolean hasSecondOrder = false;
    // Check for the classpath problem
    for (IProblem problem : unit.getProblems()) {
        if (problem.isError()) {
            if (problem.getID() == IProblem.IsClassPathCorrect) {
                writer.writeMissingType(problem.getArguments()[0]);
                report.reportMissingSecondOrder();
                hasSecondOrder = true;
            } else if (problem.getID() == IProblem.ImportNotFound) {
                String prefix = problem.getArguments()[0];
                // Go and find all the imports with this prefix
                boolean found = false;
                for (ImportDeclaration imp : (List<ImportDeclaration>) unit.imports()) {
                    String fqn = imp.getName().getFullyQualifiedName();
                    if (fqn.startsWith(prefix)) {
                        if (imp.isOnDemand()) {
                            onDemandImports.add(fqn);
                        } else {
                            String simpleName = fqn.substring(fqn.lastIndexOf('.') + 1);
                            String oldFqn = singleTypeImports.get(simpleName);
                            if (oldFqn != null && !oldFqn.equals(fqn)) {
                                logger.log(Level.SEVERE,
                                        "Two fqns with the same simple name: " + fqn + " and " + oldFqn);
                            } else {
                                singleTypeImports.put(simpleName, fqn);
                            }
                        }
                        //              writer.writeMissingType(imp.getName().getFullyQualifiedName());
                        found = true;
                    }
                }
                if (!found) {
                    logger.log(Level.SEVERE, "Unable to find import matching: " + prefix);
                    writer.writeMissingType(prefix);
                }
                report.reportMissingType();
            } else if (problem.getID() == IProblem.UndefinedType) {
                simpleNames.add(problem.getArguments()[0]);
                report.reportMissingType();
            }
        }
    }

    for (String imp : onDemandImports) {
        writer.writeMissingType(imp);
    }
    for (String imp : singleTypeImports.values()) {
        writer.writeMissingType(imp);
    }
    for (String simpleName : simpleNames) {
        if (!singleTypeImports.containsKey(simpleName)) {
            for (String imp : onDemandImports) {
                writer.writeMissingType(imp + "." + simpleName);
            }
        }
    }
    return hasSecondOrder;
}

From source file:edu.uci.ics.sourcerer.tools.java.extractor.eclipse.EclipseExtractor.java

License:Open Source License

private boolean checkForMissingTypes(CompilationUnit unit) {
    // Check for the classpath problem
    for (IProblem problem : unit.getProblems()) {
        if (problem.isError()) {
            if (problem.getID() == IProblem.IsClassPathCorrect) {
                return true;
            }/*from w  w  w  . j  av a 2s. c o  m*/
        }
    }
    return false;
}

From source file:edu.washington.cs.cupid.scripting.java.quickfix.ClasspathProcessor.java

License:Open Source License

@Override
public boolean hasCorrections(final ICompilationUnit unit, final int problemId) {
    try {/*from  w  ww . ja va2s  .c o m*/
        IResource resource = unit.getCorrespondingResource();
        if (resource.getProject() == CupidScriptingPlugin.getDefault().getCupidProject()) {
            return problemId == IProblem.UndefinedType || problemId == IProblem.IsClassPathCorrect
                    || problemId == IProblem.MissingTypeInMethod;
        } else {
            return false;
        }
    } catch (Exception ex) {
        return false;
    }
}

From source file:fede.workspace.dependencies.eclipse.java.fix.DependencyQuickFixProcessor.java

License:Apache License

public IJavaCompletionProposal[] getCorrections(IInvocationContext context, IProblemLocation[] locations)
        throws CoreException {
    List<IJavaCompletionProposal> ret = new ArrayList<IJavaCompletionProposal>();
    CompilationUnit astroot = context.getASTRoot();
    IResource r = context.getCompilationUnit().getResource();
    IProject p = r.getProject();//w w w.ja  v a2s  .  c  om
    IJavaProject jp = JavaCore.create(p);

    Item itemSource = WSPlugin.getItemFromResource(p);
    if (itemSource != null) {
        Object manager = itemSource.getType().getItemManager();
        if (manager instanceof IFixManager) {
            IFixManager fixmanager = (IFixManager) manager;
            for (IProblemLocation problem : locations) {
                ASTNode coveredNode = problem.getCoveredNode(astroot);
                String[] arguments = problem.getProblemArguments();

                switch (problem.getProblemId()) {
                case IProblem.IsClassPathCorrect:
                    if (arguments.length == 1) {
                        String qualifiedType = arguments[0];
                        String packageName = Signature.getQualifier(qualifiedType);
                        String typeName = Signature.getSimpleName(qualifiedType);
                        fixmanager.resolve(jp, itemSource, packageName, typeName, false, ret);
                    }
                    continue;
                case IProblem.UndefinedType:
                    if (coveredNode instanceof SimpleName) {
                        fixmanager.resolve(jp, itemSource, ((SimpleName) coveredNode).getIdentifier(), null,
                                false, ret);
                    }
                    break;
                default:
                    break;
                }
                ASTNode selectedNode = problem.getCoveringNode(context.getASTRoot());
                if (selectedNode == null)
                    continue;

                ImportDeclaration importDeclaration = (ImportDeclaration) ASTNodes.getParent(selectedNode,
                        ASTNode.IMPORT_DECLARATION);
                if (importDeclaration == null) {
                    continue;
                }

                String name = ASTNodes.asString(importDeclaration.getName());
                String packageName;
                String typeName = null;
                if (importDeclaration.isOnDemand()) {
                    packageName = name;
                } else {
                    packageName = Signature.getQualifier(name);
                    typeName = Signature.getSimpleName(name);
                }

                fixmanager.resolve(jp, itemSource, packageName, typeName,
                        problem.getProblemId() == IProblem.UndefinedType, ret);

            }
        }
    }
    return (IJavaCompletionProposal[]) ret.toArray(new IJavaCompletionProposal[ret.size()]);
}

From source file:net.sf.j2s.core.builder.AbstractImageBuilder.java

License:Open Source License

/**
 * Creates a marker from each problem and adds it to the resource.
 * The marker is as follows:/* w  ww  .  j  av  a2  s. c  o  m*/
 *   - its type is T_PROBLEM
 *   - its plugin ID is the JavaBuilder's plugin ID
 *    - its message is the problem's message
 *    - its priority reflects the severity of the problem
 *    - its range is the problem's range
 *    - it has an extra attribute "ID" which holds the problem's id
 *   - it's {@link IMarker#SOURCE_ID} attribute is positioned to {@link JavaBuilder#SOURCE_ID} if
 *     the problem was generated by JDT; else the {@link IMarker#SOURCE_ID} attribute is
 *     carried from the problem to the marker in extra attributes, if present.
 */
protected void storeProblemsFor(SourceFile sourceFile, CategorizedProblem[] problems) throws CoreException {
    if (sourceFile == null || problems == null || problems.length == 0)
        return;
    // once a classpath error is found, ignore all other problems for this project so the user can see the main error
    // but still try to compile as many source files as possible to help the case when the base libraries are in source
    if (!this.keepStoringProblemMarkers)
        return; // only want the one error recorded on this source file

    HashSet managedMarkerTypes = JavaModelManager.getJavaModelManager().compilationParticipants
            .managedMarkerTypes();
    problems: for (int i = 0, l = problems.length; i < l; i++) {
        CategorizedProblem problem = problems[i];
        int id = problem.getID();
        // we may use a different resource for certain problems such as IProblem.MissingNonNullByDefaultAnnotationOnPackage
        // but at the start of the next problem we should reset it to the source file's resource
        IResource resource = sourceFile.resource;

        // handle missing classfile situation
        if (id == IProblem.IsClassPathCorrect) {
            String missingClassfileName = problem.getArguments()[0];
            if (JavaBuilder.DEBUG)
                System.out.println(Messages.bind(Messages.build_incompleteClassPath, missingClassfileName));
            boolean isInvalidClasspathError = JavaCore.ERROR
                    .equals(this.javaBuilder.javaProject.getOption(JavaCore.CORE_INCOMPLETE_CLASSPATH, true));
            // insert extra classpath problem, and make it the only problem for this project (optional)
            if (isInvalidClasspathError && JavaCore.ABORT.equals(
                    this.javaBuilder.javaProject.getOption(JavaCore.CORE_JAVA_BUILD_INVALID_CLASSPATH, true))) {
                JavaBuilder.removeProblemsAndTasksFor(this.javaBuilder.currentProject); // make this the only problem for this project
                this.keepStoringProblemMarkers = false;
            }
            IMarker marker = this.javaBuilder.currentProject
                    .createMarker(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER);
            marker.setAttributes(
                    new String[] { IMarker.MESSAGE, IMarker.SEVERITY, IJavaModelMarker.CATEGORY_ID,
                            IMarker.SOURCE_ID },
                    new Object[] { Messages.bind(Messages.build_incompleteClassPath, missingClassfileName),
                            new Integer(isInvalidClasspathError ? IMarker.SEVERITY_ERROR
                                    : IMarker.SEVERITY_WARNING),
                            new Integer(CategorizedProblem.CAT_BUILDPATH), JavaBuilder.SOURCE_ID });
            // even if we're not keeping more markers, still fall through rest of the problem reporting, so that offending
            // IsClassPathCorrect problem gets recorded since it may help locate the offending reference
        }

        String markerType = problem.getMarkerType();
        boolean managedProblem = false;
        if (IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER.equals(markerType)
                || (managedProblem = managedMarkerTypes.contains(markerType))) {
            if (id == IProblem.MissingNonNullByDefaultAnnotationOnPackage
                    && !(CharOperation.equals(sourceFile.getMainTypeName(), TypeConstants.PACKAGE_INFO_NAME))) {
                // for this kind of problem, marker needs to be created on the package instead of on the source file
                // see bug 372012
                char[] fileName = sourceFile.getFileName();
                int pkgEnd = CharOperation.lastIndexOf('/', fileName);
                if (pkgEnd == -1)
                    pkgEnd = CharOperation.lastIndexOf(File.separatorChar, fileName);
                PackageFragment pkg = null;
                if (pkgEnd != -1)
                    pkg = (PackageFragment) Util.getPackageFragment(sourceFile.getFileName(), pkgEnd,
                            -1 /*no jar separator for java files*/);

                if (pkg != null) {
                    try {
                        IMarker[] existingMarkers = pkg.resource().findMarkers(
                                IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, false, IResource.DEPTH_ZERO);
                        int len = existingMarkers.length;
                        for (int j = 0; j < len; j++) {
                            if (((Integer) existingMarkers[j].getAttribute(IJavaModelMarker.ID))
                                    .intValue() == IProblem.MissingNonNullByDefaultAnnotationOnPackage) {
                                continue problems; // marker already present
                            }
                        }
                    } catch (CoreException e) {
                        // marker retrieval failed, cannot do much
                        if (JavaModelManager.VERBOSE) {
                            e.printStackTrace();
                        }
                    }
                    IResource tempRes = pkg.resource();
                    if (tempRes != null) {
                        resource = tempRes;
                    }
                }
            }
            IMarker marker = resource.createMarker(markerType);

            String[] attributeNames = JAVA_PROBLEM_MARKER_ATTRIBUTE_NAMES;
            int standardLength = attributeNames.length;
            String[] allNames = attributeNames;
            int managedLength = managedProblem ? 0 : 1;
            String[] extraAttributeNames = problem.getExtraMarkerAttributeNames();
            int extraLength = extraAttributeNames == null ? 0 : extraAttributeNames.length;
            if (managedLength > 0 || extraLength > 0) {
                allNames = new String[standardLength + managedLength + extraLength];
                System.arraycopy(attributeNames, 0, allNames, 0, standardLength);
                if (managedLength > 0)
                    allNames[standardLength] = IMarker.SOURCE_ID;
                System.arraycopy(extraAttributeNames, 0, allNames, standardLength + managedLength, extraLength);
            }

            Object[] allValues = new Object[allNames.length];
            // standard attributes
            int index = 0;
            allValues[index++] = problem.getMessage(); // message
            allValues[index++] = problem.isError() ? S_ERROR : S_WARNING; // severity
            allValues[index++] = new Integer(id); // ID
            allValues[index++] = new Integer(problem.getSourceStart()); // start
            allValues[index++] = new Integer(problem.getSourceEnd() + 1); // end
            allValues[index++] = new Integer(problem.getSourceLineNumber()); // line
            allValues[index++] = Util.getProblemArgumentsForMarker(problem.getArguments()); // arguments
            allValues[index++] = new Integer(problem.getCategoryID()); // category ID
            // SOURCE_ID attribute for JDT problems
            if (managedLength > 0)
                allValues[index++] = JavaBuilder.SOURCE_ID;
            // optional extra attributes
            if (extraLength > 0)
                System.arraycopy(problem.getExtraMarkerAttributeValues(), 0, allValues, index, extraLength);

            marker.setAttributes(allNames, allValues);

            if (!this.keepStoringProblemMarkers)
                return; // only want the one error recorded on this source file
        }
    }
}

From source file:org.apache.felix.sigil.eclipse.ui.internal.quickfix.ImportQuickFixProcessor.java

License:Apache License

public boolean hasCorrections(ICompilationUnit unit, int problemId) {
    switch (problemId) {
    case IProblem.ForbiddenReference:
    case IProblem.ImportNotFound:
    case IProblem.IsClassPathCorrect:
    case IProblem.UndefinedType:
    case IProblem.UndefinedName:
        return true;
    default://from www  . j a v a  2 s. c o m
        return false;
    }
}

From source file:org.apache.felix.sigil.eclipse.ui.internal.quickfix.ImportQuickFixProcessor.java

License:Apache License

public IJavaCompletionProposal[] getCorrections(IInvocationContext context, IProblemLocation[] locations)
        throws CoreException {
    try {/*from  w  w  w .j  av  a 2 s  .c  o  m*/
        HashMap<Object, IJavaCompletionProposal> results = new HashMap<Object, IJavaCompletionProposal>();

        ISigilProjectModel project = findProject(context);

        if (project != null) {
            for (int i = 0; i < locations.length; i++) {
                switch (locations[i].getProblemId()) {
                case IProblem.ForbiddenReference:
                    handleImportNotFound(project, context, locations[i], results);
                    break;
                case IProblem.ImportNotFound:
                    handleImportNotFound(project, context, locations[i], results);
                    break;
                case IProblem.IsClassPathCorrect:
                    handleIsClassPathCorrect(project, context, locations[i], results);
                    break;
                case IProblem.UndefinedType:
                    handleUndefinedType(project, context, locations[i], results);
                    break;
                case IProblem.UndefinedName:
                    handleUndefinedName(project, context, locations[i], results);
                    break;
                }
            }
        }

        return (IJavaCompletionProposal[]) results.values()
                .toArray(new IJavaCompletionProposal[results.size()]);
    } catch (RuntimeException e) {
        e.printStackTrace();
        throw e;
    }
}

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

License:Open Source License

public boolean hasCorrections(ICompilationUnit cu, int problemId) {
    switch (problemId) {
    case IProblem.UnterminatedString:
    case IProblem.UnusedImport:
    case IProblem.DuplicateImport:
    case IProblem.CannotImportPackage:
    case IProblem.ConflictingImport:
    case IProblem.ImportNotFound:
    case IProblem.UndefinedMethod:
    case IProblem.UndefinedConstructor:
    case IProblem.ParameterMismatch:
    case IProblem.MethodButWithConstructorName:
    case IProblem.UndefinedField:
    case IProblem.UndefinedName:
    case IProblem.PublicClassMustMatchFileName:
    case IProblem.PackageIsNotExpectedPackage:
    case IProblem.UndefinedType:
    case IProblem.TypeMismatch:
    case IProblem.UnhandledException:
    case IProblem.UnreachableCatch:
    case IProblem.InvalidCatchBlockSequence:
    case IProblem.VoidMethodReturnsValue:
    case IProblem.ShouldReturnValue:
    case IProblem.MissingReturnType:
    case IProblem.NonExternalizedStringLiteral:
    case IProblem.NonStaticAccessToStaticField:
    case IProblem.NonStaticAccessToStaticMethod:
    case IProblem.StaticMethodRequested:
    case IProblem.NonStaticFieldFromStaticInvocation:
    case IProblem.InstanceMethodDuringConstructorInvocation:
    case IProblem.InstanceFieldDuringConstructorInvocation:
    case IProblem.NotVisibleMethod:
    case IProblem.NotVisibleConstructor:
    case IProblem.NotVisibleType:
    case IProblem.NotVisibleField:
    case IProblem.BodyForAbstractMethod:
    case IProblem.AbstractMethodInAbstractClass:
    case IProblem.AbstractMethodMustBeImplemented:
    case IProblem.BodyForNativeMethod:
    case IProblem.OuterLocalMustBeFinal:
    case IProblem.UninitializedLocalVariable:
    case IProblem.UndefinedConstructorInDefaultConstructor:
    case IProblem.UnhandledExceptionInDefaultConstructor:
    case IProblem.NotVisibleConstructorInDefaultConstructor:
    case IProblem.AmbiguousType:
    case IProblem.UnusedPrivateMethod:
    case IProblem.UnusedPrivateConstructor:
    case IProblem.UnusedPrivateField:
    case IProblem.UnusedPrivateType:
    case IProblem.LocalVariableIsNeverUsed:
    case IProblem.ArgumentIsNeverUsed:
    case IProblem.MethodRequiresBody:
    case IProblem.NeedToEmulateFieldReadAccess:
    case IProblem.NeedToEmulateFieldWriteAccess:
    case IProblem.NeedToEmulateMethodAccess:
    case IProblem.NeedToEmulateConstructorAccess:
    case IProblem.SuperfluousSemicolon:
    case IProblem.UnnecessaryCast:
    case IProblem.UnnecessaryInstanceof:
    case IProblem.IndirectAccessToStaticField:
    case IProblem.IndirectAccessToStaticMethod:
    case IProblem.Task:
    case IProblem.UnusedMethodDeclaredThrownException:
    case IProblem.UnusedConstructorDeclaredThrownException:
    case IProblem.UnqualifiedFieldAccess:
    case IProblem.JavadocMissing:
    case IProblem.JavadocMissingParamTag:
    case IProblem.JavadocMissingReturnTag:
    case IProblem.JavadocMissingThrowsTag:
    case IProblem.JavadocUndefinedType:
    case IProblem.JavadocAmbiguousType:
    case IProblem.JavadocNotVisibleType:
    case IProblem.JavadocInvalidThrowsClassName:
    case IProblem.JavadocDuplicateThrowsClassName:
    case IProblem.JavadocDuplicateReturnTag:
    case IProblem.JavadocDuplicateParamName:
    case IProblem.JavadocInvalidParamName:
    case IProblem.JavadocUnexpectedTag:
    case IProblem.JavadocInvalidTag:
    case IProblem.NonBlankFinalLocalAssignment:
    case IProblem.DuplicateFinalLocalInitialization:
    case IProblem.FinalFieldAssignment:
    case IProblem.DuplicateBlankFinalFieldInitialization:
    case IProblem.AnonymousClassCannotExtendFinalClass:
    case IProblem.ClassExtendFinalClass:
    case IProblem.FinalMethodCannotBeOverridden:
    case IProblem.InheritedMethodReducesVisibility:
    case IProblem.MethodReducesVisibility:
    case IProblem.OverridingNonVisibleMethod:
    case IProblem.CannotOverrideAStaticMethodWithAnInstanceMethod:
    case IProblem.CannotHideAnInstanceMethodWithAStaticMethod:
    case IProblem.UnexpectedStaticModifierForMethod:
    case IProblem.LocalVariableHidingLocalVariable:
    case IProblem.LocalVariableHidingField:
    case IProblem.FieldHidingLocalVariable:
    case IProblem.FieldHidingField:
    case IProblem.ArgumentHidingLocalVariable:
    case IProblem.ArgumentHidingField:
    case IProblem.IllegalModifierForInterfaceMethod:
    case IProblem.IllegalModifierForInterface:
    case IProblem.IllegalModifierForClass:
    case IProblem.IllegalModifierForInterfaceField:
    case IProblem.IllegalModifierForMemberInterface:
    case IProblem.IllegalModifierForMemberClass:
    case IProblem.IllegalModifierForLocalClass:
    case IProblem.IllegalModifierForArgument:
    case IProblem.IllegalModifierForField:
    case IProblem.IllegalModifierForMethod:
    case IProblem.IllegalModifierForVariable:
    case IProblem.IllegalVisibilityModifierForInterfaceMemberType:
    case IProblem.IncompatibleReturnType:
    case IProblem.IncompatibleExceptionInThrowsClause:
    case IProblem.NoMessageSendOnArrayType:
    case IProblem.InvalidOperator:
    case IProblem.MissingSerialVersion:
    case IProblem.UnnecessaryElse:
    case IProblem.SuperclassMustBeAClass:
    case IProblem.UseAssertAsAnIdentifier:
    case IProblem.UseEnumAsAnIdentifier:
    case IProblem.RedefinedLocal:
    case IProblem.RedefinedArgument:
    case IProblem.CodeCannotBeReached:
    case IProblem.InvalidUsageOfTypeParameters:
    case IProblem.InvalidUsageOfStaticImports:
    case IProblem.InvalidUsageOfForeachStatements:
    case IProblem.InvalidUsageOfTypeArguments:
    case IProblem.InvalidUsageOfEnumDeclarations:
    case IProblem.InvalidUsageOfVarargs:
    case IProblem.InvalidUsageOfAnnotations:
    case IProblem.InvalidUsageOfAnnotationDeclarations:
    case IProblem.FieldMissingDeprecatedAnnotation:
    case IProblem.MethodMissingDeprecatedAnnotation:
    case IProblem.TypeMissingDeprecatedAnnotation:
    case IProblem.MissingOverrideAnnotation:
    case IProblem.IsClassPathCorrect:
    case IProblem.MethodReturnsVoid:
    case IProblem.ForbiddenReference:
    case IProblem.DiscouragedReference:
    case IProblem.UnnecessaryNLSTag:
    case IProblem.AssignmentHasNoEffect:
    case IProblem.UnsafeTypeConversion:
    case IProblem.UndefinedAnnotationMember:
    case IProblem.MissingValueForAnnotationMember:
    case IProblem.FallthroughCase:
    case IProblem.NonGenericType:
    case IProblem.UnhandledWarningToken:
        return true;
    default://from  w ww. j  a v a  2 s.c o  m
        if (JavaModelUtil.is50OrHigher(cu.getJavaProject())) {
            return SuppressWarningsSubProcessor.hasSuppressWarningsProposal(cu.getJavaProject(), problemId); // AJDT 3.6
        }
        return false;
    }
}

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

License:Open Source License

private void process(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals)
        throws CoreException {
    int id = problem.getProblemId();
    if (id == 0) { // no proposals for none-problem locations
        return;/*from   w w  w  . j  a v  a2  s.  c o m*/
    }
    switch (id) {
    case IProblem.UnterminatedString:
        String quoteLabel = CorrectionMessages.JavaCorrectionProcessor_addquote_description;
        int pos = moveBack(problem.getOffset() + problem.getLength(), problem.getOffset(), "\n\r", //$NON-NLS-1$
                context.getCompilationUnit());
        proposals.add(new ReplaceCorrectionProposal(quoteLabel, context.getCompilationUnit(), pos, 0, "\"", 0)); //$NON-NLS-1$
        break;
    case IProblem.UnusedImport:
    case IProblem.DuplicateImport:
    case IProblem.CannotImportPackage:
    case IProblem.ConflictingImport:
        ReorgCorrectionsSubProcessor.removeImportStatementProposals(context, problem, proposals);
        break;
    case IProblem.ImportNotFound:
        ReorgCorrectionsSubProcessor.importNotFoundProposals(context, problem, proposals);
        ReorgCorrectionsSubProcessor.removeImportStatementProposals(context, problem, proposals);
        break;
    case IProblem.UndefinedMethod:
        UnresolvedElementsSubProcessor.getMethodProposals(context, problem, false, proposals);
        break;
    case IProblem.UndefinedConstructor:
        UnresolvedElementsSubProcessor.getConstructorProposals(context, problem, proposals);
        break;
    case IProblem.UndefinedAnnotationMember:
        UnresolvedElementsSubProcessor.getAnnotationMemberProposals(context, problem, proposals);
        break;
    case IProblem.ParameterMismatch:
        UnresolvedElementsSubProcessor.getMethodProposals(context, problem, true, proposals);
        break;
    case IProblem.MethodButWithConstructorName:
        ReturnTypeSubProcessor.addMethodWithConstrNameProposals(context, problem, proposals);
        break;
    case IProblem.UndefinedField:
    case IProblem.UndefinedName:
        UnresolvedElementsSubProcessor.getVariableProposals(context, problem, null, proposals);
        break;
    case IProblem.AmbiguousType:
    case IProblem.JavadocAmbiguousType:
        UnresolvedElementsSubProcessor.getAmbiguosTypeReferenceProposals(context, problem, proposals);
        break;
    case IProblem.PublicClassMustMatchFileName:
        ReorgCorrectionsSubProcessor.getWrongTypeNameProposals(context, problem, proposals);
        break;
    case IProblem.PackageIsNotExpectedPackage:
        ReorgCorrectionsSubProcessor.getWrongPackageDeclNameProposals(context, problem, proposals);
        break;
    case IProblem.UndefinedType:
    case IProblem.JavadocUndefinedType:
        UnresolvedElementsSubProcessor.getTypeProposals(context, problem, proposals);
        break;
    case IProblem.TypeMismatch:
        // AspectJ Change
        if (problem.getProblemArguments() != null) { // Bug 265052
            TypeMismatchSubProcessor.addTypeMismatchProposals(context, problem, proposals);
        }
        break;
    case IProblem.IncompatibleReturnType:
        TypeMismatchSubProcessor.addIncompatibleReturnTypeProposals(context, problem, proposals);
        break;
    case IProblem.IncompatibleExceptionInThrowsClause:
        TypeMismatchSubProcessor.addIncompatibleThrowsProposals(context, problem, proposals);
        break;
    case IProblem.UnhandledException:
        LocalCorrectionsSubProcessor.addUncaughtExceptionProposals(context, problem, proposals);
        break;
    case IProblem.UnreachableCatch:
    case IProblem.InvalidCatchBlockSequence:
        LocalCorrectionsSubProcessor.addUnreachableCatchProposals(context, problem, proposals);
        break;
    case IProblem.VoidMethodReturnsValue:
        ReturnTypeSubProcessor.addVoidMethodReturnsProposals(context, problem, proposals);
        break;
    case IProblem.MethodReturnsVoid:
        ReturnTypeSubProcessor.addMethodRetunsVoidProposals(context, problem, proposals);
        break;
    case IProblem.MissingReturnType:
        ReturnTypeSubProcessor.addMissingReturnTypeProposals(context, problem, proposals);
        break;
    case IProblem.ShouldReturnValue:
        ReturnTypeSubProcessor.addMissingReturnStatementProposals(context, problem, proposals);
        break;
    case IProblem.NonExternalizedStringLiteral:
        LocalCorrectionsSubProcessor.addNLSProposals(context, problem, proposals);
        break;
    case IProblem.UnnecessaryNLSTag:
        LocalCorrectionsSubProcessor.getUnnecessaryNLSTagProposals(context, problem, proposals);
        break;
    case IProblem.NonStaticAccessToStaticField:
    case IProblem.NonStaticAccessToStaticMethod:
    case IProblem.IndirectAccessToStaticField:
    case IProblem.IndirectAccessToStaticMethod:
        LocalCorrectionsSubProcessor.addCorrectAccessToStaticProposals(context, problem, proposals);
        break;
    case IProblem.StaticMethodRequested:
    case IProblem.NonStaticFieldFromStaticInvocation:
    case IProblem.InstanceMethodDuringConstructorInvocation:
    case IProblem.InstanceFieldDuringConstructorInvocation:
        ModifierCorrectionSubProcessor.addNonAccessibleReferenceProposal(context, problem, proposals,
                ModifierCorrectionSubProcessor.TO_STATIC, 5);
        break;
    case IProblem.NonBlankFinalLocalAssignment:
    case IProblem.DuplicateFinalLocalInitialization:
    case IProblem.FinalFieldAssignment:
    case IProblem.DuplicateBlankFinalFieldInitialization:
    case IProblem.AnonymousClassCannotExtendFinalClass:
    case IProblem.ClassExtendFinalClass:
        ModifierCorrectionSubProcessor.addNonAccessibleReferenceProposal(context, problem, proposals,
                ModifierCorrectionSubProcessor.TO_NON_FINAL, 9);
        break;
    case IProblem.InheritedMethodReducesVisibility:
    case IProblem.MethodReducesVisibility:
    case IProblem.OverridingNonVisibleMethod:
        ModifierCorrectionSubProcessor.addChangeOverriddenModifierProposal(context, problem, proposals,
                ModifierCorrectionSubProcessor.TO_VISIBLE);
        break;
    case IProblem.FinalMethodCannotBeOverridden:
        ModifierCorrectionSubProcessor.addChangeOverriddenModifierProposal(context, problem, proposals,
                ModifierCorrectionSubProcessor.TO_NON_FINAL);
        break;
    case IProblem.CannotOverrideAStaticMethodWithAnInstanceMethod:
        ModifierCorrectionSubProcessor.addChangeOverriddenModifierProposal(context, problem, proposals,
                ModifierCorrectionSubProcessor.TO_NON_STATIC);
        break;
    case IProblem.CannotHideAnInstanceMethodWithAStaticMethod:
    case IProblem.IllegalModifierForInterfaceMethod:
    case IProblem.IllegalModifierForInterface:
    case IProblem.IllegalModifierForClass:
    case IProblem.IllegalModifierForInterfaceField:
    case IProblem.IllegalModifierForMemberInterface:
    case IProblem.IllegalModifierForMemberClass:
    case IProblem.IllegalModifierForLocalClass:
    case IProblem.IllegalModifierForArgument:
    case IProblem.IllegalModifierForField:
    case IProblem.IllegalModifierForMethod:
    case IProblem.IllegalModifierForVariable:
    case IProblem.IllegalVisibilityModifierForInterfaceMemberType:
    case IProblem.UnexpectedStaticModifierForMethod:
        ModifierCorrectionSubProcessor.addRemoveInvalidModifiersProposal(context, problem, proposals, 5);
        break;
    case IProblem.NotVisibleMethod:
    case IProblem.NotVisibleConstructor:
    case IProblem.NotVisibleType:
    case IProblem.NotVisibleField:
    case IProblem.JavadocNotVisibleType:
        ModifierCorrectionSubProcessor.addNonAccessibleReferenceProposal(context, problem, proposals,
                ModifierCorrectionSubProcessor.TO_VISIBLE, 10);
        break;
    case IProblem.BodyForAbstractMethod:
    case IProblem.AbstractMethodInAbstractClass:
        ModifierCorrectionSubProcessor.addAbstractMethodProposals(context, problem, proposals);
        break;
    case IProblem.AbstractMethodMustBeImplemented:
        LocalCorrectionsSubProcessor.addUnimplementedMethodsProposals(context, problem, proposals);
        break;
    case IProblem.MissingValueForAnnotationMember:
        LocalCorrectionsSubProcessor.addValueForAnnotationProposals(context, problem, proposals);
        break;
    case IProblem.BodyForNativeMethod:
        ModifierCorrectionSubProcessor.addNativeMethodProposals(context, problem, proposals);
        break;
    case IProblem.MethodRequiresBody:
        ModifierCorrectionSubProcessor.addMethodRequiresBodyProposals(context, problem, proposals);
        break;
    case IProblem.OuterLocalMustBeFinal:
        ModifierCorrectionSubProcessor.addNonFinalLocalProposal(context, problem, proposals);
        break;
    case IProblem.UninitializedLocalVariable:
        LocalCorrectionsSubProcessor.addUninitializedLocalVariableProposal(context, problem, proposals);
        break;
    case IProblem.UnhandledExceptionInDefaultConstructor:
    case IProblem.UndefinedConstructorInDefaultConstructor:
    case IProblem.NotVisibleConstructorInDefaultConstructor:
        LocalCorrectionsSubProcessor.addConstructorFromSuperclassProposal(context, problem, proposals);
        break;
    case IProblem.UnusedPrivateMethod:
    case IProblem.UnusedPrivateConstructor:
    case IProblem.UnusedPrivateField:
    case IProblem.UnusedPrivateType:
    case IProblem.LocalVariableIsNeverUsed:
    case IProblem.ArgumentIsNeverUsed:
        LocalCorrectionsSubProcessor.addUnusedMemberProposal(context, problem, proposals);
        break;
    case IProblem.NeedToEmulateFieldReadAccess:
    case IProblem.NeedToEmulateFieldWriteAccess:
    case IProblem.NeedToEmulateMethodAccess:
    case IProblem.NeedToEmulateConstructorAccess:
        ModifierCorrectionSubProcessor.addNonAccessibleReferenceProposal(context, problem, proposals,
                ModifierCorrectionSubProcessor.TO_NON_PRIVATE, 5);
        break;
    case IProblem.SuperfluousSemicolon:
        LocalCorrectionsSubProcessor.addSuperfluousSemicolonProposal(context, problem, proposals);
        break;
    case IProblem.UnnecessaryCast:
        LocalCorrectionsSubProcessor.addUnnecessaryCastProposal(context, problem, proposals);
        break;
    case IProblem.UnnecessaryInstanceof:
        LocalCorrectionsSubProcessor.addUnnecessaryInstanceofProposal(context, problem, proposals);
        break;
    case IProblem.UnusedMethodDeclaredThrownException:
    case IProblem.UnusedConstructorDeclaredThrownException:
        LocalCorrectionsSubProcessor.addUnnecessaryThrownExceptionProposal(context, problem, proposals);
        break;
    case IProblem.UnqualifiedFieldAccess:
        LocalCorrectionsSubProcessor.addUnqualifiedFieldAccessProposal(context, problem, proposals);
        break;
    case IProblem.Task:
        proposals.add(new TaskMarkerProposal(context.getCompilationUnit(), problem, 10));
        break;
    case IProblem.JavadocMissing:
        JavadocTagsSubProcessor.getMissingJavadocCommentProposals(context, problem, proposals);
        break;
    case IProblem.JavadocMissingParamTag:
    case IProblem.JavadocMissingReturnTag:
    case IProblem.JavadocMissingThrowsTag:
        JavadocTagsSubProcessor.getMissingJavadocTagProposals(context, problem, proposals);
        break;
    case IProblem.JavadocInvalidThrowsClassName:
    case IProblem.JavadocDuplicateThrowsClassName:
    case IProblem.JavadocDuplicateReturnTag:
    case IProblem.JavadocDuplicateParamName:
    case IProblem.JavadocInvalidParamName:
    case IProblem.JavadocUnexpectedTag:
    case IProblem.JavadocInvalidTag:
        JavadocTagsSubProcessor.getRemoveJavadocTagProposals(context, problem, proposals);
        break;
    case IProblem.LocalVariableHidingLocalVariable:
    case IProblem.LocalVariableHidingField:
    case IProblem.FieldHidingLocalVariable:
    case IProblem.FieldHidingField:
    case IProblem.ArgumentHidingLocalVariable:
    case IProblem.ArgumentHidingField:
    case IProblem.UseAssertAsAnIdentifier:
    case IProblem.UseEnumAsAnIdentifier:
    case IProblem.RedefinedLocal:
    case IProblem.RedefinedArgument:
        LocalCorrectionsSubProcessor.addInvalidVariableNameProposals(context, problem, proposals);
        break;
    case IProblem.NoMessageSendOnArrayType:
        UnresolvedElementsSubProcessor.getArrayAccessProposals(context, problem, proposals);
        break;
    case IProblem.InvalidOperator:
        LocalCorrectionsSubProcessor.getInvalidOperatorProposals(context, problem, proposals);
        break;
    case IProblem.MissingSerialVersion:
        SerialVersionSubProcessor.getSerialVersionProposals(context, problem, proposals);
        break;
    case IProblem.UnnecessaryElse:
        LocalCorrectionsSubProcessor.getUnnecessaryElseProposals(context, problem, proposals);
        break;
    case IProblem.SuperclassMustBeAClass:
        LocalCorrectionsSubProcessor.getInterfaceExtendsClassProposals(context, problem, proposals);
        break;
    case IProblem.CodeCannotBeReached:
        LocalCorrectionsSubProcessor.getUnreachableCodeProposals(context, problem, proposals);
        break;
    case IProblem.InvalidUsageOfTypeParameters:
    case IProblem.InvalidUsageOfStaticImports:
    case IProblem.InvalidUsageOfForeachStatements:
    case IProblem.InvalidUsageOfTypeArguments:
    case IProblem.InvalidUsageOfEnumDeclarations:
    case IProblem.InvalidUsageOfVarargs:
    case IProblem.InvalidUsageOfAnnotations:
    case IProblem.InvalidUsageOfAnnotationDeclarations:
        // FICXADE  Need reflection here!
        // ECLIPSE 3.8
        //                ReorgCorrectionsSubProcessor.getNeedHigherComplianceProposals(context, problem, proposals, JavaCore.VERSION_1_5);
        // ORIG
        //                ReorgCorrectionsSubProcessor.getNeed50ComplianceProposals(context, problem, proposals);
        break;
    case IProblem.NonGenericType:
        TypeArgumentMismatchSubProcessor.removeMismatchedArguments(context, problem, proposals);
        break;
    case IProblem.MissingOverrideAnnotation:
        ModifierCorrectionSubProcessor.addOverrideAnnotationProposal(context, problem, proposals);
        break;
    case IProblem.FieldMissingDeprecatedAnnotation:
    case IProblem.MethodMissingDeprecatedAnnotation:
    case IProblem.TypeMissingDeprecatedAnnotation:
        ModifierCorrectionSubProcessor.addDeprecatedAnnotationProposal(context, problem, proposals);
        break;
    case IProblem.IsClassPathCorrect:
        ReorgCorrectionsSubProcessor.getIncorrectBuildPathProposals(context, problem, proposals);
        break;
    case IProblem.ForbiddenReference:
    case IProblem.DiscouragedReference:
        ReorgCorrectionsSubProcessor.getAccessRulesProposals(context, problem, proposals);
        break;
    case IProblem.AssignmentHasNoEffect:
        LocalCorrectionsSubProcessor.getAssignmentHasNoEffectProposals(context, problem, proposals);
        break;
    case IProblem.UnsafeTypeConversion:
    case IProblem.RawTypeReference:
    case IProblem.UnsafeRawMethodInvocation:
        LocalCorrectionsSubProcessor.addTypePrametersToRawTypeReference(context, problem, proposals);
        break;
    case IProblem.FallthroughCase:
        LocalCorrectionsSubProcessor.addFallThroughProposals(context, problem, proposals);
        break;
    case IProblem.UnhandledWarningToken:
        SuppressWarningsSubProcessor.addUnknownSuppressWarningProposals(context, problem, proposals);
        break;
    default:
    }
    if (JavaModelUtil.is50OrHigher(context.getCompilationUnit().getJavaProject())) {
        SuppressWarningsSubProcessor.addSuppressWarningsProposals(context, problem, proposals);
    }
}