Search in sources :

Example 16 with Interval

use of org.eclipse.titan.common.parsers.Interval in project titan.EclipsePlug-ins by eclipse.

the class HeuristicalIntervalDetector method isWithinString.

/**
 * The method determines if the given offset is within a string in the
 * document.
 *
 * @param document
 *                the document being parsed
 * @param offset
 *                the position where parsing starts from
 * @param enclosingInterval
 *                an interval, which encloses the offset
 * @return Whether offset is within a comment.
 * @exception BadLocationException
 *                    if the offset is invalid in this document
 */
// FIXME needs correction
@Override
public boolean isWithinString(final StringBuilder document, final int offset, final Interval enclosingInterval) throws BadLocationException {
    Interval interval = enclosingInterval.getSmallestEnclosingInterval(offset);
    if (interval_type.MULTILINE_COMMENT.equals(interval.getType()) || interval_type.SINGLELINE_COMMENT.equals(interval.getType())) {
        return false;
    }
    int start = interval.getStartOffset();
    int counter = 0;
    while (start < offset) {
        char curr = document.charAt(start);
        if (curr == '"') {
            counter++;
        }
        start++;
    }
    return counter % 2 != 0;
}
Also used : Interval(org.eclipse.titan.common.parsers.Interval)

Aggregations

Interval (org.eclipse.titan.common.parsers.Interval)16 BadLocationException (org.eclipse.jface.text.BadLocationException)4 HeuristicalIntervalDetector (org.eclipse.titan.designer.editors.HeuristicalIntervalDetector)4 IRegion (org.eclipse.jface.text.IRegion)3 Position (org.eclipse.jface.text.Position)2 IDocument (org.eclipse.jface.text.IDocument)1 ITypedRegion (org.eclipse.jface.text.ITypedRegion)1 Region (org.eclipse.jface.text.Region)1 RewriteSessionEditProcessor (org.eclipse.jface.text.RewriteSessionEditProcessor)1 TextSelection (org.eclipse.jface.text.TextSelection)1 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)1 CfgInterval (org.eclipse.titan.common.parsers.cfg.CfgInterval)1