use of org.eclipse.titan.designer.AST.ILocateableNode 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.ILocateableNode 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;
}
if (selection instanceof Def_Type) {
final Def_Type df = (Def_Type) selection;
type = df.getType(CompilationTimeStamp.getBaseTimestamp());
}
final DefinitionVisitor vis = new DefinitionVisitor(type);
module.accept(vis);
final NavigableSet<ILocateableNode> nodes = vis.getLocations();
if (nodes.isEmpty()) {
return null;
}
final TextFileChange tfc = new TextFileChange(toVisit.getName(), toVisit);
final MultiTextEdit rootEdit = new MultiTextEdit();
try {
final WorkspaceJob job1 = calculateEditLocations(nodes, toVisit, rootEdit);
job1.join();
} catch (InterruptedException ie) {
ErrorReporter.logExceptionStackTrace(ie);
} catch (CoreException ce) {
ErrorReporter.logError("InsertFieldRefactoring/CreateChange.createFileChange(): " + "CoreException while calculating edit locations. ");
ErrorReporter.logExceptionStackTrace(ce);
}
if (!rootEdit.hasChildren()) {
return null;
}
tfc.setEdit(rootEdit);
return tfc;
}
use of org.eclipse.titan.designer.AST.ILocateableNode in project titan.EclipsePlug-ins by eclipse.
the class ChangeCreator method createTextEdit.
private TextEdit[] createTextEdit(final IFile toVisit, final String fileContent, final Edit e, final Map<Edit, InsertEdit> editsDone) {
// check for multi-declaration statement
if (e.declSt.isMultiDeclaration()) {
final Location cutLoc = calculateMultiDeclarationCutLoc(fileContent, e.declSt);
final String moveContent = calculateMultiDeclarationMoveContent(fileContent, e.declSt);
// remove stmt from multi-declaration
e.declSt.removeFromMultiDeclaration();
// create remove edit
final int cutLen = cutLoc.getEndOffset() - cutLoc.getOffset();
final TextEdit cut = new DeleteEdit(cutLoc.getOffset(), cutLen);
// create insert edit
InsertEdit insert = null;
if (!e.isRemoveEdit()) {
// update insert location if the insertionPoint stmt was moved
int insertOffset = ((ILocateableNode) e.insertionPoint.getAstNode()).getLocation().getOffset();
for (Map.Entry<Edit, InsertEdit> ed : editsDone.entrySet()) {
if (ed.getKey().declSt.equals(e.insertionPoint)) {
insertOffset = ed.getValue().getOffset();
break;
}
}
//
insertOffset = findLineBeginningOffset(fileContent, insertOffset);
insert = new InsertEdit(insertOffset, moveContent);
editsDone.put(e, insert);
}
if (insert != null) {
return new TextEdit[] { insert, cut };
}
return new TextEdit[] { cut };
} else {
//
final Location cutLoc = findStatementLocation(fileContent, ((ILocateableNode) e.declSt.getAstNode()).getLocation(), true);
InsertEdit insert = null;
if (!e.isRemoveEdit()) {
final Location copyLoc = findStatementLocation(fileContent, ((ILocateableNode) e.declSt.getAstNode()).getLocation(), false);
// update insert location if the insertionPoint stmt was moved
final Location insPLoc = ((ILocateableNode) e.insertionPoint.getAstNode()).getLocation();
int insertOffset = insPLoc.getOffset();
for (Map.Entry<Edit, InsertEdit> ed : editsDone.entrySet()) {
if (ed.getKey().declSt.equals(e.insertionPoint)) {
insertOffset = ed.getValue().getOffset();
break;
}
}
//
final int prefixStartOffset = findLineBeginningOffset(fileContent, insertOffset);
final String insertText = fileContent.substring(copyLoc.getOffset(), copyLoc.getEndOffset()) + "\n";
String insertPrefix = fileContent.substring(prefixStartOffset, insertOffset);
// if prefix is not whitespace only, do not use the prefix
if (!insertPrefix.trim().equals("")) {
insertPrefix = "";
}
insert = new InsertEdit(prefixStartOffset, insertPrefix + insertText);
editsDone.put(e, insert);
}
final int cutLen = cutLoc.getEndOffset() - cutLoc.getOffset();
final TextEdit cut = new DeleteEdit(cutLoc.getOffset(), cutLen);
// System.err.println("DeleteEdit: " + fileContent.substring(cutLoc.getOffset(), cutLoc.getEndOffset()));
if (insert != null) {
return new TextEdit[] { insert, cut };
}
return new TextEdit[] { cut };
}
}
use of org.eclipse.titan.designer.AST.ILocateableNode in project titan.EclipsePlug-ins by eclipse.
the class StatementNode method toString.
@Override
public String toString() {
final StringBuilder sb = new StringBuilder();
sb.append("SN(").append(astNode.toString()).append("), loc: ");
if (astNode instanceof ILocateableNode) {
final Location loc = ((ILocateableNode) astNode).getLocation();
sb.append(loc.getOffset()).append('-').append(loc.getEndOffset()).append(';');
} else {
sb.append("<none>;");
}
sb.append(" parent: ");
if (parent == null) {
sb.append("<null>; ");
} else {
sb.append("BN(").append(parent.astNode.toString()).append("); ");
}
if (moved) {
sb.append("MOVED; ");
}
if (isDeclaration()) {
sb.append("declaration: " + declaredVar);
}
return sb.toString();
}
use of org.eclipse.titan.designer.AST.ILocateableNode in project titan.EclipsePlug-ins by eclipse.
the class FindDefinitionAction method doFindDefinition.
private void doFindDefinition() {
final DefinitionListSelectionDialog dialog = new DefinitionListSelectionDialog(Display.getDefault().getActiveShell(), new DefinitionLabelProvider(), getCurrentProject());
dialog.setTitle("Find Definition");
dialog.setMessage("Type the name of a definition");
dialog.setHelpAvailable(false);
if (targetEditor instanceof TTCN3Editor) {
selection = ((TTCN3Editor) targetEditor).getSelectionProvider().getSelection();
}
if (selection instanceof TextSelection && !selection.isEmpty()) {
final IPreferencesService prefs = Platform.getPreferencesService();
final boolean reportDebugInformation = prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null);
if (reportDebugInformation) {
TITANDebugConsole.println("text selected: " + ((TextSelection) selection).getText());
}
final TextSelection tSelection = (TextSelection) selection;
dialog.setFilter(tSelection.getText());
}
dialog.init();
if (dialog.open() == Window.CANCEL || dialog.getFirstResult() == null) {
return;
}
final Object result = dialog.getFirstResult();
if (!(result instanceof ILocateableNode)) {
return;
}
showInEditor((ILocateableNode) result);
}
Aggregations