コード例 #1
0
ファイル: ScriptUtils.java プロジェクト: ambrice/eclim
 /**
  * Parses the named script from the supplied PluginResources and returns the Class that can be
  * used to create instances to invoke methods on.
  *
  * @param resources The plugin resources.
  * @param script The script path relative to the scripts directory.
  * @return The resulting class.
  */
 public static Class parseClass(PluginResources resources, String script) throws Exception {
   String path = FileUtils.separatorsToUnix(FileUtils.concat(SCRIPT_PATH, script));
   InputStream stream = resources.getResourceAsStream(path);
   if (stream == null) {
     throw new IllegalArgumentException(Services.getMessage("script.not.found", path));
   }
   return parseClass(stream);
 }
コード例 #2
0
ファイル: ScriptUtils.java プロジェクト: ambrice/eclim
  /**
   * Evaluates the specified script and returns the result.
   *
   * @param resources The plugin resources.
   * @param script The script path relative to the scripts directory.
   * @param values Any variable name / value pairs for the script.
   * @return The result of evaluating the supplied script.
   */
  public static Object evaluateScript(
      PluginResources resources, String script, Map<String, Object> values) throws Exception {
    Binding binding = new Binding(values);
    GroovyShell shell = new GroovyShell(binding);

    String path = FileUtils.separatorsToUnix(FileUtils.concat(SCRIPT_PATH, script));
    InputStream stream = resources.getResourceAsStream(path);
    if (stream == null) {
      throw new IllegalArgumentException(Services.getMessage("script.not.found", path));
    }
    return shell.evaluate(stream);
  }
コード例 #3
0
ファイル: JavaUtils.java プロジェクト: alvaroc1/eclim
  /**
   * Gets the fully qualified name of the supplied java element.
   *
   * <p>NOTE: For easy of determining fields and method segments, they are appended with a javadoc
   * style '#' instead of the normal '.'.
   *
   * @param element The IJavaElement.
   * @return The fully qualified name.
   */
  public static String getFullyQualifiedName(IJavaElement element) {
    IJavaElement parent = element;
    while (parent.getElementType() != IJavaElement.COMPILATION_UNIT
        && parent.getElementType() != IJavaElement.CLASS_FILE) {
      parent = parent.getParent();
    }

    StringBuffer elementName =
        new StringBuffer()
            .append(parent.getParent().getElementName())
            .append('.')
            .append(FileUtils.getFileName(parent.getElementName()));

    switch (element.getElementType()) {
      case IJavaElement.FIELD:
        IField field = (IField) element;
        elementName.append('#').append(field.getElementName());
        break;
      case IJavaElement.METHOD:
        IMethod method = (IMethod) element;
        elementName.append('#').append(method.getElementName()).append('(');
        String[] parameters = method.getParameterTypes();
        for (int ii = 0; ii < parameters.length; ii++) {
          if (ii != 0) {
            elementName.append(", ");
          }
          elementName.append(Signature.toString(parameters[ii]).replace('/', '.'));
        }
        elementName.append(')');
        break;
    }

    return elementName.toString();
  }