Commit 7e15c5b0 authored by ekrisza's avatar ekrisza
Browse files

style improvements

parent 3e02f423
......@@ -177,10 +177,10 @@ public class FindWindow<T extends Comparable> extends Dialog {
noResult = false;
}
if (!noResult) {
showResultTable(true);
} else {
if (noResult) {
errorHandler.reportInformation("The search hasn't found such node!");
} else {
showResultTable(true);
}
}
});
......
......@@ -166,7 +166,7 @@ public class XlsProblemExporter extends BaseProblemExporter {
Row row2 = summarySheet.createRow(2);
row2.createCell(0).setCellValue("Commulative Project Risk Factor");
int riskFactor = (new RiskFactorCalculator()).measure(project, smellCount);
int riskFactor = new RiskFactorCalculator().measure(project, smellCount);
row2.createCell(1).setCellValue(riskFactor);
summarySheet.autoSizeColumn(0);
......
......@@ -10,7 +10,6 @@ package org.eclipse.titanium.markers.handler;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.titan.designer.AST.Location;
import org.eclipse.titan.designer.AST.NULL_Location;
import org.eclipse.titanium.markers.types.CodeSmellType;
/**
......
......@@ -57,7 +57,9 @@ abstract class BaseCodeSmellSpotter {
final IPreferencesService prefs = Platform.getPreferencesService();
final ProblemTypePreference pref = CodeSmellTypeToPreferenceTypeMapper.getPreferenceType(type);
if (prefs != null) {
if (prefs == null) {
severity = IMarker.SEVERITY_WARNING;
} else {
final String prefName = pref.getPreferenceName();
final String warnLevel = prefs.getString(Activator.PLUGIN_ID, prefName, GeneralConstants.IGNORE, null);
// Validating and parsing warnLevel
......@@ -70,8 +72,6 @@ abstract class BaseCodeSmellSpotter {
} else {
throw new IllegalStateException("warnLevel should be one of IGNORE, WARNING or ERROR, not " + warnLevel);
}
} else {
severity = IMarker.SEVERITY_WARNING;
}
}
......
......@@ -259,7 +259,7 @@ public class AltstepCoverage {
while (typeIt.hasNext()) {
sb.append(", ").append(typeIt.next());
}
sb.append("\n");
sb.append('\n');
}
problems.report(reportAt, sb.toString());
}
......
......@@ -11,6 +11,7 @@ import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.eclipse.titan.designer.AST.ASTVisitor;
import org.eclipse.titan.designer.AST.Assignment;
......@@ -71,7 +72,7 @@ public class Lazy extends BaseModuleCodeSmellSpotter {
node.accept(relevantNodeBuilder);
// Evaluate tree and return with FormalParameters which have to be evaluated.
HashSet<FormalParameter> shouldBeEvaluated = relevantNodeBuilder.collectRelevantReferences();
Set<FormalParameter> shouldBeEvaluated = relevantNodeBuilder.collectRelevantReferences();
for (FormalParameter formalParameter : formalParameterCollector.getItems()) {
boolean isLazy = formalParameter.getIsLazy();
......@@ -119,7 +120,7 @@ public class Lazy extends BaseModuleCodeSmellSpotter {
private List<RelevantNodeBuilder> nodes;
// Contains possible FormalParameters of expression block of If_Statement and SelectCase_Statement.
private HashSet<FormalParameter> strictFormalParameters;
private Set<FormalParameter> strictFormalParameters;
// Contains possible FormalParameters of StatementBloc and Statement and AltGuard.
private HashSet<FormalParameter> referencedFormalParameters;
......@@ -176,7 +177,7 @@ public class Lazy extends BaseModuleCodeSmellSpotter {
return V_CONTINUE;
}
public HashSet<FormalParameter> collectRelevantReferences() {
public Set<FormalParameter> collectRelevantReferences() {
HashSet<FormalParameter> shouldBeEvaluated = new HashSet<FormalParameter>();
// After that we disregard content's of nodes
......@@ -189,14 +190,14 @@ public class Lazy extends BaseModuleCodeSmellSpotter {
return referencedFormalParameters;
} else {
HashSet<FormalParameter> tempStricts = new HashSet<FormalParameter>();
Set<FormalParameter> tempStricts = new HashSet<FormalParameter>();
for (int index = 0, nodeSize = nodes.size(); index < nodeSize; ++index) {
if (haveToContinue) {
tempStricts.addAll(nodes.get(index).strictFormalParameters);
HashSet<FormalParameter> temp = nodes.get(index).collectRelevantReferences();
Set<FormalParameter> temp = nodes.get(index).collectRelevantReferences();
if (root instanceof StatementBlock || root instanceof Definition || root instanceof AltGuard) {
shouldBeEvaluated.addAll(temp);
......
......@@ -47,7 +47,9 @@ public class Statistics {
public Statistics(final double[] nums, final IMetricEnum metric, final IRisk risk) {
final int n = nums.length;
double total = 0;
double max, dev, mean;
double max;
double dev;
double mean;
final Set<StatColumn> stats = metric.requestedStatistics();
final boolean isInt = metric.isInteger();
......
......@@ -17,7 +17,8 @@ public class LinearRisk extends BaseRisk {
@Override
public double getRiskValue(final Number value) {
double risk = 0;
double l1, l2;
double l1;
double l2;
final double val = value == null ? 0.0 : value.doubleValue();
switch (method) {
case NEVER:
......
......@@ -17,7 +17,8 @@ public class TriangleRisk extends BaseRisk {
@Override
public double getRiskValue(final Number value) {
double risk = 0;
double l1, l2;
double l1;
double l2;
final double dist = 0.5 - Math.abs(value.doubleValue() - 0.5);
switch (method) {
case NEVER:
......
......@@ -38,12 +38,14 @@ class Comparator extends ViewerComparator {
final Module m1 = (Module) e1;
final Module m2 = (Module) e2;
double risk1 = 0, risk2 = 0;
double risk1 = 0;
double risk2 = 0;
for (IMetricEnum m : metrics) {
risk1 += mw.getRiskValue(m, m1.getName());
risk2 += mw.getRiskValue(m, m2.getName());
}
double r = risk2 - risk1;
final double r = risk2 - risk1;
if (r < 0.0001) {
return -1;
} else if (r > 0.0001) {
......
......@@ -37,7 +37,7 @@ import org.apache.poi.ss.usermodel.Sheet;
*/
class XLSExporter {
private File file;
private MetricData data;
private final MetricData data;
public XLSExporter(final MetricData data) {
this.data = data;
......@@ -119,7 +119,7 @@ class XLSExporter {
}
class CNComparator implements Comparator<IContentNode> {
private MetricData data;
private final MetricData data;
public CNComparator(final MetricData data) {
this.data = data;
......
......@@ -208,15 +208,15 @@ public final class OrganizeImports {
final Module addMod = parser.getModuleByName(parser.containedModule(file));
final String importName = addMod.getIdentifier().getTtcnName();
if (!importNamesAdded.contains(importName)) {
StringBuilder impText = new StringBuilder("import from " + importName + " all;");
StringBuilder impText = new StringBuilder("import from ").append(importName).append(" all;");
if (importChangeMethod.equals(OrganizeImportPreferencePage.COMMENT_THEM)) {
impText.append(" // Added automatically to resolve " + ref.getDisplayName());
impText.append(" // Added automatically to resolve ").append(ref.getDisplayName());
}
newImports.add(new ImportText(importName, impText.toString() + NEWLINE));
importNamesAdded.add(importName);
if (reportDebug) {
StringBuilder sb = new StringBuilder("For " + ref.getDisplayName() + ": ");
StringBuilder sb = new StringBuilder("For ").append(ref.getDisplayName()).append(": ");
sb.append(impText.toString());
TITANDebugConsole.println(sb.toString());
}
......@@ -362,11 +362,7 @@ class ImportText implements Comparable<ImportText> {
return false;
}
if (moduleName.equals(((ImportText) obj).moduleName)) {
return true;
}
return false;
return moduleName.equals(((ImportText) obj).moduleName);
}
@Override
......
......@@ -49,6 +49,8 @@ public final class PreferenceConstants {
public static final String CLUSTER_AUTO_FOLDER = "Auto_folder";
public static final String CLUSTER_AUTO_REGEXP = "Auto_regexp";
public static final String CLUSTER_AUTO_NAME = "Auto_name";
public static final String BASE_RISK_FACTOR = "BASE_RISK_FACTOR";
/** private constructor to disable instantiation */
private PreferenceConstants() {
......@@ -70,6 +72,4 @@ public final class PreferenceConstants {
public static String nameMetricGraph(final String id) {
return METRIC_GRAPH + id;
}
public static final String BASE_RISK_FACTOR = "BASE_RISK_FACTOR";
}
......@@ -49,7 +49,7 @@ public class MetricsLimitPreferencePage extends PreferencePage implements IWorkb
GridLayout l = new GridLayout();
l.numColumns = 2;
page.setLayout(l);
for (org.eclipse.titanium.metrics.MetricGroup type : MetricGroup.values()) {
for (MetricGroup type : MetricGroup.values()) {
Label header = new Label(page, 0);
header.setText(type.getGroupName() + " metrics");
GridData headerData = new GridData();
......
......@@ -46,7 +46,7 @@ public class MetricsViewPreferencePage extends PreferencePage implements IWorkbe
GridLayout l = new GridLayout();
l.numColumns = 2;
page.setLayout(l);
for (org.eclipse.titanium.metrics.MetricGroup type : MetricGroup.values()) {
for (MetricGroup type : MetricGroup.values()) {
Label header = new Label(page, 0);
header.setText(type.getGroupName() + " metrics");
GridData headerData = new GridData();
......
......@@ -215,11 +215,11 @@ public class RiskFactorPreferencePage extends PreferencePage implements IWorkben
return prefStore;
}
static void insertSP(final CodeSmellType p) {
private static void insertSP(final CodeSmellType p) {
USED_MARKERS.put(p.name(), p.getHumanReadableName());
}
static void insertTask(final TaskType p) {
private static void insertTask(final TaskType p) {
USED_MARKERS.put(p.name(), p.getHumanReadableName());
}
}
\ No newline at end of file
......@@ -38,7 +38,7 @@ public final class LocationHighlighter {
try {
final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
final IEditorPart editorPart = page.openEditor(new FileEditorInput((IFile) location.getFile()), desc.getId());
if (editorPart != null && (editorPart instanceof AbstractTextEditor)) {
if (editorPart != null && editorPart instanceof AbstractTextEditor) {
((AbstractTextEditor) editorPart).setHighlightRange(location.getOffset(), 0, true);
}
......
......@@ -58,12 +58,13 @@ public class ProjectAnalyzerJob extends WorkspaceJob {
*/
@Override
public final IStatus runInWorkspace(final IProgressMonitor monitor) {
SubMonitor progress = SubMonitor.convert(monitor, 100);
final SubMonitor progress = SubMonitor.convert(monitor, 100);
if (project == null) {
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Project not specified for ProjectAnalyzerJob");
}
ProjectSourceParser parser = GlobalParser.getProjectSourceParser(project);
WorkspaceJob job = parser.analyzeAll();
final ProjectSourceParser parser = GlobalParser.getProjectSourceParser(project);
final WorkspaceJob job = parser.analyzeAll();
if (job == null) {
// maybe parsing is disabled
Display.getDefault().syncExec(new Runnable() {
......@@ -72,7 +73,7 @@ public class ProjectAnalyzerJob extends WorkspaceJob {
final Display disp = Display.getDefault();
final Shell shell = new Shell(disp, SWT.SHELL_TRIM);
shell.setText("Unavailable operation");
String errorMessage = "This operation can not be executed while project parsing is disabled.\n\n"
final String errorMessage = "This operation can not be executed while project parsing is disabled.\n\n"
+ "Please enable parsing on the preference page: Window/Preferences/ TITAN Preferences/"
+ "On-the-fly checker/ Enable parsing of TTCN-3, ASN.1 and Runtime Configuration files";
MessageDialog.openInformation(shell, "Confronting settings", errorMessage);
......@@ -81,7 +82,7 @@ public class ProjectAnalyzerJob extends WorkspaceJob {
return Status.CANCEL_STATUS;
}
IStatus preStatus = doPreWork(progress.newChild(20));
final IStatus preStatus = doPreWork(progress.newChild(20));
progress.setWorkRemaining(80);
if (!preStatus.isOK()) {
return preStatus;
......
......@@ -46,7 +46,7 @@ public class ProjectStructureExporter {
@Override
public boolean visit(final IResource resource) throws CoreException {
ResourceData data = new ResourceData();
final ResourceData data = new ResourceData();
switch (resource.getType()) {
case IResource.PROJECT:
......@@ -82,7 +82,7 @@ public class ProjectStructureExporter {
}
public void saveTo(final URI path) throws IOException {
ResourceVisitor visitor = new ResourceVisitor();
final ResourceVisitor visitor = new ResourceVisitor();
try {
project.accept(visitor);
} catch (CoreException e1) {
......@@ -92,7 +92,7 @@ public class ProjectStructureExporter {
BufferedWriter writer = null;
try {
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(path)), "UTF-8"));
MapAppender appender = new MapAppender(writer, StringUtils.lineSeparator(), ";");
final MapAppender appender = new MapAppender(writer, StringUtils.lineSeparator(), ";");
for (ResourceData data : visitor.resources) {
appender.append(data.type, data.projectRelativePath, data.absoluteURI.toString());
}
......
......@@ -57,8 +57,8 @@ public class SonarDataExporter {
final URI exportDir = URIUtil.append(projectLocation, ".sonar_titanium");
System.out.println("Export dir is: " + exportDir.getPath());
final File f = new File(exportDir);
if (!f.exists() && !f.mkdirs()) {
final File file = new File(exportDir);
if (!file.exists() && !file.mkdirs()) {
throw new IOException("Cannot create output directory: " + exportDir);
}
try {
......@@ -85,12 +85,12 @@ public class SonarDataExporter {
private void exportMetrics(final URI exportDir) throws IOException {
final URI filePath = URIUtil.append(exportDir, "metrics.xml");
final File f = new File(filePath);
FileUtils.delete(f);
final File file = new File(filePath);
FileUtils.delete(file);
final SonarMetricsExporter exporter = new SonarMetricsExporter();
try {
exporter.export(MetricData.measure(project), f);
exporter.export(MetricData.measure(project), file);
} catch (JAXBException e) {
new ConsoleErrorHandler().reportException("Error while exporting the project metrics", e);
}
......@@ -135,8 +135,8 @@ public class SonarDataExporter {
private void exportCodeSmells(final URI exportDir) throws IOException {
final URI filePath = URIUtil.append(exportDir, "code_smells.csv");
final File f = new File(filePath);
FileUtils.delete(f);
final File file = new File(filePath);
FileUtils.delete(file);
final BaseProblemExporter exporter = new SingleCsvProblemExporter(project);
exporter.exportMarkers(new NullProgressMonitor(), filePath.getPath(), Calendar.getInstance().getTime());
}
......
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