use of org.eclipse.titan.common.parsers.Interval 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.common.parsers.Interval 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;
}
use of org.eclipse.titan.common.parsers.Interval in project titan.EclipsePlug-ins by eclipse.
the class SmartIndentAfterNewLineAutoEditStrategy method smartIndentAfterNewLine.
/**
* Smart indentation after new line characters. This method handles two
* cases. First when the new line character is preceded by a closing
* bracket. In this case the new line will be appended by the same
* whitespace characters as in the line where the corresponding opening
* bracket is. In the second case when an other arbitrary character is
* followed by the new line the indentation of the current line is
* copied to the new line.
*
* @param document
* - the document being parsed
* @param command
* - the command being performed
*/
protected void smartIndentAfterNewLine(final IDocument document, final DocumentCommand command) {
int docLength = document.getLength();
if (command.offset == -1 || docLength == 0) {
return;
}
try {
int p = command.offset == docLength ? command.offset - 1 : command.offset;
int line = document.getLineOfOffset(p);
final StringBuilder builder = new StringBuilder(command.text);
String lineDelimeter = document.getLineDelimiter(line);
if (lineDelimeter == null) {
lineDelimeter = "";
}
// if the carret needs to be shifted we have to
// calculate with the new line originally in the buffer
int carretShiftSize = lineDelimeter.length();
String lineIndent = getIndentOfLine(document, line, command);
builder.append(lineIndent);
carretShiftSize += lineIndent.length();
int start = document.getLineOffset(line);
int end = start + document.getLineLength(line) - command.text.length();
// will be tabulated.
if (containsUnclosedInterval(start, command.offset)) {
Interval endInterval = rootInterval.getSmallestEnclosingInterval(command.offset);
// and if we found an interval just beginning
if (endInterval.getDepth() <= 1 || endInterval.getStartOffset() == command.offset) {
command.text = builder.toString();
return;
}
builder.append(indentString);
carretShiftSize += indentString.length();
}
boolean willInsertClosingBracket = preferenceStore.getBoolean(PreferenceConstants.CLOSE_BRACES) && canStatementBlockBeOpen(document, command.offset);
// Insert the bracket moving new line and indentation
if (preferenceStore.getBoolean(PreferenceConstants.AUTOMATICALLY_MOVE_BRACES) && (willInsertClosingBracket || containsUnopenedInterval(command.offset, end))) {
builder.append(lineDelimeter + lineIndent);
command.caretOffset = command.offset + carretShiftSize;
command.shiftsCaret = false;
}
// insert the closing bracket if needed
if (willInsertClosingBracket) {
builder.append('}');
}
command.text = builder.toString();
} catch (BadLocationException e) {
ErrorReporter.logExceptionStackTrace(e);
}
}
use of org.eclipse.titan.common.parsers.Interval in project titan.EclipsePlug-ins by eclipse.
the class FoldingSupport method recursiveTokens.
protected void recursiveTokens(final Interval interval) {
int endOffset = interval.getEndOffset();
if (documentText.length() <= endOffset || documentText.length() <= interval.getStartOffset()) {
return;
} else if (endOffset == -1) {
endOffset = documentText.length() - 1;
}
if (endOffset <= interval.getStartOffset()) {
ErrorReporter.INTERNAL_ERROR();
return;
}
int endline = interval.getEndLine();
if (endline > lastLineIndex) {
return;
} else if (endline == -1) {
endline = lastLineIndex;
}
int distance = endline - interval.getStartLine();
if (distance >= foldingDistance) {
switch(documentText.charAt(interval.getStartOffset())) {
case '{':
if (preferencesService.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.FOLD_STATEMENT_BLOCKS, true, null)) {
positions.add(new Position(interval.getStartOffset(), endOffset - interval.getStartOffset()));
}
break;
case '(':
if (preferencesService.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.FOLD_PARENTHESIS, true, null)) {
positions.add(new Position(interval.getStartOffset(), endOffset - interval.getStartOffset()));
}
break;
case '/':
case '#':
if (preferencesService.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.FOLD_COMMENTS, true, null)) {
positions.add(new Position(interval.getStartOffset(), endOffset - interval.getStartOffset()));
}
break;
default:
break;
}
}
for (Interval subIntervall : interval.getSubIntervals()) {
recursiveTokens(subIntervall);
}
}
use of org.eclipse.titan.common.parsers.Interval in project titan.EclipsePlug-ins by eclipse.
the class GeneralPairMatcher method matchPairs.
/**
* The function really doing the pair matching work.
*
* @return wheather it could find a matching bracket or not.
*/
public final boolean matchPairs() {
char currBracket;
try {
currBracket = document.getChar(offset);
} catch (BadLocationException e) {
ErrorReporter.logExceptionStackTrace(e);
return false;
}
Interval interval = GlobalIntervalHandler.getInterval(document);
int temp;
for (int i = 0; i < pairs.length; i++) {
if (pairs[i].end == currBracket) {
endPos = offset;
anchor = ICharacterPairMatcher.RIGHT;
if (interval != null) {
temp = interval.getPairLocation(offset);
if (temp != -1) {
startPos = temp;
return true;
}
}
return findStartingBracket(pairs[i]);
} else if (pairs[i].start == currBracket) {
startPos = offset;
anchor = ICharacterPairMatcher.LEFT;
if (interval != null) {
temp = interval.getPairLocation(offset);
if (temp != -1) {
endPos = temp;
return true;
}
}
return findEndingBracket(pairs[i]);
}
}
return false;
}
Aggregations