use of org.eclipse.che.ide.api.editor.text.Position in project che by eclipse.
the class JavaQuickAssistProcessor method collectQuickFixableAnnotations.
private int collectQuickFixableAnnotations(final LinearRange lineRange, Document document, final Map<Annotation, Position> annotations, final boolean goToClosest, List<Problem> resultingProblems) {
int invocationLocation = lineRange.getStartOffset();
if (goToClosest) {
LinearRange line = document.getLinearRangeForLine(document.getPositionFromIndex(lineRange.getStartOffset()).getLine());
int rangeStart = line.getStartOffset();
int rangeEnd = rangeStart + line.getLength();
ArrayList<Position> allPositions = new ArrayList<>();
List<JavaAnnotation> allAnnotations = new ArrayList<>();
int bestOffset = Integer.MAX_VALUE;
for (Annotation problem : annotations.keySet()) {
if (problem instanceof JavaAnnotation) {
JavaAnnotation ann = ((JavaAnnotation) problem);
Position pos = annotations.get(problem);
if (pos != null && isInside(pos.offset, rangeStart, rangeEnd)) {
// inside our range?
allAnnotations.add(ann);
allPositions.add(pos);
bestOffset = processAnnotation(problem, pos, invocationLocation, bestOffset);
}
}
}
if (bestOffset == Integer.MAX_VALUE) {
return invocationLocation;
}
for (int i = 0; i < allPositions.size(); i++) {
Position pos = allPositions.get(i);
if (isInside(bestOffset, pos.offset, pos.offset + pos.length)) {
resultingProblems.add(createProblem(allAnnotations.get(i), pos));
}
}
return bestOffset;
} else {
for (Annotation problem : annotations.keySet()) {
Position pos = annotations.get(problem);
if (pos != null && isInside(invocationLocation, pos.offset, pos.offset + pos.length)) {
resultingProblems.add(createProblem((JavaAnnotation) problem, pos));
}
}
return invocationLocation;
}
}
use of org.eclipse.che.ide.api.editor.text.Position in project che by eclipse.
the class JavaRefactoringRename method activateLinkedModeIntoEditor.
private void activateLinkedModeIntoEditor(final RenameRefactoringSession session, final Document document) {
mode = linkedEditor.getLinkedMode();
LinkedModel model = linkedEditor.createLinkedModel();
LinkedModeModel linkedModeModel = session.getLinkedModeModel();
List<LinkedModelGroup> groups = new ArrayList<>();
for (LinkedPositionGroup positionGroup : linkedModeModel.getGroups()) {
LinkedModelGroup group = linkedEditor.createLinkedGroup();
LinkedData data = positionGroup.getData();
if (data != null) {
LinkedModelData modelData = linkedEditor.createLinkedModelData();
modelData.setType("link");
modelData.setValues(data.getValues());
group.setData(modelData);
}
List<Position> positions = new ArrayList<>();
for (Region region : positionGroup.getPositions()) {
positions.add(new Position(region.getOffset(), region.getLength()));
}
group.setPositions(positions);
groups.add(group);
}
model.setGroups(groups);
disableAutoSave();
mode.enterLinkedMode(model);
mode.addListener(new LinkedMode.LinkedModeListener() {
@Override
public void onLinkedModeExited(boolean successful, int start, int end) {
boolean isSuccessful = false;
try {
if (successful) {
isSuccessful = true;
newName = document.getContentRange(start, end - start);
performRename(session);
}
} finally {
mode.removeListener(this);
isActiveLinkedEditor = false;
if (!isSuccessful && linkedEditor instanceof EditorWithAutoSave) {
((EditorWithAutoSave) linkedEditor).enableAutoSave();
}
}
}
});
}
use of org.eclipse.che.ide.api.editor.text.Position in project che by eclipse.
the class AbstractDocument method getEndingPositions.
/**
* A list of positions in the given category with an end position inside the given region. The order of the positions is
* arbitrary.
*
* @param category
* the position category
* @param offset
* the offset of the region
* @param length
* the length of the region
* @return a list of the positions in the region
* @throws BadPositionCategoryException
* if category is undefined in this document
* @since 3.4
*/
private List<Position> getEndingPositions(String category, int offset, int length) throws BadPositionCategoryException {
List<Position> positions = fEndPositions.get(category);
if (positions == null)
throw new BadPositionCategoryException();
int indexStart = computeIndexInPositionList(positions, offset, false);
int indexEnd = computeIndexInPositionList(positions, offset + length, false);
return positions.subList(indexStart, indexEnd);
}
use of org.eclipse.che.ide.api.editor.text.Position in project che by eclipse.
the class AbstractDocument method removePosition.
/*
* @see org.eclipse.jface.text.IDocument#removePosition(java.lang.String, org.eclipse.jface.text.Position)
*/
public void removePosition(String category, Position position) throws BadPositionCategoryException {
if (position == null)
return;
if (category == null)
throw new BadPositionCategoryException();
List<Position> c = fPositions.get(category);
if (c == null)
throw new BadPositionCategoryException();
removeFromPositionsList(c, position, true);
List<Position> endPositions = fEndPositions.get(category);
if (endPositions == null)
throw new BadPositionCategoryException();
removeFromPositionsList(endPositions, position, false);
}
use of org.eclipse.che.ide.api.editor.text.Position in project che by eclipse.
the class AnnotationModelImpl method removeAnnotation.
/**
* Removes the given annotation from the annotation model. If requested inform all model change listeners about this change.
*
* @param annotation the annotation to be removed
* @param fireModelChanged indicates whether to notify all model listeners
*/
protected void removeAnnotation(final Annotation annotation, final boolean fireModelChanged) {
if (annotations.containsKey(annotation)) {
Position pos = null;
pos = annotations.get(annotation);
annotations.remove(annotation);
positions.remove(pos);
getAnnotationModelEvent().annotationRemoved(annotation, pos);
if (fireModelChanged) {
fireModelChanged();
}
}
}
Aggregations