本文整理汇总了Java中com.sun.source.tree.ClassTree.getImplementsClause方法的典型用法代码示例。如果您正苦于以下问题:Java ClassTree.getImplementsClause方法的具体用法?Java ClassTree.getImplementsClause怎么用?Java ClassTree.getImplementsClause使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.source.tree.ClassTree
的用法示例。
在下文中一共展示了ClassTree.getImplementsClause方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: computeClass
import com.sun.source.tree.ClassTree; //导入方法依赖的package包/类
private static List<? extends TypeMirror> computeClass(Set<ElementKind> types, CompilationInfo info, TreePath parent, Tree error, int offset) {
ClassTree ct = (ClassTree) parent.getLeaf();
if (ct.getExtendsClause() == error) {
types.add(ElementKind.CLASS);
return null;
}
for (Tree t : ct.getImplementsClause()) {
if (t == error) {
types.add(ElementKind.INTERFACE);
return null;
}
}
//XXX: annotation types...
return null;
}
示例2: visitClass
import com.sun.source.tree.ClassTree; //导入方法依赖的package包/类
@Override
public Void visitClass(ClassTree node, Map<String, Object> p) {
if (getCurrentPath().getParentPath().getLeaf().getKind() != Kind.NEW_CLASS) {
filterByAcceptedKind(node.getExtendsClause(), ElementKind.CLASS);
for (Tree intf : node.getImplementsClause()) {
filterByAcceptedKind(intf, ElementKind.INTERFACE, ElementKind.ANNOTATION_TYPE);
}
}
return super.visitClass(node, p);
}
示例3: isInHeader
import com.sun.source.tree.ClassTree; //导入方法依赖的package包/类
private static boolean isInHeader(CompilationInfo info, ClassTree tree, int offset) {
CompilationUnitTree cut = info.getCompilationUnit();
SourcePositions sp = info.getTrees().getSourcePositions();
long lastKnownOffsetInHeader = sp.getStartPosition(cut, tree);
List<? extends Tree> impls = tree.getImplementsClause();
List<? extends TypeParameterTree> typeparams;
if (impls != null && !impls.isEmpty()) {
lastKnownOffsetInHeader= sp.getEndPosition(cut, impls.get(impls.size() - 1));
} else if ((typeparams = tree.getTypeParameters()) != null && !typeparams.isEmpty()) {
lastKnownOffsetInHeader= sp.getEndPosition(cut, typeparams.get(typeparams.size() - 1));
} else if (tree.getExtendsClause() != null) {
lastKnownOffsetInHeader = sp.getEndPosition(cut, tree.getExtendsClause());
} else if (tree.getModifiers() != null) {
lastKnownOffsetInHeader = sp.getEndPosition(cut, tree.getModifiers());
}
TokenSequence<JavaTokenId> ts = info.getTreeUtilities().tokensFor(tree);
ts.move((int) lastKnownOffsetInHeader);
while (ts.moveNext()) {
if (ts.token().id() == JavaTokenId.LBRACE) {
return offset < ts.offset();
}
}
return false;
}
示例4: implementMethods
import com.sun.source.tree.ClassTree; //导入方法依赖的package包/类
@TriggerTreeKind(Kind.CLASS)
@Messages({
"# {0} - the FQN of the type whose methods will be implemented",
"ERR_ImplementMethods=Implement unimplemented abstract methods of {0}"
})
public static ErrorDescription implementMethods(HintContext ctx) {
ClassTree clazz = (ClassTree) ctx.getPath().getLeaf();
Element typeEl = ctx.getInfo().getTrees().getElement(ctx.getPath());
if (typeEl == null || !typeEl.getKind().isClass())
return null;
List<Tree> candidate = new ArrayList<Tree>(clazz.getImplementsClause());
candidate.add(clazz.getExtendsClause());
Tree found = null;
for (Tree cand : candidate) {
if ( ctx.getInfo().getTrees().getSourcePositions().getStartPosition(ctx.getInfo().getCompilationUnit(), cand) <= ctx.getCaretLocation()
&& ctx.getCaretLocation() <= ctx.getInfo().getTrees().getSourcePositions().getEndPosition(ctx.getInfo().getCompilationUnit(), cand)) {
found = cand;
break;
}
}
if (found == null) return null;
TreePath foundPath = new TreePath(ctx.getPath(), found);
Element supertype = ctx.getInfo().getTrees().getElement(foundPath);
if (supertype == null || (!supertype.getKind().isClass() && !supertype.getKind().isInterface()))
return null;
List<ExecutableElement> unimplemented = computeUnimplemented(ctx.getInfo(), typeEl, supertype);
if (!unimplemented.isEmpty()) {
return ErrorDescriptionFactory.forName(ctx, foundPath, Bundle.ERR_ImplementMethods(((TypeElement) supertype).getQualifiedName().toString()), new ImplementFix(ctx.getInfo(), ctx.getPath(), (TypeElement) typeEl, (TypeElement) supertype).toEditorFix());
}
return null;
}
示例5: visitClassDeclaration
import com.sun.source.tree.ClassTree; //导入方法依赖的package包/类
public void visitClassDeclaration(ClassTree node) {
sync(node);
List<Op> breaks =
visitModifiers(node.getModifiers(), Direction.VERTICAL, Optional.<BreakTag>absent());
boolean hasSuperclassType = node.getExtendsClause() != null;
boolean hasSuperInterfaceTypes = !node.getImplementsClause().isEmpty();
builder.addAll(breaks);
token(node.getKind() == Tree.Kind.INTERFACE ? "interface" : "class");
builder.space();
visit(node.getSimpleName());
if (!node.getTypeParameters().isEmpty()) {
token("<");
}
builder.open(plusFour);
{
if (!node.getTypeParameters().isEmpty()) {
typeParametersRest(
node.getTypeParameters(),
hasSuperclassType || hasSuperInterfaceTypes ? plusFour : ZERO);
}
if (hasSuperclassType) {
builder.breakToFill(" ");
token("extends");
builder.space();
scan(node.getExtendsClause(), null);
}
if (hasSuperInterfaceTypes) {
builder.breakToFill(" ");
builder.open(node.getImplementsClause().size() > 1 ? plusFour : ZERO);
token(node.getKind() == Tree.Kind.INTERFACE ? "extends" : "implements");
builder.space();
boolean first = true;
for (Tree superInterfaceType : node.getImplementsClause()) {
if (!first) {
token(",");
builder.breakOp(" ");
}
scan(superInterfaceType, null);
first = false;
}
builder.close();
}
}
builder.close();
if (node.getMembers() == null) {
token(";");
} else {
addBodyDeclarations(node.getMembers(), BracesOrNot.YES, FirstDeclarationsOrNot.YES);
}
dropEmptyDeclarations();
}