Search in sources :

Example 1 with Expected

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();
    }
}
Also used : Expected(name.graf.emanuel.testfileeditor.model.node.Expected) Position(org.eclipse.jface.text.Position) Node(name.graf.emanuel.testfileeditor.model.node.Node) ArrayList(java.util.ArrayList) Test(name.graf.emanuel.testfileeditor.model.node.Test) TestFile(name.graf.emanuel.testfileeditor.model.TestFile) TestFile(name.graf.emanuel.testfileeditor.model.TestFile) File(name.graf.emanuel.testfileeditor.model.node.File) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 2 with Expected

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();
}
Also used : Expected(name.graf.emanuel.testfileeditor.model.node.Expected) Position(org.eclipse.jface.text.Position) Selection(name.graf.emanuel.testfileeditor.model.node.Selection) Language(name.graf.emanuel.testfileeditor.model.node.Language) Test(name.graf.emanuel.testfileeditor.model.node.Test) Class(name.graf.emanuel.testfileeditor.model.node.Class) IFile(org.eclipse.core.resources.IFile) File(name.graf.emanuel.testfileeditor.model.node.File) IDocument(org.eclipse.jface.text.IDocument)

Aggregations

Expected (name.graf.emanuel.testfileeditor.model.node.Expected)2 File (name.graf.emanuel.testfileeditor.model.node.File)2 Test (name.graf.emanuel.testfileeditor.model.node.Test)2 IDocument (org.eclipse.jface.text.IDocument)2 Position (org.eclipse.jface.text.Position)2 ArrayList (java.util.ArrayList)1 TestFile (name.graf.emanuel.testfileeditor.model.TestFile)1 Class (name.graf.emanuel.testfileeditor.model.node.Class)1 Language (name.graf.emanuel.testfileeditor.model.node.Language)1 Node (name.graf.emanuel.testfileeditor.model.node.Node)1 Selection (name.graf.emanuel.testfileeditor.model.node.Selection)1 IFile (org.eclipse.core.resources.IFile)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1