Search in sources :

Example 1 with HeuristicalIntervalDetector

use of org.eclipse.titan.designer.editors.HeuristicalIntervalDetector in project titan.EclipsePlug-ins by eclipse.

the class AbstractIndentAction method doIndent.

/**
 * Do the actual indentation work.
 */
private void doIndent() {
    if (targetEditor == null) {
        return;
    }
    final IDocument document = getDocument();
    if (null == document) {
        return;
    }
    Interval rootInterval = GlobalIntervalHandler.getInterval(document);
    if (rootInterval == null) {
        rootInterval = (new HeuristicalIntervalDetector()).buildIntervals(document);
        GlobalIntervalHandler.putInterval(document, rootInterval);
    }
    if (rootInterval == null) {
        return;
    }
    int startLine = -1;
    int endLine = -1;
    if (!selection.isEmpty()) {
        if (selection instanceof TextSelection) {
            final TextSelection tSelection = (TextSelection) selection;
            if (tSelection.getLength() != 0) {
                startLine = tSelection.getStartLine();
                endLine = tSelection.getEndLine();
            }
        }
    }
    if (startLine == -1 || endLine == -1) {
        startLine = 0;
        endLine = document.getNumberOfLines() - 1;
    }
    indentArray.clear();
    indentArray.add("");
    final int nofLines = endLine - startLine;
    int offset;
    int realOffset;
    int lineLength;
    Interval interval;
    try {
        final int regionStartOffset = document.getLineOffset(startLine);
        final int regionLength = document.getLineOffset(endLine) + document.getLineLength(endLine) - regionStartOffset;
        multiEdit = new MultiTextEdit(regionStartOffset, regionLength);
        final RewriteSessionEditProcessor processor = new RewriteSessionEditProcessor(document, multiEdit, TextEdit.UPDATE_REGIONS | TextEdit.CREATE_UNDO);
        for (int i = nofLines; i >= 0; i--) {
            lineLength = document.getLineLength(startLine + i);
            offset = document.getLineOffset(startLine + i);
            realOffset = getRealLineStart(document, offset, lineLength);
            interval = rootInterval.getSmallestEnclosingInterval(realOffset);
            final int indentLevel = lineIndentationLevel(document, realOffset, offset + lineLength, interval);
            setIndentLevel(document, document.getLineOffset(startLine + i), indentLevel);
        }
        performEdits(processor);
    } catch (BadLocationException e) {
        ErrorReporter.logExceptionStackTrace(e);
    }
    return;
}
Also used : RewriteSessionEditProcessor(org.eclipse.jface.text.RewriteSessionEditProcessor) TextSelection(org.eclipse.jface.text.TextSelection) HeuristicalIntervalDetector(org.eclipse.titan.designer.editors.HeuristicalIntervalDetector) IDocument(org.eclipse.jface.text.IDocument) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) BadLocationException(org.eclipse.jface.text.BadLocationException) Interval(org.eclipse.titan.common.parsers.Interval)

Example 2 with HeuristicalIntervalDetector

use of org.eclipse.titan.designer.editors.HeuristicalIntervalDetector in project titan.EclipsePlug-ins by eclipse.

the class ASN1ReferenceParser method referenceStartOffset.

private final int referenceStartOffset(final int offset, final IDocument document, final GeneralPairMatcher pairMatcher) throws BadLocationException {
    Interval rootInterval = GlobalIntervalHandler.getInterval(document);
    if (rootInterval == null) {
        rootInterval = (new HeuristicalIntervalDetector()).buildIntervals(document);
        GlobalIntervalHandler.putInterval(document, rootInterval);
    }
    int temporalOffset = offset;
    char currentChar = document.getChar(temporalOffset);
    Interval interval = null;
    boolean foundWhiteSpaces = false;
    boolean foundDot = false;
    while (temporalOffset > 0) {
        if (rootInterval != null) {
            interval = rootInterval.getSmallestEnclosingInterval(temporalOffset);
        }
        currentChar = document.getChar(temporalOffset);
        if (interval != null && (interval_type.SINGLELINE_COMMENT.equals(interval.getType()) || interval_type.MULTILINE_COMMENT.equals(interval.getType()))) {
            temporalOffset = interval.getStartOffset();
        } else if (currentChar == '}') {
            if (foundWhiteSpaces && !foundDot) {
                break;
            }
            foundWhiteSpaces = false;
            foundDot = false;
            IRegion pair = pairMatcher.match(document, temporalOffset + 1);
            if (pair == null) {
                return -1;
            }
            temporalOffset = pair.getOffset();
        } else if ('-' == currentChar || '_' == currentChar || Character.isLetterOrDigit(currentChar)) {
            if (foundWhiteSpaces && !foundDot) {
                break;
            }
            foundWhiteSpaces = false;
            foundDot = false;
        } else if ('.' == currentChar) {
            foundDot = true;
        } else if (' ' == currentChar || '\t' == currentChar || '\n' == currentChar || '\r' == currentChar) {
            foundWhiteSpaces = true;
        } else {
            break;
        }
        temporalOffset--;
    }
    return temporalOffset;
}
Also used : HeuristicalIntervalDetector(org.eclipse.titan.designer.editors.HeuristicalIntervalDetector) IRegion(org.eclipse.jface.text.IRegion) Interval(org.eclipse.titan.common.parsers.Interval)

Example 3 with HeuristicalIntervalDetector

use of org.eclipse.titan.designer.editors.HeuristicalIntervalDetector in project titan.EclipsePlug-ins by eclipse.

the class Configuration method getAutoEditStrategies.

@Override
public IAutoEditStrategy[] getAutoEditStrategies(final ISourceViewer sourceViewer, final String contentType) {
    HeuristicalIntervalDetector detector = new HeuristicalIntervalDetector();
    GeneralTITANAutoEditStrategy strategy2 = new ClosingBracketIndentationAutoEditStrategy();
    strategy2.setHeuristicIntervalDetector(detector);
    GeneralTITANAutoEditStrategy strategy3 = new SmartIndentAfterNewLineAutoEditStrategy();
    strategy3.setHeuristicIntervalDetector(detector);
    return new IAutoEditStrategy[] { new BracketCompletionAutoEditStrategy(), strategy2, strategy3 };
}
Also used : ClosingBracketIndentationAutoEditStrategy(org.eclipse.titan.designer.editors.ClosingBracketIndentationAutoEditStrategy) IAutoEditStrategy(org.eclipse.jface.text.IAutoEditStrategy) BracketCompletionAutoEditStrategy(org.eclipse.titan.designer.editors.BracketCompletionAutoEditStrategy) SmartIndentAfterNewLineAutoEditStrategy(org.eclipse.titan.designer.editors.ttcn3editor.SmartIndentAfterNewLineAutoEditStrategy) GeneralTITANAutoEditStrategy(org.eclipse.titan.designer.editors.GeneralTITANAutoEditStrategy) HeuristicalIntervalDetector(org.eclipse.titan.designer.editors.HeuristicalIntervalDetector)

Example 4 with HeuristicalIntervalDetector

use of org.eclipse.titan.designer.editors.HeuristicalIntervalDetector in project titan.EclipsePlug-ins by eclipse.

the class TTCN3ReferenceParser method referenceStartOffset.

private int referenceStartOffset(final int offset, final IDocument document, final GeneralPairMatcher pairMatcher) throws BadLocationException {
    Interval rootInterval = GlobalIntervalHandler.getInterval(document);
    if (rootInterval == null) {
        rootInterval = (new HeuristicalIntervalDetector()).buildIntervals(document);
        GlobalIntervalHandler.putInterval(document, rootInterval);
    }
    int temporalOffset = offset;
    char currentChar = document.getChar(temporalOffset);
    Interval interval = null;
    boolean foundWhiteSpaces = false;
    boolean foundDot = false;
    while (temporalOffset > 0) {
        if (rootInterval != null) {
            interval = rootInterval.getSmallestEnclosingInterval(temporalOffset);
        }
        currentChar = document.getChar(temporalOffset);
        if (interval != null && (interval_type.SINGLELINE_COMMENT.equals(interval.getType()) || interval_type.MULTILINE_COMMENT.equals(interval.getType()))) {
            temporalOffset = interval.getStartOffset();
        } else if (currentChar == ')' || currentChar == ']') {
            if (!foundDot) {
                break;
            }
            foundWhiteSpaces = false;
            IRegion pair = pairMatcher.match(document, temporalOffset + 1);
            if (pair == null) {
                return -1;
            }
            temporalOffset = pair.getOffset();
        } else if ('_' == currentChar || Character.isLetterOrDigit(currentChar)) {
            if (foundWhiteSpaces && !foundDot) {
                break;
            }
            foundWhiteSpaces = false;
            foundDot = false;
        } else if ('.' == currentChar) {
            foundDot = true;
        } else if (' ' == currentChar || '\t' == currentChar || '\n' == currentChar || '\r' == currentChar) {
            foundWhiteSpaces = true;
        } else if ('%' == currentChar) {
            temporalOffset--;
            break;
        } else {
            break;
        }
        temporalOffset--;
    }
    return temporalOffset;
}
Also used : HeuristicalIntervalDetector(org.eclipse.titan.designer.editors.HeuristicalIntervalDetector) IRegion(org.eclipse.jface.text.IRegion) Interval(org.eclipse.titan.common.parsers.Interval)

Example 5 with HeuristicalIntervalDetector

use of org.eclipse.titan.designer.editors.HeuristicalIntervalDetector in project titan.EclipsePlug-ins by eclipse.

the class TTCN3FoldingSupport method calculatePositions.

@Override
public List<Position> calculatePositions(final IDocument document) {
    positions.clear();
    this.lastLineIndex = document.getNumberOfLines();
    this.documentText = document.get();
    preferencesService = Platform.getPreferencesService();
    foldingDistance = preferencesService.getInt(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.FOLD_DISTANCE, 0, null);
    if (preferencesService.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.FOLDING_ENABLED, true, null)) {
        Interval interval = GlobalIntervalHandler.getInterval(document);
        if (interval == null) {
            interval = (new HeuristicalIntervalDetector()).buildIntervals(document);
            GlobalIntervalHandler.putInterval(document, interval);
        }
        for (Interval subintervall : interval.getSubIntervals()) {
            recursiveTokens(subintervall);
        }
    }
    return positions;
}
Also used : HeuristicalIntervalDetector(org.eclipse.titan.designer.editors.HeuristicalIntervalDetector) Interval(org.eclipse.titan.common.parsers.Interval)

Aggregations

HeuristicalIntervalDetector (org.eclipse.titan.designer.editors.HeuristicalIntervalDetector)7 Interval (org.eclipse.titan.common.parsers.Interval)4 IAutoEditStrategy (org.eclipse.jface.text.IAutoEditStrategy)3 BracketCompletionAutoEditStrategy (org.eclipse.titan.designer.editors.BracketCompletionAutoEditStrategy)3 ClosingBracketIndentationAutoEditStrategy (org.eclipse.titan.designer.editors.ClosingBracketIndentationAutoEditStrategy)3 GeneralTITANAutoEditStrategy (org.eclipse.titan.designer.editors.GeneralTITANAutoEditStrategy)3 IRegion (org.eclipse.jface.text.IRegion)2 SmartIndentAfterNewLineAutoEditStrategy (org.eclipse.titan.designer.editors.ttcn3editor.SmartIndentAfterNewLineAutoEditStrategy)2 BadLocationException (org.eclipse.jface.text.BadLocationException)1 IDocument (org.eclipse.jface.text.IDocument)1 RewriteSessionEditProcessor (org.eclipse.jface.text.RewriteSessionEditProcessor)1 TextSelection (org.eclipse.jface.text.TextSelection)1 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)1