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

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

Introduction

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

Prototype

int Task

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

Click Source Link

Usage

From source file:edu.brown.cs.bubbles.bedrock.BedrockUtil.java

License:Open Source License

/********************************************************************************/

static void outputProblem(IProject proj, IProblem ip, IvyXmlWriter xw) {
    xw.begin("PROBLEM");

    if (ip instanceof IMarker) {
        IMarker xmk = (IMarker) ip;/*from  w ww . j a v  a 2 s  .com*/
        xw.field("ID", xmk.getId());
    }

    xw.field("MSGID", ip.getID());
    xw.field("MESSAGE", ip.getMessage());
    char[] filc = ip.getOriginatingFileName();
    if (filc != null) {
        File fnm = new File(new String(filc));
        fnm = getFileForPath(fnm, proj);
        xw.field("FILE", fnm.getAbsolutePath());
    }
    xw.field("LINE", ip.getSourceLineNumber());
    xw.field("START", ip.getSourceStart());
    xw.field("END", ip.getSourceEnd());
    if (proj != null)
        xw.field("PROJECT", proj.getName());
    if (ip.isError())
        xw.field("ERROR", true);
    else {
        switch (ip.getID()) {
        case IProblem.Task:
            break;
        default:
            xw.field("WARNING", true);
            break;
        }
    }

    for (String s : ip.getArguments()) {
        xw.textElement("ARG", s);
    }

    BedrockPlugin.getPlugin().addFixes(ip, xw);

    xw.end("PROBLEM");
}

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

License:Open Source License

protected void storeTasksFor(SourceFile sourceFile, CategorizedProblem[] tasks) throws CoreException {
    if (sourceFile == null || tasks == null || tasks.length == 0)
        return;// ww  w. j  a va2s .  c  o  m

    IResource resource = sourceFile.resource;
    for (int i = 0, l = tasks.length; i < l; i++) {
        CategorizedProblem task = tasks[i];
        if (task.getID() == IProblem.Task) {
            IMarker marker = resource.createMarker(IJavaModelMarker.TASK_MARKER);
            Integer priority = P_NORMAL;
            String compilerPriority = task.getArguments()[2];
            if (JavaCore.COMPILER_TASK_PRIORITY_HIGH.equals(compilerPriority))
                priority = P_HIGH;
            else if (JavaCore.COMPILER_TASK_PRIORITY_LOW.equals(compilerPriority))
                priority = P_LOW;

            String[] attributeNames = JAVA_TASK_MARKER_ATTRIBUTE_NAMES;
            int standardLength = attributeNames.length;
            String[] allNames = attributeNames;
            String[] extraAttributeNames = task.getExtraMarkerAttributeNames();
            int extraLength = extraAttributeNames == null ? 0 : extraAttributeNames.length;
            if (extraLength > 0) {
                allNames = new String[standardLength + extraLength];
                System.arraycopy(attributeNames, 0, allNames, 0, standardLength);
                System.arraycopy(extraAttributeNames, 0, allNames, standardLength, extraLength);
            }

            Object[] allValues = new Object[allNames.length];
            // standard attributes
            int index = 0;
            allValues[index++] = task.getMessage();
            allValues[index++] = priority;
            allValues[index++] = new Integer(task.getID());
            allValues[index++] = new Integer(task.getSourceStart());
            allValues[index++] = new Integer(task.getSourceEnd() + 1);
            allValues[index++] = new Integer(task.getSourceLineNumber());
            allValues[index++] = Boolean.FALSE;
            allValues[index++] = JavaBuilder.SOURCE_ID;
            // optional extra attributes
            if (extraLength > 0)
                System.arraycopy(task.getExtraMarkerAttributeValues(), 0, allValues, index, extraLength);

            marker.setAttributes(allNames, allValues);
        }
    }
}

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

License:Open Source License

/**
 * Update the problem counts from one compilation result given the old and new problems,
 * either of which may be null./*from   ww  w  .  j  ava 2  s  . c  om*/
 */
protected void updateProblemCounts(IMarker[] oldProblems, CategorizedProblem[] newProblems) {
    if (newProblems != null) {
        next: for (int i = 0, l = newProblems.length; i < l; i++) {
            CategorizedProblem newProblem = newProblems[i];
            if (newProblem.getID() == IProblem.Task)
                continue; // skip task
            boolean isError = newProblem.isError();
            String message = newProblem.getMessage();

            if (oldProblems != null) {
                for (int j = 0, m = oldProblems.length; j < m; j++) {
                    IMarker pb = oldProblems[j];
                    if (pb == null)
                        continue; // already matched up with a new problem
                    boolean wasError = IMarker.SEVERITY_ERROR == pb.getAttribute(IMarker.SEVERITY,
                            IMarker.SEVERITY_ERROR);
                    if (isError == wasError && message.equals(pb.getAttribute(IMarker.MESSAGE, ""))) { //$NON-NLS-1$
                        oldProblems[j] = null;
                        continue next;
                    }
                }
            }
            if (isError)
                this.newErrorCount++;
            else
                this.newWarningCount++;
        }
    }
    if (oldProblems != null) {
        next: for (int i = 0, l = oldProblems.length; i < l; i++) {
            IMarker oldProblem = oldProblems[i];
            if (oldProblem == null)
                continue next; // already matched up with a new problem
            boolean wasError = IMarker.SEVERITY_ERROR == oldProblem.getAttribute(IMarker.SEVERITY,
                    IMarker.SEVERITY_ERROR);
            String message = oldProblem.getAttribute(IMarker.MESSAGE, ""); //$NON-NLS-1$

            if (newProblems != null) {
                for (int j = 0, m = newProblems.length; j < m; j++) {
                    CategorizedProblem pb = newProblems[j];
                    if (pb.getID() == IProblem.Task)
                        continue; // skip task
                    if (wasError == pb.isError() && message.equals(pb.getMessage()))
                        continue next;
                }
            }
            if (wasError)
                this.fixedErrorCount++;
            else
                this.fixedWarningCount++;
        }
    }
}

From source file:org.eclim.plugin.groovy.command.src.SrcUpdateCommand.java

License:Open Source License

@Override
public Object execute(CommandLine commandLine) throws Exception {
    String file = commandLine.getValue(Options.FILE_OPTION);
    String projectName = commandLine.getValue(Options.PROJECT_OPTION);
    IProject project = ProjectUtils.getProject(projectName, true);
    IFile ifile = ProjectUtils.getFile(project, file);

    // validate the src file.
    if (commandLine.hasOption(Options.VALIDATE_OPTION)) {
        ICompilationUnit src = JavaCore.createCompilationUnitFrom(ifile);
        IProblem[] problems = JavaUtils.getProblems(src);
        List<Error> errors = new ArrayList<Error>();
        String filename = src.getResource().getLocation().toOSString().replace('\\', '/');
        FileOffsets offsets = FileOffsets.compile(filename);

        for (IProblem problem : problems) {
            // exclude TODO, etc
            if (problem.getID() == IProblem.Task) {
                continue;
            }/*from   ww w .  j av  a 2 s.  c  o m*/

            int[] lineColumn = offsets.offsetToLineColumn(problem.getSourceStart());
            errors.add(new Error(problem.getMessage(), filename, lineColumn[0], lineColumn[1],
                    problem.isWarning()));
        }

        if (commandLine.hasOption(Options.BUILD_OPTION)) {
            project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, new NullProgressMonitor());
        }
        return errors;
    }

    return StringUtils.EMPTY;
}

From source file:org.eclim.plugin.jdt.command.src.SrcUpdateCommand.java

License:Open Source License

@Override
@SuppressWarnings("unchecked")
public Object execute(CommandLine commandLine) throws Exception {
    String file = commandLine.getValue(Options.FILE_OPTION);
    String projectName = commandLine.getValue(Options.PROJECT_OPTION);
    IProject project = ProjectUtils.getProject(projectName);

    // only refresh the file.
    if (!commandLine.hasOption(Options.VALIDATE_OPTION)) {
        // getting the file will refresh it.
        ProjectUtils.getFile(project, file);

        // validate the src file.
    } else {/*  w w  w . ja  va 2s.c  o  m*/
        // JavaUtils refreshes the file when getting it.
        IJavaProject javaProject = JavaUtils.getJavaProject(project);
        ICompilationUnit src = JavaUtils.getCompilationUnit(javaProject, file);

        IProblem[] problems = JavaUtils.getProblems(src);

        ArrayList<Error> errors = new ArrayList<Error>();
        String filename = src.getResource().getLocation().toOSString().replace('\\', '/');
        FileOffsets offsets = FileOffsets.compile(filename);
        for (IProblem problem : problems) {
            // exclude TODO, etc
            if (problem.getID() == IProblem.Task) {
                continue;
            }

            int[] lineColumn = offsets.offsetToLineColumn(problem.getSourceStart());

            // one day vim might support ability to mark the offending text.
            /*int[] endLineColumn =
              offsets.offsetToLineColumn(problem.getSourceEnd());*/

            errors.add(new Error(problem.getMessage(), filename, lineColumn[0], lineColumn[1],
                    problem.isWarning()));
        }

        boolean checkstyle = "true"
                .equals(getPreferences().getValue(project, "org.eclim.java.checkstyle.onvalidate"));
        if (checkstyle) {
            errors.addAll((List<Error>) Services.getCommand("java_checkstyle").execute(commandLine));
        }

        if (commandLine.hasOption(Options.BUILD_OPTION)) {
            project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, new NullProgressMonitor());
        }
        return errors;
    }
    return null;
}

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

License:Open Source License

public void acceptProblem(IProblem problem) {
    // bug 155225: use delegate for Task problems, ignore everything else
    if ((delegate != null) && (problem.getID() == IProblem.Task)) {
        ((IProblemRequestor) delegate).acceptProblem(problem);
    }// w  w  w  .j av a2s  .co m
}

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  w w  . jav  a  2 s .co 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  . ja  va 2 s .  co  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);
    }
}

From source file:org.eclipse.che.jdt.quickfix.ReorgQuickFixTest.java

License:Open Source License

@Test
public void testTodoTasks1() throws Exception {
    IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
    StringBuffer buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("public class E {\n");
    buf.append("    public void foo() {\n");
    buf.append("        // TODO: XXX\n");
    buf.append("    }\n");
    buf.append("}\n");
    ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);

    String str = "TODO: XXX";
    AssistContext context = getCorrectionContext(cu, buf.toString().indexOf(str), 0);
    ProblemLocation problem = new ProblemLocation(buf.toString().indexOf(str), str.length(), IProblem.Task,
            new String[0], true, IJavaModelMarker.TASK_MARKER);
    ArrayList proposals = collectCorrections(context, problem);

    assertNumberOfProposals(proposals, 1);
    assertCorrectLabels(proposals);//from  www  .j a  va  2  s . c  o  m

    CUCorrectionProposal proposal = (CUCorrectionProposal) proposals.get(0);
    String preview = getPreviewContent(proposal);

    buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("public class E {\n");
    buf.append("    public void foo() {\n");
    buf.append("    }\n");
    buf.append("}\n");
    assertEqualString(preview, buf.toString());
}

From source file:org.eclipse.che.jdt.quickfix.ReorgQuickFixTest.java

License:Open Source License

@Test
public void testTodoTasks2() throws Exception {
    IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
    StringBuffer buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("public class E {\n");
    buf.append("    public void foo() {\n");
    buf.append("        // Some other text TODO: XXX\n");
    buf.append("    }\n");
    buf.append("}\n");
    ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);

    String str = "TODO: XXX";
    AssistContext context = getCorrectionContext(cu, buf.toString().indexOf(str), 0);
    ProblemLocation problem = new ProblemLocation(buf.toString().indexOf(str), str.length(), IProblem.Task,
            new String[0], true, IJavaModelMarker.TASK_MARKER);
    ArrayList proposals = collectCorrections(context, problem);

    assertNumberOfProposals(proposals, 1);
    assertCorrectLabels(proposals);/*from  w w w.j  ava  2 s  .  c o  m*/

    CUCorrectionProposal proposal = (CUCorrectionProposal) proposals.get(0);
    String preview = getPreviewContent(proposal);

    buf = new StringBuffer();
    buf.append("package test1;\n");
    buf.append("public class E {\n");
    buf.append("    public void foo() {\n");
    buf.append("        // Some other text \n");
    buf.append("    }\n");
    buf.append("}\n");
    assertEqualString(preview, buf.toString());
}