Java Code Examples for org.eclipse.jface.text.Region#getOffset()

The following examples show how to use org.eclipse.jface.text.Region#getOffset() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RailroadSelectionLinker.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected ISelectable findFigureForTextOffset(IFigure figure, int offset, ISelectable currentBestFigure) {
	if(figure == null)
		return null;
	if (figure instanceof ISelectable) {
		Region textRegion = ((ISelectable) figure).getTextRegion();
		if (textRegion != null && textRegion.getOffset() <= offset
				&& textRegion.getOffset() + textRegion.getLength() >= offset) {
			if(currentBestFigure == null || currentBestFigure.getTextRegion().getLength() > textRegion.getLength()) {
				currentBestFigure = (ISelectable) figure;
			}
		}
	}
	for (Object child : figure.getChildren()) {
		if (child instanceof IFigure) {
			currentBestFigure = findFigureForTextOffset((IFigure) child, offset, currentBestFigure);
		}
	}
	return currentBestFigure;
}
 
Example 2
Source File: NLSSourceModifier.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void addAccessor(NLSSubstitution sub, TextChange change, String accessorName) {
	if (sub.getState() == NLSSubstitution.EXTERNALIZED) {
		NLSElement element= sub.getNLSElement();
		Region position= element.getPosition();
		String[] args= {sub.getValueNonEmpty(), BasicElementLabels.getJavaElementName(sub.getKey())};
		String text= Messages.format(NLSMessages.NLSSourceModifier_externalize, args);

		String resourceGetter= createResourceGetter(sub.getKey(), accessorName);

		TextEdit edit= new ReplaceEdit(position.getOffset(), position.getLength(), resourceGetter);
		if (fIsEclipseNLS && element.getTagPosition() != null) {
			MultiTextEdit multiEdit= new MultiTextEdit();
			multiEdit.addChild(edit);
			Region tagPosition= element.getTagPosition();
			multiEdit.addChild(new DeleteEdit(tagPosition.getOffset(), tagPosition.getLength()));
			edit= multiEdit;
		}
		TextChangeCompatibility.addTextEdit(change, text, edit);
	}
}
 
Example 3
Source File: ProposalConflictHelper.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean existsConflict(String proposal, ContentAssistContext context) {
	// hidden node between lastCompleteNode and currentNode?
	INode lastCompleteNode = context.getLastCompleteNode();
	Region replaceRegion = context.getReplaceRegion();
	int nodeEnd = lastCompleteNode.getEndOffset();
	if (nodeEnd < replaceRegion.getOffset())
		return false;
	
	return existsConflict(lastCompleteNode, replaceRegion.getOffset(), proposal, context);
}
 
Example 4
Source File: ModulaOccurrencesMarker.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
private Map<Annotation, Position> createConstructionAnnotations(ArrayList<Region> regions, String msg) {
    final Map<Annotation, Position> map = new HashMap<Annotation, Position>();
    for (Region reg : regions) {
        Annotation annotation = new Annotation(CONSTRUCTION_ANNOTATION_ID, false, msg);
        Position position = new Position(reg.getOffset(), reg.getLength());
        map.put(annotation, position);
    }
    return map;
}
 
Example 5
Source File: NLSUtil.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
private static boolean isPositionInElement(NLSElement element, int position) {
	Region elementPosition= element.getPosition();
	return (elementPosition.getOffset() <= position && position <= elementPosition.getOffset() + elementPosition.getLength());
}
 
Example 6
Source File: ImplementMemberFromSuperAssist.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
protected ImportOrganizingProposal createCompletionProposal(ReplacingAppendable appendable, Region replaceRegion,
		StyledString displayString, Image image) {
	return new ImportOrganizingProposal(appendable, replaceRegion.getOffset(), replaceRegion.getLength(),
			replaceRegion.getOffset(), image, displayString);
}
 
Example 7
Source File: GotoMatchingParenHandler.java    From tlaplus with MIT License 4 votes vote down vote up
/**
     * Sets currLoc, and returns the index of the selected paren in PARENS.  
     * If the region has zero length, then it selects the paren to its left and 
     * sets currLoc to the selection--or the 2-char paren it's in the
     * middle of.  Otherwise, the region has to select a paren, 
     * and currLoc is set to the position to the right of that paren.
     * 
     * @param selectedRegion
     */
    private int getSelectedParen(Region selectedRegion)
            throws ParenErrorException {
        currLoc = selectedRegion.getOffset();
        int selectedParenIdx;
        if (selectedRegion.getLength() == 0) {
          selectedParenIdx = getParenToLeftOf(currLoc);
          if (selectedParenIdx == -1) {
              int tryNext = getParenToLeftOf(currLoc + 1);
              if (tryNext == -1 || PARENS[tryNext].length() == 1) {
                throw new ParenErrorException("Paren not selected", null, null);
              }
              currLoc++;
              return tryNext;
          }       
        } else {
            String selection = null; // initialization to keep compiler happy.
            try {
                selection = document.get(selectedRegion.getOffset(),
                        selectedRegion.getLength());
            } catch (BadLocationException e) {
                // This should not happen
                System.out.println(
                   "BadLocationException in GotoMatchingParenHandler.getSelectedParen");
            }
            selectedParenIdx = 0;
            boolean notDone = true ;
            while (notDone && (selectedParenIdx < PARENS.length)) {
                if (selection.equals(PARENS[selectedParenIdx])) {
                    notDone = false;
                } 
                else {
                    selectedParenIdx++;
                }
            }
            if (notDone) {
                throw new ParenErrorException("Selection is not a paren", null, null);
            }
            currLoc = currLoc + selectedRegion.getLength();
        }
        
        // Now test if we're between "(" and "*".
        if (    selectedParenIdx == LEFT_ROUND_PAREN_IDX
             && getParenToLeftOf(currLoc + 1) == COMMENT_BEGIN_IDX) {
//            throw new ParenErrorException("Selection between  (  and  *", null);
            currLoc++;
            return BEGIN_MULTILINE_COMMENT_IDX;
        }
        return selectedParenIdx ;
    }
 
Example 8
Source File: NLSUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private static boolean isPositionInElement(NLSElement element, int position) {
	Region elementPosition= element.getPosition();
	return (elementPosition.getOffset() <= position && position <= elementPosition.getOffset() + elementPosition.getLength());
}
 
Example 9
Source File: NLSSourceModifier.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private static boolean isPositionInElement(NLSElement element, int position) {
	Region elementPosition= element.getPosition();
	return (elementPosition.getOffset() <= position && position <= elementPosition.getOffset() + elementPosition.getLength());
}