use of name.graf.emanuel.testfileeditor.model.node.File 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.File in project ch.hsr.ifs.cdttesting by IFS-HSR.
the class TestFile method addMarkerLinePropertyIfNotExists.
/*
* @author tstauber
* Checks if a markerLines= property exists for this Test's //@.config file
* and creates one in case it does not exist.
* returns the additional length
*/
private int addMarkerLinePropertyIfNotExists(final Test test) throws BadLocationException {
if (test.containsFile(CONFIG_FILE_STRING)) {
final File file = test.getFile(CONFIG_FILE_STRING);
final String fileText = getDocText(file.getPosition());
final Pattern pattern = Pattern.compile(MARKER_LINES_STRING);
final Matcher matcher = pattern.matcher(fileText);
if (!matcher.find()) {
final String insertText = MARKER_LINES_STRING.concat("\n");
final int offset = file.getPosition().getOffset() + file.getHeadPosition().getLength();
fProvider.getDocument(fInput).replace(offset, 0, insertText);
final int additionalLength = insertText.length();
adjustPostitionLength(file, additionalLength);
adjustPostitionLength(test, additionalLength);
return additionalLength;
}
}
return 0;
}
use of name.graf.emanuel.testfileeditor.model.node.File in project ch.hsr.ifs.cdttesting by IFS-HSR.
the class TestFile method addVirtLineNumToMarkerLines.
/*
* @author tstauber
* Adds the relativeLineNo to the markerLines.
*/
private int addVirtLineNumToMarkerLines(final Test test, final int relativeLineNo) throws BadLocationException {
final File file = test.getFile(CONFIG_FILE_STRING);
if (file == null) {
return 0;
}
final String fileText = getDocText(file.getPosition());
final Pattern pattern = Pattern.compile(TestFile.CONFIG_TEXT_STRING_REGEX, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(fileText);
if (matcher.find()) {
final int offset = file.getPosition().getOffset() + matcher.end();
String insertText = Integer.toString(relativeLineNo);
int additionalLength = insertText.length();
if (matcher.group(3) != null) {
insertText = ",".concat(insertText);
additionalLength++;
}
fProvider.getDocument(fInput).replace(offset, 0, insertText);
adjustPostitionLength(file, additionalLength);
adjustPostitionLength(test, additionalLength);
return additionalLength;
}
return 0;
}
use of name.graf.emanuel.testfileeditor.model.node.File 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();
}
use of name.graf.emanuel.testfileeditor.model.node.File in project ch.hsr.ifs.cdttesting by IFS-HSR.
the class TestFile method insertFileIntoTest.
/*
* @author tstauber
* Checks if a markerLines= property exists for this Test's //@.config file
* and creates one in case it does not exist.
*/
private void insertFileIntoTest(final Test test, final String name, final int offsetInTestBody) throws BadLocationException {
final int insertOffset = test.getPosition().getOffset() + test.getHeadPosition().getLength() + offsetInTestBody;
final String insertText = Tokens.FILE.concat(name).concat("\n");
final Position pos = new Position(insertOffset, insertText.length());
final Position headPos = new Position(insertOffset, insertText.length());
test.addFile(new File(name, pos, headPos, test));
adjustPostitionLength(test, insertText.length());
fProvider.getDocument(fInput).replace(insertOffset, 0, insertText);
}
Aggregations