use of com.sun.tools.javac.tree.JCTree.JCClassDecl in project robolectric by robolectric.
the class Helpers method isInShadowClass.
public static boolean isInShadowClass(TreePath path, VisitorState state) {
Tree leaf = path.getLeaf();
JCClassDecl classDecl = JCClassDecl.class.isInstance(leaf) ? (JCClassDecl) leaf : findEnclosingNode(state.getPath(), JCClassDecl.class);
return hasAnnotation(classDecl, Implements.class, state);
}
use of com.sun.tools.javac.tree.JCTree.JCClassDecl in project ceylon-compiler by ceylon.
the class CallableBuilder method build.
public JCExpression build() {
// Generate a subclass of Callable
ListBuffer<JCTree> classBody = new ListBuffer<JCTree>();
gen.at(node);
if (parameterDefaultValueMethods != null) {
for (MethodDefinitionBuilder mdb : parameterDefaultValueMethods) {
classBody.append(mdb.build());
}
}
transformation.appendMethods(classBody);
JCClassDecl classDef = gen.make().AnonymousClassDef(gen.make().Modifiers(0, annotations != null ? annotations : List.<JCAnnotation>nil()), classBody.toList());
int variadicIndex = isVariadic ? numParams - 1 : -1;
Type callableType;
if (typeModel.isTypeConstructor()) {
callableType = typeModel.getDeclaration().getExtendedType();
} else {
callableType = typeModel;
}
JCNewClass callableInstance = gen.make().NewClass(null, null, gen.makeJavaType(callableType, JT_EXTENDS | JT_CLASS_NEW), List.<JCExpression>of(gen.makeReifiedTypeArgument(callableType.getTypeArgumentList().get(0)), gen.makeReifiedTypeArgument(callableType.getTypeArgumentList().get(1)), gen.make().Literal(callableType.asString(true)), gen.make().TypeCast(gen.syms().shortType, gen.makeInteger(variadicIndex))), classDef);
JCExpression result;
if (typeModel.isTypeConstructor()) {
result = buildTypeConstructor(callableType, callableInstance);
} else {
result = callableInstance;
}
gen.at(null);
if (instanceSubstitution != null) {
instanceSubstitution.close();
}
return result;
}
use of com.sun.tools.javac.tree.JCTree.JCClassDecl in project ceylon-compiler by ceylon.
the class Attr method attribClassBody.
/**
* Finish the attribution of a class.
*/
private void attribClassBody(Env<AttrContext> env, ClassSymbol c) {
JCClassDecl tree = (JCClassDecl) env.tree;
Assert.check(c == tree.sym);
// Validate annotations
chk.validateAnnotations(tree.mods.annotations, c);
// Validate type parameters, supertype and interfaces.
attribBounds(tree.typarams);
if (!c.isAnonymous()) {
// already checked if anonymous
chk.validate(tree.typarams, env);
chk.validate(tree.extending, env);
chk.validate(tree.implementing, env);
}
// methods or unimplemented methods of an implemented interface.
if ((c.flags() & (ABSTRACT | INTERFACE)) == 0) {
if (!relax)
chk.checkAllDefined(tree.pos(), c);
}
if ((c.flags() & ANNOTATION) != 0) {
if (tree.implementing.nonEmpty())
log.error(tree.implementing.head.pos(), "cant.extend.intf.annotation");
if (tree.typarams.nonEmpty())
log.error(tree.typarams.head.pos(), "intf.annotation.cant.have.type.params");
} else {
// Check that all extended classes and interfaces
// are compatible (i.e. no two define methods with same arguments
// yet different return types). (JLS 8.4.6.3)
chk.checkCompatibleSupertypes(tree.pos(), c.type);
}
// Check that class does not import the same parameterized interface
// with two different argument lists.
chk.checkClassBounds(tree.pos(), c.type);
tree.type = c.type;
for (List<JCTypeParameter> l = tree.typarams; l.nonEmpty(); l = l.tail) {
Assert.checkNonNull(env.info.scope.lookup(l.head.name).scope);
}
// Check that a generic class doesn't extend Throwable
if (!sourceLanguage.isCeylon() && !c.type.allparams().isEmpty() && types.isSubtype(c.type, syms.throwableType))
log.error(tree.extending.pos(), "generic.throwable");
// Check that all methods which implement some
// method conform to the method they implement.
chk.checkImplementations(tree);
// check that a resource implementing AutoCloseable cannot throw InterruptedException
checkAutoCloseable(tree.pos(), env, c.type);
for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) {
// Attribute declaration
attribStat(l.head, env);
// Make an exception for static constants.
if (c.owner.kind != PCK && ((c.flags() & STATIC) == 0 || c.name == names.empty) && (TreeInfo.flags(l.head) & (STATIC | INTERFACE)) != 0) {
Symbol sym = null;
if (l.head.getTag() == JCTree.VARDEF)
sym = ((JCVariableDecl) l.head).sym;
if (sym == null || sym.kind != VAR || ((VarSymbol) sym).getConstValue() == null)
log.error(l.head.pos(), "icls.cant.have.static.decl", c);
}
}
// Check for cycles among non-initial constructors.
chk.checkCyclicConstructors(tree);
// Check for cycles among annotation elements.
chk.checkNonCyclicElements(tree);
// Check for proper use of serialVersionUID
if (env.info.lint.isEnabled(LintCategory.SERIAL) && isSerializable(c) && (c.flags() & Flags.ENUM) == 0 && (c.flags() & ABSTRACT) == 0) {
checkSerialVersionUID(tree, c);
}
}
use of com.sun.tools.javac.tree.JCTree.JCClassDecl in project bazel by bazelbuild.
the class AnnotationProcessingPlugin method recordInfo.
private void recordInfo(JCCompilationUnit toplevel) {
CompilationUnit.Builder builder = CompilationUnit.newBuilder();
if (toplevel.sourcefile != null) {
// FileObject#getName() returns the original exec root-relative path of
// the source file, which is want we want.
// Paths.get(sourcefile.toUri()) would absolutize the path.
Path path = Paths.get(toplevel.sourcefile.getName());
builder.setPath(processingModule.stripSourceRoot(path).toString());
builder.setGeneratedByAnnotationProcessor(processingModule.isGenerated(path));
}
if (toplevel.getPackageName() != null) {
builder.setPkg(toplevel.getPackageName().toString());
}
for (JCTree decl : toplevel.defs) {
if (decl instanceof JCClassDecl) {
builder.addTopLevel(((JCClassDecl) decl).getSimpleName().toString());
}
}
processingModule.recordUnit(builder.build());
}
use of com.sun.tools.javac.tree.JCTree.JCClassDecl in project bazel by bazelbuild.
the class TreePrunerTest method parseField.
JCVariableDecl parseField(String line) {
JCCompilationUnit unit = parseLines("class T {", line, "}");
JCClassDecl classDecl = (JCClassDecl) getOnlyElement(unit.defs);
return (JCVariableDecl) getOnlyElement(classDecl.defs);
}
Aggregations