use of com.sun.source.tree.ClassTree in project j2objc by google.
the class TreeConverter method convertAnnotationTypeDeclaration.
private TreeNode convertAnnotationTypeDeclaration(ClassTree node, TreePath parent) {
AnnotationTypeDeclaration newNode = new AnnotationTypeDeclaration();
TreePath path = getTreePath(parent, node);
Element element = getElement(path);
convertBodyDeclaration(node, path, node.getModifiers(), newNode);
for (Tree bodyDecl : node.getMembers()) {
if (bodyDecl.getKind() == Kind.METHOD) {
MethodTree methodTree = (MethodTree) bodyDecl;
TreePath methodPath = getTreePath(path, methodTree);
ExecutableElement methodElement = (ExecutableElement) getElement(methodPath);
Tree defaultValue = methodTree.getDefaultValue();
ModifiersTree modifiers = methodTree.getModifiers();
AnnotationTypeMemberDeclaration newMember = new AnnotationTypeMemberDeclaration().setDefault((Expression) convert(defaultValue, methodPath)).setExecutableElement(methodElement);
newMember.setModifiers((int) ((JCModifiers) modifiers).flags).setAnnotations(convertAnnotations(modifiers, getTreePath(methodPath, modifiers))).setJavadoc((Javadoc) getAssociatedJavaDoc(methodTree, methodPath));
newNode.addBodyDeclaration(newMember);
} else {
newNode.addBodyDeclaration((BodyDeclaration) convert(bodyDecl, path));
}
}
return newNode.setName(convertSimpleName(element, getTypeMirror(path), getNamePosition(node))).setTypeElement((TypeElement) element);
}
use of com.sun.source.tree.ClassTree in project j2objc by google.
the class TreeConverter method convertClassDeclarationHelper.
private TypeDeclaration convertClassDeclarationHelper(ClassTree node, TreePath parent) {
TreePath path = getTreePath(parent, node);
TypeDeclaration newNode = new TypeDeclaration();
TypeElement element = (TypeElement) getElement(path);
convertBodyDeclaration(node, parent, node.getModifiers(), newNode);
List<BodyDeclaration> bodyDeclarations = newNode.getBodyDeclarations();
for (Tree bodyDecl : node.getMembers()) {
Object member = convert(bodyDecl, path);
if (member instanceof BodyDeclaration) {
// Not true for enum constants.
bodyDeclarations.add((BodyDeclaration) member);
} else if (member instanceof Block) {
BlockTree javacBlock = (BlockTree) bodyDecl;
Block block = (Block) member;
bodyDeclarations.add(new Initializer(block, javacBlock.isStatic()));
}
}
newNode.setName(convertSimpleName(element, getTypeMirror(path), getNamePosition(node)));
newNode.setTypeElement(element);
return newNode;
}
use of com.sun.source.tree.ClassTree in project ceylon-compiler by ceylon.
the class T6404194 method main.
public static void main(String... args) throws IOException {
class MyFileObject extends SimpleJavaFileObject {
MyFileObject() {
super(URI.create("myfo:///Test.java"), SOURCE);
}
@Override
public String getCharContent(boolean ignoreEncodingErrors) {
// 01234567890123456 7890 123456789012345
return "@SuppressWarning(\"foo\") @Deprecated class Test { Test() { } }";
}
}
JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
List<JavaFileObject> compilationUnits = Collections.<JavaFileObject>singletonList(new MyFileObject());
JavacTask task = (JavacTask) javac.getTask(null, null, null, null, null, compilationUnits);
Trees trees = Trees.instance(task);
CompilationUnitTree toplevel = task.parse().iterator().next();
ClassTree classTree = (ClassTree) toplevel.getTypeDecls().get(0);
List<? extends Tree> annotations = classTree.getModifiers().getAnnotations();
Tree tree1 = annotations.get(0);
Tree tree2 = annotations.get(1);
long pos = trees.getSourcePositions().getStartPosition(toplevel, tree1);
if (pos != 0)
throw new AssertionError(String.format("Start pos for %s is incorrect (%s)!", tree1, pos));
pos = trees.getSourcePositions().getEndPosition(toplevel, tree1);
if (pos != 23)
throw new AssertionError(String.format("End pos for %s is incorrect (%s)!", tree1, pos));
pos = trees.getSourcePositions().getStartPosition(toplevel, tree2);
if (pos != 24)
throw new AssertionError(String.format("Start pos for %s is incorrect (%s)!", tree2, pos));
pos = trees.getSourcePositions().getEndPosition(toplevel, tree2);
if (pos != 35)
throw new AssertionError(String.format("End pos for %s is incorrect (%s)!", tree2, pos));
}
use of com.sun.source.tree.ClassTree in project vertx-docgen by vert-x3.
the class JavaDocGenerator method renderSource.
public String renderSource(TypeElement elt, String source) {
TreePath path = docTrees.getPath(elt);
ClassTree classTree = (ClassTree) path.getLeaf();
return renderSource(path, Collections.singletonList(classTree), source);
}
use of com.sun.source.tree.ClassTree in project checker-framework by typetools.
the class MustCallTransfer method createTemporaryVar.
/**
* Creates a variable declaration for the given expression node, if possible.
*
* @param node an expression node
* @return a variable tree for the node, or null if an appropriate containing element cannot be
* located
*/
@Nullable
protected VariableTree createTemporaryVar(Node node) {
ExpressionTree tree = (ExpressionTree) node.getTree();
TypeMirror treeType = TreeUtils.typeOf(tree);
Element enclosingElement;
TreePath path = atypeFactory.getPath(tree);
if (path == null) {
enclosingElement = TreeUtils.elementFromTree(tree).getEnclosingElement();
} else {
ClassTree classTree = TreePathUtil.enclosingClass(path);
enclosingElement = TreeUtils.elementFromTree(classTree);
}
if (enclosingElement == null) {
return null;
}
// Declare and initialize a new, unique variable
VariableTree tmpVarTree = treeBuilder.buildVariableDecl(treeType, uniqueName("temp-var"), enclosingElement, tree);
return tmpVarTree;
}
Aggregations