From 7b406a020cc58a2f533e6b6ea91de2ca5ce876ef Mon Sep 17 00:00:00 2001 From: Vodorok Date: Thu, 19 Sep 2019 18:06:55 +0200 Subject: [PATCH] CodacyFixes --- .../plugin/codechecker/CodeChecker.java | 19 +++++++++++-------- .../plugin/codechecker/ICodeChecker.java | 10 ++++++++-- .../eclipse/plugin/config/CommonGui.java | 7 +++++-- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/codechecker/CodeChecker.java b/bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/codechecker/CodeChecker.java index cde129b2..f4f261d2 100644 --- a/bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/codechecker/CodeChecker.java +++ b/bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/codechecker/CodeChecker.java @@ -14,6 +14,7 @@ import org.codechecker.eclipse.plugin.runtime.ShellExecutorHelper; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; import com.google.common.base.Optional; @@ -21,6 +22,7 @@ * Internal representation of a CodeChecker package. */ public class CodeChecker implements ICodeChecker { + private static final String OPTION_SEPARATOR = " "; private static final String LOCATION_KEY = "location"; private static final String RESULTS_KEY = "results"; @@ -91,30 +93,31 @@ public String analyze(Path logFile, boolean logToConsole, IProgressMonitor monit } @Override - public String getAnalyzeString(CcConfigurationBase config, Path logFile) { + public String getAnalyzeString(CcConfigurationBase config, @Nullable Path logFile) { if (logFile != null) { subMap.put(RESULTS_KEY, logFile.getParent().toAbsolutePath().resolve(Paths.get(RESULTS_FOLDER)).toFile()); subMap.put(LOGFILE_KEY, logFile.toAbsolutePath().toFile()); } - String[] temp = getSubstituteAnalyzeString(config).split(" "); + String[] temp = getSubstituteAnalyzeString(config).split(OPTION_SEPARATOR); StringBuilder cmd = new StringBuilder(); for (String s : temp) { + String tempString = s; if (s.startsWith("${")) { - StringBuilder sb = new StringBuilder(s); + StringBuilder sb = new StringBuilder(tempString); sb.delete(0, 2).deleteCharAt(sb.length() - 1); if (subMap.containsKey(sb.toString())) - s = subMap.get(sb.toString()).toString(); + tempString = subMap.get(sb.toString()).toString(); } - cmd.append(s); - cmd.append(' '); + cmd.append(tempString); + cmd.append(OPTION_SEPARATOR); } return cmd.toString(); } private String getSubstituteAnalyzeString(CcConfigurationBase config) { return LOCATION_SUB + " analyze" + " -j " - + config.get(ConfigTypes.ANAL_THREADS) + " -n javarunner" + " -o " + RESULTS_SUB + " " + LOGFILE_SUB - + " " + config.get(ConfigTypes.ANAL_OPTIONS); + + config.get(ConfigTypes.ANAL_THREADS) + " -n javarunner" + " -o " + RESULTS_SUB + OPTION_SEPARATOR + + LOGFILE_SUB + OPTION_SEPARATOR + config.get(ConfigTypes.ANAL_OPTIONS); } } diff --git a/bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/codechecker/ICodeChecker.java b/bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/codechecker/ICodeChecker.java index 53c1538d..a33b1a8b 100644 --- a/bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/codechecker/ICodeChecker.java +++ b/bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/codechecker/ICodeChecker.java @@ -6,6 +6,7 @@ import org.codechecker.eclipse.plugin.config.CcConfigurationBase; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; /** * Interface representing a CodeChecker package. @@ -40,10 +41,15 @@ public interface ICodeChecker { /** * Returns the analyze command to be run, without extra parameters. - * + * + * @param logFile + * A Path to the build log in the following format: + * http://clang.llvm.org/docs/JSONCompilationDatabase.html . + * @param config + * The configuration being used. * @return The analyze command as String. */ - public String getAnalyzeString(CcConfigurationBase config, Path logFile); + public String getAnalyzeString(CcConfigurationBase config, @Nullable Path logFile); /** * Executes CodeChecker check command on the build log received in the logFile diff --git a/bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/config/CommonGui.java b/bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/config/CommonGui.java index 38140974..638f1a17 100644 --- a/bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/config/CommonGui.java +++ b/bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/config/CommonGui.java @@ -58,6 +58,9 @@ public class CommonGui { private static final int FORM_COLUMNS = 3; private static final int FORM_ONE_ROW = 1; + private static final int AN_CMD_DISP_HGT = 300; + private static final int TRI_LINE_TEXT_HGT = 52; + private boolean globalGui;// whether this class is for global or project // specific preferences private boolean useGlobalSettings;// if this is project specific page, @@ -176,7 +179,7 @@ public Control createContents(final Composite parent) { toolkit.createLabel(comp, "Extra analysis options"); analysisOptions = toolkit.createText(comp, "", SWT.WRAP | SWT.BORDER | SWT.V_SCROLL); - GridDataFactory.fillDefaults().grab(false, true).hint(TEXTWIDTH, 52).applyTo(analysisOptions); + GridDataFactory.fillDefaults().grab(false, true).hint(TEXTWIDTH, TRI_LINE_TEXT_HGT).applyTo(analysisOptions); analysisOptions.addModifyListener(new ModifyListener() { @Override @@ -199,7 +202,7 @@ public void modifyText(ModifyEvent e) { toolkit.createLabel(comp, ""); toolkit.createLabel(comp, "Final analysis command"); analysisCmdDisplay = toolkit.createText(comp, "", SWT.MULTI | SWT.WRAP | SWT.V_SCROLL); - GridDataFactory.fillDefaults().grab(false, true).hint(TEXTWIDTH, 300).applyTo(analysisCmdDisplay); + GridDataFactory.fillDefaults().grab(false, true).hint(TEXTWIDTH, AN_CMD_DISP_HGT).applyTo(analysisCmdDisplay); analysisCmdDisplay.setEditable(false); analysisCmdDisplay.getVerticalBar().setEnabled(true); toolkit.createLabel(comp, "");