Search in sources :

Example 36 with Location

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

the class ChangeCreator method insertField.

public int insertField(final TTCN3_Set_Seq_Choice_BaseType ss, final ILocateableNode node, final MultiTextEdit rootEdit, int vmLen) {
    final Location nodeLocation = node.getLocation();
    final int noc = ss.getNofComponents();
    if (settings.getPosition() < noc) {
        vmLen += 6;
        final ILocateableNode cf = (ILocateableNode) ss.getComponentByIndex(settings.getPosition());
        final Location l = new Location(nodeLocation.getFile(), nodeLocation.getLine(), cf.getLocation().getOffset(), cf.getLocation().getEndOffset() + vmLen);
        rootEdit.addChild(new InsertEdit(l.getOffset(), settings.getType() + " " + settings.getId().getTtcnName() + ", \n  "));
    } else {
        vmLen += 5;
        final ILocateableNode cf = (ILocateableNode) ss.getComponentByIndex(noc - 1);
        final Location l = new Location(nodeLocation.getFile(), nodeLocation.getLine(), cf.getLocation().getEndOffset(), cf.getLocation().getEndOffset() + vmLen);
        rootEdit.addChild(new InsertEdit(l.getOffset() - 1, ",\n  " + settings.getType() + " " + settings.getId().getTtcnName()));
    }
    return vmLen;
}
Also used : InsertEdit(org.eclipse.text.edits.InsertEdit) ILocateableNode(org.eclipse.titan.designer.AST.ILocateableNode) Location(org.eclipse.titan.designer.AST.Location)

Example 37 with Location

use of org.eclipse.titan.designer.AST.Location 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;
    }
    final DefinitionVisitor vis = new DefinitionVisitor();
    module.accept(vis);
    final List<FormalParameter> nodes = vis.getLocations();
    // Calculate edit locations
    final List<Location> locations = new ArrayList<Location>();
    try {
        final WorkspaceJob job1 = calculateEditLocations(nodes, toVisit, locations);
        job1.join();
    } catch (InterruptedException ie) {
        ErrorReporter.logExceptionStackTrace(ie);
    } catch (CoreException ce) {
        ErrorReporter.logError("LazyficationRefactoring: " + "CoreException while calculating edit locations in " + toVisit.getName() + ".");
        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);
    for (Location l : locations) {
        rootEdit.addChild(new InsertEdit(l.getOffset(), "@lazy "));
    }
    return tfc;
}
Also used : FormalParameter(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter) InsertEdit(org.eclipse.text.edits.InsertEdit) ArrayList(java.util.ArrayList) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange) 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 38 with Location

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

the class DCListener method doubleClick.

@Override
public void doubleClick(final DoubleClickEvent event) {
    if (event.getSelection() instanceof IStructuredSelection) {
        final Object o = ((IStructuredSelection) event.getSelection()).getFirstElement();
        Location loc = null;
        if (o instanceof Module) {
            loc = ((Module) o).getLocation();
            LocationHighlighter.jumpToLocation(loc);
        }
    }
}
Also used : IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Module(org.eclipse.titan.designer.AST.Module) Location(org.eclipse.titan.designer.AST.Location)

Example 39 with Location

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

the class IfInsteadAltguard method process.

@Override
public void process(final IVisitableNode node, final Problems problems) {
    if (node instanceof AltGuard) {
        final AltGuard ag = (AltGuard) node;
        final StatementBlock statements = ag.getStatementBlock();
        if (statements != null && !statements.isEmpty()) {
            final Statement firstStatement = statements.getStatementByIndex(0);
            if (firstStatement instanceof If_Statement) {
                final Value condition = ((If_Statement) firstStatement).getIfClauses().getClauses().get(0).getExpression();
                Location reportAt;
                if (condition != null) {
                    reportAt = condition.getLocation();
                } else {
                    reportAt = firstStatement.getLocation();
                }
                problems.report(reportAt, MIGHT_ALTGUARD);
            }
        }
    }
}
Also used : AltGuard(org.eclipse.titan.designer.AST.TTCN3.statements.AltGuard) Statement(org.eclipse.titan.designer.AST.TTCN3.statements.Statement) If_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.If_Statement) Value(org.eclipse.titan.designer.AST.Value) If_Statement(org.eclipse.titan.designer.AST.TTCN3.statements.If_Statement) StatementBlock(org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock) Location(org.eclipse.titan.designer.AST.Location)

Example 40 with Location

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

the class TTCNPPEditor method updateInactiveCodeAnnotations.

public void updateInactiveCodeAnnotations(final List<Location> inactiveCodeLocations) {
    if ((inactiveCodeLocations == null || inactiveCodeLocations.isEmpty()) && (inactiveCodeAnnotations == null || inactiveCodeAnnotations.length == 0)) {
        return;
    }
    IEditorInput editorInput = getEditorInput();
    if (editorInput == null) {
        return;
    }
    IDocumentProvider documentProvider = getDocumentProvider();
    if (documentProvider == null) {
        return;
    }
    IAnnotationModel annotationModel = documentProvider.getAnnotationModel(editorInput);
    if (annotationModel == null) {
        return;
    }
    Object lockObject = (annotationModel instanceof ISynchronizable) ? ((ISynchronizable) annotationModel).getLockObject() : annotationModel;
    synchronized (lockObject) {
        Map<Annotation, Position> annotationMap = new HashMap<Annotation, Position>();
        if (inactiveCodeLocations != null) {
            for (Location loc : inactiveCodeLocations) {
                Annotation annotationToAdd = new Annotation(INACTIVE_CODE_ANNOTATION_TYPE, false, "Inactive code");
                Position position = new Position(loc.getOffset(), loc.getEndOffset() - loc.getOffset());
                annotationMap.put(annotationToAdd, position);
            }
        }
        if (annotationModel instanceof IAnnotationModelExtension) {
            ((IAnnotationModelExtension) annotationModel).replaceAnnotations(inactiveCodeAnnotations, annotationMap);
        } else {
            if (inactiveCodeAnnotations != null) {
                for (Annotation annotationToRemove : inactiveCodeAnnotations) {
                    annotationModel.removeAnnotation(annotationToRemove);
                }
            }
            for (Map.Entry<Annotation, Position> entry : annotationMap.entrySet()) {
                annotationModel.addAnnotation(entry.getKey(), entry.getValue());
            }
        }
        inactiveCodeAnnotations = annotationMap.keySet().toArray(new Annotation[annotationMap.keySet().size()]);
    }
}
Also used : Position(org.eclipse.jface.text.Position) HashMap(java.util.HashMap) ISynchronizable(org.eclipse.jface.text.ISynchronizable) IAnnotationModelExtension(org.eclipse.jface.text.source.IAnnotationModelExtension) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) Annotation(org.eclipse.jface.text.source.Annotation) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) Map(java.util.Map) HashMap(java.util.HashMap) IEditorInput(org.eclipse.ui.IEditorInput) Location(org.eclipse.titan.designer.AST.Location)

Aggregations

Location (org.eclipse.titan.designer.AST.Location)109 Identifier (org.eclipse.titan.designer.AST.Identifier)24 ReParseException (org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException)24 NULL_Location (org.eclipse.titan.designer.AST.NULL_Location)21 IIdentifierReparser (org.eclipse.titan.designer.parsers.ttcn3parser.IIdentifierReparser)18 IdentifierReparser (org.eclipse.titan.designer.parsers.ttcn3parser.IdentifierReparser)18 Module (org.eclipse.titan.designer.AST.Module)16 ArrayList (java.util.ArrayList)15 IFile (org.eclipse.core.resources.IFile)13 HashMap (java.util.HashMap)11 Reference (org.eclipse.titan.designer.AST.Reference)10 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)10 Assignment (org.eclipse.titan.designer.AST.Assignment)9 IDocument (org.eclipse.jface.text.IDocument)8 InsertEdit (org.eclipse.text.edits.InsertEdit)8 ILocateableNode (org.eclipse.titan.designer.AST.ILocateableNode)8 CoreException (org.eclipse.core.runtime.CoreException)7 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)7 TITANMarker (org.eclipse.titan.common.parsers.TITANMarker)7 Definition (org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)7