Search in sources :

Example 56 with ProjectSourceParser

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

the class OccurencesMarker method doMark.

private void doMark(final IDocument document, final int offset) {
    IAnnotationModel annotationModel = getAnnotationModel();
    if (annotationModel == null) {
        removeOccurences(false);
        error(document, offset, "AnnotationModel is null");
        return;
    }
    IFile file = (IFile) editor.getEditorInput().getAdapter(IFile.class);
    if (file == null) {
        removeOccurences(false);
        error(document, offset, "can not determine the file in the editor.");
        return;
    }
    ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
    if (projectSourceParser == null) {
        removeOccurences(false);
        error(document, offset, "Can not find the projectsourceparser for the project: " + file.getProject());
        return;
    }
    final Module module = projectSourceParser.containedModule(file);
    if (module == null) {
        removeOccurences(false);
        error(document, offset, "The module can not be found in the project.");
        return;
    }
    if (printASTElem.getValue()) {
        ASTLocationChainVisitor locVisitor = new ASTLocationChainVisitor(offset);
        module.accept(locVisitor);
        locVisitor.printChain();
    }
    final Reference reference = getReferenceParser().findReferenceForOpening(file, offset, document);
    if (reference == null) {
        removeOccurences(false);
        // "The reference can not be parsed.");
        return;
    }
    final Location referenceLocaton = reference.getLocation();
    if (referenceLocaton.getOffset() == referenceLocaton.getEndOffset()) {
        removeOccurences(false);
        return;
    }
    // if (reportDebugInformation) {
    // ASTLocationConsistencyVisitor visitor = new
    // ASTLocationConsistencyVisitor(document,
    // module.get_moduletype()==Module.module_type.TTCN3_MODULE);
    // module.accept(visitor);
    // }
    final List<Hit> result = findOccurrences(document, reference, module, offset);
    if (result.isEmpty()) {
        return;
    }
    Map<Annotation, Position> annotationMap = new HashMap<Annotation, Position>();
    for (Hit hit : result) {
        if (hit.identifier != null) {
            int hitOffset = hit.identifier.getLocation().getOffset();
            int hitEndOffset = hit.identifier.getLocation().getEndOffset();
            if (hitOffset >= 0 && hitEndOffset >= 0 && hitEndOffset >= hitOffset) {
                final Annotation annotationToAdd = new Annotation(ANNOTATION_TYPE, false, hit.identifier.getDisplayName());
                final Position position = new Position(hitOffset, hitEndOffset - hitOffset);
                annotationMap.put(annotationToAdd, position);
            }
        }
    }
    synchronized (getLockObject(annotationModel)) {
        if (annotationModel instanceof IAnnotationModelExtension) {
            ((IAnnotationModelExtension) annotationModel).replaceAnnotations(occurrenceAnnotations, annotationMap);
        } else {
            if (occurrenceAnnotations != null) {
                for (Annotation annotationToRemove : occurrenceAnnotations) {
                    annotationModel.removeAnnotation(annotationToRemove);
                }
            }
            for (Map.Entry<Annotation, Position> entry : annotationMap.entrySet()) {
                annotationModel.addAnnotation(entry.getKey(), entry.getValue());
            }
        }
        occurrenceAnnotations = annotationMap.keySet().toArray(new Annotation[annotationMap.keySet().size()]);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) Position(org.eclipse.jface.text.Position) HashMap(java.util.HashMap) Reference(org.eclipse.titan.designer.AST.Reference) IAnnotationModelExtension(org.eclipse.jface.text.source.IAnnotationModelExtension) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) Annotation(org.eclipse.jface.text.source.Annotation) Hit(org.eclipse.titan.designer.AST.ReferenceFinder.Hit) ASTLocationChainVisitor(org.eclipse.titan.designer.AST.ASTLocationChainVisitor) Module(org.eclipse.titan.designer.AST.Module) HashMap(java.util.HashMap) Map(java.util.Map) Location(org.eclipse.titan.designer.AST.Location)

Example 57 with ProjectSourceParser

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

the class T3Doc method getCommentStringBasedOnReference.

public static String getCommentStringBasedOnReference(final DeclarationCollector declarationCollector, final List<DeclarationCollectionHelper> collected, final IEditorPart targetEditor, final IRegion hoverRegion, final IReferenceParser referenceParser, final ITextViewer textViewer) {
    if (!T3Doc.isT3DocEnable()) {
        return null;
    }
    Reference ref = declarationCollector.getReference();
    if (ref == null) {
        return null;
    }
    if ((ref.getMyScope() instanceof NamedBridgeScope || ref.getMyScope() instanceof FormalParameterList) && !collected.isEmpty()) {
        DeclarationCollectionHelper declaration = collected.get(0);
        if (declaration.node instanceof TTCN3_Sequence_Type || declaration.node instanceof FormalParameter) {
            final IFile file = (IFile) targetEditor.getEditorInput().getAdapter(IFile.class);
            ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
            final Module tempModule = projectSourceParser.containedModule(file);
            Assignment ass = tempModule.getEnclosingAssignment(hoverRegion.getOffset());
            if (ass != null) {
                Reference reference = referenceParser.findReferenceForOpening(file, hoverRegion.getOffset(), textViewer.getDocument());
                String str = reference.getDisplayName();
                List<String> al = T3Doc.getCommentStrings(ass.getCommentLocation(), str);
                if (!al.isEmpty()) {
                    final StringBuilder sb = new StringBuilder();
                    for (String string : al) {
                        sb.append(string);
                    }
                    return sb.toString();
                }
            }
        }
    }
    return null;
}
Also used : FormalParameter(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter) IFile(org.eclipse.core.resources.IFile) Reference(org.eclipse.titan.designer.AST.Reference) TTCN3_Sequence_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Sequence_Type) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) DeclarationCollectionHelper(org.eclipse.titan.designer.editors.actions.DeclarationCollectionHelper) Assignment(org.eclipse.titan.designer.AST.Assignment) FormalParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList) NamedBridgeScope(org.eclipse.titan.designer.AST.NamedBridgeScope) Module(org.eclipse.titan.designer.AST.Module) TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module)

Example 58 with ProjectSourceParser

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

the class ASN1Editor method doSave.

@Override
public void doSave(final IProgressMonitor progressMonitor) {
    final IFile file = (IFile) getEditorInput().getAdapter(IFile.class);
    if (file != null) {
        FileSaveTracker.fileBeingSaved(file);
    }
    super.doSave(progressMonitor);
    if (file != null && isSemanticCheckingDelayed()) {
        final WorkspaceJob op = new WorkspaceJob("Reconciliation on save") {

            @Override
            public IStatus runInWorkspace(final IProgressMonitor monitor) {
                ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
                projectSourceParser.reportOutdating(file);
                strategy.analyze(true);
                return Status.OK_STATUS;
            }
        };
        op.setPriority(Job.LONG);
        op.setSystem(true);
        op.setUser(false);
        op.setProperty(IProgressConstants.ICON_PROPERTY, ImageCache.getImageDescriptor("titan.gif"));
        op.schedule();
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IFile(org.eclipse.core.resources.IFile) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser)

Example 59 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 ASN1Editor)) {
        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 = ((ASN1Editor) targetEditor).getCarretOffset();
    }
    ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
    final Module module = projectSourceParser.containedModule(file);
    if (module == null) {
        // TODO: How could this happen??? (NPE occured)
        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 : ASN1Editor(org.eclipse.titan.designer.editors.asn1editor.ASN1Editor) 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 60 with ProjectSourceParser

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

the class RenameRefactoring method runAction.

/**
 * Helper function used by RenameRefactoringAction classes for TTCN-3,
 * ASN.1 and TTCNPP editors
 */
public static void runAction(final IEditorPart targetEditor, final ISelection selection) {
    final IStatusLineManager statusLineManager = targetEditor.getEditorSite().getActionBars().getStatusLineManager();
    statusLineManager.setErrorMessage(null);
    final IFile file = (IFile) targetEditor.getEditorInput().getAdapter(IFile.class);
    if (file == null) {
        statusLineManager.setErrorMessage(FILENOTIDENTIFIABLE);
        return;
    }
    if (!TITANNature.hasTITANNature(file.getProject())) {
        statusLineManager.setErrorMessage(TITANNature.NO_TITAN_FILE_NATURE_FOUND);
        return;
    }
    final IPreferencesService prefs = Platform.getPreferencesService();
    final 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.getConsole().newMessageStream().println("text selected: " + ((TextSelection) selection).getText());
        }
        TextSelection tSelection = (TextSelection) selection;
        offset = tSelection.getOffset() + tSelection.getLength();
    } else {
        offset = ((IEditorWithCarretOffset) targetEditor).getCarretOffset();
    }
    // run semantic analysis to have up-to-date AST
    // FIXME: it does not work for incremental parsing
    final ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
    final WorkspaceJob job = projectSourceParser.analyzeAll();
    if (job == null) {
        if (reportDebugInformation) {
            TITANDebugConsole.getConsole().newMessageStream().println("Rename refactoring: WorkspaceJob to analyze project could not be created.");
        }
        return;
    }
    try {
        job.join();
    } catch (InterruptedException e) {
        ErrorReporter.logExceptionStackTrace(e);
        return;
    }
    // find the module
    if (ResourceExclusionHelper.isExcluded(file)) {
        targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(MessageFormat.format(EXCLUDEDFROMBUILD, file.getFullPath()));
        return;
    }
    final Module module = projectSourceParser.containedModule(file);
    if (module == null) {
        statusLineManager.setErrorMessage(MessageFormat.format(NOTFOUNDMODULE, file.getName()));
        return;
    }
    ReferenceFinder rf = findOccurrencesLocationBased(module, offset);
    if (rf == null) {
        rf = new ReferenceFinder();
        boolean isDetected = rf.detectAssignmentDataByOffset(module, offset, targetEditor, true, reportDebugInformation);
        if (!isDetected) {
            return;
        }
    }
    RenameRefactoring renameRefactoring = new RenameRefactoring(file, module, rf);
    RenameRefactoringWizard renameWizard = new RenameRefactoringWizard(renameRefactoring);
    RefactoringWizardOpenOperation operation = new RefactoringWizardOpenOperation(renameWizard);
    try {
        operation.run(targetEditor.getEditorSite().getShell(), "");
    } catch (InterruptedException irex) {
        // operation was canceled
        if (reportDebugInformation) {
            TITANDebugConsole.getConsole().newMessageStream().println("Rename refactoring has been cancelled");
        }
    } finally {
        // ===================================
        // === Re-analysis after renaming ====
        // ===================================
        Map<Module, List<Hit>> changed = rf.findAllReferences(module, file.getProject(), null, reportDebugInformation);
        final Set<Module> modules = new HashSet<Module>();
        modules.add(module);
        modules.addAll(changed.keySet());
        reanalyseAstAfterRefactoring(file.getProject(), modules);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IStatusLineManager(org.eclipse.jface.action.IStatusLineManager) TextSelection(org.eclipse.jface.text.TextSelection) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) RefactoringWizardOpenOperation(org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation) ReferenceFinder(org.eclipse.titan.designer.AST.ReferenceFinder) List(java.util.List) ArrayList(java.util.ArrayList) Module(org.eclipse.titan.designer.AST.Module) ASN1Module(org.eclipse.titan.designer.AST.ASN1.definitions.ASN1Module) HashSet(java.util.HashSet)

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