Search in sources :

Example 91 with Module

use of org.eclipse.titan.designer.AST.Module in project titan.EclipsePlug-ins by eclipse.

the class ChangeCreator method createFileChange.

private Change createFileChange(final IFile toVisit) {
    if (toVisit == null) {
        return null;
    }
    final ProjectSourceParser sourceParser = GlobalParser.getProjectSourceParser(toVisit.getProject());
    final Module module = sourceParser.containedModule(toVisit);
    if (module == null) {
        return null;
    }
    // find all locations in the module that should be edited
    final DefinitionVisitor vis = new DefinitionVisitor();
    module.accept(vis);
    final NavigableSet<Definition> nodes = vis.getLocations();
    if (nodes.isEmpty()) {
        return null;
    }
    // calculate edit locations
    final List<Definition> locations = new ArrayList<Definition>();
    try {
        final WorkspaceJob job1 = calculateEditLocations(nodes, toVisit, locations);
        job1.join();
    } catch (InterruptedException ie) {
        ErrorReporter.logExceptionStackTrace(ie);
    } catch (CoreException ce) {
        ErrorReporter.logError("UngroupModuleparRefactoring/CreateChange.createFileChange(): " + "CoreException while calculating edit locations. ");
        ErrorReporter.logExceptionStackTrace(ce);
    }
    if (locations.isEmpty()) {
        return null;
    }
    // create a change for each edit location
    final TextFileChange tfc = new TextFileChange(toVisit.getName(), toVisit);
    final MultiTextEdit rootEdit = new MultiTextEdit();
    tfc.setEdit(rootEdit);
    int precedeOffset = -1;
    final String fileContents = loadFileContent(toVisit);
    for (Definition node : locations) {
        final Location l = node.getCumulativeDefinitionLocation();
        final Location typeLocation = node.getType(CompilationTimeStamp.getBaseTimestamp()).getLocation();
        final Location identifierLocation = node.getIdentifier().getLocation();
        if (precedeOffset != l.getOffset()) {
            precedeOffset = l.getOffset();
            final int len = l.getEndOffset() - l.getOffset();
            rootEdit.addChild(new DeleteEdit(l.getOffset(), len + 1));
        }
        String typeText = fileContents.substring(typeLocation.getOffset(), typeLocation.getEndOffset()).trim();
        String name = fileContents.substring(identifierLocation.getOffset(), identifierLocation.getEndOffset()).trim();
        String newModulePar = "";
        if (node instanceof Def_ModulePar) {
            Def_ModulePar modulePar = (Def_ModulePar) node;
            if (modulePar.getDefaultValue() != null) {
                final Location valueLocation = modulePar.getDefaultValue().getLocation();
                String valueText = fileContents.substring(valueLocation.getOffset(), valueLocation.getEndOffset()).trim();
                newModulePar = "modulepar " + typeText + " " + name + " := " + valueText + ";\n";
            } else {
                newModulePar = "modulepar " + typeText + " " + name + ";\n";
            }
        } else if (node instanceof Def_ModulePar_Template) {
            Def_ModulePar_Template modulePar = (Def_ModulePar_Template) node;
            if (modulePar.getDefaultTemplate() != null) {
                final Location valueLocation = modulePar.getDefaultTemplate().getLocation();
                String temlateText = fileContents.substring(valueLocation.getOffset(), valueLocation.getEndOffset()).trim();
                newModulePar = "modulepar template " + typeText + " " + name + " := " + temlateText + ";\n";
            } else {
                newModulePar = "modulepar template " + typeText + " " + name + ";\n";
            }
        }
        rootEdit.addChild(new InsertEdit(l.getOffset(), newModulePar));
    }
    return tfc;
}
Also used : InsertEdit(org.eclipse.text.edits.InsertEdit) Def_ModulePar_Template(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ModulePar_Template) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) ArrayList(java.util.ArrayList) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) Def_ModulePar(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ModulePar) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange) DeleteEdit(org.eclipse.text.edits.DeleteEdit) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) CoreException(org.eclipse.core.runtime.CoreException) Module(org.eclipse.titan.designer.AST.Module) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) Location(org.eclipse.titan.designer.AST.Location)

Example 92 with Module

use of org.eclipse.titan.designer.AST.Module 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 93 with Module

use of org.eclipse.titan.designer.AST.Module 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 94 with Module

use of org.eclipse.titan.designer.AST.Module 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 95 with Module

use of org.eclipse.titan.designer.AST.Module in project titan.EclipsePlug-ins by eclipse.

the class OutlinePage method refresh.

public void refresh() {
    Control control = getControl();
    if (control.isDisposed()) {
        return;
    }
    control.setRedraw(false);
    Module module = getModule();
    if (getTreeViewer().getInput() == module) {
        getTreeViewer().refresh();
        getTreeViewer().expandToLevel(2);
    } else {
        getTreeViewer().setInput(getModule());
    }
    control.setRedraw(true);
}
Also used : Control(org.eclipse.swt.widgets.Control) Module(org.eclipse.titan.designer.AST.Module)

Aggregations

Module (org.eclipse.titan.designer.AST.Module)130 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)51 ArrayList (java.util.ArrayList)37 TTCN3Module (org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module)36 IFile (org.eclipse.core.resources.IFile)32 Assignment (org.eclipse.titan.designer.AST.Assignment)22 Identifier (org.eclipse.titan.designer.AST.Identifier)21 Location (org.eclipse.titan.designer.AST.Location)16 Reference (org.eclipse.titan.designer.AST.Reference)16 ImportModule (org.eclipse.titan.designer.AST.TTCN3.definitions.ImportModule)16 HashMap (java.util.HashMap)14 List (java.util.List)13 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)11 IPreferencesService (org.eclipse.core.runtime.preferences.IPreferencesService)11 IProject (org.eclipse.core.resources.IProject)10 IResource (org.eclipse.core.resources.IResource)10 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)10 Assignments (org.eclipse.titan.designer.AST.Assignments)9 Scope (org.eclipse.titan.designer.AST.Scope)9 TextSelection (org.eclipse.jface.text.TextSelection)8