Commit 17917a84 authored by Kristof Szabados's avatar Kristof Szabados
Browse files

moved check earlier.


Signed-off-by: Kristof Szabados's avatarKristof Szabados <Kristof.Szabados@ericsson.com>
parent 29c88e4e
......@@ -364,6 +364,16 @@ public class ChangeCreator {
* Returns the {@link Location} of the {@DeleteEdit} to remove a variable from a declaration list
* */
private Location calculateMultiDeclarationCutLoc(final String fileContent, final StatementNode declStNode) {
final Definition_Statement declStmt = (Definition_Statement)declStNode.getAstNode();
final Location declStmtLoc = declStmt.getLocation();
final String stmtContent = fileContent.substring(declStmtLoc.getOffset(), declStmtLoc.getEndOffset());
if (!stmtContent.contains(",")) {
ErrorReporter.logError("ChangeCreator.calculateMultiDeclarationCutLoc(): Given statement" +
" is not a multi-declaration statement; loc: " + declStmtLoc.getOffset() + "-" +
declStmtLoc.getEndOffset() + " in file " + declStmtLoc.getFile());
return null;
}
/*
* rules for removing multideclaration parts:
* if part is only one left: remove statement
......@@ -374,16 +384,8 @@ public class ChangeCreator {
final MultiDeclaration md = declStNode.getMultiDeclaration();
final StatementNode firstDeclPart = md.getFirstStatement();
final Definition defVarToMove = declStNode.getDeclaredVar().getDefinition();
final Definition_Statement declStmt = (Definition_Statement)declStNode.getAstNode();
final boolean firstDefInMdMoved = firstDeclPart.isMoved();
final Location declStmtLoc = declStmt.getLocation();
final String stmtContent = fileContent.substring(declStmtLoc.getOffset(), declStmtLoc.getEndOffset());
if (!stmtContent.contains(",")) {
ErrorReporter.logError("ChangeCreator.calculateMultiDeclarationCutLoc(): Given statement" +
" is not a multi-declaration statement; loc: " + declStmtLoc.getOffset() + "-" +
declStmtLoc.getEndOffset() + " in file " + declStmtLoc.getFile());
return null;
}
//
if (md.getSize() <= 1) {
final Location cutLoc = findStatementLocation(fileContent, declStmt.getLocation(), true);
......@@ -497,10 +499,6 @@ public class ChangeCreator {
* Returns the content of an {@InsertEdit} to move a variable from a declaration list
* */
private String calculateMultiDeclarationMoveContent(final String fileContent, final StatementNode declStNode) {
final MultiDeclaration md = declStNode.getMultiDeclaration();
final StatementNode firstDeclPart = md.getFirstStatement();
final Definition firstDefInStmt = firstDeclPart.getDeclaredVar().getDefinition();
final Definition defVarToMove = declStNode.getDeclaredVar().getDefinition();
final Definition_Statement declStmt = (Definition_Statement)declStNode.getAstNode();
final Location declStmtLoc = declStmt.getLocation();
final String stmtContent = fileContent.substring(declStmtLoc.getOffset(), declStmtLoc.getEndOffset());
......@@ -510,6 +508,11 @@ public class ChangeCreator {
declStmtLoc.getEndOffset() + " in file " + declStmtLoc.getFile());
return null;
}
final MultiDeclaration md = declStNode.getMultiDeclaration();
final StatementNode firstDeclPart = md.getFirstStatement();
final Definition firstDefInStmt = firstDeclPart.getDeclaredVar().getDefinition();
final Definition defVarToMove = declStNode.getDeclaredVar().getDefinition();
int prefixOffset;
int prefixEndOffset;
if (firstDefInStmt.equals(defVarToMove)) {
......@@ -662,14 +665,14 @@ public class ChangeCreator {
return V_CONTINUE;
}
if (node instanceof Reference && suspendReferencesForNode == null) {
final Reference ref = (Reference)node;
final Assignment as = ref.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
final StatementNode refSt = (StatementNode)currStack.peek();
if (refSt == null) {
//should be a return type or runs on reference (ignore it)
return V_SKIP;
}
final Reference ref = (Reference)node;
final Assignment as = ref.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
//does the statement contain function calls?
if (as instanceof Def_Function || as instanceof Def_Extfunction) {
refSt.setHasFunctionCall();
......
......@@ -124,6 +124,11 @@ class ChangeCreator {
}
private void makeChange(final SelectCase_Statement statement, final MultiTextEdit rootEdit, final List<Reference> elements){
final List<SelectCase> scs = statement.getSelectCases().getSelectCaseArray();
if(scs.size() < elements.size()){
return;
}
// Insert the "union" word after the "select"
final ReplaceEdit insertUnion = new ReplaceEdit(statement.getLocation().getOffset()+6, 0, " union");
......@@ -135,11 +140,7 @@ class ChangeCreator {
final ReplaceEdit changeExpression = new ReplaceEdit(statementBegin, statementEnd-statementBegin, elementName);
// Calculate the case branch changes
ReplaceEdit[] changeCases = new ReplaceEdit[elements.size()];
final List<SelectCase> scs = statement.getSelectCases().getSelectCaseArray();
if(scs.size() < elements.size()){
return;
}
final ReplaceEdit[] changeCases = new ReplaceEdit[elements.size()];
for(Integer i = 0; i < elements.size(); i++){
final int startOfIschosen = scs.get(i).getLocation().getOffset();
final int startOfStatement = scs.get(i).getStatementBlock().getLocation().getOffset();
......
......@@ -56,8 +56,6 @@ public class UngroupModuleparActionFromBrowser extends AbstractHandler implement
}
private void performUngroupModulepar() {
// getting the active editor
final TTCN3Editor targetEditor = Utils.getActiveEditor();
//find selection
if (!(selection instanceof IStructuredSelection)) {
return;
......@@ -69,6 +67,8 @@ public class UngroupModuleparActionFromBrowser extends AbstractHandler implement
Utils.updateASTBeforeRefactoring(projsToUpdate, "UngroupModulepar");
Activator.getDefault().pauseHandlingResourceChanges();
// getting the active editor
final TTCN3Editor targetEditor = Utils.getActiveEditor();
//create refactoring
final UngroupModuleparRefactoring refactoring = new UngroupModuleparRefactoring(structSelection);
//open wizard
......
......@@ -56,8 +56,6 @@ public class MinimizeVisibilityActionFromBrowser extends AbstractHandler impleme
}
private void performMinimizeVisibility() {
// getting the active editor
final TTCN3Editor targetEditor = Utils.getActiveEditor();
//find selection
if (!(selection instanceof IStructuredSelection)) {
return;
......@@ -69,6 +67,8 @@ public class MinimizeVisibilityActionFromBrowser extends AbstractHandler impleme
Utils.updateASTBeforeRefactoring(projsToUpdate, "MinimizeVisibility");
Activator.getDefault().pauseHandlingResourceChanges();
// getting the active editor
final TTCN3Editor targetEditor = Utils.getActiveEditor();
//create refactoring
final MinimizeVisibilityRefactoring refactoring = new MinimizeVisibilityRefactoring(structSelection);
//open wizard
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment