コード例 #1
0
  /**
   * Returns the package of the specified completion.
   *
   * @param c The completion.
   * @param desc The description text being parsed. Used for errors if we cannot determine the
   *     package.
   * @return The package.
   */
  private String getPackage(Completion c, String desc) {

    String pkg = null;

    if (c instanceof JSClassCompletion) {
      pkg = ((JSClassCompletion) c).getPackageName();
    }
    if (c instanceof JSCompletion) {
      String definedIn = ((JSCompletion) c).getEnclosingClassName(true);
      if (definedIn != null) {
        int lastDot = definedIn.lastIndexOf('.');
        if (lastDot > -1) {
          pkg = definedIn.substring(0, lastDot);
        }
      }
    } else {
      Logger.logError(
          "Can't determine package from completion type: "
              + c.getClass()
              + " ("
              + c.toString()
              + ") - href: "
              + desc);
    }

    return pkg;
  }
コード例 #2
0
ファイル: LogThread.java プロジェクト: jodli/Insurance
 public void handleLog(LogEntry logEntry) {
   try {
     logQueue.put(logEntry);
   } catch (InterruptedException ignored) {
     Logger.logError(ignored.getMessage(), ignored);
   }
 }
コード例 #3
0
  // Constructor for new RController
  private RController() {
    logger = Logger.getInstance();
    if (!Rengine.versionCheck()) {
      logger.logError("** Version mismatch - Java files don't match library version.");
    } else {
      logger.log("Creating Rengine");
      this.re = new Rengine(new String[] {}, false, new TextConsole());
      logger.log("Rengine created, waiting for R");

      // Wait for REngine new thread to finish loading
      if (!re.waitForR()) {
        logger.logError("Cannot load R");
      } else {
        this.hasLoaded = true;
      }
    }
  }
コード例 #4
0
ファイル: ConsoleView.java プロジェクト: jodli/Insurance
 private void addHTML(String html) {
   synchronized (kit) {
     try {
       kit.insertHTML(doc, doc.getLength(), html, 0, 0, null);
     } catch (BadLocationException | IOException ignored) {
       Logger.logError(ignored.getMessage(), ignored);
     }
     displayArea.setCaretPosition(displayArea.getDocument().getLength());
   }
 }
コード例 #5
0
  /** Applies the operator to the given value */
  public Object apply(Object pLeft, Object pRight, Logger pLogger) throws EvaluatException {
    if (pLeft == null && pRight == null) {
      if (pLogger.isLoggingWarning()) {
        pLogger.logWarning(Constants.ARITH_OP_NULL, getOperatorSymbol());
      }
      return PrimitiveObjects.getInteger(0);
    }

    if (Coercions.isBigDecimal(pLeft)
        || Coercions.isBigInteger(pLeft)
        || Coercions.isBigDecimal(pRight)
        || Coercions.isBigInteger(pRight)) {

      BigDecimal left =
          (BigDecimal) Coercions.coerceToPrimitiveNumber(pLeft, BigDecimal.class, pLogger);
      BigDecimal right =
          (BigDecimal) Coercions.coerceToPrimitiveNumber(pRight, BigDecimal.class, pLogger);

      try {
        return left.divide(right, BigDecimal.ROUND_HALF_UP);
      } catch (Exception exc) {
        if (pLogger.isLoggingError()) {
          pLogger.logError(Constants.ARITH_ERROR, getOperatorSymbol(), "" + left, "" + right);
        }
        return PrimitiveObjects.getInteger(0);
      }
    } else {

      double left = Coercions.coerceToPrimitiveNumber(pLeft, Double.class, pLogger).doubleValue();
      double right = Coercions.coerceToPrimitiveNumber(pRight, Double.class, pLogger).doubleValue();

      try {
        return PrimitiveObjects.getDouble(left / right);
      } catch (Exception exc) {
        if (pLogger.isLoggingError()) {
          pLogger.logError(Constants.ARITH_ERROR, getOperatorSymbol(), "" + left, "" + right);
        }
        return PrimitiveObjects.getInteger(0);
      }
    }
  }
コード例 #6
0
  public static boolean save(File file, final FileInputStream inputStream) {

    try {

      final FileOutputStream output = new FileOutputStream(file);

      output.write(IOUtils.toByteArray(inputStream));

      output.close();

    } catch (final FileNotFoundException e) {
      Logger.logError(TAG, e.getMessage());

      return false;

    } catch (final IOException e) {
      Logger.logError(TAG, e.getMessage());

      return false;
    }

    return true;
  }
コード例 #7
0
 @Override
 void finishReporting() {
   if (reportFilepath != null) {
     if (numberOfProblems != problems.size()) {
       logger.logError(
           "There is an invalid number of problems handled: "
               + numberOfProblems
               + " counted, but "
               + problems.size()
               + " stored",
           null);
     }
     generateFile(new File(reportFilepath), problems.asMap());
   }
 }
コード例 #8
0
  public static boolean save(
      final Context context, final String name, final FileInputStream inputStream) {

    try {

      final FileOutputStream output = context.openFileOutput(name, Context.MODE_PRIVATE);

      output.write(IOUtils.toByteArray(inputStream));

      output.close();

    } catch (final FileNotFoundException e) {
      Logger.logError(TAG, e.getMessage());

      return false;

    } catch (final IOException e) {
      Logger.logError(TAG, e.getMessage());

      return false;
    }

    return true;
  }
コード例 #9
0
 private void generateFile(
     final File file, final Map<IPath, Collection<RobotProblemWithPosition>> map) {
   logger.log("Generating report file '" + file.getAbsolutePath() + "'");
   try (ReportWithCheckstyleFormat checkstyleReporter = new ReportWithCheckstyleFormat(file)) {
     checkstyleReporter.writeHeader();
     checkstyleReporter.writeEntries(map);
     checkstyleReporter.writeFooter();
     logger.log("Report file '" + file.getAbsolutePath() + "' has been generated");
   } catch (final IOException e) {
     logger.logError(
         "Unable to create report file '"
             + file.getAbsolutePath()
             + "'. Reason: "
             + e.getMessage(),
         e);
   }
 }
コード例 #10
0
  public static boolean save(final File directory, final Bitmap bitmap) {

    try {

      final FileOutputStream stream = new FileOutputStream(directory);

      bitmap.compress(Bitmap.CompressFormat.PNG, QUALITY, stream);

      stream.close();

    } catch (final IOException e) {
      Logger.logError(TAG, e.getMessage());

      return false;
    }

    return true;
  }
コード例 #11
0
  /** Executed in main task thread. */
  @Override
  public void run() {

    try {
      onRun();
    } catch (InterruptedException e) {
      mCancelFlg = true;
    } catch (ClosedByInterruptException e) {
      mCancelFlg = true;
    } catch (Exception e) {
      Logger.logError(e);
    }
    mMessageHandler.post(
        new Runnable() {
          public void run() {
            doFinish();
          };
        });
  }
コード例 #12
0
  public static void deleteSeriesAlert(
      Context context,
      final CatalogueDBAdapter dbHelper,
      final Series series,
      final Runnable onDeleted) {

    // When we get here, we know the names are genuinely different and the old series is used in
    // more than one place.
    String message = "Delete series";
    try {
      message =
          String.format(
              context.getResources().getString(R.string.really_delete_series), series.name);
    } catch (NullPointerException e) {
      Logger.logError(e);
    }
    final AlertDialog alertDialog = new AlertDialog.Builder(context).setMessage(message).create();

    alertDialog.setTitle(R.string.delete_series);
    alertDialog.setIcon(android.R.drawable.ic_menu_info_details);
    alertDialog.setButton(
        DialogInterface.BUTTON_POSITIVE,
        context.getResources().getString(R.string.ok),
        new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int which) {
            dbHelper.deleteSeries(series);
            alertDialog.dismiss();
            onDeleted.run();
          }
        });

    alertDialog.setButton(
        DialogInterface.BUTTON_NEGATIVE,
        context.getResources().getString(R.string.cancel),
        new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int which) {
            alertDialog.dismiss();
          }
        });

    alertDialog.show();
  }
コード例 #13
0
ファイル: ConsoleView.java プロジェクト: jodli/Insurance
  private void createUIComponents() {
    displayArea = new JEditorPane("text/html", "");
    displayArea.setEditable(false);
    kit = new HTMLEditorKit();
    displayArea.setEditorKit(kit);

    JScrollPane scrollPane = new JScrollPane(displayArea);
    scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

    logType = ELogType.valueOf(SettingsUtils.getValue(ESetting.LOGTYPE));
    refreshLogs();
    Logger.addListener(this);

    System.setOut(new OutputOverride(System.out, LogLevel.INFO));
    System.setErr(new OutputOverride(System.err, LogLevel.ERROR));
    try {
      Logger.addListener(new LogWriter(new File(launcherLogFile)));
    } catch (IOException e1) {
      Logger.logError(e1.getMessage(), e1);
    }
  }
コード例 #14
0
  /**
   * Returns the class for a completion (class completions return the class itself, member
   * completions return the enclosing class).
   */
  private String getClass(Completion c, String desc) {

    String clazz = null;

    if (c instanceof JSClassCompletion) {
      clazz = ((JSClassCompletion) c).getClassName(true);
    } else if (c instanceof JSCompletion) {
      JSCompletion jsc = (JSCompletion) c;
      clazz = jsc.getEnclosingClassName(true);
    } else {
      Logger.logError(
          "Can't determine class from completion type: "
              + c.getClass()
              + " ("
              + c.toString()
              + ") - href: "
              + desc);
    }

    return clazz;
  }
コード例 #15
0
ファイル: RushCore.java プロジェクト: JoniDS/RushCore
  public static void initialize(
      final RushUpgradeManager rushUpgradeManager,
      RushSaveStatementGenerator saveStatementGenerator,
      RushConflictSaveStatementGenerator rushConflictSaveStatementGenerator,
      RushDeleteStatementGenerator deleteStatementGenerator,
      RushJoinStatementGenerator rushJoinStatementGenerator,
      RushClassFinder rushClassFinder,
      RushTableStatementGenerator rushTableStatementGenerator,
      final RushStatementRunner statementRunner,
      final RushQueProvider queProvider,
      final RushConfig rushConfig,
      RushClassLoader rushClassLoader,
      RushStringSanitizer rushStringSanitizer,
      Logger logger,
      RushObjectSerializer rushObjectSerializer,
      RushObjectDeserializer rushObjectDeserializer,
      RushColumns rushColumns,
      final InitializeListener initializeListener) {

    if (rushCore != null) {
      logger.logError(
          "RushCore has already been initialized, make sure initialize is only called once.");
    }

    rushCore =
        new RushCore(
            saveStatementGenerator,
            rushConflictSaveStatementGenerator,
            deleteStatementGenerator,
            rushJoinStatementGenerator,
            statementRunner,
            queProvider,
            rushConfig,
            rushTableStatementGenerator,
            rushClassLoader,
            rushStringSanitizer,
            logger,
            rushObjectSerializer,
            rushObjectDeserializer,
            rushColumns);
    rushCore.loadAnnotationCache(rushClassFinder);

    final boolean isFirstRun = statementRunner.isFirstRun();
    final RushQue que = queProvider.blockForNextQue();
    new Thread(
            new Runnable() {
              @Override
              public void run() {
                if (isFirstRun) {
                  rushCore.createTables(new ArrayList<>(rushCore.annotationCache.keySet()), que);
                } else if (rushConfig.inDebug()
                    || statementRunner.requiresUpgrade(rushConfig.dbVersion(), que)) {
                  rushCore.upgrade(
                      new ArrayList<>(rushCore.annotationCache.keySet()), rushUpgradeManager, que);
                } else {
                  queProvider.queComplete(que);
                }
                statementRunner.initializeComplete(rushConfig.dbVersion());
                if (initializeListener != null) {
                  initializeListener.initialized(isFirstRun);
                }
              }
            })
        .start();
  }
コード例 #16
0
  /** {@inheritDoc} */
  public void urlClicked(HyperlinkEvent e, Completion c, DescWindowCallback callback) {

    // A "real" URL (starts with http://, for example) should be opened
    // in the system browser, not the completion description window.
    URL url = e.getURL();
    if (url != null) {
      // Try loading in external browser (Java 6+ only).
      try {
        Util.browse(new URI(url.toString()));
      } catch (/*IO*/ URISyntaxException ioe) {
        UIManager.getLookAndFeel().provideErrorFeedback(null);
        ioe.printStackTrace();
      }
      return;
    }

    // A relative path URL (no leading "http://") results in a null URL.
    // Class should be in the same package as the one we're currently
    // viewing.  Example:  java.lang.String class documentation
    String desc = e.getDescription();
    Logger.log(desc);
    if (desc != null) {

      if (isRelativeUrl(desc)) {
        int ext = desc.indexOf(".htm");
        if (ext > -1) {

          // Could be <a href="Character.html#section"> link.  A
          // popular href format is "../../util/Formatter.html#syntax".
          // We must determine "relative" package location.
          String anchor = getAnchor(desc);
          String clazz = desc.substring(0, ext);
          int backups = 0;
          while (clazz.startsWith("../")) {
            backups++;
            clazz = clazz.substring(3);
          }
          clazz = clazz.replace('/', '.');

          String pkg = getPackage(c, desc);
          if (pkg != null) {
            clazz = doBackups(pkg, backups) + "." + clazz;
            JavaScriptLanguageSupport jls = getJavaScriptLanguageSupport();
            ClassFile cf = jls.getJarManager().getClassEntry(clazz);
            if (cf != null) {
              JSClassCompletion cc = new JSClassCompletion(c.getProvider(), cf);
              callback.showSummaryFor(cc, anchor);
            }
          }
        }
      }

      // Could be format "com.mycompany.pkg.MyClass", with optional
      // #method() (for example, @see's).
      else {

        JavaScriptLanguageSupport jls = getJavaScriptLanguageSupport();

        String clazz = desc;
        String member = null;
        int pound = desc.indexOf('#');
        if (pound > -1) { // TODO: Handle properly
          member = clazz.substring(pound + 1);
          clazz = clazz.substring(0, pound);
        }

        // Just a class name, i.e. "String", "java.util.regex.Pattern".
        if (member == null) {
          boolean guessedPackage = false;
          if (clazz.indexOf('.') == -1) {
            String pkg = getPackage(c, desc);
            if (pkg != null) {
              clazz = pkg + "." + clazz;
            }
            guessedPackage = true;
          }
          ClassFile cf = jls.getJarManager().getClassEntry(clazz);
          if (cf == null && guessedPackage) {
            // Wasn't in the same package as "c", try java.lang
            int lastDot = clazz.lastIndexOf('.');
            clazz = "java.lang." + clazz.substring(lastDot + 1);
            cf = jls.getJarManager().getClassEntry(clazz);
          }
          if (cf != null) {
            JSClassCompletion cc = new JSClassCompletion(c.getProvider(), cf);
            callback.showSummaryFor(cc, null);
          } else {
            UIManager.getLookAndFeel().provideErrorFeedback(null);
            Logger.log("Unknown class: " + clazz);
          }
        }

        // Member specified, such as "String#format(...)",
        // "java.util.regex.Pattern.compile(...)", or "#method()".
        else {

          boolean guessedPackage = false;

          if (pound == 0) { // Member of this class (i.e. "#foobar(bas)")
            // "clazz" was incorrect previously in this case
            clazz = getClass(c, desc);
          } else { // i.e. "String#CASE_INSENSITIVE_ORDER"
            // If no package specified, assume clazz is in the same
            // package as the currently displayed completion.
            if (clazz.indexOf('.') == -1) {
              String pkg = getPackage(c, desc);
              if (pkg != null) {
                clazz = pkg + "." + clazz;
              }
              guessedPackage = true;
            }
          }

          ClassFile cf = clazz != null ? jls.getJarManager().getClassEntry(clazz) : null;
          if (cf == null && guessedPackage) {
            // Wasn't in the same package as "c", try java.lang
            int lastDot = clazz.lastIndexOf('.');
            clazz = "java.lang." + clazz.substring(lastDot + 1);
            cf = jls.getJarManager().getClassEntry(clazz);
          }

          if (cf != null) {

            Completion memberCompletion = null;
            int lparen = member.indexOf('(');
            if (lparen == -1) { // A field, or method with args omitted
              FieldInfo fi = cf.getFieldInfoByName(member);
              if (fi != null) { // Try fields first, it's most likely
                memberCompletion = new JSFieldCompletion(c.getProvider(), fi);
              } else { // Try methods second
                List miList = cf.getMethodInfoByName(member, -1);
                if (miList != null && miList.size() > 0) {
                  MethodInfo mi = (MethodInfo) miList.get(0); // Just show the first if multiple
                  memberCompletion = new JSFunctionCompletion(c.getProvider(), mi);
                }
              }
            } else {
              String[] args = getArgs(member);
              String methodName = member.substring(0, lparen);
              List miList = cf.getMethodInfoByName(methodName, args.length);
              if (miList != null && miList.size() > 0) {
                if (miList.size() > 1) {
                  // TODO: Pick correct overload based on args
                  Logger.log("Multiple overload support not yet implemented");
                } else {
                  MethodInfo mi = (MethodInfo) miList.get(0);
                  memberCompletion = new JSFunctionCompletion(c.getProvider(), mi);
                }
              }
            }

            if (memberCompletion != null) {
              callback.showSummaryFor(memberCompletion, null);
            }

          } else {
            UIManager.getLookAndFeel().provideErrorFeedback(null);
            Logger.logError("Unknown class: " + clazz + " (href: " + desc + ")");
          }
        }
      }
    }
  }