Cleanup (warnings; typos; formatting)
authorRoman Shevchenko <roman.shevchenko@jetbrains.com>
Thu, 6 Nov 2014 13:28:45 +0000 (14:28 +0100)
committerRoman Shevchenko <roman.shevchenko@jetbrains.com>
Thu, 6 Nov 2014 13:29:47 +0000 (14:29 +0100)
jps/model-impl/src/org/jetbrains/jps/model/java/impl/JavaSdkUtil.java
platform/lang-api/src/com/intellij/openapi/projectRoots/JdkUtil.java
platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ProjectSdksModel.java
platform/platform-impl/src/com/intellij/ide/actions/OpenFileAction.java

index 64ee02b8b9b3d469686eb8e436c2e2760ca3268f..07a3449283687c3124af796cb02e2feaf4220845 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2012 JetBrains s.r.o.
+ * Copyright 2000-2014 JetBrains s.r.o.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@ package org.jetbrains.jps.model.java.impl;
 import com.intellij.openapi.util.SystemInfo;
 import com.intellij.openapi.util.io.FileUtil;
 import com.intellij.util.containers.ContainerUtil;
+import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
 import java.io.File;
@@ -30,11 +31,11 @@ import java.util.Set;
  * @author nik
  */
 public class JavaSdkUtil {
-  public static List<File> getJdkClassesRoots(File home, boolean isJre) {
+  @NotNull
+  public static List<File> getJdkClassesRoots(@NotNull File home, boolean isJre) {
     FileFilter jarFileFilter = new FileFilter() {
       @Override
-      @SuppressWarnings({"HardCodedStringLiteral"})
-      public boolean accept(File f) {
+      public boolean accept(@NotNull File f) {
         return !f.isDirectory() && f.getName().endsWith(".jar");
       }
     };
index 337909b318e5b6514f78461489293a9f65b1a4ed..5772c4c1e19c7cdbd3cdd5eeea545c01cfbf53d1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2013 JetBrains s.r.o.
+ * Copyright 2000-2014 JetBrains s.r.o.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -25,7 +25,6 @@ import com.intellij.execution.configurations.SimpleJavaParameters;
 import com.intellij.ide.util.PropertiesComponent;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.project.Project;
-import com.intellij.openapi.util.Comparing;
 import com.intellij.openapi.util.io.FileUtil;
 import com.intellij.openapi.util.text.StringUtilRt;
 import com.intellij.openapi.vfs.CharsetToolkit;
@@ -61,16 +60,10 @@ public class JdkUtil {
     VirtualFile homeDirectory = jdk.getHomeDirectory();
     if (homeDirectory == null) return null;
 
-    VirtualFile rtJar = homeDirectory.findFileByRelativePath("jre/lib/rt.jar");
-    if (rtJar == null) {
-      rtJar = homeDirectory.findFileByRelativePath("lib/rt.jar");
-    }
-    if (rtJar == null) {
-      rtJar = homeDirectory.findFileByRelativePath("jre/lib/vm.jar"); // for IBM jdk
-    }
-    if (rtJar == null) {
-      rtJar = homeDirectory.findFileByRelativePath("../Classes/classes.jar"); // for mac
-    }
+    VirtualFile rtJar = homeDirectory.findFileByRelativePath("jre/lib/rt.jar");                 // JDK
+    if (rtJar == null) rtJar = homeDirectory.findFileByRelativePath("lib/rt.jar");              // JRE
+    if (rtJar == null) rtJar = homeDirectory.findFileByRelativePath("jre/lib/vm.jar");          // IBM JDK
+    if (rtJar == null) rtJar = homeDirectory.findFileByRelativePath("../Classes/classes.jar");  // Apple JDK
 
     if (rtJar == null) {
       String versionString = jdk.getVersionString();
@@ -107,17 +100,16 @@ public class JdkUtil {
     return null;
   }
 
-  public static boolean checkForJdk(final File homePath) {
+  public static boolean checkForJdk(@NotNull File homePath) {
     File binPath = new File(homePath.getAbsolutePath() + File.separator + "bin");
     if (!binPath.exists()) return false;
 
     FileFilter fileFilter = new FileFilter() {
       @Override
-      @SuppressWarnings({"HardCodedStringLiteral"})
-      public boolean accept(File f) {
+      public boolean accept(@NotNull File f) {
         if (f.isDirectory()) return false;
-        return Comparing.strEqual(FileUtil.getNameWithoutExtension(f), "javac") ||
-               Comparing.strEqual(FileUtil.getNameWithoutExtension(f), "javah");
+        String name = FileUtil.getNameWithoutExtension(f);
+        return "javac".equals(name) || "javah".equals(name);
       }
     };
     File[] children = binPath.listFiles(fileFilter);
@@ -126,16 +118,15 @@ public class JdkUtil {
            checkForRuntime(homePath.getAbsolutePath());
   }
 
-  public static boolean checkForJre(String homePath) {
+  public static boolean checkForJre(@NotNull String homePath) {
     homePath = new File(FileUtil.toSystemDependentName(homePath)).getAbsolutePath();
     File binPath = new File(homePath + File.separator + "bin");
     if (!binPath.exists()) return false;
 
     FileFilter fileFilter = new FileFilter() {
       @Override
-      @SuppressWarnings({"HardCodedStringLiteral"})
-      public boolean accept(File f) {
-        return !f.isDirectory() && Comparing.strEqual(FileUtil.getNameWithoutExtension(f), "java");
+      public boolean accept(@NotNull File f) {
+        return !f.isDirectory() && "java".equals(FileUtil.getNameWithoutExtension(f));
       }
     };
     File[] children = binPath.listFiles(fileFilter);
@@ -144,12 +135,12 @@ public class JdkUtil {
            checkForRuntime(homePath);
   }
 
-  public static boolean checkForRuntime(final String homePath) {
-    return new File(new File(new File(homePath, "jre"), "lib"), "rt.jar").exists() ||
-           new File(new File(homePath, "lib"), "rt.jar").exists() ||
-           new File(new File(new File(homePath, ".."), "Classes"), "classes.jar").exists() ||  // Apple JDK
-           new File(new File(new File(homePath, "jre"), "lib"), "vm.jar").exists() ||  // IBM JDK
-           new File(homePath, "classes").isDirectory();  // custom build
+  public static boolean checkForRuntime(@NotNull String homePath) {
+    return new File(homePath, "jre/lib/rt.jar").exists() ||          // JDK
+           new File(homePath, "lib/rt.jar").exists() ||              // JRE
+           new File(homePath, "../Classes/classes.jar").exists() ||  // Apple JDK
+           new File(homePath, "jre/lib/vm.jar").exists() ||          // IBM JDK
+           new File(homePath, "classes").isDirectory();              // custom build
   }
 
   public static GeneralCommandLine setupJVMCommandLine(final String exePath,
@@ -258,7 +249,7 @@ public class JdkUtil {
 
     commandLine.addParameters(javaParameters.getProgramParametersList().getList());
 
-    commandLine.setWorkDirectory(javaParameters.getWorkingDirectory());
+    commandLine.withWorkDirectory(javaParameters.getWorkingDirectory());
 
     return commandLine;
   }
@@ -275,24 +266,24 @@ public class JdkUtil {
   }
 
   private static void appendEncoding(SimpleJavaParameters javaParameters, GeneralCommandLine commandLine, ParametersList parametersList) {
-    // Value of -Dfile.encoding and charset of GeneralCommandLine should be in sync in order process's input and output be correctly handled.
+    // Value of file.encoding and charset of GeneralCommandLine should be in sync in order process's input and output be correctly handled.
     String encoding = parametersList.getPropertyValue("file.encoding");
     if (encoding == null) {
       Charset charset = javaParameters.getCharset();
       if (charset == null) charset = EncodingManager.getInstance().getDefaultCharset();
       if (charset == null) charset = CharsetToolkit.getDefaultSystemCharset();
-      commandLine.addParameter("-Dfile.encoding=" + charset.name());
-      commandLine.setCharset(charset);
+      if (charset != null) {
+        commandLine.addParameter("-Dfile.encoding=" + charset.name());
+        commandLine.withCharset(charset);
+      }
     }
     else {
       try {
         Charset charset = Charset.forName(encoding);
-        commandLine.setCharset(charset);
-      }
-      catch (UnsupportedCharsetException ignore) {
-      }
-      catch (IllegalCharsetNameException ignore) {
+        commandLine.withCharset(charset);
       }
+      catch (UnsupportedCharsetException ignore) { }
+      catch (IllegalCharsetNameException ignore) { }
     }
   }
 
index 87df147a745f1e8761a474b491d29a436eed2cbb..1ccbeadddeb885bbc408cbfe19c12c9189e4ec19 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2012 JetBrains s.r.o.
+ * Copyright 2000-2014 JetBrains s.r.o.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -13,7 +13,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package com.intellij.openapi.roots.ui.configuration.projectRoot;
 
 import com.intellij.openapi.actionSystem.AnAction;
@@ -36,14 +35,15 @@ import com.intellij.openapi.util.Condition;
 import com.intellij.util.ArrayUtilRt;
 import com.intellij.util.Consumer;
 import com.intellij.util.EventDispatcher;
+import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
 import javax.swing.*;
 import java.util.*;
 
 /**
- * User: anna
- * Date: 05-Jun-2006
+ * @author anna
+ * @since 05-Jun-2006
  */
 public class ProjectSdksModel implements SdkModel {
   private static final Logger LOG = Logger.getInstance("com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectSdksModel");
@@ -116,7 +116,7 @@ public class ProjectSdksModel implements SdkModel {
     return myProjectSdks;
   }
 
-  public boolean isModified(){
+  public boolean isModified() {
     return myModified;
   }
 
@@ -201,7 +201,7 @@ public class ProjectSdksModel implements SdkModel {
       final SdkAdditionalData sdkAdditionalData = currItem.getSdkAdditionalData();
       if (sdkAdditionalData instanceof ValidatableSdkAdditionalData) {
         try {
-          ((ValidatableSdkAdditionalData) sdkAdditionalData).checkValid(this);
+          ((ValidatableSdkAdditionalData)sdkAdditionalData).checkValid(this);
         }
         catch (ConfigurationException e) {
           if (rootConfigurable != null) {
@@ -249,14 +249,12 @@ public class ProjectSdksModel implements SdkModel {
     final SdkType[] types = SdkType.getAllTypes();
     for (final SdkType type : types) {
       if (filter != null && !filter.value(type)) continue;
-      final AnAction addAction = new DumbAwareAction(type.getPresentableName(),
-                                              null,
-                                              type.getIconForAddAction()) {
-          @Override
-          public void actionPerformed(AnActionEvent e) {
-            doAdd(parent, type, updateTree);
-          }
-        };
+      final AnAction addAction = new DumbAwareAction(type.getPresentableName(), null, type.getIconForAddAction()) {
+        @Override
+        public void actionPerformed(@NotNull AnActionEvent e) {
+          doAdd(parent, type, updateTree);
+        }
+      };
       group.add(addAction);
     }
   }
@@ -290,8 +288,8 @@ public class ProjectSdksModel implements SdkModel {
     if (!sdkType.setupSdkPaths(newJdk, this)) return;
 
     if (newJdk.getVersionString() == null) {
-       Messages.showMessageDialog(ProjectBundle.message("sdk.java.corrupt.error", home),
-                                  ProjectBundle.message("sdk.java.corrupt.title"), Messages.getErrorIcon());
+      String message = ProjectBundle.message("sdk.java.corrupt.error", home);
+      Messages.showMessageDialog(message, ProjectBundle.message("sdk.java.corrupt.title"), Messages.getErrorIcon());
     }
 
     doAdd(newJdk, callback);
index 55d4474787a44cd87133d5815e9b82b76ba8e1a1..5dc35db167f213ed4e2ab1c48babdc83727717f6 100644 (file)
@@ -49,7 +49,7 @@ import java.util.List;
 
 public class OpenFileAction extends AnAction implements DumbAware {
   @Override
-  public void actionPerformed(AnActionEvent e) {
+  public void actionPerformed(@NotNull AnActionEvent e) {
     final Project project = e.getProject();
     final boolean showFiles = project != null || PlatformProjectOpenProcessor.getInstanceIfItExists() != null;
     final FileChooserDescriptor descriptor = showFiles ? new ProjectOrFileChooserDescriptor() : new ProjectOnlyFileChooserDescriptor();
@@ -141,7 +141,7 @@ public class OpenFileAction extends AnAction implements DumbAware {
     }
   }
 
-  // vanilla OpenProjectFileChooserDescriptor only accepts project files; this on is overridden to accept any files
+  // vanilla OpenProjectFileChooserDescriptor only accepts project files; this one is overridden to accept any files
   private static class ProjectOrFileChooserDescriptor extends OpenProjectFileChooserDescriptor {
     private final FileChooserDescriptor myStandardDescriptor = FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor();
 
@@ -157,7 +157,7 @@ public class OpenFileAction extends AnAction implements DumbAware {
 
     @Override
     public boolean isFileSelectable(VirtualFile file) {
-      return file.isDirectory() ? super.isFileSelectable(file) :  myStandardDescriptor.isFileSelectable(file);
+      return file.isDirectory() ? super.isFileSelectable(file) : myStandardDescriptor.isFileSelectable(file);
     }
 
     @Override