Ejemplo n.º 1
0
 void store() {
   if (javaServerRadioButton.isSelected())
     NbPreferences.forModule(NetworkingPanel.class)
         .put("NetworkConnection", InsecureClientManager.class.getName());
   else NbPreferences.root().put("NetworkConnection", "JSON CONNECTION CLASS");
   NbPreferences.root().put("ServerAddress", serverAddressField.getText());
 }
  /** Creates new form DuplicateColumnUI */
  public ConvertColumnToDynamicTimestampsUI() {
    initComponents();

    timestampText.setText(
        NbPreferences.forModule(ConvertColumnToDynamicTimestampsUI.class)
            .get(TIMESTAMP_PREFERENCE, DEFAULT_TIMESTAMP));
    replaceColumnCheckbox.setSelected(
        NbPreferences.forModule(ConvertColumnToDynamicTimestampsUI.class)
            .getBoolean(REPLACE_COLUMN_PREFERENCE, false));
  }
Ejemplo n.º 3
0
 void load() {
   javaServerRadioButton.setSelected(true);
   serverAddressField.setText(NbPreferences.root().get("ServerAddress", "master.betaville.net"));
   if (NbPreferences.root()
       .get("NetworkConnection", InsecureClientManager.class.getName())
       .equals(InsecureClientManager.class.getName())) {
     javaServerRadioButton.setSelected(true);
   } else {
     webServiceRadioButton.setSelected(true);
   }
 }
Ejemplo n.º 4
0
 private void storeHistory() {
   Preferences preferences;
   if (SelectProviderPanel.USE_PROJECT_PROPERTIES) {
     preferences =
         ProjectUtils.getPreferences(wizardDescriptor.getProject(), ProviderControl.class, false);
   } else {
     preferences = NbPreferences.forModule(ProviderControl.class);
     field.setStorage(propertyKey, NbPreferences.forModule(ProviderControl.class));
   }
   field.setStorage(propertyKey, preferences);
   field.store();
 }
 private String formatCurrency(String amount) {
   String text = "";
   if (NbPreferences.root().getBoolean("inFront", false)) {
     text += NbPreferences.root().get("currency", " €");
   }
   text += amount;
   if (NbPreferences.root().getBoolean("inFront", false)) {
   } else {
     text += NbPreferences.root().get("currency", " €");
   }
   return text;
 }
    public void save(WebSiteExporter exporter) {
      this.attribures = exporter.isExportAttributes();
      this.colors = exporter.isExportColors();
      this.dynamic = exporter.isExportDynamic();
      this.position = exporter.isExportPosition();
      this.position = exporter.isExportSize();

      NbPreferences.forModule(WebSiteExporterUI.class).putBoolean(LAST_ATTRIBUTES, attribures);
      NbPreferences.forModule(WebSiteExporterUI.class).putBoolean(LAST_ATTRIBUTES, colors);
      NbPreferences.forModule(WebSiteExporterUI.class).putBoolean(LAST_ATTRIBUTES, dynamic);
      NbPreferences.forModule(WebSiteExporterUI.class).putBoolean(LAST_ATTRIBUTES, position);
      NbPreferences.forModule(WebSiteExporterUI.class).putBoolean(LAST_ATTRIBUTES, size);
    }
    public void load(WebSiteExporter exporter) {
      attribures =
          NbPreferences.forModule(WebSiteExporterUI.class).getBoolean(LAST_ATTRIBUTES, attribures);
      colors = NbPreferences.forModule(WebSiteExporterUI.class).getBoolean(LAST_ATTRIBUTES, colors);
      dynamic =
          NbPreferences.forModule(WebSiteExporterUI.class).getBoolean(LAST_ATTRIBUTES, dynamic);
      position =
          NbPreferences.forModule(WebSiteExporterUI.class).getBoolean(LAST_ATTRIBUTES, position);
      size = NbPreferences.forModule(WebSiteExporterUI.class).getBoolean(LAST_ATTRIBUTES, size);

      exporter.setExportAttributes(attribures);
      exporter.setExportColors(colors);
      exporter.setExportDynamic(dynamic);
      exporter.setExportPosition(position);
      exporter.setExportSize(size);
    }
Ejemplo n.º 8
0
  @Override
  public void startup() {
    final String OPEN_LAST_PROJECT_ON_STARTUP = "Open_Last_Project_On_Startup";
    final String NEW_PROJECT_ON_STARTUP = "New_Project_On_Startup";
    boolean openLastProject =
        NbPreferences.forModule(ProjectControllerImpl.class)
            .getBoolean(OPEN_LAST_PROJECT_ON_STARTUP, false);
    boolean newProjectStartup =
        NbPreferences.forModule(ProjectControllerImpl.class)
            .getBoolean(NEW_PROJECT_ON_STARTUP, false);

    // Default project
    if (!openLastProject && newProjectStartup) {
      newProject();
    }
  }
  private String formatWithIVA(BigDecimal price) {
    BigDecimal iva =
        new BigDecimal(NbPreferences.root().get("iva", "21")).divide(new BigDecimal("100"));

    BigDecimal total = price.add(price.multiply(iva));

    return formatCurrency(total.setScale(2, RoundingMode.HALF_UP).toPlainString());
  }
Ejemplo n.º 10
0
  /**
   * Return the backing store Preferences
   *
   * @return Preferences
   */
  protected final Preferences getPreferences() {
    String name = DEFAULT_NODE_NAME;
    if (nodeName != null) {
      name = nodeName;
    }

    Preferences prefs = NbPreferences.forModule(this.getClass()).node("options").node(name);

    return prefs;
  }
Ejemplo n.º 11
0
    @Override
    public ChangeInfo implement() throws Exception {
      if (disable) {
        NbPreferences.forModule(RunFindBugs.class).node("global-settings").putBoolean(bugId, false);
      } else {
        OptionsDisplayer.getDefault().open("Editor/Hints/text/findbugs+x-java/" + bugId);
      }

      return null;
    }
 protected final Preferences getPreferences(boolean allowGrouped) {
   if (allowGrouped) {
     Group act = Group.getActiveGroup();
     if (act != null) {
       // TODO replace with NbPreferences.forModule()
       return act.prefs()
           .node(OpenProjectListSettings.class.getPackage().getName().replace(".", "/"));
     }
   }
   return NbPreferences.forModule(OpenProjectListSettings.class);
 }
  @Override
  public void selectPerspective(Perspective perspective) {
    if (perspective.getName().equals(selectedPerspective)) {
      return;
    }

    openAndCloseMembers(perspective);

    selectedPerspective = perspective.getName();
    NbPreferences.root().put(SELECTED_PERSPECTIVE_PREFERENCE, selectedPerspective);
  }
Ejemplo n.º 14
0
 private void initComboBox(String root) {
   Preferences preferences;
   if (SelectProviderPanel.USE_PROJECT_PROPERTIES) {
     preferences =
         ProjectUtils.getPreferences(wizardDescriptor.getProject(), ProviderControl.class, false);
   } else {
     preferences = NbPreferences.forModule(ProviderControl.class);
   }
   field.setStorage(propertyKey, preferences);
   field.read(root);
 }
  @Override
  public void unSetup() {
    String timestampString = timestampText.getText();
    boolean replaceColumn = replaceColumnCheckbox.isSelected();

    NbPreferences.forModule(ConvertColumnToDynamicTimestampsUI.class)
        .put(TIMESTAMP_PREFERENCE, timestampString);
    NbPreferences.forModule(ConvertColumnToDynamicTimestampsUI.class)
        .putBoolean(REPLACE_COLUMN_PREFERENCE, replaceColumn);

    if (!validationPanel.isProblem()) {
      manipulator.setTitle(titleTextField.getText());
      manipulator.setReplaceColumn(replaceColumn);

      double timestamp = AttributeUtils.parseDateTimeOrTimestamp(timestampString);

      manipulator.setLow(timestamp);
      manipulator.setHigh(timestamp);
    }
  }
Ejemplo n.º 16
0
  @Override
  public SonarRunnerResult execute() throws Exception {
    PrintStreamConsumer out =
        new PrintStreamConsumer(null) {

          @Override
          public void consumeLine(String line) {
            io.getOut().println(line);
          }
        };

    PrintStreamConsumer err =
        new PrintStreamConsumer(null) {

          @Override
          public void consumeLine(String line) {
            io.getErr().println(line);
          }
        };
    SonarRunnerProccess sonarRunnerProccess =
        new SonarRunnerProccess(getServerUrl(), getProjectContext().getProject());
    sonarRunnerProccess.setAnalysisMode(
        SonarRunnerProccess.AnalysisMode.valueOf(
            NbPreferences.forModule(SonarQubeOptionsPanel.class)
                .get("runner.analysisMode", "Preview")
                .toUpperCase()));
    String jvmArguments =
        NbPreferences.forModule(SonarQubeOptionsPanel.class).get("runner.jvmArguments", "");
    sonarRunnerProccess.setJvmArguments(Arrays.asList(jvmArguments.split(" +")));
    sonarRunnerProccess.setOutConsumer(out);
    sonarRunnerProccess.setErrConsumer(err);
    return sonarRunnerProccess.executeRunner(
        getUserCredentials(),
        new ProcessMonitor() {

          @Override
          public boolean stop() {
            return stopped;
          }
        });
  }
 void store() {
   // TODO store modified settings
   // Example:
   // Preferences.userNodeForPackage(BuildActionsPanel.class).putBoolean("someFlag",
   // someCheckBox.isSelected());
   // or for org.openide.util with API spec. version >= 7.4:
   // NbPreferences.forModule(BuildActionsPanel.class).putBoolean("someFlag",
   // someCheckBox.isSelected());
   // or:
   // SomeSystemOption.getDefault().setSomeStringProperty(someTextField.getText());
   NbPreferences.forModule(BuildActionsPanel.class).put("build", jTextArea1.getText());
 }
 void load() {
   // TODO read settings and initialize GUI
   // Example:
   // someCheckBox.setSelected(Preferences.userNodeForPackage(BuildActionsPanel.class).getBoolean("someFlag", false));
   // or for org.openide.util with API spec. version >= 7.4:
   // someCheckBox.setSelected(NbPreferences.forModule(BuildActionsPanel.class).getBoolean("someFlag", false));
   // or:
   // someTextField.setText(SomeSystemOption.getDefault().getSomeStringProperty());
   String text = NbPreferences.forModule(BuildActionsPanel.class).get("build", null);
   if (text != null) {
     jTextArea1.setText(text);
   }
 }
  public PerspectiveControllerImpl() {
    // Load perspectives
    perspectives = Lookup.getDefault().lookupAll(Perspective.class).toArray(new Perspective[0]);
    members =
        Lookup.getDefault().lookupAll(PerspectiveMember.class).toArray(new PerspectiveMember[0]);

    // Find if there is a default
    String firstPerspective = perspectives.length > 0 ? perspectives[0].getName() : null;
    String defaultPerspectiveName = System.getProperty("org.gephi.perspective.default");
    if (defaultPerspectiveName != null) {
      for (Perspective p : perspectives) {
        if (p.getName().equals(defaultPerspectiveName)) {
          selectedPerspective = p.getName();
          break;
        }
      }
    }
    if (selectedPerspective == null) {
      selectedPerspective =
          NbPreferences.root().get(SELECTED_PERSPECTIVE_PREFERENCE, firstPerspective);
    }

    // Store selected in prefs
    NbPreferences.root().put(SELECTED_PERSPECTIVE_PREFERENCE, selectedPerspective);

    WindowManager.getDefault()
        .invokeWhenUIReady(
            new Runnable() {

              @Override
              public void run() {
                // Set to previously selected perspective
                Perspective selectedPerspectiveInstance = getSelectedPerspective();

                openAndCloseMembers(selectedPerspectiveInstance);
              }
            });
  }
 public void getUserPreferences() {
   if (maincont == null) {
     return;
   }
   Preferences p =
       NbPreferences.forModule(
           com.iontorrent.torrentscout.explorer.options.TorrentExplorerPanel.class);
   int span = p.getInt("span", 8);
   int size = p.getInt("masksize", 100);
   automatic_nn = p.getBoolean("automatic_nn", true);
   maincont.setRasterSize(size);
   maincont.setSpan(span);
   maincont.setMedianFunction("median");
 }
Ejemplo n.º 21
0
/** Sets up an options category under Miscellaneous. */
@OptionsPanelController.SubRegistration(
    id = "TermAdvancedOption", // NOI18N
    displayName = "#CTL_Term_options", // NOI18N
    keywords = "#KW_TerminalOptions", // NOI18N
    keywordsCategory = "Advanced/TermAdvancedOption" // NOI18N
    // tooltip="#CTL_Term_options" // NOI18N
    )
public final class TermAdvancedOption extends OptionsPanelController {
  private TermOptions termOptions;
  private TermOptions clonedTermOptions;
  private TermOptionsPanel panel;

  /** Preferences in which we store term settings. */
  private static final Preferences prefs = NbPreferences.forModule(TermAdvancedOption.class);

  private void reset() {
    termOptions = TermOptions.getDefault(prefs);
    clonedTermOptions = termOptions.makeCopy();
    panel.setTermOptions(clonedTermOptions);
  }

  // implement OptionsPanelController
  @Override
  public JComponent getComponent(Lookup masterLookup) {
    panel = new TermOptionsPanel();
    return panel;
  }

  /** Load data from model. Called after getComponent(). */

  // implement OptionsPanelController
  @Override
  public void update() {
    reset();
  }

  // implement OptionsPanelController
  @Override
  public void cancel() {
    reset();
  }

  // implement OptionsPanelController
  @Override
  public void applyChanges() {
    if (termOptions == null) return; // update wasn't called
    // assign will fire a property change
    termOptions.assign(clonedTermOptions);
    termOptions.storeTo(prefs);
  }

  // implement OptionsPanelController
  @Override
  public boolean isChanged() {
    clonedTermOptions = termOptions.makeCopy();
    if (clonedTermOptions == null) {
      return false;
    } else {
      return clonedTermOptions.isDirty();
    }
  }

  // implement OptionsPanelController
  @Override
  public boolean isValid() {
    // always valid
    return true;
  }

  // implement OptionsPanelController
  @Override
  public HelpCtx getHelpCtx() {
    return new HelpCtx("netbeans.optionsDialog.advanced.terminal"); // NOI18N
  }

  // implement OptionsPanelController
  @Override
  public void addPropertyChangeListener(PropertyChangeListener l) {}

  // implement OptionsPanelController
  @Override
  public void removePropertyChangeListener(PropertyChangeListener l) {}
}
Ejemplo n.º 22
0
 private RserveConnectionFactory() {
   NbPreferences.forModule(RserveConnectionFactory.class).addPreferenceChangeListener(this);
   loadPreferences();
 }
Ejemplo n.º 23
0
  public static final class Accessor {
    private final Preferences preferences = NbPreferences.forModule(NamedOption.class);

    public final boolean getBoolean(String name) {
      NamedOption option = findOption(name);
      if (option.getKind() == OptionKind.Boolean) {
        return preferences.getBoolean(option.getName(), (Boolean) option.getDefaultValue());
      }
      throw new IllegalArgumentException(
          "Option " + option.getName() + " is not boolean"); // NOI18N
    }

    public final void setBoolean(String name, boolean value) {
      NamedOption option = findOption(name);
      if (option.getKind() == OptionKind.Boolean) {
        preferences.putBoolean(option.getName(), value);
        return;
      }
      throw new IllegalArgumentException(
          "Option " + option.getName() + " is not boolean"); // NOI18N
    }

    public final int getInteger(String name) {
      NamedOption option = findOption(name);
      if (option.getKind() == OptionKind.Integer) {
        return preferences.getInt(option.getName(), (Integer) option.getDefaultValue());
      }
      throw new IllegalArgumentException(
          "Option " + option.getName() + " is not integer"); // NOI18N
    }

    public final void setInteger(String name, int value) {
      NamedOption option = findOption(name);
      if (option.getKind() == OptionKind.Integer) {
        preferences.putInt(option.getName(), value);
        return;
      }
      throw new IllegalArgumentException(
          "Option " + option.getName() + " is not integer"); // NOI18N
    }

    public final String getString(String name) {
      NamedOption option = findOption(name);
      if (option.getKind() == OptionKind.String) {
        return preferences.get(option.getName(), (String) option.getDefaultValue());
      }
      throw new IllegalArgumentException("Option " + option.getName() + " is not string"); // NOI18N
    }

    public final void setString(String name, String value) {
      NamedOption option = findOption(name);
      if (option.getKind() == OptionKind.String) {
        preferences.get(option.getName(), value);
        return;
      }
      throw new IllegalArgumentException("Option " + option.getName() + " is not string"); // NOI18N
    }

    private NamedOption findOption(String name) {
      for (String category :
          Arrays.asList(
              HIGHLIGTING_CATEGORY, HINTS_CATEGORY, MAKE_PROJECT_CATEGORY, OTHER_CATEGORY)) {
        for (NamedOption option : Lookups.forPath(category).lookupAll(NamedOption.class)) {
          if (name.equals(option.getName())) {
            return option;
          }
        }
      }
      for (NamedOption option : Lookup.getDefault().lookupAll(NamedOption.class)) {
        if (name.equals(option.getName())) {
          return option;
        }
      }
      throw new IllegalArgumentException("Not found option " + name); // NOI18N
    }
  }
Ejemplo n.º 24
0
 private void loadPreferences() {
   unixRlocations =
       NbPreferences.forModule(RserveConnectionFactory.class)
           .get(RserveConnectionFactory.KEY_RBINARY_LOCATIONS, defaultUnixRlocations)
           .split(",");
   rArgs =
       NbPreferences.forModule(RserveConnectionFactory.class)
           .get(RserveConnectionFactory.KEY_RARGS, defaultRargs);
   String rbinary =
       NbPreferences.forModule(RserveConnectionFactory.class).get(KEY_RBINARY_LOCATION, null);
   if (rbinary != null && !rbinary.isEmpty()) {
     rBinaryLocation = new File(rbinary);
   }
   rserveCalls =
       NbPreferences.forModule(RserveConnectionFactory.class)
           .get(RserveConnectionFactory.KEY_RSERVECALLS, defaultRserveCalls)
           .split(",");
   rServeArgs =
       NbPreferences.forModule(RserveConnectionFactory.class)
           .get(RserveConnectionFactory.KEY_RSERVEARGS, defaultRserveArgs);
   rserveCall =
       NbPreferences.forModule(RserveConnectionFactory.class)
           .get(RserveConnectionFactory.KEY_RSERVECALL, null);
   rserveRemoteHost =
       NbPreferences.forModule(RserveConnectionFactory.class)
           .get(RserveConnectionFactory.KEY_RSERVE_HOST, "127.0.0.1");
   rserveRemotePort =
       NbPreferences.forModule(RserveConnectionFactory.class)
           .get(RserveConnectionFactory.KEY_RSERVE_PORT, "6311");
   boolean localServer =
       Boolean.valueOf(
           NbPreferences.forModule(RserveConnectionFactory.class)
               .get(RserveConnectionFactory.KEY_RSERVE_LOCAL, "true"));
   isLocalServer = localServer;
   debug =
       Boolean.valueOf(
           NbPreferences.forModule(RserveConnectionFactory.class)
               .get(RserveConnectionFactory.KEY_RSERVE_DEBUG, "false"));
   userName =
       NbPreferences.forModule(RserveConnectionFactory.class)
           .get(RserveConnectionFactory.KEY_RSERVE_USER, null);
   StringBuilder sb = new StringBuilder();
   sb.append("unixRlocations: ").append(Arrays.toString(unixRlocations)).append("\n");
   sb.append("rBinaryLocation: ").append(rBinaryLocation).append("\n");
   sb.append("rArgs: ").append(rArgs).append("\n");
   sb.append("rServeArgs: ").append(rServeArgs).append("\n");
   sb.append("rserveCalls: ").append(Arrays.toString(rserveCalls)).append("\n");
   sb.append("rserveCall: ").append(rserveCall).append("\n");
   sb.append("Remote Host: ").append(rserveRemoteHost).append("\n");
   sb.append("Remote Port: ").append(rserveRemotePort).append("\n");
   sb.append("Current mode: ").append(isLocalServer ? "Local" : "Remote").append("\n");
   sb.append("Debug mode: ").append(debug ? "TRUE" : "FALSE").append("\n");
   Logger.getLogger(RserveConnectionFactory.class.getName()).info(sb.toString());
 }
 protected final Preferences getPreferences() {
   return NbPreferences.forModule(OpenProjectListSettings.class);
 }
Ejemplo n.º 26
0
 void load() {
   openSchema.setSelected(
       NbPreferences.forModule(RunnerPanel.class).getBoolean(SCHEMA_OPEN, true));
   showOutputWindow.setSelected(
       NbPreferences.forModule(RunnerPanel.class).getBoolean(OUTPUT_SHOW, false));
 }
Ejemplo n.º 27
0
 void store() {
   NbPreferences.forModule(RunnerPanel.class).putBoolean(SCHEMA_OPEN, openSchema.isSelected());
   NbPreferences.forModule(RunnerPanel.class)
       .putBoolean(OUTPUT_SHOW, showOutputWindow.isSelected());
 }
Ejemplo n.º 28
0
 public String getNickname() {
   return NbPreferences.root().node("/org/chartsy/chat").get("nickname", "");
 }
Ejemplo n.º 29
0
  public static List<ErrorDescription> runFindBugs(
      CompilationInfo info,
      Preferences customSettings,
      String singleBug,
      FileObject sourceRoot,
      Iterable<? extends String> classNames,
      FindBugsProgress progress,
      SigFilesValidator validator) {
    List<ErrorDescription> result = new ArrayList<ErrorDescription>();

    try {
      Class.forName(
          "org.netbeans.modules.findbugs.NbClassFactory",
          true,
          RunFindBugs.class.getClassLoader()); // NOI18N
      Project p = new Project();
      URL[] binaryRoots =
          CacheBinaryForSourceQuery.findCacheBinaryRoots(sourceRoot.toURL()).getRoots();

      if (classNames == null) {
        for (URL binary : binaryRoots) {
          try {
            p.addFile(new File(binary.toURI()).getAbsolutePath());
          } catch (URISyntaxException ex) {
            Exceptions.printStackTrace(ex);
          }
        }
      } else {
        ClassPath binary = ClassPathSupport.createClassPath(binaryRoots);
        List<FileObject> sigFiles = new ArrayList<FileObject>();

        for (String className : classNames) {
          FileObject classFO = binary.findResource(className.replace('.', '/') + ".sig"); // NOI18N

          if (classFO != null) {
            sigFiles.add(classFO);
          } else {
            LOG.log(
                Level.WARNING,
                "Cannot find sig file for: "
                    + className); // TODO: should probably become FINE eventually
          }
        }

        assert validator != null;

        if (!validator.validate(sigFiles)) return null;

        for (FileObject classFO : sigFiles) {
          p.addFile(new File(classFO.toURI()).getAbsolutePath());
        }

        addCompileRootAsSource(p, sourceRoot);
      }

      ClassPath compile = ClassPath.getClassPath(sourceRoot, ClassPath.COMPILE);

      for (FileObject compileRoot : compile.getRoots()) {
        addCompileRoot(p, compileRoot);
      }

      BugCollectionBugReporter r =
          new BugCollectionBugReporter(p) {
            @Override
            protected void emitLine(String line) {
              LOG.log(Level.FINE, line);
            }
          };

      r.setPriorityThreshold(Integer.MAX_VALUE);
      r.setRankThreshold(Integer.MAX_VALUE);

      FindBugs2 engine = new FindBugs2();

      engine.setProject(p);
      engine.setNoClassOk(true);
      engine.setBugReporter(r);

      if (progress != null) {
        engine.setProgressCallback(progress);
      }

      boolean inEditor = validator != null;
      Preferences settings =
          customSettings != null
              ? customSettings
              : NbPreferences.forModule(RunFindBugs.class).node("global-settings");
      UserPreferences preferences;

      if (singleBug != null) {
        singleBug = singleBug.substring(PREFIX_FINDBUGS.length());
        preferences = forSingleBug(singleBug);
      } else {
        preferences = readPreferences(settings, customSettings != null);
      }

      if (preferences == null) {
        // nothing enabled, stop
        return result;
      }

      engine.setUserPreferences(preferences);
      engine.setDetectorFactoryCollection(DetectorFactoryCollection.instance());

      LOG.log(Level.FINE, "Running FindBugs");

      engine.execute();

      Map<FileObject, List<BugInstance>> file2Bugs = new HashMap<FileObject, List<BugInstance>>();

      for (BugInstance b : r.getBugCollection().getCollection()) {
        if (singleBug != null && !singleBug.equals(b.getBugPattern().getType())) continue;
        if (singleBug == null
            && !settings.getBoolean(
                b.getBugPattern().getType(),
                customSettings == null && isEnabledByDefault(b.getBugPattern()))) {
          continue;
        }

        SourceLineAnnotation sourceLine = b.getPrimarySourceLineAnnotation();
        FileObject sourceFile = null;

        if (sourceLine != null) {
          sourceFile = sourceRoot.getFileObject(sourceLine.getSourcePath());

          if (sourceFile != null) {
            List<BugInstance> bugs = file2Bugs.get(sourceFile);

            if (bugs == null) {
              file2Bugs.put(sourceFile, bugs = new ArrayList<BugInstance>());
            }

            bugs.add(b);
          } else {
            LOG.log(
                Level.WARNING,
                "{0}, location: {1}:{2}",
                new Object[] {b, sourceLine.getSourcePath(), sourceLine.getStartLine()});
          }
        }
      }

      for (Entry<FileObject, List<BugInstance>> e : file2Bugs.entrySet()) {
        int[] lineOffsets = null;
        FileObject sourceFile = e.getKey();
        DataObject d = DataObject.find(sourceFile);
        EditorCookie ec = d.getLookup().lookup(EditorCookie.class);
        Document doc = ec.getDocument();
        JavaSource js = null;

        for (BugInstance b : e.getValue()) {
          SourceLineAnnotation sourceLine = b.getPrimarySourceLineAnnotation();

          if (sourceLine.getStartLine() >= 0) {
            LazyFixList fixes =
                prepareFixes(b, inEditor, sourceFile, sourceLine.getStartLine(), null);

            if (doc != null) {
              result.add(
                  ErrorDescriptionFactory.createErrorDescription(
                      PREFIX_FINDBUGS + b.getType(),
                      Severity.VERIFIER,
                      b.getMessageWithoutPrefix(),
                      b.getBugPattern().getDetailHTML(),
                      fixes,
                      doc,
                      sourceLine.getStartLine()));
            } else {
              if (lineOffsets == null) {
                lineOffsets = computeLineMap(sourceFile, FileEncodingQuery.getEncoding(sourceFile));
              }

              int edLine = 2 * (Math.min(sourceLine.getStartLine(), lineOffsets.length / 2) - 1);

              result.add(
                  ErrorDescriptionFactory.createErrorDescription(
                      PREFIX_FINDBUGS + b.getType(),
                      Severity.VERIFIER,
                      b.getMessageWithoutPrefix(),
                      b.getBugPattern().getDetailHTML(),
                      fixes,
                      sourceFile,
                      lineOffsets[edLine],
                      lineOffsets[edLine + 1]));
            }
          } else {
            if (js == null) {
              js = JavaSource.forFileObject(sourceFile);
            }
            addByElementAnnotation(b, info, sourceFile, js, result, inEditor);
          }
        }
      }
    } catch (ClassNotFoundException ex) {
      Exceptions.printStackTrace(ex);
    } catch (IOException ex) {
      Exceptions.printStackTrace(ex);
    } catch (InterruptedException ex) {
      LOG.log(Level.FINE, null, ex);
    }

    return result;
  }
Ejemplo n.º 30
0
 private Preferences getPreferences() {
   return NbPreferences.forModule(YiiOptions.class).node(PREFERENCES_PATH);
 }