Search in sources :

Example 11 with Interval

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

the class GeneralTITANAutoEditStrategy method findMatchingOpenBracket.

/**
 * Returns the line number of the next bracket after end.
 *
 * @returns the line number of the next matching bracket after end
 * @param document
 *                - the document being parsed
 * @param end
 *                - the end position to search back from (exclusive
 *                limit)
 * @return The position of the matching open bracket
 * @exception BadLocationException
 *                    if the offset is invalid in this document
 */
protected final int findMatchingOpenBracket(final IDocument document, final int end) throws BadLocationException {
    Interval interval;
    interval = rootInterval.getSmallestEnclosingInterval(end);
    return document.getLineOfOffset(interval.getStartOffset());
}
Also used : Interval(org.eclipse.titan.common.parsers.Interval)

Example 12 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 == '"' || curr == '\'') {
            counter++;
        }
        start++;
    }
    return counter % 2 != 0;
}
Also used : Interval(org.eclipse.titan.common.parsers.Interval)

Example 13 with Interval

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

the class IntervallBasedDamagerRepairer method getDamageRegion.

@Override
public IRegion getDamageRegion(final ITypedRegion partition, final DocumentEvent e, final boolean documentPartitioningChanged) {
    Interval interval = GlobalIntervalHandler.getInterval(fDocument);
    if (interval != null) {
        int maxLength = Math.max(0, (e.getText() == null ? e.getLength() : e.getText().length()));
        int endoffset = e.getOffset() + maxLength;
        Interval smallest = interval.getSmallestEnclosingInterval(e.getOffset(), endoffset);
        Interval canaryInterval = smallest.getSmallestEnclosingInterval(e.getOffset());
        if (interval_type.MULTILINE_COMMENT.equals(canaryInterval.getType())) {
            return new Region(canaryInterval.getStartOffset(), Math.min(smallest.getEndOffset() - canaryInterval.getStartOffset() + maxLength, fDocument.getLength()));
        }
    }
    return super.getDamageRegion(partition, e, documentPartitioningChanged);
}
Also used : Region(org.eclipse.jface.text.Region) ITypedRegion(org.eclipse.jface.text.ITypedRegion) IRegion(org.eclipse.jface.text.IRegion) Interval(org.eclipse.titan.common.parsers.Interval)

Example 14 with Interval

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

the class OpenDeclaration method getSection.

/**
 * Provides position dependent section information.
 *
 * @param document
 *                The document where the check takes place.
 * @param offset
 *                The current position of the cursor.
 * @return The type of the section for the current position of the
 *         cursor.
 */
public section_type getSection(final IDocument document, final int offset) {
    Interval interval = GlobalIntervalHandler.getInterval(document);
    if (interval == null) {
        return section_type.UNKNOWN;
    }
    for (Interval subInterval : interval.getSubIntervals()) {
        int startOffset = subInterval.getStartOffset();
        int endOffset = subInterval.getEndOffset();
        if (subInterval instanceof CfgInterval && startOffset <= offset && endOffset >= offset) {
            return ((CfgInterval) subInterval).getSectionType();
        }
    }
    return section_type.UNKNOWN;
}
Also used : CfgInterval(org.eclipse.titan.common.parsers.cfg.CfgInterval) Interval(org.eclipse.titan.common.parsers.Interval) CfgInterval(org.eclipse.titan.common.parsers.cfg.CfgInterval)

Example 15 with Interval

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

the class ConfigFoldingSupport method recursiveTokens.

@Override
protected void recursiveTokens(final Interval interval) {
    int endOffset = interval.getEndOffset();
    int startOffset = interval.getStartOffset();
    if (documentText.length() <= endOffset || documentText.length() <= startOffset) {
        return;
    } else if (endOffset == -1) {
        endOffset = documentText.length() - 1;
    }
    int distance = interval.getEndLine() - interval.getStartLine();
    if (distance >= foldingDistance) {
        char temp = documentText.charAt(startOffset);
        switch(temp) {
            case '{':
            case '[':
                if (preferencesService.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.FOLD_STATEMENT_BLOCKS, true, null)) {
                    positions.add(new Position(startOffset, endOffset - startOffset));
                }
                break;
            case '(':
                if (preferencesService.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.FOLD_PARENTHESIS, true, null)) {
                    positions.add(new Position(startOffset, endOffset - startOffset));
                }
                break;
            case '/':
                if (preferencesService.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.FOLD_COMMENTS, true, null)) {
                    positions.add(new Position(startOffset, endOffset - startOffset));
                }
                break;
            default:
                break;
        }
    }
    for (Interval subIntervall : interval.getSubIntervals()) {
        recursiveTokens(subIntervall);
    }
}
Also used : Position(org.eclipse.jface.text.Position) 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