Package com.sun.tools.javac.tree.JCTree

Examples of com.sun.tools.javac.tree.JCTree.JCMethodDecl


    // Note that List is not java.util.List, and it's not very nice to deal with.
    ArrayList<JCTree> allDefsExceptConstructor = new ArrayList<>();
    for (JCTree individualDef : def.defs) {
      if (individualDef instanceof JCMethodDecl) {
        JCMethodDecl methodDecl = (JCMethodDecl) individualDef;
        if (!methodDecl.name.toString().equals("<init>")) {
          allDefsExceptConstructor.add(individualDef);
        }
      } else {
        allDefsExceptConstructor.add(individualDef);
View Full Code Here


    } else {
      return Description.NO_MATCH;
    }
    // We don't have start position for a method symbol, so we replace everything between result
    // type and body.
    JCMethodDecl decl = (JCMethodDecl) methodTree;
    Fix fix = SuggestedFix.replace(
        decl.restype.getStartPosition() + 4, decl.body.getStartPosition(), " " + fixedName + "() ");
    return describeMatch(methodTree, fix);
  }
View Full Code Here

      Type type = ((JCFieldAccess) lhs).type;
      TreePath path = state.getPath();
      while (path != null && path.getLeaf().getKind() != METHOD) {
        path = path.getParentPath();
      }
      JCMethodDecl method = (JCMethodDecl) path.getLeaf();
      int minEditDistance = Integer.MAX_VALUE;
      String replacement = null;
      for (JCVariableDecl var : method.params) {
        if (var.type == type) {
          int editDistance = EditDistance.getEditDistance(rhsName, var.name.toString());
View Full Code Here

      // find method parameters of the type "Collection"
      TreePath path = state.getPath();
      while (path != null && path.getLeaf().getKind() != METHOD) {
        path = path.getParentPath();
      }
      JCMethodDecl method = (JCMethodDecl) path.getLeaf();
      int minEditDistance = Integer.MAX_VALUE;
      String replacement = null;
      for (JCVariableDecl var : method.params) {
        if (variableType(isSubtypeOf("java.util.Collection")).matches(var, state)) {
          int editDistance = EditDistance.getEditDistance(rhsName, var.name.toString());
View Full Code Here

  public boolean compileClassFieldsAndMethods(ParsedClass cl) {
    if(!isAjaxServiceClass(cl)) return false;
    parser.code.append("function " + parser.getObfuscatedName(cl.name) + "() {}\n");
   
    for(JCTree tr : cl.type.getMembers()) if(tr instanceof JCMethodDecl){
      JCMethodDecl m = (JCMethodDecl)tr;
      if(parser.isConstructor(m)) continue;
      //System.out.println(m.modifiers());
      String mName = m.getName().toString();
      boolean isAjax = parser.hasAnnotation("Arguments", m.getModifiers());

      if(parser.isAbstract(m.getModifiers()) || parser.isStatic(m.getModifiers()) || !isAjax) continue;
      String clName = cl.name;
      clName = Character.toLowerCase(cl.name.charAt(0)) + clName.substring(1);
     
      String params = parser.getObfuscatedName("params");
            String callback = parser.getObfuscatedName("callback");
View Full Code Here

  public boolean compileClassFieldsAndMethods(ParsedClass cl) {
    if(!isEntityClass(cl)) return false;
    cl.skipInnerObfuscation = true;
   
    parser.code.append("function " + parser.getObfuscatedName(cl));
    JCMethodDecl constructor = null;
   
    for(JCTree tr : cl.type.getMembers()) if(tr instanceof JCMethodDecl){
      JCMethodDecl m = (JCMethodDecl)tr;
     
      if(parser.isConstructor(m) && parser.hasAnnotation("AJAX", m.getModifiers()) && constructor==null) {
        constructor = m;
        //System.out.println(cl.name + " - " +m.parameters());
        parser.parseParameters("(", m.getParameters(), ") {\n");
        //compiler.parse(m.parameters());
      }
    }
   
    if(constructor==null) {
      parser.code.append("() {\n");
    }
   
        if(null!=cl.type.getExtendsClause()) {
            String superType = cl.type.getExtendsClause().toString();          
        if(!parser.hasAnnotation(IgnoreExtends.class.getSimpleName(), cl.type.getModifiers()) && !parser.classes.get(superType).isNative) {
            parser.code.append(parser.getObfuscatedName(superType)+".call(this);\n");
        }
        }

    Map<String, JCVariableDecl> fields = new TreeMap<String, JCVariableDecl>();
   
    for(JCTree tr : cl.type.getMembers()) if(tr instanceof JCVariableDecl) {
      JCVariableDecl f = (JCVariableDecl)tr;
      if(parser.isStatic(f.getModifiers())) continue;
//      System.out.println(f);
      if(parser.hasAnnotation(AjaxTransient.class.getSimpleName(), f.getModifiers())) continue;
      if(null!=f.getInitializer()) {
        fields.put(f.getName().toString(), f);         
      }
    }
   
    for(JCTree tr : cl.type.getMembers()) if(tr instanceof JCMethodDecl) {
      JCMethodDecl m = (JCMethodDecl)tr;
     
      if(parser.isConstructor(m)) continue;
     
      //System.out.println(m.modifiers());
      String mName = m.getName().toString();
      boolean isAbstract = parser.isAbstract(m.getModifiers());
      boolean isStatic = parser.isStatic(m.getModifiers());
      boolean isAjax = !parser.hasAnnotation(AjaxTransient.class.getSimpleName(), m.getModifiers())
        || parser.hasAnnotation("Id", m.getModifiers());

      if(isAbstract || isStatic || !isAjax) continue;
     
      if(mName.startsWith("get") && m.getParameters().size() == 0) {
        String name = Character.toLowerCase(mName.charAt(3)) + mName.substring(4);
              fields.remove(name);
            VarType type = cl.methods.get(mName).retType;
        printFieldInitializer(cl, name, type, fields, VarType.isPrimitiveType(m.getReturnType()));
      }
    }
   
    for(Map.Entry<String, JCVariableDecl> fe: fields.entrySet()) {
            VarType type = cl.fields.get(fe.getKey()).type;
View Full Code Here

    int nBegin = mName.startsWith("is") ? 2 : 3;
   
    String name = Character.toLowerCase(mName.charAt(nBegin)) + mName.substring(nBegin+1);
//    System.out.println(mName);

    JCMethodDecl mDecl = cl.methods.get(mName).decl;
    boolean isAjaxTransient = mDecl!=null && parser.hasAnnotation(AjaxTransient.class.getSimpleName(), mDecl.getModifiers());
   
    if(isAjaxTransient) {
      throw new RuntimeException("Only @AJAX getXXX(), isXXX() and plain setXXX(value) are supported: " + mName);     
    }
   
View Full Code Here

        if(isStatic) cl.staticFields.add(fName);
        cl.fields.put(fName, new ParsedField(fName, field.getType(), cl));
        //System.out.println(name+" :: "+fr.getName().toString()+ " :: " + field.getType());
      }
      if(decl instanceof JCMethodDecl) {
        JCMethodDecl method = (JCMethodDecl)decl;
        String mName = method.getName().toString();
       
        if(isConstructor(method)) {
          if(method.getBody().getStatements().size() == 0) continue;
          if(cl.constructor != null) {
            printWarning("Dublicate constructor in class " + name);
          } else cl.constructor = method;
        } else {
          if(!cl.isNative && myProperties.contains(mName)) {
            throwCompileError(method, "Dublicate field or method: " + name+"."+mName);
          }
         
          if(cl.methods.containsKey(mName) && cl.methods.get(mName).decl.getParameters().size()!=method.getParameters().size()) {
            throwCompileError(method, "Dublicate method: " + name+"."+mName);           
          }
         
          myProperties.add(mName);
          if(isStatic(method.getModifiers())) cl.staticMethods.add(mName);
          cl.methods.put(mName, new ParsedMethod(mName, method, cl, null));
          //System.out.println(name+" :: "+mName+ " :: " + method.getReturnType2());
        }
      }
    }
View Full Code Here

    code.append("}\n");
   
    // Methods
    if(!isInterface(cl.type))
    for(JCTree tr : cl.type.getMembers()) if(tr instanceof JCMethodDecl){
      JCMethodDecl m = (JCMethodDecl)tr;
     
      //if(m.isConstructor()) continue;
      //System.out.println(m.modifiers());
      String mName = m.getName().toString();
     
      if(isConstructor(m)) {
        if(cl.constructor == null) continue;
        mName = cl.name;
      }
     
      if(isAbstract(m.getModifiers())) continue;
      if(hasAnnotation(Native.class.getSimpleName(), m.getModifiers())) continue;

      boolean isStatic = isStatic(m.getModifiers());
      boolean isFinal  = isFinal(m.getModifiers());
      boolean isNative = hasAnnotation(NativeCode.class.getSimpleName(), m.getModifiers());
     
      currentParsedMethod = cl.methods.get(mName);
            if(currentParsedMethod != null && currentParsedMethod.mayBeExcluded) {
          code.append("/*method " + currentParsedMethod.id + " start*/\n");
      }
     
      if(!isStatic && !isFinal && !isConstructor(m)) {
        code.append(getObfuscatedName(cl.name) + ".prototype." + getObfuscatedName(cl.name + "_" + mName) + ifObfuscated("=", " =\n"));// + methodName +";\n");
      }
     
      String methodName = getObfuscatedName(cl.name) + (isStatic ? "." : ".prototype.") + getObfuscatedName(isConstructor(m) ? mName + "_constructor" : mName, cl.skipInnerObfuscation);
      code.append(methodName + ifObfuscated("=function", " = function"));
      if(isNative) {
        boolean wasObfuscated = obfuscate;
        obfuscate = false;
       
        int numLocal = localVars.size();
        parseParameters("(", m.getParameters(), ")");
        obfuscate = wasObfuscated;
       
        String nativeCode = getAnnotationValue(NativeCode.class.getSimpleName(), m.getModifiers());
        Matcher mat = toObfuscatePat.matcher(nativeCode);
        while(mat.find()) {
          try {
            nativeCode = nativeCode.replace(mat.group(), getObfuscatedName(mat.group(1)));
          }catch(Throwable e) {}
        }
//        System.out.println("nativeCode: " + nativeCode);
        code.append(nativeCode+"\n");
        localVars.setSize(numLocal);
      } else {
        //if(null == m.getBody()) System.out.println(methodName);
        //selfPrefix = "this";
        //System.out.println(m);
        parseMethodMainBlock(m.getParameters(), m.getBody());
      }

            if(currentParsedMethod != null && currentParsedMethod.mayBeExcluded) {
                code.append("/*method " + currentParsedMethod.id + " stop*/\n");
            }
View Full Code Here

          parse(f.getInitializer());
        }
        if(o instanceof JCMethodDecl) {
          if(i>0) code.append(","+indentPrefix);
          i++;
          JCMethodDecl m = (JCMethodDecl)o;
//          System.out.println(m.getName().toString() + " :: " + cl.skipInnerObfuscation + " :: " + cl.isNative);
          code.append(getObfuscatedName(m.getName().toString(), cl.skipInnerObfuscation || cl.isNative) + ": function");
          parseMethodMainBlock(m.getParameters(), m.getBody());
        }
      }
      if(debugLevel>0) code.setLength(code.length()-1);
      code.append(null == claz || !claz.isInterface ? "})" : "}");
      indentPrefix = ip;
View Full Code Here

TOP

Related Classes of com.sun.tools.javac.tree.JCTree.JCMethodDecl

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.