Search in sources :

Example 1 with TestFile

use of name.graf.emanuel.testfileeditor.model.TestFile in project ch.hsr.ifs.cdttesting by IFS-HSR.

the class Editor method createSourceViewer.

@Override
protected ISourceViewer createSourceViewer(final Composite parent, final IVerticalRuler ruler, final int styles) {
    final ISourceViewer viewer = new ProjectionViewer(parent, ruler, getOverviewRuler(), isOverviewRulerVisible(), styles);
    getSourceViewerDecorationSupport(viewer);
    final IEditorInput input = getEditorInput();
    final IDocument document = getDocumentProvider().getDocument(input);
    file = new TestFile((FileEditorInput) input, getDocumentProvider());
    file.parse();
    document.addDocumentListener(new IDocumentListener() {

        @Override
        public void documentChanged(final DocumentEvent event) {
            file.parse();
        }

        @Override
        public void documentAboutToBeChanged(final DocumentEvent event) {
        }
    });
    return viewer;
}
Also used : TestFile(name.graf.emanuel.testfileeditor.model.TestFile) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IDocumentListener(org.eclipse.jface.text.IDocumentListener) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) ProjectionViewer(org.eclipse.jface.text.source.projection.ProjectionViewer) DocumentEvent(org.eclipse.jface.text.DocumentEvent) IEditorInput(org.eclipse.ui.IEditorInput) IDocument(org.eclipse.jface.text.IDocument)

Example 2 with TestFile

use of name.graf.emanuel.testfileeditor.model.TestFile 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 3 with TestFile

use of name.graf.emanuel.testfileeditor.model.TestFile in project ch.hsr.ifs.cdttesting by IFS-HSR.

the class VirtualLineNumberRuler method createControl.

@Override
public Control createControl(final CompositeRuler parentRuler, final Composite parentControl) {
    fparentRuler = parentRuler;
    textWidget = parentRuler.getTextViewer();
    final TestFile file = textEditor.getAdapter(TestFile.class);
    file.addObserver(this);
    update(file, null);
    final RGB foreground = getColor(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER_COLOR);
    final RGB background = getColor(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND);
    setForeground(EditorsPlugin.getDefault().getSharedTextColors().getColor(foreground));
    setBackground(EditorsPlugin.getDefault().getSharedTextColors().getColor(background));
    final Control fCanvas = super.createControl(parentRuler, parentControl);
    fMouseHandler = new MouseHandler();
    fCanvas.addMouseListener(fMouseHandler);
    fCanvas.addMouseMoveListener(fMouseHandler);
    fCanvas.addMouseWheelListener(fMouseHandler);
    return fCanvas;
}
Also used : Control(org.eclipse.swt.widgets.Control) TestFile(name.graf.emanuel.testfileeditor.model.TestFile) RGB(org.eclipse.swt.graphics.RGB)

Example 4 with TestFile

use of name.graf.emanuel.testfileeditor.model.TestFile in project ch.hsr.ifs.cdttesting by IFS-HSR.

the class JumpToRTSHandler method jump.

private void jump() {
    if (className != null) {
        IType cls = null;
        try {
            cls = project.findType(className);
        } catch (JavaModelException e) {
            return;
        }
        try {
            IFile file = project.getProject().getFile(getTestFileName(cls));
            IWorkbench workbench = PlatformUI.getWorkbench();
            IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
            FileEditorInput input = new FileEditorInput(file);
            IDocumentProvider provider = new TextFileDocumentProvider();
            provider.connect(input);
            IDocument document = provider.getDocument(input);
            TestFile testFile = new TestFile(input, provider);
            testFile.parse();
            IEditorDescriptor defaultEditor = workbench.getEditorRegistry().getDefaultEditor(file.getName());
            String editorId = defaultEditor.getId();
            if (!className.equals(testName)) {
                for (Test test : testFile.getTests()) {
                    if (test.toString().equals(testName)) {
                        int line = document.getLineOfOffset(test.getPosition().getOffset());
                        IMarker lineMarker = file.createMarker(IMarker.TEXT);
                        lineMarker.setAttribute(IMarker.LINE_NUMBER, line + 1);
                        lineMarker.setAttribute(IDE.EDITOR_ID_ATTR, editorId);
                        IDE.openEditor(page, lineMarker);
                        lineMarker.delete();
                        return;
                    }
                }
            } else {
                IDE.openEditor(page, file);
            }
        } catch (CoreException | BadLocationException | NullPointerException e) {
            e.printStackTrace();
            MessageDialog.openError(shell, "Jump to RTS", "Failed to find associated RTS file.");
        }
    }
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) IFile(org.eclipse.core.resources.IFile) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) TextFileDocumentProvider(org.eclipse.ui.editors.text.TextFileDocumentProvider) IType(org.eclipse.jdt.core.IType) IWorkbench(org.eclipse.ui.IWorkbench) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) CoreException(org.eclipse.core.runtime.CoreException) Test(name.graf.emanuel.testfileeditor.model.node.Test) FileEditorInput(org.eclipse.ui.part.FileEditorInput) TestFile(name.graf.emanuel.testfileeditor.model.TestFile) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IMarker(org.eclipse.core.resources.IMarker) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

TestFile (name.graf.emanuel.testfileeditor.model.TestFile)4 IDocument (org.eclipse.jface.text.IDocument)3 Test (name.graf.emanuel.testfileeditor.model.node.Test)2 BadLocationException (org.eclipse.jface.text.BadLocationException)2 FileEditorInput (org.eclipse.ui.part.FileEditorInput)2 ArrayList (java.util.ArrayList)1 Expected (name.graf.emanuel.testfileeditor.model.node.Expected)1 File (name.graf.emanuel.testfileeditor.model.node.File)1 Node (name.graf.emanuel.testfileeditor.model.node.Node)1 IFile (org.eclipse.core.resources.IFile)1 IMarker (org.eclipse.core.resources.IMarker)1 CoreException (org.eclipse.core.runtime.CoreException)1 IType (org.eclipse.jdt.core.IType)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 DocumentEvent (org.eclipse.jface.text.DocumentEvent)1 IDocumentListener (org.eclipse.jface.text.IDocumentListener)1 Position (org.eclipse.jface.text.Position)1 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)1 ProjectionViewer (org.eclipse.jface.text.source.projection.ProjectionViewer)1 RGB (org.eclipse.swt.graphics.RGB)1