Search in sources :

Example 11 with TTCN3Module

use of org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module in project titan.EclipsePlug-ins by eclipse.

the class CycleCheck method process.

@Override
public void process(final IProject project, final Problems problems) {
    final ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(project);
    final Set<String> knownModuleNames = projectSourceParser.getKnownModuleNames();
    final List<Module> modules = new ArrayList<Module>();
    for (final String moduleName : new TreeSet<String>(knownModuleNames)) {
        modules.add(projectSourceParser.getModuleByName(moduleName));
    }
    Collections.sort(modules, new Comparator<Module>() {

        @Override
        public int compare(final Module o1, final Module o2) {
            return o1.getName().compareTo(o2.getName());
        }
    });
    final CycleCheck check = new CycleCheck(modules);
    for (final List<Module> cycle : check.cycles) {
        final StringBuilder sb = new StringBuilder("Importation cycle detected: ");
        for (final Module module : cycle) {
            sb.append(module.getName());
            sb.append(" -> ");
        }
        sb.append(cycle.get(0).getName());
        final String errMsg = sb.toString();
        // Try to find the locations to report, i.e. the import statements.
        // We handle only the case of TTCN3Module-s.
        final Iterator<Module> it = cycle.iterator();
        Module imported = it.next();
        Module importer;
        while (it.hasNext()) {
            importer = it.next();
            if (importer instanceof TTCN3Module) {
                for (final ImportModule im : ((TTCN3Module) importer).getImports()) {
                    if (im.getName().equals(imported.getName())) {
                        problems.report(im.getLocation(), errMsg);
                    }
                }
            }
            imported = importer;
        }
        importer = cycle.get(0);
        if (importer instanceof TTCN3Module) {
            for (final ImportModule im : ((TTCN3Module) importer).getImports()) {
                if (im.getName().equals(imported.getName())) {
                    problems.report(im.getLocation(), errMsg);
                }
            }
        }
    }
}
Also used : TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module) ArrayList(java.util.ArrayList) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) ImportModule(org.eclipse.titan.designer.AST.TTCN3.definitions.ImportModule) TreeSet(java.util.TreeSet) ImportModule(org.eclipse.titan.designer.AST.TTCN3.definitions.ImportModule) Module(org.eclipse.titan.designer.AST.Module) TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module)

Example 12 with TTCN3Module

use of org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module 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 13 with TTCN3Module

use of org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module in project titan.EclipsePlug-ins by eclipse.

the class AddImport method run.

@Override
public void run(final IAction action) {
    TITANDebugConsole.println("Add import called: ");
    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;
    }
    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 = ((TTCN3Editor) targetEditor).getCarretOffset();
    }
    DeclarationCollector declarationCollector = OpenDeclarationHelper.findVisibleDeclarations(targetEditor, new TTCN3ReferenceParser(false), ((TTCN3Editor) targetEditor).getDocument(), offset, false);
    if (declarationCollector == null) {
        return;
    }
    List<DeclarationCollectionHelper> collected = declarationCollector.getCollected();
    if (collected.isEmpty()) {
        // FIXME add semantic check guard on project level.
        ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
        if (reportDebugInformation) {
            TITANDebugConsole.println("No visible elements found");
        }
        for (String moduleName2 : projectSourceParser.getKnownModuleNames()) {
            Module module2 = projectSourceParser.getModuleByName(moduleName2);
            if (module2 != null) {
                // Visit each file in the project one by
                // one instead of
                // "module2.getAssignments().addDeclaration(declarationCollector)".
                Assignments assignments = module2.getAssignments();
                for (int i = 0; i < assignments.getNofAssignments(); i++) {
                    assignments.getAssignmentByIndex(i).addDeclaration(declarationCollector, 0);
                }
            }
        }
        if (declarationCollector.getCollectionSize() == 0) {
            targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(NOTTTCN3DECLARATION);
            return;
        }
        if (reportDebugInformation) {
            TITANDebugConsole.println("Elements were only found in not visible modules");
        }
        DeclarationCollectionHelper resultToInsert = null;
        if (collected.size() == 1) {
            resultToInsert = collected.get(0);
        } else {
            OpenDeclarationLabelProvider labelProvider = new OpenDeclarationLabelProvider();
            ElementListSelectionDialog dialog = new ElementListSelectionDialog(null, labelProvider);
            dialog.setTitle("Add Import");
            dialog.setMessage("Choose element to generate an import statement for.");
            dialog.setElements(collected.toArray());
            if (dialog.open() == Window.OK) {
                if (reportDebugInformation) {
                    TITANDebugConsole.getConsole().newMessageStream().println("Selected: " + dialog.getFirstResult());
                }
                resultToInsert = (DeclarationCollectionHelper) dialog.getFirstResult();
            }
        }
        if (resultToInsert == null) {
            return;
        }
        IFile newfile = (IFile) resultToInsert.location.getFile();
        Module newModule = projectSourceParser.containedModule(newfile);
        if (newModule == null) {
            targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage("Could not identify the module in file " + newfile.getName());
            return;
        }
        String ttcnName = newModule.getIdentifier().getTtcnName();
        TITANDebugConsole.println("the new module to insert: " + ttcnName);
        final IFile actualFile = (IFile) targetEditor.getEditorInput().getAdapter(IFile.class);
        Module actualModule = projectSourceParser.containedModule(actualFile);
        int insertionOffset = ((TTCN3Module) actualModule).getAssignmentsScope().getLocation().getOffset() + 1;
        MultiTextEdit multiEdit = new MultiTextEdit(insertionOffset, 0);
        RewriteSessionEditProcessor processor = new RewriteSessionEditProcessor(((TTCN3Editor) targetEditor).getDocument(), multiEdit, TextEdit.UPDATE_REGIONS | TextEdit.CREATE_UNDO);
        multiEdit.addChild(new InsertEdit(insertionOffset, "\nimport from " + ttcnName + " all;\n"));
        try {
            processor.performEdits();
        } catch (BadLocationException e) {
            ErrorReporter.logExceptionStackTrace(e);
        }
    } else {
        if (reportDebugInformation) {
            for (DeclarationCollectionHelper foundDeclaration : collected) {
                TITANDebugConsole.println("declaration:" + foundDeclaration.location.getFile() + ": " + foundDeclaration.location.getOffset() + " - " + foundDeclaration.location.getEndOffset() + " is available");
            }
        }
    }
    Display.getDefault().asyncExec(new Runnable() {

        @Override
        public void run() {
            MessageDialog.openWarning(null, "Study feature", "Adding a missing importation is still under study");
        }
    });
}
Also used : TTCN3Editor(org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor) InsertEdit(org.eclipse.text.edits.InsertEdit) IFile(org.eclipse.core.resources.IFile) DeclarationCollector(org.eclipse.titan.designer.editors.actions.DeclarationCollector) TTCN3ReferenceParser(org.eclipse.titan.designer.editors.ttcn3editor.TTCN3ReferenceParser) TextSelection(org.eclipse.jface.text.TextSelection) Assignments(org.eclipse.titan.designer.AST.Assignments) OpenDeclarationLabelProvider(org.eclipse.titan.designer.editors.actions.OpenDeclarationLabelProvider) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) DeclarationCollectionHelper(org.eclipse.titan.designer.editors.actions.DeclarationCollectionHelper) RewriteSessionEditProcessor(org.eclipse.jface.text.RewriteSessionEditProcessor) ElementListSelectionDialog(org.eclipse.ui.dialogs.ElementListSelectionDialog) Module(org.eclipse.titan.designer.AST.Module) TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 14 with TTCN3Module

use of org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module in project titan.EclipsePlug-ins by eclipse.

the class BrokenPartsChecker method definitionsChecker.

private void definitionsChecker(final Map<Module, List<Assignment>> moduleAndBrokenDefs) {
    progress.setTaskName("Semantic check");
    progress.setWorkRemaining(moduleAndBrokenDefs.size());
    for (Map.Entry<Module, List<Assignment>> entry : moduleAndBrokenDefs.entrySet()) {
        final Module module = entry.getKey();
        progress.subTask("Semantically checking broken parts in module: " + module.getName());
        if (module instanceof TTCN3Module) {
            ((TTCN3Module) module).checkWithDefinitions(compilationCounter, entry.getValue());
        } else {
            module.check(compilationCounter);
        }
        progress.worked(1);
    }
}
Also used : TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module) List(java.util.List) Module(org.eclipse.titan.designer.AST.Module) TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module) Map(java.util.Map)

Example 15 with TTCN3Module

use of org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module in project titan.EclipsePlug-ins by eclipse.

the class BrokenPartsViaReferences method processStartModules.

public void processStartModules(final List<Module> startModules, final Map<Module, List<AssignmentHandler>> moduleAndBrokenAssignments) {
    for (Module startModule : startModules) {
        if (isTooSlow()) {
            return;
        }
        if (startModule instanceof TTCN3Module && startModule.getLastCompilationTimeStamp() != null && !startModule.isCheckRoot()) {
            // definition name has not changed but module semantically has not been checked:
            final Assignments startAssignments = startModule.getAssignments();
            final List<AssignmentHandler> brokens = new ArrayList<AssignmentHandler>();
            final List<AssignmentHandler> notBrokens = new ArrayList<AssignmentHandler>();
            for (Assignment assignment : startAssignments) {
                MarkerHandler.markAllSemanticMarkersForRemoval(assignment);
            }
            for (int d = 0; d < startAssignments.getNofAssignments(); ++d) {
                final Assignment startAssignment = startAssignments.getAssignmentByIndex(d);
                final AssignmentHandler assignmentHandler = AssignmentHandlerFactory.getDefinitionHandler(startAssignment);
                startAssignment.check(timestamp);
                startAssignment.accept(assignmentHandler);
                if (startAssignment.isCheckRoot()) {
                    assignmentHandler.setIsInfected(true);
                    startAssignment.notCheckRoot();
                    assignmentHandler.addReason("Definition's infected, because of incremental parsing.");
                    brokens.add(assignmentHandler);
                } else if (assignmentHandler.getIsInfected()) {
                    assignmentHandler.addReason("Definition contains an infected reference.");
                    brokens.add(assignmentHandler);
                } else {
                    notBrokens.add(assignmentHandler);
                }
            }
            if (!brokens.isEmpty()) {
                checkLocalAssignments(brokens, notBrokens);
                if (moduleAndBrokenAssignments.containsKey(startModule)) {
                    moduleAndBrokenAssignments.get(startModule).addAll(brokens);
                } else {
                    moduleAndBrokenAssignments.put(startModule, brokens);
                }
            }
        } else {
            if (startModule.getLastCompilationTimeStamp() == null) {
                // The markers have been marked for removal only for ASN1 modules
                startModule.check(timestamp);
            }
            // puts additional markers!
            final List<AssignmentHandler> startAssignments = getAssignmentsFrom(startModule);
            for (AssignmentHandler assignmentHandler : startAssignments) {
                assignmentHandler.initStartParts();
                assignmentHandler.assignment.notCheckRoot();
                assignmentHandler.addReason("Parent module's CompilationTimeStamp is null.");
            }
            if (moduleAndBrokenAssignments.containsKey(startModule)) {
                moduleAndBrokenAssignments.get(startModule).addAll(startAssignments);
            } else {
                moduleAndBrokenAssignments.put(startModule, startAssignments);
            }
        }
        startModule.notCheckRoot();
    }
}
Also used : Undefined_Assignment(org.eclipse.titan.designer.AST.ASN1.Undefined_Assignment) ASN1Assignment(org.eclipse.titan.designer.AST.ASN1.ASN1Assignment) Assignment(org.eclipse.titan.designer.AST.Assignment) TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module) Assignments(org.eclipse.titan.designer.AST.Assignments) ArrayList(java.util.ArrayList) Module(org.eclipse.titan.designer.AST.Module) TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module)

Aggregations

TTCN3Module (org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module)22 Module (org.eclipse.titan.designer.AST.Module)17 ArrayList (java.util.ArrayList)13 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)9 ImportModule (org.eclipse.titan.designer.AST.TTCN3.definitions.ImportModule)7 IFile (org.eclipse.core.resources.IFile)6 Qualifiers (org.eclipse.titan.designer.AST.TTCN3.attributes.Qualifiers)5 SingleWithAttribute (org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute)5 HashSet (java.util.HashSet)4 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)4 Location (org.eclipse.titan.designer.AST.Location)4 List (java.util.List)3 TreeSet (java.util.TreeSet)3 IProject (org.eclipse.core.resources.IProject)3 BadLocationException (org.eclipse.jface.text.BadLocationException)3 InsertEdit (org.eclipse.text.edits.InsertEdit)3 IType (org.eclipse.titan.designer.AST.IType)3 Reference (org.eclipse.titan.designer.AST.Reference)3 AttributeSpecification (org.eclipse.titan.designer.AST.TTCN3.attributes.AttributeSpecification)3 ExtensionAttribute (org.eclipse.titan.designer.AST.TTCN3.attributes.ExtensionAttribute)3