Search in sources :

Example 1 with Language

use of name.graf.emanuel.testfileeditor.model.node.Language 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

Class (name.graf.emanuel.testfileeditor.model.node.Class)1 Expected (name.graf.emanuel.testfileeditor.model.node.Expected)1 File (name.graf.emanuel.testfileeditor.model.node.File)1 Language (name.graf.emanuel.testfileeditor.model.node.Language)1 Selection (name.graf.emanuel.testfileeditor.model.node.Selection)1 Test (name.graf.emanuel.testfileeditor.model.node.Test)1 IFile (org.eclipse.core.resources.IFile)1 IDocument (org.eclipse.jface.text.IDocument)1 Position (org.eclipse.jface.text.Position)1