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;
}
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;
}
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 };
}
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;
}
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;
}
Aggregations