Search in sources :

Example 11 with Problem

use of org.eclipse.che.ide.ext.java.shared.dto.Problem in project che by eclipse.

the class JavaCorrectionProcessor method collectProposals.

public static IStatus collectProposals(IInvocationContext context, /*IAnnotationModel model, */
List<Problem> annotations, boolean addQuickFixes, boolean addQuickAssists, Collection<IJavaCompletionProposal> proposals) {
    ArrayList<ProblemLocation> problems = new ArrayList<>();
    // collect problem locations and corrections from marker annotations
    for (Problem curr : annotations) {
        problems.add(new ProblemLocation(curr));
    }
    //		for (int i= 0; i < annotations.length; i++) {
    //			Annotation curr= annotations[i];
    //			ProblemLocation problemLocation= null;
    //			if (curr instanceof IJavaAnnotation) {
    //				problemLocation= getProblemLocation((IJavaAnnotation) curr, model);
    //				if (problemLocation != null) {
    //					problems.add(problemLocation);
    //				}
    //			}
    ////			if (problemLocation == null && addQuickFixes && curr instanceof SimpleMarkerAnnotation) {
    ////				collectMarkerProposals((SimpleMarkerAnnotation) curr, proposals);
    ////			}
    //		}
    MultiStatus resStatus = null;
    IProblemLocation[] problemLocations = problems.toArray(new IProblemLocation[problems.size()]);
    if (addQuickFixes) {
        IStatus status = collectCorrections(context, problemLocations, proposals);
        if (!status.isOK()) {
            resStatus = new MultiStatus(JavaPlugin.ID_PLUGIN, IStatus.ERROR, CorrectionMessages.JavaCorrectionProcessor_error_quickfix_message, null);
            resStatus.add(status);
        }
    }
    if (addQuickAssists) {
        IStatus status = collectAssists(context, problemLocations, proposals);
        if (!status.isOK()) {
            if (resStatus == null) {
                resStatus = new MultiStatus(JavaPlugin.ID_PLUGIN, IStatus.ERROR, CorrectionMessages.JavaCorrectionProcessor_error_quickassist_message, null);
            }
            resStatus.add(status);
        }
    }
    if (resStatus != null) {
        return resStatus;
    }
    return Status.OK_STATUS;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) ArrayList(java.util.ArrayList) MultiStatus(org.eclipse.core.runtime.MultiStatus) Problem(org.eclipse.che.ide.ext.java.shared.dto.Problem) IProblemLocation(org.eclipse.jdt.ui.text.java.IProblemLocation) IProblemLocation(org.eclipse.jdt.ui.text.java.IProblemLocation)

Example 12 with Problem

use of org.eclipse.che.ide.ext.java.shared.dto.Problem in project che by eclipse.

the class PomReconcilerTest method testReconcilePomWhenPomContainsDependecyWithIncorrectAtrifactId.

@Test
public void testReconcilePomWhenPomContainsDependecyWithIncorrectAtrifactId() throws Exception {
    String brokenDependency = "    <dependency>\n" + "        <groupId>junit</groupId>\n" + "        <artifactId>jjjjjjjunit</artifactId>\n" + "        <version>3.8.1</version>\n" + "        <scope>test</scope>\n" + "    </dependency>\n";
    MavenServerService serverService = new MavenServerService(null, projectRegistry, pm, projectManager, null, null);
    FolderEntry testProject = createTestProject(PROJECT_NAME, getPomContentWithDependency(brokenDependency));
    VirtualFileEntry pom = testProject.getChild("pom.xml");
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJECT_NAME);
    mavenWorkspace.update(Collections.singletonList(project));
    mavenWorkspace.waitForUpdate();
    List<Problem> problems = serverService.reconcilePom(String.format("/%s/pom.xml", PROJECT_NAME));
    assertThat(problems).hasSize(1);
    assertThat(problems.get(0).isError()).isTrue();
    assertThat(pom).isNotNull();
}
Also used : FolderEntry(org.eclipse.che.api.project.server.FolderEntry) VirtualFileEntry(org.eclipse.che.api.project.server.VirtualFileEntry) MavenServerService(org.eclipse.che.plugin.maven.server.rest.MavenServerService) Problem(org.eclipse.che.ide.ext.java.shared.dto.Problem) IProject(org.eclipse.core.resources.IProject) Test(org.testng.annotations.Test) MavenServerManagerTest(org.eclipse.che.plugin.maven.server.rmi.MavenServerManagerTest)

Example 13 with Problem

use of org.eclipse.che.ide.ext.java.shared.dto.Problem in project che by eclipse.

the class PomReconcilingStrategy method doReconcile.

private void doReconcile(final List<Problem> problems) {
    if (this.annotationModel == null) {
        return;
    }
    ProblemRequester problemRequester;
    if (this.annotationModel instanceof ProblemRequester) {
        problemRequester = (ProblemRequester) this.annotationModel;
        problemRequester.beginReporting();
    } else {
        editor.setErrorState(EditorWithErrors.EditorState.NONE);
        return;
    }
    try {
        boolean error = false;
        boolean warning = false;
        for (Problem problem : problems) {
            if (!error) {
                error = problem.isError();
            }
            if (!warning) {
                warning = problem.isWarning();
            }
            problemRequester.acceptProblem(problem);
        }
        if (error) {
            editor.setErrorState(EditorWithErrors.EditorState.ERROR);
        } else if (warning) {
            editor.setErrorState(EditorWithErrors.EditorState.WARNING);
        } else {
            editor.setErrorState(EditorWithErrors.EditorState.NONE);
        }
    } catch (final Exception e) {
        Log.error(getClass(), e);
    } finally {
        problemRequester.endReporting();
    }
}
Also used : ProblemRequester(org.eclipse.che.ide.ext.java.client.editor.ProblemRequester) Problem(org.eclipse.che.ide.ext.java.shared.dto.Problem) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 14 with Problem

use of org.eclipse.che.ide.ext.java.shared.dto.Problem in project che by eclipse.

the class JavaQuickAssistProcessor method computeQuickAssistProposals.

@Override
public void computeQuickAssistProposals(final QuickAssistInvocationContext quickAssistContext, final CodeAssistCallback callback) {
    final TextEditor textEditor = quickAssistContext.getTextEditor();
    final Document document = textEditor.getDocument();
    LinearRange tempRange;
    tempRange = textEditor.getSelectedLinearRange();
    final LinearRange range = tempRange;
    final boolean goToClosest = (range.getLength() == 0);
    final QueryAnnotationsEvent.AnnotationFilter filter = new QueryAnnotationsEvent.AnnotationFilter() {

        @Override
        public boolean accept(final Annotation annotation) {
            if (!(annotation instanceof JavaAnnotation)) {
                return false;
            } else {
                JavaAnnotation javaAnnotation = (JavaAnnotation) annotation;
                return (!javaAnnotation.isMarkedDeleted());
            }
        }
    };
    final QueryAnnotationsEvent.QueryCallback queryCallback = new QueryAnnotationsEvent.QueryCallback() {

        @Override
        public void respond(final Map<Annotation, Position> annotations) {
            List<Problem> problems = new ArrayList<>();
            /*final Map<Annotation, Position> problems =*/
            int offset = collectQuickFixableAnnotations(range, document, annotations, goToClosest, problems);
            if (offset != range.getStartOffset()) {
                TextEditor presenter = ((TextEditor) textEditor);
                presenter.getCursorModel().setCursorPosition(offset);
            }
            setupProposals(callback, textEditor, offset, problems);
        }
    };
    final QueryAnnotationsEvent event = new QueryAnnotationsEvent.Builder().withFilter(filter).withCallback(queryCallback).build();
    document.getDocumentHandle().getDocEventBus().fireEvent(event);
}
Also used : LinearRange(org.eclipse.che.ide.api.editor.text.LinearRange) ArrayList(java.util.ArrayList) Document(org.eclipse.che.ide.api.editor.document.Document) QueryAnnotationsEvent(org.eclipse.che.ide.api.editor.annotation.QueryAnnotationsEvent) Annotation(org.eclipse.che.ide.api.editor.text.annotation.Annotation) TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) Problem(org.eclipse.che.ide.ext.java.shared.dto.Problem) Map(java.util.Map)

Example 15 with Problem

use of org.eclipse.che.ide.ext.java.shared.dto.Problem 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

Problem (org.eclipse.che.ide.ext.java.shared.dto.Problem)15 VirtualFileEntry (org.eclipse.che.api.project.server.VirtualFileEntry)7 FolderEntry (org.eclipse.che.api.project.server.FolderEntry)6 MavenServerService (org.eclipse.che.plugin.maven.server.rest.MavenServerService)6 MavenServerManagerTest (org.eclipse.che.plugin.maven.server.rmi.MavenServerManagerTest)6 Test (org.testng.annotations.Test)6 IProject (org.eclipse.core.resources.IProject)5 ArrayList (java.util.ArrayList)3 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)2 ServerException (org.eclipse.che.api.core.ServerException)2 MavenProjectProblem (org.eclipse.che.maven.data.MavenProjectProblem)2 BadLocationException (org.eclipse.jface.text.BadLocationException)2 Document (org.eclipse.jface.text.Document)2 Inject (com.google.inject.Inject)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiParam (io.swagger.annotations.ApiParam)1 ApiResponse (io.swagger.annotations.ApiResponse)1 ApiResponses (io.swagger.annotations.ApiResponses)1 IOException (java.io.IOException)1 Collections (java.util.Collections)1