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


Java BlockTree类代码示例

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


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

示例1: visitBlock

import com.sun.source.tree.BlockTree; //导入依赖的package包/类
public Boolean visitBlock(BlockTree node, TreePath p) {
    if (p == null) {
        super.visitBlock(node, p);
        return false;
    }

    if (p.getLeaf().getKind() != Kind.BLOCK) {
        //single-statement blocks are considered to be equivalent to statements
        //TODO: some parents may need to be more strict, esp. synchronized and do-while
        assert node.getStatements().size() == 1;
        assert !node.isStatic();

        if (p.getLeaf() == searchingFor.getLeaf())
            return false;

        return checkLists(node.getStatements(), Collections.singletonList(p.getLeaf()), p.getParentPath());
    }

    BlockTree at = (BlockTree) p.getLeaf();

    if (node.isStatic() != at.isStatic()) {
        return false;
    }

    return checkLists(node.getStatements(), at.getStatements(), p);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:CopyFinder.java

示例2: visitBlock

import com.sun.source.tree.BlockTree; //导入依赖的package包/类
public Boolean visitBlock(BlockTree node, ConstructorData p) {
    List<? extends StatementTree> statements = new ArrayList<StatementTree>(node.getStatements());
    
    for (int i = 0; i < statements.size(); i++) {
        StatementTree st = statements.get(i);
        
        if (st.getKind() == Kind.IF) {
            IfTree it = (IfTree) st; 
            if (it.getElseStatement() == null && Utilities.exitsFromAllBranchers(info, new TreePath(new TreePath(getCurrentPath(), it), it.getThenStatement()))) {
                generalizedIf(it.getCondition(), it.getThenStatement(), statements.subList(i + 1, statements.size()), false);
                break;
            }
        }
        
        scan(st, null);
    }
    
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:Flow.java

示例3: createHashCodeMethod

import com.sun.source.tree.BlockTree; //导入依赖的package包/类
private static MethodTree createHashCodeMethod(WorkingCopy wc, Iterable<? extends VariableElement> hashCodeFields, Scope scope) {
    TreeMaker make = wc.getTreeMaker();
    Set<Modifier> mods = EnumSet.of(Modifier.PUBLIC);        

    int startNumber = generatePrimeNumber(2, 10);
    int multiplyNumber = generatePrimeNumber(10, 100);
    List<StatementTree> statements = new ArrayList<>();
    //int hash = <startNumber>;
    statements.add(make.Variable(make.Modifiers(EnumSet.noneOf(Modifier.class)), "hash", make.PrimitiveType(TypeKind.INT), make.Literal(startNumber))); //NOI18N        
    for (VariableElement ve : hashCodeFields) {
        TypeMirror tm = ve.asType();
        ExpressionTree variableRead = prepareExpression(wc, HASH_CODE_PATTERNS, tm, ve, scope);
        statements.add(make.ExpressionStatement(make.Assignment(make.Identifier("hash"), make.Binary(Tree.Kind.PLUS, make.Binary(Tree.Kind.MULTIPLY, make.Literal(multiplyNumber), make.Identifier("hash")), variableRead)))); //NOI18N
    }
    statements.add(make.Return(make.Identifier("hash"))); //NOI18N        
    BlockTree body = make.Block(statements, false);
    ModifiersTree modifiers = prepareModifiers(wc, mods,make);
    
    return make.Method(modifiers, "hashCode", make.PrimitiveType(TypeKind.INT), Collections.<TypeParameterTree> emptyList(), Collections.<VariableTree>emptyList(), Collections.<ExpressionTree>emptyList(), body, null); //NOI18N
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:EqualsHashCodeGenerator.java

示例4: generateMethodContents

import com.sun.source.tree.BlockTree; //导入依赖的package包/类
private void generateMethodContents(List<StatementTree> methodStatements) {
    Iterator<TypeMirrorHandle> additionalType = additionalLocalTypes.iterator();
    Iterator<String> additionalName = additionalLocalNames.iterator();
    while (additionalType.hasNext() && additionalName.hasNext()) {
        TypeMirror tm = additionalType.next().resolve(copy);
        if (tm == null) {
            //XXX:
            return;
        }
        Tree type = make.Type(tm);
        methodStatements.add(make.Variable(make.Modifiers(EnumSet.noneOf(Modifier.class)), additionalName.next(), type, null));
    }
    if (from == to && statements.get(from).getKind() == Tree.Kind.BLOCK) {
        methodStatements.addAll(((BlockTree) statements.get(from)).getStatements());
    } else {
        methodStatements.addAll(statements.subList(from, to + 1));
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:IntroduceMethodFix.java

示例5: getBounds

import com.sun.source.tree.BlockTree; //导入依赖的package包/类
private int[] getBounds(TreeUtilities tu, SourcePositions sp, CompilationUnitTree cut, Tree tree) {
    int[] bounds = {-1, -1};
    if (tree != null) {
        if (tree.getKind() == Tree.Kind.BLOCK) {
            List<? extends StatementTree> stats = ((BlockTree) tree).getStatements();
            if (stats != null && !stats.isEmpty()) {
                bounds[0] = getStart(tu, sp, cut, stats.get(0));
                bounds[1] = getEnd(tu, sp, cut, stats.get(stats.size() - 1));
            }
        } else {
            bounds[0] = getStart(tu, sp, cut, tree);
            bounds[1] = getEnd(tu, sp, cut, tree);
        }
    }
    return bounds;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:RemoveSurroundingCodeAction.java

示例6: visitBlock

import com.sun.source.tree.BlockTree; //导入依赖的package包/类
@Override
public Mirror visitBlock(BlockTree arg0, EvaluationContext evaluationContext) {
    Mirror lastResult = null;
    try {
        evaluationContext.pushBlock();
        for (StatementTree statementTree : arg0.getStatements()) {
            Mirror res = statementTree.accept(this, evaluationContext);
            if (res != null) {
                lastResult = res;
            }
            if (res instanceof CommandMirror) {
                break;
            }
        }
    } finally {
        evaluationContext.popBlock();
    }
    return lastResult;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:EvaluatorVisitor.java

示例7: composeNewTestMethod

import com.sun.source.tree.BlockTree; //导入依赖的package包/类
/**
 */
protected MethodTree composeNewTestMethod(String testMethodName,
                                          BlockTree testMethodBody,
                                          List<ExpressionTree> throwsList,
                                          WorkingCopy workingCopy) {
    TreeMaker maker = workingCopy.getTreeMaker();
    return maker.Method(
            maker.Modifiers(createModifierSet(PUBLIC)),
            testMethodName,
            maker.PrimitiveType(TypeKind.VOID),
            Collections.<TypeParameterTree>emptyList(),
            Collections.<VariableTree>emptyList(),
            throwsList,
            testMethodBody,
            null);          //default value - used by annotations
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:JUnit3TestGenerator.java

示例8: createGetter

import com.sun.source.tree.BlockTree; //导入依赖的package包/类
private MethodTree createGetter(ModifiersTree mods, TypeMirror valueType) {
    StringBuilder getterName = GeneratorUtils.getCapitalizedName(config.getName());
    getterName.insert(0, valueType.getKind() == TypeKind.BOOLEAN ? "is" : "get");
    ReturnTree returnTree = make.Return(make.MethodInvocation(Collections.EMPTY_LIST, make.MemberSelect(make.Identifier(config.getName()), hasGet ? "get" : "getValue"), Collections.EMPTY_LIST));
    BlockTree getterBody = make.Block(Collections.singletonList(returnTree), false);
    Tree valueTree;
    if (valueType.getKind() == TypeKind.DECLARED) {
        valueTree = make.QualIdent(((DeclaredType) valueType).asElement());
    } else if (valueType.getKind().isPrimitive()) {
        valueTree = make.PrimitiveType(valueType.getKind());
    } else {
        valueTree = make.Identifier(valueType.toString());
    }
    MethodTree getter = make.Method(mods, getterName, valueTree, Collections.EMPTY_LIST, Collections.EMPTY_LIST, Collections.EMPTY_LIST, getterBody, null);
    return getter;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:AddJavaFXPropertyMaker.java

示例9: findMatchingMethodInvocation

import com.sun.source.tree.BlockTree; //导入依赖的package包/类
private StatementTree findMatchingMethodInvocation(CompilationInfo info, BlockTree block, int offset) {
    for (StatementTree t : block.getStatements()) {
        if (t.getKind() != Kind.EXPRESSION_STATEMENT) continue;

        long statementStart = info.getTrees().getSourcePositions().getStartPosition(info.getCompilationUnit(), t);

        if (offset < statementStart) return null;

        ExpressionStatementTree est = (ExpressionStatementTree) t;
        long statementEnd = info.getTrees().getSourcePositions().getEndPosition(info.getCompilationUnit(), t);
        long expressionEnd = info.getTrees().getSourcePositions().getEndPosition(info.getCompilationUnit(), est.getExpression());

        if (expressionEnd <= offset && offset < statementEnd) {
            return t;
        }
    }

    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:AssignResultToVariable.java

示例10: computeWarning

import com.sun.source.tree.BlockTree; //导入依赖的package包/类
@TriggerTreeKind(Tree.Kind.ENHANCED_FOR_LOOP)
@Messages("ERR_ForLoopToFunctionalHint=Can use functional operations")
public static ErrorDescription computeWarning(HintContext ctx) {
    if (ctx.getInfo().getElements().getTypeElement("java.util.stream.Streams") == null && !DISABLE_CHECK_FOR_STREAM) return null;
    
    PreconditionsChecker pc = new PreconditionsChecker(ctx.getPath().getLeaf(), ctx.getInfo());
    if (pc.isSafeToRefactor()) {
        EnhancedForLoopTree eflt = (EnhancedForLoopTree)ctx.getPath().getLeaf();
        StatementTree stmt = eflt.getStatement();
        if (stmt == null) {
            return null;
        }
        if (stmt.getKind() == Tree.Kind.BLOCK) {
            BlockTree bt = (BlockTree)stmt;
            if (bt.getStatements() == null || bt.getStatements().isEmpty()) {
                return null;
            }
        }
        Fix fix = new FixImpl(ctx.getInfo(), ctx.getPath(), null).toEditorFix();
        return ErrorDescriptionFactory.forName(ctx, ctx.getPath(), Bundle.ERR_ForLoopToFunctionalHint(), fix);
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:ForLoopToFunctionalHint.java

示例11: isLastInControlFlow

import com.sun.source.tree.BlockTree; //导入依赖的package包/类
private boolean isLastInControlFlow(TreePath pathToInstruction) {
    Tree currentTree = pathToInstruction.getLeaf();
    Tree parentTree = pathToInstruction.getParentPath().getLeaf();
    if (parentTree.equals(this.loop)) {
        return true;
    } else if (parentTree.getKind() == Tree.Kind.BLOCK) {
        List<? extends StatementTree> ls = ((BlockTree) parentTree).getStatements();
        if (ls.get(ls.size() - 1).equals(currentTree)) {
            return isLastInControlFlow(pathToInstruction.getParentPath());
        } else {
            return false;
        }

    } else if (parentTree.getKind() == Tree.Kind.AND.IF && ((IfTree) parentTree).getElseStatement() != null) {
        return false;
    } else {
        return this.isLastInControlFlow(pathToInstruction.getParentPath());
    }


}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:PreconditionsChecker.java

示例12: findEnclosingMethodOrLambdaOrInitializer

import com.sun.source.tree.BlockTree; //导入依赖的package包/类
/**
 * find the enclosing method, lambda expression or initializer block for the leaf of some tree
 * path
 *
 * @param path the tree path
 * @return the closest enclosing method / lambda
 */
@Nullable
public static TreePath findEnclosingMethodOrLambdaOrInitializer(TreePath path) {
  while (path != null) {
    if (path.getLeaf() instanceof MethodTree || path.getLeaf() instanceof LambdaExpressionTree) {
      return path;
    }
    TreePath parent = path.getParentPath();
    if (parent != null && parent.getLeaf() instanceof ClassTree) {
      if (path.getLeaf() instanceof BlockTree) {
        // found initializer block
        return path;
      }
      if (path.getLeaf() instanceof VariableTree
          && ((VariableTree) path.getLeaf()).getInitializer() != null) {
        // found field with an inline initializer
        return path;
      }
    }
    path = parent;
  }
  return null;
}
 
开发者ID:uber,项目名称:NullAway,代码行数:30,代码来源:NullabilityUtil.java

示例13: performRewrite

import com.sun.source.tree.BlockTree; //导入依赖的package包/类
@Override
protected void performRewrite(TransformationContext ctx) throws Exception {
    Tree t = ctx.getPath().getLeaf();
    if (t.getKind() != Tree.Kind.BLOCK) {
        return;
    }
    BlockTree bl = (BlockTree)t;
    WorkingCopy wc = ctx.getWorkingCopy();
    GeneratorUtilities gu = GeneratorUtilities.get(wc);
    gu.importComments(bl, wc.getCompilationUnit());
    TreeMaker mk = wc.getTreeMaker();
    BlockTree nbl = mk.Block(bl.getStatements(), true);
    gu.copyComments(bl, nbl, true);
    gu.copyComments(bl, nbl, false);
    wc.rewrite(bl, nbl);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:InitializerCanBeStatic.java

示例14: findOuterIf

import com.sun.source.tree.BlockTree; //导入依赖的package包/类
private static TreePath findOuterIf(HintContext ctx, TreePath treePath) {
    while (!ctx.isCanceled()) {
        treePath = treePath.getParentPath();
        if (treePath == null) {
            break;
        }
        Tree leaf = treePath.getLeaf();
        
        if (leaf.getKind() == Kind.IF) {
            return treePath;
        }
        
        if (leaf.getKind() == Kind.BLOCK) {
            BlockTree b = (BlockTree)leaf;
            if (b.getStatements().size() == 1) {
                // ok, empty blocks can be around synchronized(this) 
                // statements
                continue;
            }
        }
        
        return null;
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:DoubleCheck.java

示例15: needsStaticRelativeTo

import com.sun.source.tree.BlockTree; //导入依赖的package包/类
static boolean needsStaticRelativeTo(CompilationInfo info, TreePath targetClass, TreePath occurrence) {
    while (occurrence != null && targetClass.getLeaf() != occurrence.getLeaf()) {
        switch (occurrence.getLeaf().getKind()) {
            case METHOD:
                if (((MethodTree) occurrence.getLeaf()).getModifiers().getFlags().contains(Modifier.STATIC)) {
                    return true;
                }
                break;
            case BLOCK:
                if (((BlockTree) occurrence.getLeaf()).isStatic()) {
                    return true;
                }
                break;
            case INTERFACE:
                return true;
        }

        occurrence = occurrence.getParentPath();
    }

    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:IntroduceHint.java


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