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;
}
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;
}
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);
}
}
}
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);
}
}
}
}
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()]);
}
}
Aggregations