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

Code style improvements

parent fa8db7b5
......@@ -90,29 +90,29 @@ public class CheckCodeSmells extends AbstractHandler {
*/
private void collectResourcesToBeAnalyzed(final Deque<IResource> res, final Map<IProject, List<IFile>> files, final List<IProject> projects) {
while (!res.isEmpty()) {
final IResource r = res.pollFirst();
if (r instanceof IProject) {
final IProject proj = (IProject) r;
projects.add(proj);
} else if (r instanceof IFolder) {
final IResource resource = res.pollFirst();
if (resource instanceof IProject) {
final IProject project = (IProject) resource;
projects.add(project);
} else if (resource instanceof IFolder) {
try {
for (IResource r2 : ((IFolder) r).members()) {
for (IResource r2 : ((IFolder) resource).members()) {
res.addLast(r2);
}
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace("Error while collecting resources", e);
}
} else if (r instanceof IFile) {
final IFile file = (IFile) r;
} else if (resource instanceof IFile) {
final IFile file = (IFile) resource;
final String extension = file.getFileExtension();
if ("ttcn".equals(extension) || "ttcn3".equals(extension)) {
final IProject project = file.getProject();
List<IFile> ls = files.get(project);
if (ls == null) {
ls = new ArrayList<IFile>();
files.put(project, ls);
List<IFile> filesInProject = files.get(project);
if (filesInProject == null) {
filesInProject = new ArrayList<IFile>();
files.put(project, filesInProject);
}
ls.add(file);
filesInProject.add(file);
}
}
}
......@@ -131,11 +131,11 @@ public class CheckCodeSmells extends AbstractHandler {
public IStatus doPostWork(final IProgressMonitor monitor) {
final SubMonitor progress = SubMonitor.convert(monitor, 100);
if (!onTheFlyEnabled) {
MarkerHandler mh;
MarkerHandler handler;
synchronized (project) {
mh = analyzer.analyzeProject(progress.newChild(100), project);
handler = analyzer.analyzeProject(progress.newChild(100), project);
}
mh.showAll();
handler.showAll();
}
return Status.OK_STATUS;
}
......@@ -160,12 +160,12 @@ public class CheckCodeSmells extends AbstractHandler {
final String actualModuleName = projectSourceParser.containedModule(file);
final Module module = projectSourceParser.getModuleByName(actualModuleName);
if (module != null) {
MarkerHandler mh;
progress.subTask("Analyzing module " + module.getName());
MarkerHandler handler;
synchronized (project) {
mh = analyzer.analyzeModule(progress.newChild(1), module);
handler = analyzer.analyzeModule(progress.newChild(1), module);
}
mh.showAll();
handler.showAll();
}
}
}
......
......@@ -87,7 +87,7 @@ public class ComponentGraphAction extends AbstractHandler implements IObjectActi
final Job generator = new Job("Generator") {
@Override
protected IStatus run(IProgressMonitor monitor) {
protected IStatus run(final IProgressMonitor monitor) {
monitor.beginTask("Parsing project", 30);
Display.getDefault().asyncExec(new Runnable() {
@Override
......
......@@ -99,40 +99,40 @@ public final class ExportProblems extends AbstractHandler implements IObjectActi
return;
}
final Object o = structSelection.getFirstElement();
if (!(o instanceof IProject)) {
final Object firstElement = structSelection.getFirstElement();
if (!(firstElement instanceof IProject)) {
ErrorReporter.logError("The export problems command needs to be called on a project ");
return;
}
final IProject p = (IProject) o;
final IProject project = (IProject) firstElement;
final IPreferencesService preferencesService = Platform.getPreferencesService();
final boolean reportDebugInformation =
preferencesService.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null);
if (reportDebugInformation) {
TITANDebugConsole.println("Problem markers are to export from " + p.getName());
TITANDebugConsole.println("Problem markers are to export from " + project.getName());
}
boolean write = false;
String fn;
String fileName;
final Shell shell = Display.getCurrent().getActiveShell();
do {
final FileDialog d = new FileDialog(shell, SWT.SAVE);
d.setText("Export problem markers to xls");
d.setFilterExtensions(new String[] { "*.xls" });
final FileDialog dialog = new FileDialog(shell, SWT.SAVE);
dialog.setText("Export problem markers to xls");
dialog.setFilterExtensions(new String[] { "*.xls" });
final IPath path = p.getLocation();
final IPath path = project.getLocation();
if (path != null) {
d.setFilterPath(path.toPortableString());
dialog.setFilterPath(path.toPortableString());
}
final Calendar now = Calendar.getInstance();
d.setFileName("Problems--" + p.getName() + "--" + now.get(Calendar.YEAR) + "-" + (1 + now.get(Calendar.MONTH)) + "-"
dialog.setFileName("Problems--" + project.getName() + "--" + now.get(Calendar.YEAR) + "-" + (1 + now.get(Calendar.MONTH)) + "-"
+ now.get(Calendar.DAY_OF_MONTH));
fn = d.open();
if (fn != null) {
if (new File(fn).exists()) {
fileName = dialog.open();
if (fileName != null) {
if (new File(fileName).exists()) {
write = MessageDialog.openConfirm(Display.getCurrent().getActiveShell(), "File exist",
"This file already exists. Please confirm overwrite.");
} else {
......@@ -144,14 +144,14 @@ public final class ExportProblems extends AbstractHandler implements IObjectActi
}
} while (!write);
final String fileName = fn;
final String fileName2 = fileName;
new ProjectAnalyzerJob("Exporting reported code smells") {
@Override
public IStatus doPostWork(final IProgressMonitor monitor) {
final BaseProblemExporter exporter = new XlsProblemExporter(getProject());
try {
exporter.exportMarkers(monitor, fileName, Calendar.getInstance().getTime());
exporter.exportMarkers(monitor, fileName2, Calendar.getInstance().getTime());
if (reportDebugInformation) {
TITANDebugConsole.println("Successfully exported markers to xls");
}
......@@ -163,6 +163,6 @@ public final class ExportProblems extends AbstractHandler implements IObjectActi
}
return Status.OK_STATUS;
}
}.quickSchedule(p);
}.quickSchedule(project);
}
}
......@@ -63,19 +63,19 @@ public class MetricsViewOpener extends AbstractHandler implements IObjectActionD
return;
}
final Object o = structSelection.getFirstElement();
if (!(o instanceof IProject)) {
final Object firstElement = structSelection.getFirstElement();
if (!(firstElement instanceof IProject)) {
ErrorReporter.logError("The open metrics view command needs to be called on a project ");
return;
}
final IProject p = (IProject) o;
final IProject project = (IProject) firstElement;
try {
final IViewPart mv = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
final IViewPart activeView = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
.showView("org.eclipse.titanium.metrics.view");
if (mv instanceof MetricsView) {
final MetricsView metricsView = (MetricsView) mv;
metricsView.setSelectedProject(p);
if (activeView instanceof MetricsView) {
final MetricsView metricsView = (MetricsView) activeView;
metricsView.setSelectedProject(project);
metricsView.startMeasuring();
}
......
......@@ -45,6 +45,7 @@ public class ModuleGraphAction extends AbstractHandler implements IObjectActionD
private ISelection selection;
public ModuleGraphAction() {
// Do nothing
}
/**
......
......@@ -116,31 +116,31 @@ public final class OrganizeFromBrowser extends AbstractHandler implements IObjec
}
while (!res.isEmpty()) {
final IResource r = res.pollFirst();
if (r instanceof IProject) {
final IProject proj = (IProject) r;
final IResource resource = res.pollFirst();
if (resource instanceof IProject) {
final IProject project = (IProject) resource;
try {
for (IResource r2 : proj.members()) {
for (IResource r2 : project.members()) {
res.addLast(r2);
}
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace("Error while collecting members of project " + proj.getName(),e);
ErrorReporter.logExceptionStackTrace("Error while collecting members of project " + project.getName(),e);
}
}
if (r instanceof IFolder) {
if (resource instanceof IFolder) {
try {
final IResource[] resInFolder = ((IFolder) r).members();
for (IResource r2 : resInFolder) {
final IResource[] folder = ((IFolder) resource).members();
for (IResource r2 : folder) {
res.addLast(r2);
}
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace("Error while collecting members of folder " + r.getName(),e);
ErrorReporter.logExceptionStackTrace("Error while collecting members of folder " + resource.getName(),e);
}
} else if (r instanceof IFile) {
final IFile file = (IFile) r;
} else if (resource instanceof IFile) {
final IFile file = (IFile) resource;
final String extension = file.getFileExtension();
if ("ttcn".equals(extension) || "ttcn3".equals(extension)) {
files.add((IFile) r);
files.add((IFile) resource);
}
}
}
......@@ -151,11 +151,11 @@ public final class OrganizeFromBrowser extends AbstractHandler implements IObjec
TITANDebugConsole.println("These files will be organized: " + files.toString());
}
final OrganizeImportsOp op = new OrganizeImportsOp(files);
final ProgressMonitorDialog pmd = new ProgressMonitorDialog(null);
final OrganizeImportsOp operation = new OrganizeImportsOp(files);
final ProgressMonitorDialog progressMonitorDialog = new ProgressMonitorDialog(null);
try {
pmd.run(true, true, op);
progressMonitorDialog.run(true, true, operation);
} catch (InvocationTargetException e) {
ErrorReporter.logExceptionStackTrace("Error while organizing imports",e);
} catch (InterruptedException e) {
......
......@@ -14,7 +14,6 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jface.action.IAction;
import org.eclipse.ltk.core.refactoring.TextFileChange;
import org.eclipse.titan.common.logging.ErrorReporter;
import org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor;
......@@ -32,19 +31,16 @@ import org.eclipse.ui.PlatformUI;
*/
public final class OrganizeFromEditor extends AbstractHandler {
public void setActiveEditor(final IAction action, final IEditorPart targetEditor) {
}
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
final IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
if (editor == null || !(editor instanceof TTCN3Editor || (editor instanceof TTCNPPEditor))) {
if (editor == null || !(editor instanceof TTCN3Editor || editor instanceof TTCNPPEditor)) {
ErrorReporter.logError("The editor is not found or not a Titan TTCN-3 editor");
return null;
}
IFile file = (IFile) editor.getEditorInput().getAdapter(IFile.class);
final IFile file = (IFile) editor.getEditorInput().getAdapter(IFile.class);
TextFileChange change = null;
try {
change = OrganizeImports.organizeImportsChange(file);
......@@ -52,13 +48,14 @@ public final class OrganizeFromEditor extends AbstractHandler {
ErrorReporter.logExceptionStackTrace("Error while creating the needed import changes",e);
return null;
}
try {
change.perform(new NullProgressMonitor());
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace("Error while performing the needed import changes",e);
}
IProject project = file.getProject();
final IProject project = file.getProject();
GlobalParser.getProjectSourceParser(project).reportOutdating(file);
GlobalParser.getProjectSourceParser(project).analyzeAll();
......
......@@ -63,19 +63,19 @@ public class TopViewOpener extends AbstractHandler implements IObjectActionDeleg
return;
}
final Object o = structSelection.getFirstElement();
if (!(o instanceof IProject)) {
final Object firstElement = structSelection.getFirstElement();
if (!(firstElement instanceof IProject)) {
ErrorReporter.logError("The open top risk view command needs to be called on a project ");
return;
}
final IProject p = (IProject) o;
final IProject project = (IProject) firstElement;
try {
final IViewPart tv = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
final IViewPart activeView = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
.showView("org.eclipse.titanium.metrics.topview");
if (tv instanceof TopView) {
final TopView topView = (TopView) tv;
topView.setSelectedProject(p);
if (activeView instanceof TopView) {
final TopView topView = (TopView) activeView;
topView.setSelectedProject(project);
topView.startMeasuring();
}
......
......@@ -19,7 +19,7 @@ import org.eclipse.titan.designer.Activator;
public class ClearAllProjects implements IApplication {
@Override
public Object start(IApplicationContext context) throws Exception {
public Object start(final IApplicationContext context) throws Exception {
Platform.getBundle("org.eclipse.titan.designer").start();
final String[] projectFiles = (String[]) context.getArguments().get(IApplicationContext.APPLICATION_ARGS);
......
......@@ -24,7 +24,7 @@ public class ExportDataForSonar extends InformationExporter {
private List<IProject> projectsToExport = new ArrayList<IProject>();
@Override
protected boolean checkParameters(String[] args) {
protected boolean checkParameters(final String[] args) {
// Use Apache CLI if more functionality is needed
if (args.length == 0) {
projectsToExport = getAllAccessibleProjects();
......@@ -41,10 +41,10 @@ public class ExportDataForSonar extends InformationExporter {
return false;
}
List<String> projectNames = Arrays.asList(args[1].split(","));
IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot();
final List<String> projectNames = Arrays.asList(args[1].split(","));
final IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot();
for (String name : projectNames) {
IProject project = wsRoot.getProject(name);
final IProject project = wsRoot.getProject(name);
if (!project.isAccessible()) {
System.out.println("Project '" + name + "' is not accessible.");
return false;
......@@ -55,13 +55,13 @@ public class ExportDataForSonar extends InformationExporter {
}
private void printUsage() {
String applicationName = ExportDataForSonar.class.getCanonicalName();
final String applicationName = ExportDataForSonar.class.getCanonicalName();
System.out.println("Usage: ./eclipse " + applicationName + " [-p project1,project2,...,projectN]");
}
@Override
protected void exportInformationForProject(String[] args, IProject project, IProgressMonitor monitor) {
SonarDataExporter exporter = new SonarDataExporter(project);
protected void exportInformationForProject(final String[] args, final IProject project, final IProgressMonitor monitor) {
final SonarDataExporter exporter = new SonarDataExporter(project);
try {
exporter.exportDataForProject();
} catch (IOException e) {
......
......@@ -19,7 +19,7 @@ import org.eclipse.titan.designer.wizards.GUIProjectImporter;
public class ImportProjectsFromPrj implements IApplication {
@Override
public Object start(IApplicationContext context) throws Exception {
public Object start(final IApplicationContext context) throws Exception {
if (!GeneralConstants.DEBUG) {
ErrorReporter.INTERNAL_ERROR("Loading prj files in headless mode is in prototype mode "
+ "and so should not be available in released versions yet");
......
......@@ -51,7 +51,7 @@ public abstract class InformationExporter implements IApplication {
protected abstract void exportInformationForProject(final String[] args, final IProject project, IProgressMonitor monitor);
@Override
public Object start(IApplicationContext context) throws Exception {
public Object start(final IApplicationContext context) throws Exception {
if (!GeneralConstants.DEBUG) {
ErrorReporter.INTERNAL_ERROR("Experimental functionaility for the Titanium project");
}
......@@ -63,20 +63,20 @@ public abstract class InformationExporter implements IApplication {
}
if (args.length >= 1){
File path = new File(args[0].substring(0, args[0].lastIndexOf(File.separator)));
final File path = new File(args[0].substring(0, args[0].lastIndexOf(File.separator)));
if (!path.exists() && !path.mkdirs()) {
System.err.println("Couldn't create output directory!");
return Integer.valueOf(-1);
}
}
List<IProject> existingProjects = getProjectsToHandle();
final List<IProject> existingProjects = getProjectsToHandle();
List<Job> jobs = new ArrayList<Job>();
final List<Job> jobs = new ArrayList<Job>();
for (IProject project : existingProjects) {
jobs.add(new ProjectAnalyzerJob("Exporting information for project " + project.getName()) {
@Override
public IStatus doPostWork(IProgressMonitor monitor) {
public IStatus doPostWork(final IProgressMonitor monitor) {
System.out.println("Exporting information for " + getProject().getName());
exportInformationForProject(args, getProject(), monitor);
return Status.OK_STATUS;
......@@ -116,7 +116,7 @@ public abstract class InformationExporter implements IApplication {
protected List<IProject> getAllAccessibleProjects() {
final IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
List<IProject> existingProjects = new ArrayList<IProject>();
final List<IProject> existingProjects = new ArrayList<IProject>();
for (IProject project : projects) {
if (project.isAccessible()) {
existingProjects.add(project);
......
......@@ -26,7 +26,7 @@ import org.eclipse.titanium.markers.export.ExportedProblemMerger;
public class MergeExportedMarkerTables implements IApplication {
@Override
public Object start(IApplicationContext context) throws Exception {
public Object start(final IApplicationContext context) throws Exception {
final String[] args = (String[]) context.getArguments().get(IApplicationContext.APPLICATION_ARGS);
......@@ -35,7 +35,7 @@ public class MergeExportedMarkerTables implements IApplication {
return Integer.valueOf(-1);
}
List<File> files = new LinkedList<File>();
final List<File> files = new LinkedList<File>();
File file;
String name = null;
......@@ -80,24 +80,24 @@ public class MergeExportedMarkerTables implements IApplication {
* The name of the output file, if null "Summary" will be the
* filename
*/
private boolean merge(List<File> files, String outfileName) {
private boolean merge(final List<File> files, final String outfileName) {
File outfile = null;
if (outfileName != null) {
outfile = new File(outfileName + ".xls");
} else {
outfile = new File("Summary.xls");
}
int i = 1;
int counter = 1;
while (outfile.exists()) {
if (outfileName != null) {
outfile = new File(outfileName + i + ".xls");
outfile = new File(outfileName + counter + ".xls");
} else {
outfile = new File("Summary" + i + ".xls");
outfile = new File("Summary" + counter + ".xls");
}
i += 1;
counter += 1;
}
ExportedProblemMerger epm = new ExportedProblemMerger(files, outfile);
final ExportedProblemMerger epm = new ExportedProblemMerger(files, outfile);
return epm.run();
}
}
......@@ -31,10 +31,10 @@ import edu.uci.ics.jung.graph.DirectedSparseGraph;
* @author Gabor Jenei
*/
public class SaveModuleDot extends InformationExporter {
private DirectedSparseGraph<NodeDescriptor, EdgeDescriptor> g=null;
private DirectedSparseGraph<NodeDescriptor, EdgeDescriptor> graph=null;
@Override
protected boolean checkParameters(String[] args) {
protected boolean checkParameters(final String[] args) {
if (args.length < 1) {
System.out.println("Usage: <output path> [-c<clustering algorithm name>]");
System.out.println("The possible clustering algorithms are: ");
......@@ -46,9 +46,9 @@ public class SaveModuleDot extends InformationExporter {
}
@Override
protected void exportInformationForProject(final String[] args, final IProject project, IProgressMonitor monitor) {
protected void exportInformationForProject(final String[] args, final IProject project, final IProgressMonitor monitor) {
final ErrorHandler errorHandler = new ConsoleErrorHandler();
GraphGenerator generator = new ModuleGraphGenerator(project, errorHandler);
final GraphGenerator generator = new ModuleGraphGenerator(project, errorHandler);
try {
generator.generateGraph();
......@@ -60,16 +60,16 @@ public class SaveModuleDot extends InformationExporter {
}
if(clusterName.isEmpty()){
g = generator.getGraph();
graph = generator.getGraph();
} else {
BaseCluster clusterer = new ClustererBuilder().
final BaseCluster clusterer = new ClustererBuilder().
setAlgorithm(clusterName).setGraph(generator.getGraph()).setProject(project).build();
clusterer.run(monitor, false);
g = clusterer.getGraph();
graph = clusterer.getGraph();
}
String fileName=args[0] + project.getName() + ".dot";
GraphHandler.saveGraphToDot(g, fileName, project.getName());
final String fileName=args[0] + project.getName() + ".dot";
GraphHandler.saveGraphToDot(graph, fileName, project.getName());
errorHandler.reportInformation("The graphs have been successfully saved. See results at "+
new File(fileName).getAbsolutePath());
} catch (Exception e) {
......
......@@ -31,10 +31,10 @@ import edu.uci.ics.jung.graph.DirectedSparseGraph;
* @author Gabor Jenei
*/
public class SaveModuleNet extends InformationExporter {
private DirectedSparseGraph<NodeDescriptor, EdgeDescriptor> g=null;
private DirectedSparseGraph<NodeDescriptor, EdgeDescriptor> graph=null;
@Override
protected boolean checkParameters(String[] args) {
protected boolean checkParameters(final String[] args) {
if (args.length < 1) {
System.out.println("Usage: <output path> [-c<clustering algorithm name>]");
System.out.println("The possible clustering algorithms are: ");
......@@ -46,9 +46,9 @@ public class SaveModuleNet extends InformationExporter {
}
@Override
protected void exportInformationForProject(final String[] args, final IProject project, IProgressMonitor monitor) {
protected void exportInformationForProject(final String[] args, final IProject project, final IProgressMonitor monitor) {
final ErrorHandler errorHandler = new ConsoleErrorHandler();
GraphGenerator generator = new ModuleGraphGenerator(project, errorHandler);
final GraphGenerator generator = new ModuleGraphGenerator(project, errorHandler);
try {