本文整理汇总了Java中com.sun.source.tree.BlockTree.isStatic方法的典型用法代码示例。如果您正苦于以下问题:Java BlockTree.isStatic方法的具体用法?Java BlockTree.isStatic怎么用?Java BlockTree.isStatic使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.source.tree.BlockTree
的用法示例。
在下文中一共展示了BlockTree.isStatic方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sameKind
import com.sun.source.tree.BlockTree; //导入方法依赖的package包/类
private static boolean sameKind(Tree t1, Tree t2) {
Kind k1 = t1.getKind();
Kind k2 = t2.getKind();
if (k1 == k2) {
return true;
}
if (isSingleStatemenBlockAndStatement(t1, t2) || isSingleStatemenBlockAndStatement(t2, t1)) {
return true;
}
if (k2 == Kind.BLOCK && StatementTree.class.isAssignableFrom(k1.asInterface())) {
BlockTree bt = (BlockTree) t2;
if (bt.isStatic()) {
return false;
}
switch (bt.getStatements().size()) {
case 1:
return true;
case 2:
return isMultistatementWildcardTree(bt.getStatements().get(0))
|| isMultistatementWildcardTree(bt.getStatements().get(1));
case 3:
return isMultistatementWildcardTree(bt.getStatements().get(0))
|| isMultistatementWildcardTree(bt.getStatements().get(2));
}
return false;
}
if ( (k1 != Kind.MEMBER_SELECT && k1 != Kind.IDENTIFIER)
|| (k2 != Kind.MEMBER_SELECT && k2 != Kind.IDENTIFIER)) {
return false;
}
return isPureMemberSelect(t1, true) && isPureMemberSelect(t2, true);
}
示例2: computeTree2Init
import com.sun.source.tree.BlockTree; //导入方法依赖的package包/类
/**
* @param enclosingClassPath TreePath to class
* @param state visitor state
* @return a map from each initializer <em>i</em> to the fields known to be initialized before
* <em>i</em> executes
*/
private Multimap<Tree, Element> computeTree2Init(
TreePath enclosingClassPath, VisitorState state) {
ClassTree enclosingClass = (ClassTree) enclosingClassPath.getLeaf();
ImmutableMultimap.Builder<Tree, Element> builder = ImmutableMultimap.builder();
// NOTE: this set includes both instance and static fields
Set<Element> initThusFar = new LinkedHashSet<>();
Set<MethodTree> constructors = new LinkedHashSet<>();
AccessPathNullnessAnalysis nullnessAnalysis = getNullnessAnalysis(state);
// NOTE: we assume the members are returned in their syntactic order. This has held
// true in our testing
for (Tree memberTree : enclosingClass.getMembers()) {
if (memberTree instanceof VariableTree || memberTree instanceof BlockTree) {
// putAll does not keep a reference to initThusFar, so we don't need to make a copy here
builder.putAll(memberTree, initThusFar);
}
if (memberTree instanceof BlockTree) {
BlockTree blockTree = (BlockTree) memberTree;
// add whatever gets initialized here
TreePath memberPath = new TreePath(enclosingClassPath, memberTree);
if (blockTree.isStatic()) {
initThusFar.addAll(
nullnessAnalysis.getNonnullStaticFieldsAtExit(memberPath, state.context));
} else {
initThusFar.addAll(
nullnessAnalysis.getNonnullFieldsOfReceiverAtExit(memberPath, state.context));
}
}
if (memberTree instanceof MethodTree) {
MethodTree methodTree = (MethodTree) memberTree;
if (isConstructor(methodTree)) {
constructors.add(methodTree);
}
}
}
// all the initializer blocks have run before any code inside a constructor
constructors.stream().forEach((c) -> builder.putAll(c, initThusFar));
Symbol.ClassSymbol classSymbol = ASTHelpers.getSymbol(enclosingClass);
FieldInitEntities entities = class2Entities.get(classSymbol);
if (entities.instanceInitializerMethods().size() == 1) {
MethodTree initMethod = entities.instanceInitializerMethods().iterator().next();
// collect the fields that may not be initialized by *some* constructor NC
Set<Symbol> constructorUninitSymbols = class2ConstructorUninit.get(classSymbol);
// fields initialized after constructors is initThusFar + (nonNullFields - constructorUninit)
Sets.SetView<Element> initAfterConstructors =
Sets.union(
initThusFar,
Sets.difference(entities.nonnullInstanceFields(), constructorUninitSymbols));
builder.putAll(initMethod, initAfterConstructors);
}
if (entities.staticInitializerMethods().size() == 1) {
MethodTree staticInitMethod = entities.staticInitializerMethods().iterator().next();
// constructors aren't relevant here; just use initThusFar
builder.putAll(staticInitMethod, initThusFar);
}
return builder.build();
}
示例3: collectEntities
import com.sun.source.tree.BlockTree; //导入方法依赖的package包/类
private FieldInitEntities collectEntities(ClassTree tree, VisitorState state) {
Symbol.ClassSymbol classSymbol = ASTHelpers.getSymbol(tree);
Set<Symbol> nonnullInstanceFields = new LinkedHashSet<>();
Set<Symbol> nonnullStaticFields = new LinkedHashSet<>();
List<BlockTree> instanceInitializerBlocks = new ArrayList<>();
List<BlockTree> staticInitializerBlocks = new ArrayList<>();
Set<MethodTree> constructors = new LinkedHashSet<>();
Set<MethodTree> instanceInitializerMethods = new LinkedHashSet<>();
Set<MethodTree> staticInitializerMethods = new LinkedHashSet<>();
// we assume getMembers() returns members in the same order as the declarations
for (Tree memberTree : tree.getMembers()) {
switch (memberTree.getKind()) {
case METHOD:
// check if it is a constructor or an @Initializer method
MethodTree methodTree = (MethodTree) memberTree;
Symbol.MethodSymbol symbol = ASTHelpers.getSymbol(methodTree);
if (isConstructor(methodTree)) {
constructors.add(methodTree);
} else if (isInitializerMethod(state, symbol)) {
if (symbol.isStatic()) {
staticInitializerMethods.add(methodTree);
} else {
instanceInitializerMethods.add(methodTree);
}
}
break;
case VARIABLE:
// field declaration
VariableTree varTree = (VariableTree) memberTree;
Symbol fieldSymbol = ASTHelpers.getSymbol(varTree);
if (fieldSymbol.type.isPrimitive() || skipDueToFieldAnnotation(fieldSymbol)) {
continue;
}
if (varTree.getInitializer() != null) {
// note that we check that the initializer does the right thing in
// matchVariable()
continue;
}
if (fieldSymbol.isStatic()) {
nonnullStaticFields.add(fieldSymbol);
} else {
nonnullInstanceFields.add(fieldSymbol);
}
break;
case BLOCK:
// initializer block
BlockTree blockTree = (BlockTree) memberTree;
if (blockTree.isStatic()) {
staticInitializerBlocks.add(blockTree);
} else {
instanceInitializerBlocks.add(blockTree);
}
break;
case ENUM:
case CLASS:
case INTERFACE:
case ANNOTATION_TYPE:
// do nothing
break;
default:
throw new RuntimeException(memberTree.getKind().toString() + " " + memberTree);
}
}
return FieldInitEntities.create(
classSymbol,
ImmutableSet.copyOf(nonnullInstanceFields),
ImmutableSet.copyOf(nonnullStaticFields),
ImmutableList.copyOf(instanceInitializerBlocks),
ImmutableList.copyOf(staticInitializerBlocks),
ImmutableSet.copyOf(constructors),
ImmutableSet.copyOf(instanceInitializerMethods),
ImmutableSet.copyOf(staticInitializerMethods));
}
示例4: visitBlock
import com.sun.source.tree.BlockTree; //导入方法依赖的package包/类
/**
* Helper method for blocks.
*/
private void visitBlock(
BlockTree node,
CollapseEmptyOrNot collapseEmptyOrNot,
AllowLeadingBlankLine allowLeadingBlankLine,
AllowTrailingBlankLine allowTrailingBlankLine) {
sync(node);
if (node.isStatic()) {
token("static");
builder.space();
}
if (collapseEmptyOrNot.isYes() && node.getStatements().isEmpty()) {
if (builder.peekToken().equals(Optional.of(";"))) {
// TODO(cushon): is this needed?
token(";");
} else {
tokenBreakTrailingComment("{", plusTwo);
builder.blankLineWanted(BlankLineWanted.NO);
token("}", plusTwo);
}
} else {
builder.open(ZERO);
builder.open(plusTwo);
tokenBreakTrailingComment("{", plusTwo);
if (allowLeadingBlankLine == AllowLeadingBlankLine.NO) {
builder.blankLineWanted(BlankLineWanted.NO);
} else {
builder.blankLineWanted(BlankLineWanted.PRESERVE);
}
visitStatements(node.getStatements());
builder.close();
builder.forcedBreak();
builder.close();
if (allowTrailingBlankLine == AllowTrailingBlankLine.NO) {
builder.blankLineWanted(BlankLineWanted.NO);
} else {
builder.blankLineWanted(BlankLineWanted.PRESERVE);
}
markForPartialFormat();
token("}", plusTwo);
}
}