Commit ccbec6d7 authored by Kristof Szabados's avatar Kristof Szabados
Browse files

could be final


Signed-off-by: Kristof Szabados's avatarKristof Szabados <Kristof.Szabados@ericsson.com>
parent d3da5431
...@@ -55,14 +55,14 @@ class ChangeCreator { ...@@ -55,14 +55,14 @@ class ChangeCreator {
private Change change; private Change change;
ChangeCreator(final IFile selectedFile, MoveFunctionSettings settings, List<FunctionData> functions, IProject project) { ChangeCreator(final IFile selectedFile, final MoveFunctionSettings settings, final List<FunctionData> functions, final IProject project) {
this.selectedFile = selectedFile; this.selectedFile = selectedFile;
this.settings = settings; this.settings = settings;
this.functions = functions; this.functions = functions;
this.project = project; this.project = project;
} }
ChangeCreator(final IFile selectedFile, MoveFunctionSettings settings, List<FunctionData> functions, IProject project, Map<Module, List<Module>> mi) { ChangeCreator(final IFile selectedFile, final MoveFunctionSettings settings, final List<FunctionData> functions, final IProject project, final Map<Module, List<Module>> mi) {
this.selectedFile = selectedFile; this.selectedFile = selectedFile;
this.settings = settings; this.settings = settings;
this.functions = functions; this.functions = functions;
...@@ -105,7 +105,7 @@ class ChangeCreator { ...@@ -105,7 +105,7 @@ class ChangeCreator {
return null; return null;
} }
boolean noDestination = true; boolean noDestination = true;
for (FunctionData fd : functions) { for (final FunctionData fd : functions) {
if (fd.isToBeMoved() && fd.getFinalDestination() != null) { if (fd.isToBeMoved() && fd.getFinalDestination() != null) {
noDestination = false; noDestination = false;
} }
...@@ -126,36 +126,36 @@ class ChangeCreator { ...@@ -126,36 +126,36 @@ class ChangeCreator {
cc.add(tfc); cc.add(tfc);
final MultiTextEdit rootEdit = new MultiTextEdit(); final MultiTextEdit rootEdit = new MultiTextEdit();
tfc.setEdit(rootEdit); tfc.setEdit(rootEdit);
for(FunctionData function : functions) { for(final FunctionData function : functions) {
if(function.getFinalDestination() == null || !function.isToBeMoved()) { if(function.getFinalDestination() == null || !function.isToBeMoved()) {
continue; continue;
} }
TextFileChange tfcDestination = new TextFileChange(function.getFinalDestination().getModule().getName(), (IFile) function.getFinalDestination().getModule().getLocation().getFile()); final TextFileChange tfcDestination = new TextFileChange(function.getFinalDestination().getModule().getName(), (IFile) function.getFinalDestination().getModule().getLocation().getFile());
MultiTextEdit rootEdit2 = new MultiTextEdit(); final MultiTextEdit rootEdit2 = new MultiTextEdit();
tfcDestination.setEdit(rootEdit2); tfcDestination.setEdit(rootEdit2);
cc.add(tfcDestination); cc.add(tfcDestination);
int length = function.getDefiniton().getLocation().getEndOffset() - function.getDefiniton().getLocation().getOffset(); final int length = function.getDefiniton().getLocation().getEndOffset() - function.getDefiniton().getLocation().getOffset();
DeleteEdit deleteEdit = new DeleteEdit(function.getDefiniton().getLocation().getOffset(), length); final DeleteEdit deleteEdit = new DeleteEdit(function.getDefiniton().getLocation().getOffset(), length);
rootEdit.addChild(deleteEdit); rootEdit.addChild(deleteEdit);
if (!moduleImports.containsKey(function.getFinalDestination().getModule())) { if (!moduleImports.containsKey(function.getFinalDestination().getModule())) {
moduleImports.put(function.getFinalDestination().getModule(), new ArrayList<Module>()); moduleImports.put(function.getFinalDestination().getModule(), new ArrayList<Module>());
} }
InsertEdit importEdit = insertMissingImports(function.getFinalDestination().getModule(), function.getUsedModules()); final InsertEdit importEdit = insertMissingImports(function.getFinalDestination().getModule(), function.getUsedModules());
if (importEdit != null) { if (importEdit != null) {
rootEdit2.addChild(importEdit); rootEdit2.addChild(importEdit);
} }
findFunctionUses(function); findFunctionUses(function);
for (Module m : function.getUsedBy()) { for (final Module m : function.getUsedBy()) {
TextFileChange tfcModuleUsedMethod = new TextFileChange(m.getName(), (IFile) m.getLocation().getFile()); final TextFileChange tfcModuleUsedMethod = new TextFileChange(m.getName(), (IFile) m.getLocation().getFile());
MultiTextEdit rootEdit3 = new MultiTextEdit(); final MultiTextEdit rootEdit3 = new MultiTextEdit();
tfcModuleUsedMethod.setEdit(rootEdit3); tfcModuleUsedMethod.setEdit(rootEdit3);
int offset = m.getLocation().getEndOffset(); int offset = m.getLocation().getEndOffset();
Assignments assignments = m.getAssignments(); final Assignments assignments = m.getAssignments();
int nOfAssignments = assignments.getNofAssignments(); final int nOfAssignments = assignments.getNofAssignments();
for (int i=0; i<nOfAssignments; i++) { for (int i=0; i<nOfAssignments; i++) {
int assignmentOffset = assignments.getAssignmentByIndex(i).getLocation().getOffset(); final int assignmentOffset = assignments.getAssignmentByIndex(i).getLocation().getOffset();
if (offset > assignmentOffset) { if (offset > assignmentOffset) {
offset = assignmentOffset; offset = assignmentOffset;
} }
...@@ -171,11 +171,11 @@ class ChangeCreator { ...@@ -171,11 +171,11 @@ class ChangeCreator {
} }
private InsertEdit insertMissingImports(Module destinationModule, List<Module> usedModules) { private InsertEdit insertMissingImports(final Module destinationModule, final List<Module> usedModules) {
List<Module> importedModules = destinationModule.getImportedModules(); final List<Module> importedModules = destinationModule.getImportedModules();
String importText = ""; String importText = "";
for (Module m : usedModules) { for (final Module m : usedModules) {
if (!importedModules.contains(m) if (!importedModules.contains(m)
&& !m.equals(destinationModule) && !m.equals(destinationModule)
&& !moduleImports.get(destinationModule).contains(m)) { && !moduleImports.get(destinationModule).contains(m)) {
...@@ -188,10 +188,10 @@ class ChangeCreator { ...@@ -188,10 +188,10 @@ class ChangeCreator {
final MultiTextEdit rootEdit = new MultiTextEdit(); final MultiTextEdit rootEdit = new MultiTextEdit();
insertImports.setEdit(rootEdit); insertImports.setEdit(rootEdit);
int offset = destinationModule.getLocation().getEndOffset(); int offset = destinationModule.getLocation().getEndOffset();
Assignments assignments = destinationModule.getAssignments(); final Assignments assignments = destinationModule.getAssignments();
int nOfAssignments = assignments.getNofAssignments(); final int nOfAssignments = assignments.getNofAssignments();
for (int i=0; i<nOfAssignments; i++) { for (int i=0; i<nOfAssignments; i++) {
int assignmentOffset = assignments.getAssignmentByIndex(i).getLocation().getOffset(); final int assignmentOffset = assignments.getAssignmentByIndex(i).getLocation().getOffset();
if (offset > assignmentOffset) { if (offset > assignmentOffset) {
offset = assignmentOffset; offset = assignmentOffset;
} }
...@@ -203,11 +203,11 @@ class ChangeCreator { ...@@ -203,11 +203,11 @@ class ChangeCreator {
return new InsertEdit(offset, importText); return new InsertEdit(offset, importText);
} }
private void findFunctionUses(FunctionData function) { private void findFunctionUses(final FunctionData function) {
final ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(project); final ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(project);
for(Module m : projectSourceParser.getModules()) { for(final Module m : projectSourceParser.getModules()) {
if (!m.equals(function.getFinalDestination().getModule())) { if (!m.equals(function.getFinalDestination().getModule())) {
ModuleVisitor vis = new ModuleVisitor(function.getDefiniton()); final ModuleVisitor vis = new ModuleVisitor(function.getDefiniton());
m.accept(vis); m.accept(vis);
if (vis.getIsUsed() if (vis.getIsUsed()
& !m.getImportedModules().contains(function.getFinalDestination().getModule()) & !m.getImportedModules().contains(function.getFinalDestination().getModule())
...@@ -223,7 +223,7 @@ class ChangeCreator { ...@@ -223,7 +223,7 @@ class ChangeCreator {
private Def_Function function; private Def_Function function;
private boolean isUsed; private boolean isUsed;
public ModuleVisitor(Def_Function function) { public ModuleVisitor(final Def_Function function) {
this.function = function; this.function = function;
this.isUsed = false; this.isUsed = false;
} }
......
...@@ -27,7 +27,7 @@ public class FunctionData implements Comparable<FunctionData> { ...@@ -27,7 +27,7 @@ public class FunctionData implements Comparable<FunctionData> {
private MoveFunctionMethod method; private MoveFunctionMethod method;
private List<Module> usedBy; private List<Module> usedBy;
public FunctionData(Def_Function definiton, String functionBody) { public FunctionData(final Def_Function definiton, final String functionBody) {
this.definiton = definiton; this.definiton = definiton;
this.functionBody = functionBody; this.functionBody = functionBody;
toBeMoved = true; toBeMoved = true;
...@@ -36,42 +36,42 @@ public class FunctionData implements Comparable<FunctionData> { ...@@ -36,42 +36,42 @@ public class FunctionData implements Comparable<FunctionData> {
usedBy = new ArrayList<Module>(); usedBy = new ArrayList<Module>();
} }
public void setToBeMoved(boolean toBeMoved) { public void setToBeMoved(final boolean toBeMoved) {
this.toBeMoved = toBeMoved; this.toBeMoved = toBeMoved;
} }
public void setModule(Module module) { public void setModule(final Module module) {
this.module = module; this.module = module;
} }
public void addDestination(Module destination, Integer rating, int newImports) { public void addDestination(final Module destination, final Integer rating, final int newImports) {
destinations.add(new Destination(destination, rating, this, newImports)); destinations.add(new Destination(destination, rating, this, newImports));
} }
public void addUsedModule(Module module) { public void addUsedModule(final Module module) {
usedModules.add(module); usedModules.add(module);
} }
public void addUsedModules(List<Module> modules) { public void addUsedModules(final List<Module> modules) {
usedModules.addAll(modules); usedModules.addAll(modules);
} }
public void addUsedBy(Module m) { public void addUsedBy(final Module m) {
usedBy.add(m); usedBy.add(m);
} }
public void setUsedModules(List<Module> modules) { public void setUsedModules(final List<Module> modules) {
usedModules = modules; usedModules = modules;
} }
public void setFinalDestination(Destination destination) { public void setFinalDestination(final Destination destination) {
this.finalDestination = destination; this.finalDestination = destination;
if(destination != null) { if(destination != null) {
destination.setFunctionData(this); destination.setFunctionData(this);
} }
} }
public void setRefactoringMethod(MoveFunctionMethod rMethod) { public void setRefactoringMethod(final MoveFunctionMethod rMethod) {
this.method = rMethod; this.method = rMethod;
} }
...@@ -112,7 +112,7 @@ public class FunctionData implements Comparable<FunctionData> { ...@@ -112,7 +112,7 @@ public class FunctionData implements Comparable<FunctionData> {
} }
@Override @Override
public int compareTo(FunctionData arg0) { public int compareTo(final FunctionData arg0) {
return this.getDefiniton().getIdentifier().getDisplayName().compareToIgnoreCase(arg0.getDefiniton().getIdentifier().getDisplayName()); return this.getDefiniton().getIdentifier().getDisplayName().compareToIgnoreCase(arg0.getDefiniton().getIdentifier().getDisplayName());
} }
...@@ -132,7 +132,7 @@ class Destination implements Comparable<Destination> { ...@@ -132,7 +132,7 @@ class Destination implements Comparable<Destination> {
} }
public Destination(Module module, int rating, FunctionData functionData, int newImports) { public Destination(final Module module, final int rating, final FunctionData functionData, final int newImports) {
this.module = module; this.module = module;
this.rating = rating; this.rating = rating;
this.functionData = functionData; this.functionData = functionData;
...@@ -156,24 +156,24 @@ class Destination implements Comparable<Destination> { ...@@ -156,24 +156,24 @@ class Destination implements Comparable<Destination> {
return newImports; return newImports;
} }
public void setModule(Module module) { public void setModule(final Module module) {
this.module = module; this.module = module;
} }
public void setRating(int rating) { public void setRating(final int rating) {
this.rating = rating; this.rating = rating;
} }
public void setFunctionData(FunctionData functionData) { public void setFunctionData(final FunctionData functionData) {
this.functionData = functionData; this.functionData = functionData;
} }
public void setNewImports(int newImports) { public void setNewImports(final int newImports) {
this.newImports = newImports; this.newImports = newImports;
} }
@Override @Override
public int compareTo(Destination arg0) { public int compareTo(final Destination arg0) {
return arg0.rating - this.rating; return arg0.rating - this.rating;
} }
} }
...@@ -41,9 +41,9 @@ public class MoveFunctionWizard extends RefactoringWizard implements ...@@ -41,9 +41,9 @@ public class MoveFunctionWizard extends RefactoringWizard implements
@Override @Override
protected void addUserInputPages() { protected void addUserInputPages() {
setDefaultPageTitle(WIZ_WINDOWTITLE1); setDefaultPageTitle(WIZ_WINDOWTITLE1);
MoveFunctionWizardFunctionsPage functionsPage = new MoveFunctionWizardFunctionsPage(WIZ_WINDOWTITLE2, refactoring); final MoveFunctionWizardFunctionsPage functionsPage = new MoveFunctionWizardFunctionsPage(WIZ_WINDOWTITLE2, refactoring);
addPage(functionsPage); addPage(functionsPage);
MoveFunctionWizardDestinationsPage destinationsPage = new MoveFunctionWizardDestinationsPage(WIZ_WINDOWTITLE3, refactoring); final MoveFunctionWizardDestinationsPage destinationsPage = new MoveFunctionWizardDestinationsPage(WIZ_WINDOWTITLE3, refactoring);
addPage(destinationsPage); addPage(destinationsPage);
} }
} }
...@@ -46,7 +46,7 @@ public class MoveFunctionWizardDestinationsPage extends UserInputWizardPage { ...@@ -46,7 +46,7 @@ public class MoveFunctionWizardDestinationsPage extends UserInputWizardPage {
protected static boolean displayZeros; protected static boolean displayZeros;
private Button displayZerosCheckBox; private Button displayZerosCheckBox;
MoveFunctionWizardDestinationsPage(final String name, MoveFunctionRefactoring refactoring) { MoveFunctionWizardDestinationsPage(final String name, final MoveFunctionRefactoring refactoring) {
super(name); super(name);
this.refactoring = refactoring; this.refactoring = refactoring;
refactoring.getSettings().setType(MoveFunctionType.MODULE); refactoring.getSettings().setType(MoveFunctionType.MODULE);
...@@ -61,17 +61,17 @@ public class MoveFunctionWizardDestinationsPage extends UserInputWizardPage { ...@@ -61,17 +61,17 @@ public class MoveFunctionWizardDestinationsPage extends UserInputWizardPage {
initializeDialogUnits(top); initializeDialogUnits(top);
top.setLayout(new GridLayout(1, false)); top.setLayout(new GridLayout(1, false));
Composite comp = new Composite(top, SWT.NONE); final Composite comp = new Composite(top, SWT.NONE);
initializeDialogUnits(comp); initializeDialogUnits(comp);
comp.setLayout(new GridLayout(1, false)); comp.setLayout(new GridLayout(1, false));
Label label = new Label(comp, SWT.NONE); final Label label = new Label(comp, SWT.NONE);
label.setText("Choose method: "); label.setText("Choose method: ");
Button shortestModule = new Button(comp, SWT.RADIO); final Button shortestModule = new Button(comp, SWT.RADIO);
shortestModule.setText("choose shortest module"); shortestModule.setText("choose shortest module");
shortestModule.setSelection(true); shortestModule.setSelection(true);
shortestModule.addSelectionListener(new SelectionAdapter() { shortestModule.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) { public void widgetSelected(final SelectionEvent event) {
if (refactoring.getSettings().getMethod().equals(MoveFunctionMethod.LENGTH) && !refactoring.getSettings().isChanged()) { if (refactoring.getSettings().getMethod().equals(MoveFunctionMethod.LENGTH) && !refactoring.getSettings().isChanged()) {
refactoring.getSettings().setChanged(false); refactoring.getSettings().setChanged(false);
} }
...@@ -85,10 +85,10 @@ public class MoveFunctionWizardDestinationsPage extends UserInputWizardPage { ...@@ -85,10 +85,10 @@ public class MoveFunctionWizardDestinationsPage extends UserInputWizardPage {
}); });
Button leastImports = new Button(comp, SWT.RADIO); final Button leastImports = new Button(comp, SWT.RADIO);
leastImports.setText("insert the least new imports"); leastImports.setText("insert the least new imports");
leastImports.addSelectionListener(new SelectionAdapter() { leastImports.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) { public void widgetSelected(final SelectionEvent event) {
if (refactoring.getSettings().getMethod().equals(MoveFunctionMethod.IMPORTS) && !refactoring.getSettings().isChanged()) { if (refactoring.getSettings().getMethod().equals(MoveFunctionMethod.IMPORTS) && !refactoring.getSettings().isChanged()) {
refactoring.getSettings().setChanged(false); refactoring.getSettings().setChanged(false);
} }
...@@ -109,10 +109,10 @@ public class MoveFunctionWizardDestinationsPage extends UserInputWizardPage { ...@@ -109,10 +109,10 @@ public class MoveFunctionWizardDestinationsPage extends UserInputWizardPage {
}; };
}); });
*/ */
Button component = new Button(comp, SWT.RADIO); final Button component = new Button(comp, SWT.RADIO);
component.setText("by component"); component.setText("by component");
component.addSelectionListener(new SelectionAdapter() { component.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) { public void widgetSelected(final SelectionEvent event) {
if (refactoring.getSettings().getMethod().equals(MoveFunctionMethod.COMPONENT) && !refactoring.getSettings().isChanged()) { if (refactoring.getSettings().getMethod().equals(MoveFunctionMethod.COMPONENT) && !refactoring.getSettings().isChanged()) {
refactoring.getSettings().setChanged(false); refactoring.getSettings().setChanged(false);
} }
...@@ -135,8 +135,8 @@ public class MoveFunctionWizardDestinationsPage extends UserInputWizardPage { ...@@ -135,8 +135,8 @@ public class MoveFunctionWizardDestinationsPage extends UserInputWizardPage {
displayZerosCheckBox.addSelectionListener(new SelectionAdapter() { displayZerosCheckBox.addSelectionListener(new SelectionAdapter() {
@Override @Override
public void widgetSelected(SelectionEvent event) { public void widgetSelected(final SelectionEvent event) {
Button btn = (Button) event.getSource(); final Button btn = (Button) event.getSource();
displayZeros = btn.getSelection(); displayZeros = btn.getSelection();
tree.refresh(); tree.refresh();
} }
...@@ -151,9 +151,9 @@ public class MoveFunctionWizardDestinationsPage extends UserInputWizardPage { ...@@ -151,9 +151,9 @@ public class MoveFunctionWizardDestinationsPage extends UserInputWizardPage {
excludedModulesField.addModifyListener(new ModifyListener() { excludedModulesField.addModifyListener(new ModifyListener() {
@Override @Override
public void modifyText(final ModifyEvent e) { public void modifyText(final ModifyEvent e) {
String regex = excludedModulesField.getText().replaceAll(",", "|").replaceAll(" +", " ").trim(); final String regex = excludedModulesField.getText().replaceAll(",", "|").replaceAll(" +", " ").trim();
try { try {
Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE); final Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
if (refactoring.getSettings().getExcludedModuleNames().equals(pattern) && !refactoring.getSettings().isChanged()) { if (refactoring.getSettings().getExcludedModuleNames().equals(pattern) && !refactoring.getSettings().isChanged()) {
refactoring.getSettings().setChanged(false); refactoring.getSettings().setChanged(false);
...@@ -173,11 +173,11 @@ public class MoveFunctionWizardDestinationsPage extends UserInputWizardPage { ...@@ -173,11 +173,11 @@ public class MoveFunctionWizardDestinationsPage extends UserInputWizardPage {
setErrorMessage(null); setErrorMessage(null);
} }
public void displayDestinations(Composite parent) { public void displayDestinations(final Composite parent) {
Composite comp = new Composite(parent, SWT.NONE); final Composite comp = new Composite(parent, SWT.NONE);
initializeDialogUnits(comp); initializeDialogUnits(comp);
comp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); comp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
comp.setLayout(new FillLayout()); comp.setLayout(new FillLayout());
refactoring.getDestinations(); refactoring.getDestinations();
tree = new CheckboxTreeViewer (comp, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); tree = new CheckboxTreeViewer (comp, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
...@@ -187,7 +187,7 @@ public class MoveFunctionWizardDestinationsPage extends UserInputWizardPage { ...@@ -187,7 +187,7 @@ public class MoveFunctionWizardDestinationsPage extends UserInputWizardPage {
tree.expandToLevel(2); tree.expandToLevel(2);
tree.addCheckStateListener(new ICheckStateListener() { tree.addCheckStateListener(new ICheckStateListener() {
public void checkStateChanged(CheckStateChangedEvent event) { public void checkStateChanged(final CheckStateChangedEvent event) {
if (event.getElement() instanceof FunctionData) { if (event.getElement() instanceof FunctionData) {
if (event.getChecked()) { if (event.getChecked()) {
tree.setChecked(event.getElement(), event.getChecked()); tree.setChecked(event.getElement(), event.getChecked());
...@@ -200,11 +200,11 @@ public class MoveFunctionWizardDestinationsPage extends UserInputWizardPage { ...@@ -200,11 +200,11 @@ public class MoveFunctionWizardDestinationsPage extends UserInputWizardPage {
} }
} }
else if (event.getElement() instanceof Destination) { else if (event.getElement() instanceof Destination) {
Destination dest = (Destination)event.getElement(); final Destination dest = (Destination)event.getElement();
tree.setChecked(dest, event.getChecked()); tree.setChecked(dest, event.getChecked());
for (Map.Entry<Module, List<FunctionData>> entry : refactoring.getFunctions().entrySet()) { for (final Map.Entry<Module, List<FunctionData>> entry : refactoring.getFunctions().entrySet()) {
if (entry.getValue().contains(dest.getFunctionData())) { if (entry.getValue().contains(dest.getFunctionData())) {
for (FunctionData fd : entry.getValue()) { for (final FunctionData fd : entry.getValue()) {
if (dest.getFunctionData().equals(fd)) { if (dest.getFunctionData().equals(fd)) {
if (fd.getFinalDestination() != null & !dest.equals(fd.getFinalDestination())) { if (fd.getFinalDestination() != null & !dest.equals(fd.getFinalDestination())) {
tree.setChecked(fd.getFinalDestination(), false); tree.setChecked(fd.getFinalDestination(), false);
...@@ -236,8 +236,8 @@ public class MoveFunctionWizardDestinationsPage extends UserInputWizardPage { ...@@ -236,8 +236,8 @@ public class MoveFunctionWizardDestinationsPage extends UserInputWizardPage {
public void setTreeChecked() { public void setTreeChecked() {