Package com.sun.source.tree

Examples of com.sun.source.tree.MethodTree


  private boolean hasMainMethod(ClassTree clazz) {
    for (Tree member : clazz.getMembers()) {
      if (!(member instanceof MethodTree)) {
        continue;
      }
      MethodTree method = (MethodTree) member;

      if (isMainMethod(method)) {
        return true;
      }
    }
View Full Code Here


    }
  }

  private void checkMethod(TypeElement classElement, Tree member, GenerationContext<Void> context, Multimap<String, Element> existingNames) {
    if (member instanceof MethodTree) {
      MethodTree method = (MethodTree) member;
      ExecutableElement methodElement = TreeUtils.elementFromDeclaration(method);
      if (JavaNodes.isNative(methodElement)) {
        // do nothing with the native methods as no code will be generated.
        // the check will be done only for the method that has a body and that is supposed to me the most
        // generic version of the overloaded method
View Full Code Here

  public static boolean isConstructor(Tree tree) {
    if (!(tree instanceof MethodTree)) {
      return false;
    }
    MethodTree method = (MethodTree) tree;
    return "<init>".equals(method.getName().toString()) && !method.getModifiers().getFlags().contains(Modifier.STATIC);
  }
View Full Code Here

        String code = "package test; public class Test {private void test() {Object o = null; boolean b = o != null && o instanceof String;} private Test() {}}";

        JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, Arrays.asList("-bootclasspath", bootPath, "-Xjcov"), null, Arrays.asList(new MyFileObject(code)));
        CompilationUnitTree cut = ct.parse().iterator().next();
        ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0);
        MethodTree method = (MethodTree) clazz.getMembers().get(0);
        VariableTree condSt = (VariableTree) method.getBody().getStatements().get(1);
        BinaryTree cond = (BinaryTree) condSt.getInitializer();
        JCTree condJC = (JCTree) cond;

        if (condJC.pos != 93)
            throw new IllegalStateException("Unexpected position=" + condJC.pos);
View Full Code Here

          continue;
        if (mods.contains(Modifier.PUBLIC) || mods.contains(Modifier.PROTECTED))
          current.addField(fn);
      }
      else if (member.getKind() == Tree.Kind.METHOD) {
        MethodTree mtree = (MethodTree)member;
        Set<Modifier> mods = mtree.getModifiers().getFlags();
        if (mods.contains(Modifier.PUBLIC) || mods.contains(Modifier.PROTECTED)) {
          List<FieldNode> params = new ArrayList<FieldNode>();
          for (VariableTree vt : mtree.getParameters())
            params.add(getField(vt));
          String mname = mtree.getName().toString();
          if (mname.equals("<init>"))
            mname = root.getSimpleName().toString();
          MethodNode mn = new MethodNode(mname, mtree.getReturnType(), mods,
              params);
          MethodNode mExcluded = null;
          try {
            List<MethodNode> temp = exclusions.get(exclusions.indexOf(current)).methods;
            mExcluded = temp.get(temp.indexOf(mn));
          } catch(IndexOutOfBoundsException e) {}
          if (mExcluded != null && mExcluded.exceptions.isEmpty())
            continue;
          for (ExpressionTree et : mtree.getThrows())
            if (!(mExcluded != null && mExcluded.exceptions.contains(et.toString())))
              mn.addException(et.toString());
          current.addMethod(mn);
        }
      }
View Full Code Here

        "}");
  }

  private MethodTree methodTree() {
     // Checked implicitly in CompilationTestUtils by Tree.Kind parameter
    @SuppressWarnings("unchecked")
    MethodTree ret = (MethodTree) MoreTrees.findSubtree(baseTree(), Tree.Kind.METHOD, "toString");
    return ret;
  }
View Full Code Here

TOP

Related Classes of com.sun.source.tree.MethodTree

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.