use of com.sun.source.util.TreePath in project ceylon by eclipse.
the class T6598108 method main.
public static void main(String[] args) throws Exception {
// NOI18N
final String bootPath = System.getProperty("sun.boot.class.path");
final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
assert tool != null;
final JavacTask ct = (JavacTask) tool.getTask(null, null, null, Arrays.asList("-bootclasspath", bootPath), null, Arrays.asList(new MyFileObject()));
CompilationUnitTree cut = ct.parse().iterator().next();
TreePath tp = new TreePath(new TreePath(cut), cut.getTypeDecls().get(0));
Scope s = Trees.instance(ct).getScope(tp);
TypeElement type = ct.getElements().getTypeElement("com.sun.java.util.jar.pack.Package.File");
if (Trees.instance(ct).isAccessible(s, type)) {
// "false" would be expected here.
throw new IllegalStateException("");
}
}
use of com.sun.source.util.TreePath in project ceylon by eclipse.
the class T6852595 method main.
public static void main(String[] args) throws IOException {
JavaFileObject sfo = new SimpleJavaFileObject(URI.create("myfo:/Test.java"), Kind.SOURCE) {
public CharSequence getCharContent(boolean ignoreEncodingErrors) {
return "class BadName { Object o = j; }";
}
};
List<? extends JavaFileObject> files = Arrays.asList(sfo);
JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
JavacTask ct = (JavacTask) tool.getTask(null, null, null, null, null, files);
Iterable<? extends CompilationUnitTree> compUnits = ct.parse();
CompilationUnitTree cu = compUnits.iterator().next();
ClassTree cdef = (ClassTree) cu.getTypeDecls().get(0);
JCVariableDecl vdef = (JCVariableDecl) cdef.getMembers().get(0);
TreePath path = TreePath.getPath(cu, vdef.init);
Trees.instance(ct).getScope(path);
}
use of com.sun.source.util.TreePath in project btrace by btraceio.
the class VerifierVisitor method visitReturn.
@Override
public Boolean visitReturn(ReturnTree node, Void v) {
if (node.getExpression() != null) {
TreePath tp = verifier.getTreeUtils().getPath(verifier.getCompilationUnit(), node);
while (tp != null) {
tp = tp.getParentPath();
Tree leaf = tp.getLeaf();
if (leaf.getKind() == Tree.Kind.METHOD) {
if (isAnnotated((MethodTree) leaf)) {
return reportError("return.type.should.be.void", node);
} else {
return super.visitReturn(node, v);
}
}
}
}
return super.visitReturn(node, v);
}
use of com.sun.source.util.TreePath in project btrace by btraceio.
the class VerifierVisitor method getElement.
private Element getElement(Tree t) {
TreePath tp = verifier.getTreeUtils().getPath(verifier.getCompilationUnit(), t);
Element e = verifier.getTreeUtils().getElement(tp);
if (e == null) {
// hack to make JDK 7 symbol resolution working
if (t instanceof MethodInvocationTree) {
JCTree.JCExpression jce = ((JCTree.JCMethodInvocation) t).meth;
if (jce instanceof IdentifierTree) {
e = ((JCTree.JCIdent) jce).sym;
} else if (jce instanceof MemberSelectTree) {
e = ((JCTree.JCFieldAccess) jce).sym;
}
} else if (t instanceof JCTree.JCIdent) {
e = ((JCTree.JCIdent) t).sym;
} else if (t instanceof JCTree.JCNewClass) {
e = ((JCTree.JCIdent) ((JCTree.JCNewClass) t).clazz).sym;
} else if (t instanceof JCTree.JCThrow) {
e = ((JCTree.JCNewClass) ((JCTree.JCThrow) t).expr).type.tsym;
}
}
return e;
}
use of com.sun.source.util.TreePath in project btrace by btraceio.
the class VerifierVisitor method checkSampling.
private boolean checkSampling(MethodTree node) {
TreePath mPath = verifier.getTreeUtils().getPath(verifier.getCompilationUnit(), node);
ExecutableElement ee = (ExecutableElement) verifier.getTreeUtils().getElement(mPath);
Sampled s = ee.getAnnotation(Sampled.class);
OnMethod om = ee.getAnnotation(OnMethod.class);
if (s != null && om != null) {
Kind k = om.location().value();
switch(k) {
case ENTRY:
case RETURN:
case ERROR:
case CALL:
{
return true;
}
default:
{
// noop
}
}
reportError("sampler.invalid.location", node);
return false;
}
return true;
}
Aggregations