use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.
the class SelectionFinder method createDebugInfo.
private String createDebugInfo() {
final StringBuilder sb = new StringBuilder();
sb.append("ExtractToFunctionRefactoring->SelectionFinder debug info: \n");
sb.append(" Runs on reference: ");
sb.append(runsOnRef == null ? "null" : runsOnRef.getId());
sb.append(", enclosing function: ");
if (parentFunc == null) {
sb.append("null");
} else if (parentFunc instanceof Definition) {
sb.append(((Definition) parentFunc).getIdentifier());
} else if (parentFunc instanceof ControlPart) {
sb.append("<controlpart>");
} else {
sb.append("<invalid: ").append(parentFunc).append('>');
}
sb.append('\n');
sb.append(" Return clause: ");
sb.append(returnType == null ? "null" : returnType.getIdentifier());
sb.append(" Warnings: ");
for (RefactoringStatusEntry rse : warnings) {
sb.append("severity: " + rse.getSeverity() + "; msg: " + rse.getMessage());
sb.append('\n');
}
return sb.toString();
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.
the class ChangeCreator method analyzeFunction.
/**
* Analyze a function or testcase
*/
private List<Edit> analyzeFunction(final Definition def) {
if (!(def instanceof Def_Function || def instanceof Def_Testcase)) {
ErrorReporter.logError("ChangeCreator.analyzeFunction(): def must be a Def_Function or a Def_Testcase! def type: " + def.getClass());
return null;
}
final FunctionAnalyzer vis = new FunctionAnalyzer();
def.accept(vis);
final Environment env = vis.getResult();
final List<Edit> eds = env.refactor();
return eds;
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.
the class ChangeCreator method createFileChange.
/**
* Creates the {@link #change} object, which contains all the inserted and edited texts
* in the selected resources.
*/
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;
}
//
// collect functions
Set<Definition> funcs;
final FunctionCollector vis = new FunctionCollector();
if (defSelection == null) {
module.accept(vis);
funcs = vis.getResult();
} else {
if (defSelection instanceof Def_Function || defSelection instanceof Def_Testcase) {
// TODO any other possibilities for the type of 'defSelection'?
funcs = new HashSet<Definition>();
funcs.add(defSelection);
} else {
ErrorReporter.logError("Variable scope reduction called for " + defSelection.getIdentifier().getDisplayName() + ", but it is only supported for functions and testcases. ");
return null;
}
}
// create edits
final List<Edit> allEdits = new ArrayList<Edit>();
for (Definition def : funcs) {
final List<Edit> edits = analyzeFunction(def);
if (edits == null) {
continue;
}
allEdits.addAll(edits);
}
if (allEdits.isEmpty()) {
return null;
}
final String fileContents = loadFileContent(toVisit);
// create text edits
//
final TextFileChange tfc = new TextFileChange(toVisit.getName(), toVisit);
final MultiTextEdit rootEdit = new MultiTextEdit();
tfc.setEdit(rootEdit);
// TODO this is an O(n^2) algorithm
// merge overlapping DeleteEdits
// used, when removing all parts of a multi-declaration statement:
// the DeleteEdit for removing the last part covers all the DeleteEdits for the other parts
// WARNING merging edits might make debugging more difficult, since the overlapping edit errors are avoided
final List<TextEdit> allTes = new LinkedList<TextEdit>();
// collect processed (insert) edits with their created insert edit
final Map<Edit, InsertEdit> editsDone = new HashMap<Edit, InsertEdit>();
for (Edit e : allEdits) {
final TextEdit[] tes = createTextEdit(toVisit, fileContents, e, editsDone);
for (TextEdit te : tes) {
if (!(te instanceof DeleteEdit)) {
allTes.add(te);
// System.err.println("$ nonde added: " + te.getOffset() + "-" + te.getExclusiveEnd());
continue;
}
DeleteEdit dte = (DeleteEdit) te;
final ListIterator<TextEdit> it = allTes.listIterator();
while (it.hasNext()) {
final TextEdit currTe = it.next();
if (!(currTe instanceof DeleteEdit)) {
continue;
}
final DeleteEdit currDte = (DeleteEdit) currTe;
// if the new edit (dte) overlaps currDte, merge them
if (doesDeleteEditsOverlap(dte, currDte)) {
// System.err.println("$ de removed: " + currDte.getOffset() + "-" + currDte.getExclusiveEnd());
it.remove();
dte = mergeDeleteEdits(dte, currDte);
// System.err.println("$ merged des: " + dte.getOffset() + "-" + dte.getExclusiveEnd());
}
}
// System.err.println("$ de added: " + dte.getOffset() + "-" + dte.getExclusiveEnd());
allTes.add(dte);
}
}
Collections.reverse(allTes);
for (TextEdit te : allTes) {
rootEdit.addChild(te);
}
return tfc;
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.
the class MinimizeScopeActionFromEditor method findSelection.
private Definition findSelection() {
// getting the active editor
final IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
TTCN3Editor targetEditor;
if (editor == null || !(editor instanceof TTCN3Editor)) {
return null;
} else {
targetEditor = (TTCN3Editor) editor;
}
final IStatusLineManager statusLineManager = targetEditor.getEditorSite().getActionBars().getStatusLineManager();
// getting current selection
final ISelectionService selectionService = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService();
final TextSelection textSelection = extractSelection(selectionService.getSelection());
// iterating through part of the module
final IResource selectedRes = extractResource(targetEditor);
if (!(selectedRes instanceof IFile)) {
ErrorReporter.logError("SelectionFinder.findSelection(): Selected resource `" + selectedRes.getName() + "' is not a file.");
return null;
}
final IFile selectedFile = (IFile) selectedRes;
final ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(selectedFile.getProject());
final Module selectedModule = projectSourceParser.containedModule(selectedFile);
// getting current selection nodes
final int selectionOffset = textSelection.getOffset() + textSelection.getLength();
final SelectionFinderVisitor selVisitor = new SelectionFinderVisitor(selectionOffset);
selectedModule.accept(selVisitor);
final Definition selectedDef = selVisitor.getSelection();
if (selectedDef == null) {
ErrorReporter.logWarning("SelectionFinder.findSelection(): Visitor did not find a definition in the selection.");
statusLineManager.setErrorMessage(ERR_MSG_NO_SELECTION);
return null;
}
return selectedDef;
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.
the class DependencyCollector method collectDependencies.
private void collectDependencies(final Definition start, final Set<ILocateableNode> allDefs, final Set<IResource> imports, final Set<IResource> asnFiles) {
Set<Definition> currDefs;
Set<Definition> prevDefs = new HashSet<Definition>();
prevDefs.add(start);
// TODO containsAll(): is this ok for sure?
while (!(allDefs.containsAll(prevDefs))) {
currDefs = new HashSet<Definition>();
allDefs.addAll(prevDefs);
for (Definition d : prevDefs) {
final DependencyFinderVisitor vis = new DependencyFinderVisitor(currDefs, imports, asnFiles);
d.accept(vis);
}
prevDefs = currDefs;
}
}
Aggregations