Search in sources :

Example 36 with ProjectSourceParser

use of org.eclipse.titan.designer.parsers.ProjectSourceParser in project titan.EclipsePlug-ins by eclipse.

the class ContentAssistProcessor method computeCompletionProposals.

// FIXME add semantic check guard on project level.
@Override
public ICompletionProposal[] computeCompletionProposals(final ITextViewer viewer, final int offset) {
    if (editor == null) {
        return new ICompletionProposal[] {};
    }
    IFile file = (IFile) editor.getEditorInput().getAdapter(IFile.class);
    if (file == null) {
        return new ICompletionProposal[] {};
    }
    IDocument doc = viewer.getDocument();
    TTCN3ReferenceParser refParser = new TTCN3ReferenceParser(true);
    Reference ref = refParser.findReferenceForCompletion(file, offset, doc);
    if (ref == null || ref.getSubreferences().isEmpty()) {
        return new ICompletionProposal[] {};
    }
    Scope scope = null;
    ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
    Module tempModule = projectSourceParser.containedModule(file);
    String moduleName = null;
    if (tempModule != null) {
        moduleName = tempModule.getName();
        scope = tempModule.getSmallestEnclosingScope(refParser.getReplacementOffset());
        ref.setMyScope(scope);
        ref.detectModid();
    }
    IPreferencesService prefs = Platform.getPreferencesService();
    if (prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null)) {
        TITANDebugConsole.println("parsed the reference: " + ref);
    }
    TemplateContextType contextType = new TemplateContextType(TTCN3CodeSkeletons.CONTEXT_IDENTIFIER, TTCN3CodeSkeletons.CONTEXT_NAME);
    ProposalCollector propCollector = new ProposalCollector(Identifier_type.ID_TTCN, TTCN3CodeSkeletons.CONTEXT_IDENTIFIER, contextType, doc, ref, refParser.getReplacementOffset());
    propCollector.setProjectParser(projectSourceParser);
    if (moduleName == null) {
        // rootless behavior
        if (ref.getModuleIdentifier() == null) {
            Set<String> moduleNames = projectSourceParser.getKnownModuleNames();
            Module module;
            for (String name : moduleNames) {
                module = projectSourceParser.getModuleByName(name);
                if (module != null) {
                    propCollector.addProposal(name, name, ImageCache.getImage("ttcn.gif"), TTCN3Module.MODULE);
                    module.getAssignments().addProposal(propCollector);
                }
            }
        } else {
            Module module = projectSourceParser.getModuleByName(ref.getModuleIdentifier().getName());
            if (module != null) {
                module.getAssignments().addProposal(propCollector);
            }
        }
    } else {
        /*
			 * search for the best scope in the module's scope
			 * hierarchy and call proposal adding function on the
			 * found scope instead of what can be found here
			 */
        if (scope != null) {
            scope.addProposal(propCollector);
        }
    }
    propCollector.sortTillMarked();
    propCollector.markPosition();
    if (ref.getSubreferences().size() != 1) {
        if (PreferenceConstantValues.SORT_ALPHABETICALLY.equals(sortingpolicy)) {
            propCollector.sortAll();
        }
        return propCollector.getCompletitions();
    }
    Set<String> knownModuleNames = projectSourceParser.getKnownModuleNames();
    for (String knownModuleName : knownModuleNames) {
        Identifier tempIdentifier = new Identifier(Identifier_type.ID_NAME, knownModuleName);
        Module tempModule2 = projectSourceParser.getModuleByName(knownModuleName);
        propCollector.addProposal(tempIdentifier, ImageCache.getImage(tempModule2.getOutlineIcon()), "module");
    }
    propCollector.sortTillMarked();
    propCollector.markPosition();
    if (ref.getModuleIdentifier() == null) {
        if (scope == null) {
            TTCN3CodeSkeletons.addSkeletonProposals(doc, refParser.getReplacementOffset(), propCollector);
        } else {
            scope.addSkeletonProposal(propCollector);
        }
        propCollector.addTemplateProposal("refers", new Template("refers( function/altstep/testcase name )", "", propCollector.getContextIdentifier(), "refers( ${fatName} );", false), TTCN3CodeSkeletons.SKELETON_IMAGE);
        propCollector.addTemplateProposal("derefers", new Template("derefers( function/altstep/testcase name )(parameters)", "", propCollector.getContextIdentifier(), "derefers( ${fatName} ) ( ${parameters} );", false), TTCN3CodeSkeletons.SKELETON_IMAGE);
        propCollector.sortTillMarked();
        propCollector.markPosition();
        TTCN3CodeSkeletons.addPredefinedSkeletonProposals(doc, refParser.getReplacementOffset(), propCollector);
        if (scope == null) {
            TTCN3Keywords.addKeywordProposals(propCollector);
        } else {
            scope.addKeywordProposal(propCollector);
        }
        propCollector.sortTillMarked();
        propCollector.markPosition();
    } else {
        if (scope == null || !(scope instanceof StatementBlock)) {
            if (PreferenceConstantValues.SORT_ALPHABETICALLY.equals(sortingpolicy)) {
                propCollector.sortAll();
            }
            return propCollector.getCompletitions();
        }
        String fakeModule = ref.getModuleIdentifier().getName();
        if ("any component".equals(fakeModule) || "all component".equals(fakeModule)) {
            Component_Type.addAnyorAllProposal(propCollector, 0);
        } else if ("any port".equals(fakeModule) || "all port".equals(fakeModule)) {
            PortTypeBody.addAnyorAllProposal(propCollector, 0);
        } else if ("any timer".equals(fakeModule) || "all timer".equals(fakeModule)) {
            Timer.addAnyorAllProposal(propCollector, 0);
        }
    }
    if (PreferenceConstantValues.SORT_ALPHABETICALLY.equals(sortingpolicy)) {
        propCollector.sortAll();
    }
    return propCollector.getCompletitions();
}
Also used : IFile(org.eclipse.core.resources.IFile) Reference(org.eclipse.titan.designer.AST.Reference) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService) Template(org.eclipse.jface.text.templates.Template) ProposalCollector(org.eclipse.titan.designer.editors.ProposalCollector) Identifier(org.eclipse.titan.designer.AST.Identifier) Scope(org.eclipse.titan.designer.AST.Scope) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) Module(org.eclipse.titan.designer.AST.Module) TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module) TemplateContextType(org.eclipse.jface.text.templates.TemplateContextType) IDocument(org.eclipse.jface.text.IDocument) StatementBlock(org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock)

Example 37 with ProjectSourceParser

use of org.eclipse.titan.designer.parsers.ProjectSourceParser in project titan.EclipsePlug-ins by eclipse.

the class ReconcilingStrategy method reconcile.

@Override
public void reconcile(final DirtyRegion dirtyRegion, final IRegion subRegion) {
    if (editor == null || document == null) {
        return;
    }
    int lineBreaks = 0;
    try {
        if (DirtyRegion.INSERT.equals(dirtyRegion.getType())) {
            actualCode.insert(dirtyRegion.getOffset(), dirtyRegion.getText());
            lineBreaks = org.eclipse.titan.designer.editors.ttcn3editor.ReconcilingStrategy.calculateLineBreaks(dirtyRegion.getText(), document.getLegalLineDelimiters());
        } else {
            lineBreaks = org.eclipse.titan.designer.editors.ttcn3editor.ReconcilingStrategy.calculateLineBreaks(actualCode.substring(dirtyRegion.getOffset(), dirtyRegion.getOffset() + dirtyRegion.getLength()), document.getLegalLineDelimiters());
            actualCode.delete(dirtyRegion.getOffset(), dirtyRegion.getOffset() + dirtyRegion.getLength());
        }
    } catch (StringIndexOutOfBoundsException e) {
        ErrorReporter.logExceptionStackTrace(e);
        ErrorReporter.logError("String length: " + actualCode.length() + " region type: " + dirtyRegion.getType() + " region offset: " + dirtyRegion.getOffset() + " region length: " + dirtyRegion.getLength() + " region text: '" + dirtyRegion.getText() + "'\n" + "Actual size of the document: " + document.get().length());
        actualCode = new StringBuilder(document.get());
    }
    if (dirtyRegion.getOffset() == 0 && document.getLength() == dirtyRegion.getLength()) {
        // thing
        if (!editor.isDirty()) {
            return;
        }
        IPreferencesService prefs = Platform.getPreferencesService();
        if (prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.USEONTHEFLYPARSING, true, null)) {
            analyze(false);
        }
        return;
    }
    int firstLine;
    try {
        firstLine = document.getLineOfOffset(dirtyRegion.getOffset());
    } catch (BadLocationException e) {
        ErrorReporter.logWarningExceptionStackTrace(e);
        firstLine = 0;
    }
    final IFile editedFile = (IFile) editor.getEditorInput().getAdapter(IFile.class);
    if (editedFile == null) {
        return;
    }
    final TTCN3ReparseUpdater reparser;
    int length = dirtyRegion.getLength();
    if (DirtyRegion.INSERT.equals(dirtyRegion.getType())) {
        reparser = new TTCN3ReparseUpdater(editedFile, actualCode.toString(), firstLine + 1, lineBreaks, dirtyRegion.getOffset(), dirtyRegion.getOffset(), length);
    } else {
        reparser = new TTCN3ReparseUpdater(editedFile, actualCode.toString(), firstLine + 1, -1 * lineBreaks, dirtyRegion.getOffset(), dirtyRegion.getOffset() + length, -1 * length);
    }
    final IProject project = editedFile.getProject();
    if (project == null) {
        return;
    }
    final ProjectSourceParser sourceParser = GlobalParser.getProjectSourceParser(project);
    sourceParser.updateSyntax(editedFile, reparser);
    if (!editor.isSemanticCheckingDelayed()) {
        sourceParser.analyzeAll();
        WorkspaceJob op = new WorkspaceJob(OUTLINEUPDATE) {

            @Override
            public IStatus runInWorkspace(final IProgressMonitor monitor) {
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        List<Position> positions = (new TTCN3FoldingSupport()).calculatePositions(document);
                        editor.updateFoldingStructure(positions);
                        editor.refreshOutlinePage();
                    }
                });
                return Status.OK_STATUS;
            }
        };
        op.setPriority(Job.LONG);
        op.setSystem(true);
        op.setUser(false);
        op.setProperty(IProgressConstants.ICON_PROPERTY, ImageCache.getImageDescriptor("titan.gif"));
        op.setRule(project);
        op.schedule();
    } else {
        sourceParser.reportSyntacticOutdatingOnly(editedFile);
        sourceParser.analyzeAllOnlySyntactically();
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService) IProject(org.eclipse.core.resources.IProject) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TTCN3ReparseUpdater(org.eclipse.titan.designer.parsers.ttcn3parser.TTCN3ReparseUpdater) List(java.util.List) TTCN3FoldingSupport(org.eclipse.titan.designer.editors.ttcn3editor.TTCN3FoldingSupport) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 38 with ProjectSourceParser

use of org.eclipse.titan.designer.parsers.ProjectSourceParser in project titan.EclipsePlug-ins by eclipse.

the class ReconcilingStrategy method analyze.

public void analyze(final boolean isInitial) {
    final IFile editedFile = (IFile) editor.getEditorInput().getAdapter(IFile.class);
    if (editedFile == null || ResourceExclusionHelper.isExcluded(editedFile)) {
        return;
    }
    IProject project = editedFile.getProject();
    if (project == null) {
        return;
    }
    Display.getDefault().asyncExec(new Runnable() {

        @Override
        public void run() {
            List<Position> positions = (new TTCN3FoldingSupport()).calculatePositions(document);
            getEditor().updateFoldingStructure(positions);
        }
    });
    final ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(project);
    if (isInitial || !editor.isSemanticCheckingDelayed()) {
        projectSourceParser.reportOutdating(editedFile);
        projectSourceParser.analyzeAll();
        WorkspaceJob op = new WorkspaceJob(OUTLINEUPDATE) {

            @Override
            public IStatus runInWorkspace(final IProgressMonitor monitor) {
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        if (!MarkerHandler.hasMarker(GeneralConstants.ONTHEFLY_SYNTACTIC_MARKER, editedFile)) {
                            getEditor().updateOutlinePage();
                        }
                        Module module = projectSourceParser.containedModule(editedFile);
                        if (module != null && module instanceof TTCN3Module) {
                            final List<Location> icList = ((TTCN3Module) module).getInactiveCodeLocations();
                            getEditor().updateInactiveCodeAnnotations(icList);
                        }
                    }
                });
                return Status.OK_STATUS;
            }
        };
        op.setPriority(Job.LONG);
        op.setSystem(true);
        op.setUser(false);
        op.setProperty(IProgressConstants.ICON_PROPERTY, ImageCache.getImageDescriptor("titan.gif"));
        op.setRule(project);
        op.schedule();
    } else {
        projectSourceParser.reportSyntacticOutdatingOnly(editedFile);
        projectSourceParser.analyzeAllOnlySyntactically();
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module) IFile(org.eclipse.core.resources.IFile) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) List(java.util.List) TTCN3FoldingSupport(org.eclipse.titan.designer.editors.ttcn3editor.TTCN3FoldingSupport) Module(org.eclipse.titan.designer.AST.Module) TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module) IProject(org.eclipse.core.resources.IProject) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser)

Example 39 with ProjectSourceParser

use of org.eclipse.titan.designer.parsers.ProjectSourceParser in project titan.EclipsePlug-ins by eclipse.

the class OpenDeclaration method doOpenDeclaration.

private final void doOpenDeclaration() {
    if (targetEditor == null || !(targetEditor instanceof TTCNPPEditor)) {
        return;
    }
    targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(null);
    IFile file = (IFile) targetEditor.getEditorInput().getAdapter(IFile.class);
    if (file == null) {
        targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(FILENOTIDENTIFIABLE);
        return;
    }
    if (!TITANNature.hasTITANNature(file.getProject())) {
        targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(TITANNature.NO_TITAN_FILE_NATURE_FOUND);
        return;
    }
    if (ResourceExclusionHelper.isExcluded(file)) {
        MessageDialog.openError(null, "Open Declaration does not work within excluded resources", "This module is excluded from build. To use the Open Declaration " + "feature please click on the 'Toggle exclude from build state' in the context menu of the Project Explorer. ");
        return;
    }
    IPreferencesService prefs = Platform.getPreferencesService();
    boolean reportDebugInformation = prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null);
    int offset;
    if (!selection.isEmpty() && selection instanceof TextSelection && !"".equals(((TextSelection) selection).getText())) {
        if (reportDebugInformation) {
            TITANDebugConsole.println("text selected: " + ((TextSelection) selection).getText());
        }
        TextSelection tSelection = (TextSelection) selection;
        offset = tSelection.getOffset() + tSelection.getLength();
    } else {
        offset = ((TTCNPPEditor) targetEditor).getCarretOffset();
    }
    ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
    final Module module = projectSourceParser.containedModule(file);
    if (module == null) {
        if (reportDebugInformation) {
            TITANDebugConsole.println("Can not find the module.");
        }
        return;
    }
    IdentifierFinderVisitor visitor = new IdentifierFinderVisitor(offset);
    module.accept(visitor);
    final Declaration decl = visitor.getReferencedDeclaration();
    if (decl == null) {
        if (reportDebugInformation) {
            TITANDebugConsole.println("No visible elements found");
        }
        return;
    }
    selectAndRevealDeclaration(decl.getIdentifier().getLocation());
}
Also used : TTCNPPEditor(org.eclipse.titan.designer.editors.ttcnppeditor.TTCNPPEditor) IFile(org.eclipse.core.resources.IFile) IdentifierFinderVisitor(org.eclipse.titan.designer.declarationsearch.IdentifierFinderVisitor) TextSelection(org.eclipse.jface.text.TextSelection) Declaration(org.eclipse.titan.designer.declarationsearch.Declaration) Module(org.eclipse.titan.designer.AST.Module) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser)

Example 40 with ProjectSourceParser

use of org.eclipse.titan.designer.parsers.ProjectSourceParser in project titan.EclipsePlug-ins by eclipse.

the class OpenDeclaration method doOpenDeclaration.

private final void doOpenDeclaration() {
    if (targetEditor == null || !(targetEditor instanceof TTCN3Editor)) {
        return;
    }
    targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(null);
    IFile file = (IFile) targetEditor.getEditorInput().getAdapter(IFile.class);
    if (file == null) {
        targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(FILENOTIDENTIFIABLE);
        return;
    }
    if (!TITANNature.hasTITANNature(file.getProject())) {
        targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(TITANNature.NO_TITAN_FILE_NATURE_FOUND);
        return;
    }
    if (ResourceExclusionHelper.isExcluded(file)) {
        MessageDialog.openError(null, "Open Declaration does not work within excluded resources", "This module is excluded from build. To use the Open Declaration " + "feature please click on the 'Toggle exclude from build state' in the context menu of the Project Explorer. ");
        return;
    }
    IPreferencesService prefs = Platform.getPreferencesService();
    boolean reportDebugInformation = prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null);
    int offset;
    if (selection instanceof TextSelection && !selection.isEmpty() && !"".equals(((TextSelection) selection).getText())) {
        if (reportDebugInformation) {
            TITANDebugConsole.println("text selected: " + ((TextSelection) selection).getText());
        }
        TextSelection tSelection = (TextSelection) selection;
        offset = tSelection.getOffset() + tSelection.getLength();
    } else {
        offset = ((TTCN3Editor) targetEditor).getCarretOffset();
    }
    ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
    final Module module = projectSourceParser.containedModule(file);
    if (module == null) {
        if (reportDebugInformation) {
            TITANDebugConsole.println("The file " + file.getLocation() + "does not seem to contain a valid module.");
            CompilationTimeStamp timestamp = projectSourceParser.getLastTimeChecked();
            if (timestamp == null) {
                TITANDebugConsole.println("The project " + file.getProject() + " was not yet analyzed semantically");
            } else {
                TITANDebugConsole.println("The project " + file.getProject() + " was last checked in " + projectSourceParser.getLastTimeChecked().toString());
            }
        }
        return;
    }
    IdentifierFinderVisitor visitor = new IdentifierFinderVisitor(offset);
    module.accept(visitor);
    final Declaration decl = visitor.getReferencedDeclaration();
    if (decl == null) {
        if (reportDebugInformation) {
            TITANDebugConsole.println("No visible elements found");
        }
        return;
    }
    selectAndRevealDeclaration(decl.getIdentifier().getLocation());
    return;
}
Also used : TTCN3Editor(org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor) IFile(org.eclipse.core.resources.IFile) IdentifierFinderVisitor(org.eclipse.titan.designer.declarationsearch.IdentifierFinderVisitor) TextSelection(org.eclipse.jface.text.TextSelection) CompilationTimeStamp(org.eclipse.titan.designer.parsers.CompilationTimeStamp) Declaration(org.eclipse.titan.designer.declarationsearch.Declaration) Module(org.eclipse.titan.designer.AST.Module) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser)

Aggregations

ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)72 Module (org.eclipse.titan.designer.AST.Module)51 IFile (org.eclipse.core.resources.IFile)34 ArrayList (java.util.ArrayList)23 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)23 IProject (org.eclipse.core.resources.IProject)19 TTCN3Module (org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module)14 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)12 IPreferencesService (org.eclipse.core.runtime.preferences.IPreferencesService)11 Identifier (org.eclipse.titan.designer.AST.Identifier)11 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)10 Location (org.eclipse.titan.designer.AST.Location)10 List (java.util.List)9 Reference (org.eclipse.titan.designer.AST.Reference)9 ImportModule (org.eclipse.titan.designer.AST.TTCN3.definitions.ImportModule)9 CoreException (org.eclipse.core.runtime.CoreException)8 TextSelection (org.eclipse.jface.text.TextSelection)8 TextFileChange (org.eclipse.ltk.core.refactoring.TextFileChange)8 HashMap (java.util.HashMap)7 HashSet (java.util.HashSet)7