コード例 #1
0
ファイル: SourceUnit.java プロジェクト: andreyvit/groovy
  /**
   * Returns a sampling of the source at the specified line and column, of null if it is
   * unavailable.
   */
  public String getSample(int line, int column, Janitor janitor) {
    String sample = null;
    String text = source.getLine(line, janitor);

    if (text != null) {
      if (column > 0) {
        String marker = Utilities.repeatString(" ", column - 1) + "^";

        if (column > 40) {
          int start = column - 30 - 1;
          int end = (column + 10 > text.length() ? text.length() : column + 10 - 1);
          sample =
              "   "
                  + text.substring(start, end)
                  + Utilities.eol()
                  + "   "
                  + marker.substring(start, marker.length());
        } else {
          sample = "   " + text + Utilities.eol() + "   " + marker;
        }
      } else {
        sample = text;
      }
    }

    return sample;
  }
コード例 #2
0
  private void printMethod(PrintWriter out, ClassNode clazz, MethodNode methodNode) {
    if (methodNode.getName().equals("<clinit>")) return;
    if (methodNode.isPrivate() || !Utilities.isJavaIdentifier(methodNode.getName())) return;
    if (methodNode.isSynthetic() && methodNode.getName().equals("$getStaticMetaClass")) return;

    printAnnotations(out, methodNode);
    if (!clazz.isInterface()) printModifiers(out, methodNode.getModifiers());

    printGenericsBounds(out, methodNode.getGenericsTypes());
    out.print(" ");
    printType(out, methodNode.getReturnType());
    out.print(" ");
    out.print(methodNode.getName());

    printParams(out, methodNode);

    ClassNode[] exceptions = methodNode.getExceptions();
    for (int i = 0; i < exceptions.length; i++) {
      ClassNode exception = exceptions[i];
      if (i == 0) {
        out.print("throws ");
      } else {
        out.print(", ");
      }
      printType(out, exception);
    }

    if ((methodNode.getModifiers() & Opcodes.ACC_ABSTRACT) != 0) {
      out.println(";");
    } else {
      out.print(" { ");
      ClassNode retType = methodNode.getReturnType();
      printReturn(out, retType);
      out.println("}");
    }
  }