当前位置: 首页>>代码示例>>Java>>正文


Java JCNewClass类代码示例

本文整理汇总了Java中com.sun.tools.javac.tree.JCTree.JCNewClass的典型用法代码示例。如果您正苦于以下问题:Java JCNewClass类的具体用法?Java JCNewClass怎么用?Java JCNewClass使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


JCNewClass类属于com.sun.tools.javac.tree.JCTree包,在下文中一共展示了JCNewClass类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: process

import com.sun.tools.javac.tree.JCTree.JCNewClass; //导入依赖的package包/类
@Override
void process(JCNewClass oldTree, JCNewClass newTree, boolean hasErrors) {
    if (!hasErrors) {
        List<Type> inferredArgs, explicitArgs;
        if (oldTree.def != null) {
            inferredArgs = newTree.def.implementing.nonEmpty()
                              ? newTree.def.implementing.get(0).type.getTypeArguments()
                              : newTree.def.extending.type.getTypeArguments();
            explicitArgs = oldTree.def.implementing.nonEmpty()
                              ? oldTree.def.implementing.get(0).type.getTypeArguments()
                              : oldTree.def.extending.type.getTypeArguments();
        } else {
            inferredArgs = newTree.type.getTypeArguments();
            explicitArgs = oldTree.type.getTypeArguments();
        }
        for (Type t : inferredArgs) {
            if (!types.isSameType(t, explicitArgs.head)) {
                return;
            }
            explicitArgs = explicitArgs.tail;
        }
        //exact match
        log.warning(oldTree.clazz, Warnings.DiamondRedundantArgs);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:Analyzer.java

示例2: resolutionExceptionBlock

import com.sun.tools.javac.tree.JCTree.JCNewClass; //导入依赖的package包/类
private JCBlock resolutionExceptionBlock() {
    if (resolutionExceptionBlock == null) {
        JCExpression expClass = null;
        // Split the exception class name at dots
        for (String id : SPIResolutionException.class.getName().split("\\.")) {
            Name nm = names.fromString(id);
            if (expClass == null) {
                expClass = make.Ident(nm);
            } else {
                expClass = make.Select(expClass, nm);
            }
        }
        JCNewClass exp = make.NewClass(null,
                null, expClass, List.of(make.Literal(keyIndex)), null);
        resolutionExceptionBlock = make.Block(0L, List.of(make.Throw(exp)));
    }
    return resolutionExceptionBlock;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:Corraller.java

示例3: process

import com.sun.tools.javac.tree.JCTree.JCNewClass; //导入依赖的package包/类
@Override
void process(JCNewClass oldTree, JCNewClass newTree, boolean hasErrors) {
    if (!hasErrors) {
        List<Type> inferredArgs, explicitArgs;
        if (oldTree.def != null) {
            inferredArgs = newTree.def.implementing.nonEmpty()
                              ? newTree.def.implementing.get(0).type.getTypeArguments()
                              : newTree.def.extending.type.getTypeArguments();
            explicitArgs = oldTree.def.implementing.nonEmpty()
                              ? oldTree.def.implementing.get(0).type.getTypeArguments()
                              : oldTree.def.extending.type.getTypeArguments();
        } else {
            inferredArgs = newTree.type.getTypeArguments();
            explicitArgs = oldTree.type.getTypeArguments();
        }
        for (Type t : inferredArgs) {
            if (!types.isSameType(t, explicitArgs.head)) {
                return;
            }
            explicitArgs = explicitArgs.tail;
        }
        //exact match
        log.warning(oldTree.clazz, "diamond.redundant.args");
    }
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:26,代码来源:Analyzer.java

示例4: resolutionExceptionBlock

import com.sun.tools.javac.tree.JCTree.JCNewClass; //导入依赖的package包/类
private JCBlock resolutionExceptionBlock() {
    if (resolutionExceptionBlock == null) {
        JCExpression expClass = null;
        // Split the exception class name at dots
        for (String id : SPIResolutionException.class.getName().split("\\.")) {
            Name nm = names.fromString(id);
            if (expClass == null) {
                expClass = make.Ident(nm);
            } else {
                expClass = make.Select(expClass, nm);
            }
        }
        JCNewClass exp = make.NewClass(null,
                null, expClass, List.of(make.Literal(keyIndex)), null);
        resolutionExceptionBlock = make.Block(0L, List.<JCStatement>of(
                make.Throw(exp)));
    }
    return resolutionExceptionBlock;
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:20,代码来源:Corraller.java

示例5: printEnumMember

import com.sun.tools.javac.tree.JCTree.JCNewClass; //导入依赖的package包/类
private void printEnumMember(JCVariableDecl tree) {
	printAnnotations(tree.mods.annotations, true);
	print(tree.name);
	if (tree.init instanceof JCNewClass) {
		JCNewClass constructor = (JCNewClass) tree.init;
		if (constructor.args != null && constructor.args.nonEmpty()) {
			print("(");
			print(constructor.args, ", ");
			print(")");
		}
		
		if (constructor.def != null && constructor.def.defs != null) {
			println(" {");
			indent++;
			printClassMembers(constructor.def.defs, false, false);
			consumeComments(endPos(tree));
			indent--;
			aPrint("}");
		}
	}
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:22,代码来源:PrettyPrinter.java

示例6: printEnumMember

import com.sun.tools.javac.tree.JCTree.JCNewClass; //导入依赖的package包/类
public void printEnumMember(JCVariableDecl tree) throws IOException {
	printAnnotations(tree.mods.annotations);
	print(tree.name);
	if (tree.init instanceof JCNewClass) {
		JCNewClass constructor = (JCNewClass) tree.init;
		if (constructor.args != null && constructor.args.nonEmpty()) {
			print("(");
			printExprs(constructor.args);
			print(")");
		}
		if (constructor.def != null && constructor.def.defs != null) {
			print(" ");
			printBlock(constructor.def.defs, constructor.def);
		}
	}
}
 
开发者ID:mobmead,项目名称:EasyMPermission,代码行数:17,代码来源:PrettyCommentsPrinter.java

示例7: visitNewClass

import com.sun.tools.javac.tree.JCTree.JCNewClass; //导入依赖的package包/类
@Override
public Pair<ASTRecord, Integer> visitNewClass(NewClassTree node, Insertion ins) {
  JCNewClass na = (JCNewClass) node;
  JCExpression className = na.clazz;
  // System.out.printf("classname %s (%s)%n", className, className.getClass());
  while (! (className.getKind() == Tree.Kind.IDENTIFIER)) { // IdentifierTree
    if (className instanceof JCAnnotatedType) {
      className = ((JCAnnotatedType) className).underlyingType;
    } else if (className instanceof JCTypeApply) {
      className = ((JCTypeApply) className).clazz;
    } else if (className instanceof JCFieldAccess) {
      // This occurs for fully qualified names, e.g. "new java.lang.Object()".
      // I'm not quite sure why the field "selected" is taken, but "name" would
      // be a type mismatch. It seems to work, see NewPackage test case.
      className = ((JCFieldAccess) className).selected;
    } else {
      throw new Error(String.format("unrecognized JCNewClass.clazz (%s): %s%n" +
              "   surrounding new class tree: %s%n", className.getClass(), className, node));
    }
    // System.out.printf("classname %s (%s)%n", className, className.getClass());
  }

  return visitIdentifier((IdentifierTree) className, ins);
}
 
开发者ID:typetools,项目名称:annotation-tools,代码行数:25,代码来源:TreeFinder.java

示例8: selectedIsInstance

import com.sun.tools.javac.tree.JCTree.JCNewClass; //导入依赖的package包/类
/**
 * Returns true if the expression is a member access on an instance, rather than a static type.
 * Supports member method invocations and field accesses.
 */
public static Matcher<ExpressionTree> selectedIsInstance() {
  return new Matcher<ExpressionTree>() {
    @Override
    public boolean matches(ExpressionTree expr, VisitorState state) {
      if (!(expr instanceof JCFieldAccess)) {
        // TODO(cushon): throw IllegalArgumentException?
        return false;
      }
      JCExpression selected = ((JCFieldAccess) expr).getExpression();
      if (selected instanceof JCNewClass) {
        return true;
      }
      Symbol sym = ASTHelpers.getSymbol(selected);
      return sym instanceof VarSymbol;
    }
  };
}
 
开发者ID:google,项目名称:error-prone,代码行数:22,代码来源:Matchers.java

示例9: getSymbol

import com.sun.tools.javac.tree.JCTree.JCNewClass; //导入依赖的package包/类
/**
 * Gets the symbol for a tree. Returns null if this tree does not have a symbol because it is of
 * the wrong type, if {@code tree} is null, or if the symbol cannot be found due to a compilation
 * error.
 */
// TODO(eaftan): refactor other code that accesses symbols to use this method
public static Symbol getSymbol(Tree tree) {
  if (tree instanceof JCFieldAccess) {
    return ((JCFieldAccess) tree).sym;
  }
  if (tree instanceof JCIdent) {
    return ((JCIdent) tree).sym;
  }
  if (tree instanceof JCMethodInvocation) {
    return ASTHelpers.getSymbol((MethodInvocationTree) tree);
  }
  if (tree instanceof JCNewClass) {
    return ASTHelpers.getSymbol((NewClassTree) tree);
  }
  if (tree instanceof MemberReferenceTree) {
    return ((JCMemberReference) tree).sym;
  }
  if (tree instanceof JCAnnotatedType) {
    return getSymbol(((JCAnnotatedType) tree).underlyingType);
  }

  return getDeclaredSymbol(tree);
}
 
开发者ID:google,项目名称:error-prone,代码行数:29,代码来源:ASTHelpers.java

示例10: matchNewClass

import com.sun.tools.javac.tree.JCTree.JCNewClass; //导入依赖的package包/类
@Override
public Description matchNewClass(NewClassTree tree, VisitorState state) {
  // check instantiations of `@ImmutableTypeParameter`s in generic constructor invocations
  checkInvocation(
      tree, ((JCNewClass) tree).constructorType, state, ((JCNewClass) tree).constructor);
  // check instantiations of `@ImmutableTypeParameter`s in class constructor invocations
  ImmutableAnalysis analysis = new ImmutableAnalysis(this, state, wellKnownMutability);
  Violation info =
      analysis.checkInstantiation(
          ASTHelpers.getSymbol(tree.getIdentifier()).getTypeParameters(),
          ASTHelpers.getType(tree).getTypeArguments());
  if (info.isPresent()) {
    state.reportMatch(buildDescription(tree).setMessage(info.message()).build());
  }
  return NO_MATCH;
}
 
开发者ID:google,项目名称:error-prone,代码行数:17,代码来源:ImmutableChecker.java

示例11: handleMonitorGuards

import com.sun.tools.javac.tree.JCTree.JCNewClass; //导入依赖的package包/类
private static HeldLockSet handleMonitorGuards(VisitorState state, HeldLockSet locks) {
  JCNewClass newClassTree = ASTHelpers.findEnclosingNode(state.getPath(), JCNewClass.class);
  if (newClassTree == null) {
    return locks;
  }
  Symbol clazzSym = ASTHelpers.getSymbol(newClassTree.clazz);
  if (!(clazzSym instanceof ClassSymbol)) {
    return locks;
  }
  if (!((ClassSymbol) clazzSym).fullname.contentEquals(MONITOR_GUARD_CLASS)) {
    return locks;
  }
  Optional<GuardedByExpression> lockExpression =
      GuardedByBinder.bindExpression(
          Iterables.getOnlyElement(newClassTree.getArguments()), state);
  if (!lockExpression.isPresent()) {
    return locks;
  }
  return locks.plus(lockExpression.get());
}
 
开发者ID:google,项目名称:error-prone,代码行数:21,代码来源:HeldLockAnalyzer.java

示例12: classCreatorRest

import com.sun.tools.javac.tree.JCTree.JCNewClass; //导入依赖的package包/类
/** ClassCreatorRest = Arguments [ClassBody]
 */
JCNewClass classCreatorRest(int newpos,
                              JCExpression encl,
                              List<JCExpression> typeArgs,
                              JCExpression t)
{
    List<JCExpression> args = arguments();
    JCClassDecl body = null;
    if (S.token() == LBRACE) {
        int pos = S.pos();
        List<JCTree> defs = classOrInterfaceBody(names.empty, false);
        JCModifiers mods = F.at(Position.NOPOS).Modifiers(0);
        body = toP(F.at(pos).AnonymousClassDef(mods, defs));
    }
    return toP(F.at(newpos).NewClass(encl, typeArgs, t, args, body));
}
 
开发者ID:sebastianoe,项目名称:s4j,代码行数:18,代码来源:JavacParser.java

示例13: matches

import com.sun.tools.javac.tree.JCTree.JCNewClass; //导入依赖的package包/类
@Override
public boolean matches(NewClassTree newClassTree, VisitorState state) {
  /* TODO(eaftan): Don't catch NullPointerException.  Need to do this right now
   * for internal use, but remember to remove later. */
  try {
    JCNewClass newClass = (JCNewClass) newClassTree;
    String thisClassName = newClass.constructor.getEnclosingElement().toString();
    com.sun.tools.javac.util.List<Type> thisParameterTypes = 
        newClass.constructor.type.getParameterTypes();
    List<String> thisParameterTypesAsStrings = new ArrayList<String>(thisParameterTypes.length());
    for (Type t : thisParameterTypes) {
      thisParameterTypesAsStrings.add(t.toString());
    }
    
    return thisClassName.equals(className) && thisParameterTypesAsStrings.equals(parameterTypes);
  } catch (NullPointerException e) {
    return false;
  }
}
 
开发者ID:diy1,项目名称:error-prone-aspirator,代码行数:20,代码来源:Constructor.java

示例14: printEnumMember

import com.sun.tools.javac.tree.JCTree.JCNewClass; //导入依赖的package包/类
public void printEnumMember(JCVariableDecl tree) throws IOException {
    printAnnotations(tree.mods.annotations);
    print(tree.name);
    if (tree.init instanceof JCNewClass) {
        JCNewClass constructor = (JCNewClass) tree.init;
        if (constructor.args != null && constructor.args.nonEmpty()) {
            print("(");
            printExprs(constructor.args);
            print(")");
        }
        if (constructor.def != null && constructor.def.defs != null) {
            print(" ");
            printBlock(constructor.def.defs, constructor.def);
        }
    }
}
 
开发者ID:redundent,项目名称:lombok,代码行数:17,代码来源:PrettyCommentsPrinter.java

示例15: matchNewClass

import com.sun.tools.javac.tree.JCTree.JCNewClass; //导入依赖的package包/类
private boolean matchNewClass(JCNewClass t1, JCNewClass t2) {
    return t1.constructor == t2.constructor &&
           treesMatch(t1.getIdentifier(), t2.getIdentifier()) &&
           listsMatch(t1.typeargs, t2.typeargs) &&
           listsMatch(t1.args, t2.args) &&
           (t1.varargsElement == t2.varargsElement) &&
           treesMatch(t1.def, t2.def);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:CasualDiff.java


注:本文中的com.sun.tools.javac.tree.JCTree.JCNewClass类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。