use of org.eclipse.titan.designer.AST.TTCN3.statements.Statement in project titan.EclipsePlug-ins by eclipse.
the class StatementList method createDebugInfo.
public String createDebugInfo() {
final StringBuilder sb = new StringBuilder();
sb.append("ExtractToFunctionRefactoring->StatementList debug info:");
sb.append("\n Loc: ");
if (location == null) {
sb.append("null");
} else {
sb.append(location.getFile().getFullPath());
sb.append(": ");
sb.append(location.getOffset());
sb.append("->");
sb.append(location.getEndOffset());
}
sb.append("\n MySB info: ");
if (myStatementBlock == null || myStatementBlock.getMyDefinition() == null) {
sb.append("null");
} else {
sb.append(myStatementBlock.getMyDefinition().getIdentifier());
}
sb.append("\n Statements: ");
if (statements == null) {
sb.append("null");
} else {
sb.append("(count: ");
sb.append(statements.size());
sb.append(") \n");
for (Statement s : statements) {
sb.append(" ");
sb.append(s.getStatementName());
sb.append(", loc: ");
if (s.getLocation() == null) {
sb.append("null");
} else {
sb.append(s.getLocation().getOffset());
sb.append("->");
sb.append(s.getLocation().getEndOffset());
sb.append(" in line ");
sb.append(s.getLocation().getLine());
}
sb.append('\n');
}
}
sb.append('\n');
return sb.toString();
}
use of org.eclipse.titan.designer.AST.TTCN3.statements.Statement in project titan.EclipsePlug-ins by eclipse.
the class IfContext method process_internal.
protected void process_internal() {
final If_Statement st = getNode();
final If_Clauses ics = st.getIfClauses();
final Context child = getChild();
if (child != null && child.getNode().equals(ics)) {
// the log statement is in one of the conditional clauses
final List<If_Clause> icl = ics.getClauses();
final Context clauseContext = child.getChild();
if (clauseContext != null && icl.contains(clauseContext.getNode())) {
final IVisitableNode ic = clauseContext.getNode();
final ClauseVisitor vis = new ClauseVisitor();
ic.accept(vis);
final List<Reference> refs = vis.getResult();
for (Reference ref : refs) {
varNamesInConditions.add(ref.getDisplayName());
}
}
} else {
// the log statement is in the else block
final List<Reference> refs = extractAllIdsFromClauses(ics);
for (Reference ref : refs) {
varNamesInConditions.add(ref.getDisplayName());
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.statements.Statement 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.TTCN3.statements.Statement in project titan.EclipsePlug-ins by eclipse.
the class ContainsRef method process.
@Override
public void process(final IVisitableNode node, final Problems problems) {
if (node instanceof Operation_Altguard) {
final Operation_Altguard ag = (Operation_Altguard) node;
final Statement action = ag.getGuardStatement();
if (action instanceof Receive_Port_Statement) {
final Receive_Port_Statement receive = (Receive_Port_Statement) action;
final SuspiciouslyUsedIf susp = new SuspiciouslyUsedIf(receive);
ag.accept(susp);
if (susp.doesSmell()) {
problems.report(susp.getSuspicious().getLocation(), SHOULD_BRANCH);
}
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.statements.Statement 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;
}
Aggregations