use of name.graf.emanuel.testfileeditor.model.node.Expected in project ch.hsr.ifs.cdttesting by IFS-HSR.
the class VirtualLineNumberRuler method update.
@Override
public void update(final Observable o, final Object arg) {
if (o instanceof TestFile) {
final List<Integer> startLineNumbers = new ArrayList<>();
final List<Integer> endLineNumbers = new ArrayList<>();
final TestFile file = (TestFile) o;
final IDocument document = getEditor().getDocumentProvider().getDocument(getEditor().getEditorInput());
final Test[] tests = file.getTests();
try {
for (final Test test : tests) {
final Node[] files = test.getChildren();
Position nodePosition = test.getPosition();
int realLine = document.getLineOfOffset(nodePosition.offset);
endLineNumbers.add(realLine + 1);
for (final Node testNode : files) {
nodePosition = testNode.getPosition();
realLine = document.getLineOfOffset(nodePosition.offset) + 1;
if (testNode instanceof File) {
final String name = testNode.toString();
if (name.endsWith(".cpp") || name.endsWith(".h") || name.endsWith(".hpp")) {
startLineNumbers.add(realLine);
} else {
endLineNumbers.add(realLine);
}
} else if (testNode instanceof Expected) {
startLineNumbers.add(realLine);
} else {
endLineNumbers.add(realLine);
}
}
}
} catch (final BadLocationException e) {
e.printStackTrace();
}
modelLineToRulerLineMap.clear();
int largestNumber = 0;
final int lines = document.getNumberOfLines() + 1;
boolean inFile = false;
int rulerLine = 1;
for (int line = 1; line < lines; ++line) {
if (startLineNumbers.contains(line)) {
inFile = true;
rulerLine = 1;
continue;
} else if (endLineNumbers.contains(line)) {
inFile = false;
} else if (inFile) {
if (rulerLine > largestNumber) {
largestNumber = rulerLine;
}
modelLineToRulerLineMap.put(line - 1, rulerLine++);
}
}
maxDigits = Integer.toString(largestNumber).length();
redraw();
}
}
use of name.graf.emanuel.testfileeditor.model.node.Expected in project ch.hsr.ifs.cdttesting by IFS-HSR.
the class TestFile method doParse.
private void doParse() throws BadLocationException, BadPositionCategoryException, CoreException {
final IDocument document = fProvider.getDocument(fInput);
final int NOF_LINES = document.getNumberOfLines();
fTests.clear();
fProblems.clear();
cleanMarkers();
Test currentTest = null;
Test previousTest = null;
File currentFile = null;
File previousFile = null;
ParseState currentState = ParseState.INIT;
int currentSelectionStart = 0;
for (int currentLine = 0; currentLine < NOF_LINES; ++currentLine) {
final int lineOffset = document.getLineOffset(currentLine);
final int lineLength = document.getLineLength(currentLine);
final String lineContent = document.get(lineOffset, lineLength);
if (lineContent.length() > 3) {
switch(lineContent.substring(0, Tokens.TOKENLENGTH)) {
case Tokens.TEST:
final Position headPos_TEST = new Position(lineOffset, lineLength);
final Position pos_TEST = new Position(lineOffset, document.getLength() - lineOffset);
document.addPosition(PARTITION_TEST_NAME, headPos_TEST);
currentTest = new Test(lineContent.trim().substring(Tokens.TOKENLENGTH), pos_TEST, headPos_TEST, this);
if (previousTest != null) {
previousTest.getPosition().setLength(lineOffset - previousTest.getPosition().getOffset());
}
previousTest = currentTest;
if (fTests.contains(currentTest)) {
final Problem duplicateTest = new DuplicateTest(currentTest.toString(), currentLine + 1, headPos_TEST);
reportProblem(duplicateTest);
fProblems.add(new DuplicateTest(currentTest.toString(), currentLine + 1, headPos_TEST));
} else {
fTests.add(currentTest);
}
currentState = ParseState.TEST;
break;
case Tokens.LANGUAGE:
if (previousFile != null) {
previousFile.getPosition().setLength(lineOffset - previousFile.getPosition().getOffset());
previousFile = null;
}
if (currentTest != null) {
final Position pos_LANG = new Position(lineOffset, lineLength);
document.addPosition(PARTITION_TEST_LANGUAGE, pos_LANG);
currentTest.setLang(new Language(lineContent.trim().substring(Tokens.TOKENLENGTH), pos_LANG, currentTest));
}
break;
case Tokens.EXPECTED:
if (previousFile != null) {
previousFile.getPosition().setLength(lineOffset - previousFile.getPosition().getOffset());
previousFile = null;
}
switch(currentState) {
case SELECTION:
final Position pos_SEL_OPEN = new Position(currentSelectionStart, lineOffset - currentSelectionStart);
document.addPosition(PARTITION_TEST_EXPECTED, pos_SEL_OPEN);
currentFile.setSelection(new Selection(pos_SEL_OPEN, currentFile));
currentState = ParseState.FILE;
case FILE:
if (currentTest != null) {
final Position pos_FILE = new Position(lineOffset, lineLength);
document.addPosition(PARTITION_TEST_EXPECTED, pos_FILE);
currentTest.setExpected(new Expected(currentTest, lineContent.trim().substring(Tokens.TOKENLENGTH), pos_FILE));
}
break;
default:
}
break;
case Tokens.FILE:
if (currentTest != null) {
if (currentState == ParseState.SELECTION) {
final Position pos_SEL_OPEN = new Position(currentSelectionStart, lineOffset - currentSelectionStart);
document.addPosition(PARTITION_TEST_SELECTION, pos_SEL_OPEN);
currentFile.setSelection(new Selection(pos_SEL_OPEN, currentFile));
}
final Position headPos_FILE = new Position(lineOffset, lineLength);
final Position pos_FILE = new Position(lineOffset, lineLength);
document.addPosition(PARTITION_TEST_FILE, headPos_FILE);
currentFile = new File(lineContent.trim().substring(Tokens.TOKENLENGTH), pos_FILE, headPos_FILE, currentTest);
if (previousFile != null) {
previousFile.getPosition().setLength(lineOffset - previousFile.getPosition().getOffset());
}
previousFile = currentFile;
currentTest.addFile(currentFile);
currentState = ParseState.FILE;
}
break;
case Tokens.CLASS:
if (previousFile != null) {
previousFile.getPosition().setLength(lineOffset - previousFile.getPosition().getOffset());
previousFile = null;
}
if (currentState == ParseState.TEST) {
final Position pos_CLASS = new Position(lineOffset, lineLength);
document.addPosition(PARTITION_TEST_CLASS, pos_CLASS);
currentTest.setClassname(new Class(lineContent.trim().substring(Tokens.TOKENLENGTH), pos_CLASS, currentTest));
}
break;
case Tokens.SELECTION_OPEN:
if (currentState == ParseState.FILE) {
currentState = ParseState.SELECTION;
currentSelectionStart = lineOffset + lineContent.indexOf(Tokens.SELECTION_OPEN);
}
break;
}
}
if (lineContent.contains(Tokens.SELECTION_CLOSE) && currentState == ParseState.SELECTION) {
final Position pos_SEL_CLOSE = new Position(currentSelectionStart, lineOffset + lineContent.indexOf(Tokens.SELECTION_CLOSE) - currentSelectionStart);
document.addPosition(PARTITION_TEST_SELECTION, pos_SEL_CLOSE);
currentFile.setSelection(new Selection(pos_SEL_CLOSE, currentFile));
currentState = ParseState.FILE;
}
}
setChanged();
}
Aggregations