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;
}
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();
}
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();
}
}
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);
}
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;
}
Aggregations