use of com.sun.source.tree.ClassTree in project st-js by st-js.
the class IdentifierGlobalScopeNameClashCheck method findVariablesInMethod.
private static void findVariablesInMethod(final String name, final GenerationContext<Void> context) {
MethodTree enclosingMethod = getEnclosingMethod(context.getCurrentPath());
if (enclosingMethod == null) {
// don't see a reason why!?
return;
}
enclosingMethod.accept(new TreeScanner<Void, Void>() {
private boolean checkStopped;
@Override
public Void visitClass(ClassTree arg0, Void arg1) {
// stop the checks if a new type is encountered
checkStopped = true;
return super.visitClass(arg0, arg1);
}
@Override
public Void visitVariable(VariableTree var, Void arg1) {
if (!checkStopped && var.getName().toString().equals(name)) {
context.addError(var, "A variable with the same name as your global variable is already defined in this method's scope. " + "Please rename either the local variable/parameter or the global variable.");
}
return super.visitVariable(var, arg1);
}
}, null);
}
use of com.sun.source.tree.ClassTree in project st-js by st-js.
the class ClassWriter method getMembers.
/**
* @return the JavaScript node for the class' members
*/
private JS getMembers(WriterVisitor<JS> visitor, ClassTree clazz, GenerationContext<JS> context) {
// the following members must not appear in the initializer function:
// - constructors (they are printed elsewhere)
// - abstract methods (they should be omitted)
List<Tree> nonConstructors = getAllMembersExceptConstructors(clazz);
if (nonConstructors.isEmpty()) {
return context.js().keyword(Keyword.NULL);
}
@SuppressWarnings("unchecked") List<JS> params = Arrays.asList(context.js().name(JavascriptKeywords.CONSTRUCTOR), context.js().name(JavascriptKeywords.PROTOTYPE));
List<JS> stmts = new ArrayList<JS>();
for (Tree member : nonConstructors) {
stmts.add(visitor.scan(member, context));
}
return context.js().function(null, params, context.js().block(stmts));
}
use of com.sun.source.tree.ClassTree in project st-js by st-js.
the class ClassWriter method getSuperClass.
/**
* @return the node to put in the super class. for intefaces, the super class goes also in the interfaces list
*/
private JS getSuperClass(ClassTree clazz, GenerationContext<JS> context) {
Element type = TreeUtils.elementFromDeclaration(clazz);
if (clazz.getExtendsClause() == null || type.getKind() == ElementKind.INTERFACE) {
// no super class found
return context.js().keyword(Keyword.NULL);
}
TreeWrapper<Tree, JS> superType = context.getCurrentWrapper().child(clazz.getExtendsClause());
if (superType.isSyntheticType()) {
return context.js().keyword(Keyword.NULL);
}
DependencyType depType = getDependencyTypeForClassDef(type);
return context.js().name(superType.getTypeName(depType));
}
use of com.sun.source.tree.ClassTree in project AndroidLife by CaMnter.
the class IdScanner method visitClassDef.
@Override
public void visitClassDef(JCTree.JCClassDecl jcClassDecl) {
for (JCTree tree : jcClassDecl.defs) {
if (tree instanceof ClassTree) {
ClassTree classTree = (ClassTree) tree;
String className = classTree.getSimpleName().toString();
if (SUPPORTED_TYPES.contains(className)) {
ClassName rClassName = ClassName.get(rPackageName, "R", className);
VarScanner scanner = new VarScanner(ids, rClassName, respectivePackageName);
((JCTree) classTree).accept(scanner);
}
}
}
}
use of com.sun.source.tree.ClassTree in project checker-framework by typetools.
the class TypeFromTypeTreeVisitor method getTypeVariableFromDeclaration.
/**
* If a tree is can be found for the declaration of the type variable {@code type}, then a {@link
* AnnotatedTypeVariable} is returned with explicit annotations from the type variables declared
* bounds. If a tree cannot be found, then {@code type}, converted to a use, is returned.
*
* @param type type variable used to find declaration tree
* @param f annotated type factory
* @return the AnnotatedTypeVariable from the declaration of {@code type} or {@code type} if no
* tree is found.
*/
private AnnotatedTypeVariable getTypeVariableFromDeclaration(AnnotatedTypeVariable type, AnnotatedTypeFactory f) {
TypeVariable typeVar = type.getUnderlyingType();
TypeParameterElement tpe = (TypeParameterElement) typeVar.asElement();
Element elt = tpe.getGenericElement();
if (elt instanceof TypeElement) {
TypeElement typeElt = (TypeElement) elt;
int idx = typeElt.getTypeParameters().indexOf(tpe);
ClassTree cls = (ClassTree) f.declarationFromElement(typeElt);
if (cls == null || cls.getTypeParameters().isEmpty()) {
// contains all necessary information and we can return that.
return type.asUse();
}
// will return a declaration ATV. So change it to a use.
return visitTypeParameter(cls.getTypeParameters().get(idx), f).asUse();
} else if (elt instanceof ExecutableElement) {
ExecutableElement exElt = (ExecutableElement) elt;
int idx = exElt.getTypeParameters().indexOf(tpe);
MethodTree meth = (MethodTree) f.declarationFromElement(exElt);
if (meth == null) {
// + elt);
return type.asUse();
}
// This works the same as the case above. Even though `meth` itself is not a
// type declaration tree, the elements of `meth.getTypeParameters()` still are.
AnnotatedTypeVariable result = visitTypeParameter(meth.getTypeParameters().get(idx), f).shallowCopy();
result.setDeclaration(false);
return result;
} else if (TypesUtils.isCapturedTypeVariable(typeVar)) {
// not an element at all, namely Symtab.noSymbol.
return type.asUse();
} else {
throw new BugInCF("TypeFromTree.forTypeVariable: not a supported element: " + elt);
}
}
Aggregations