@Override public void visitSelect(JCTree.JCFieldAccess jcFieldAccess) { Symbol symbol = jcFieldAccess.sym; if (symbol.getEnclosingElement() != null && symbol.getEnclosingElement().getEnclosingElement() != null && symbol.getEnclosingElement().getEnclosingElement().enclClass() != null) { try { int value = (Integer) requireNonNull(((Symbol.VarSymbol) symbol).getConstantValue()); resourceIds.put(value, new Id(value, symbol)); } catch (Exception ignored) { } } }
@Override public void visitSelect(JCTree.JCFieldAccess jcFieldAccess) { // This "visit" method is called for each parameter in the annotation, but only if the // parameter is a field type (eg R.layout.resource_name is a field inside the R.layout // class). This means this method will not pick up things like booleans and strings. // This is the resource parameter inside the annotation Symbol symbol = jcFieldAccess.sym; if (symbol instanceof VarSymbol && symbol.getEnclosingElement() != null // The R.resourceType class && symbol.getEnclosingElement().getEnclosingElement() != null // The R class && symbol.getEnclosingElement().getEnclosingElement().enclClass() != null) { ResourceValue result = parseResourceSymbol((VariableElement) symbol); if (result != null) { results.add(result); } } }
private UStaticIdent staticMember(Symbol symbol) { return UStaticIdent.create( (ClassSymbol) symbol.getEnclosingElement(), symbol.getSimpleName(), template(symbol.asType())); }
@Override public boolean matches(MethodTree methodTree, VisitorState state) { Symbol symbol = ASTHelpers.getSymbol(methodTree); return symbol.getEnclosingElement().getQualifiedName().contentEquals(className) && symbol.isConstructor(); } };
if (symbol.getEnclosingElement() instanceof PackageSymbol) { return Description.NO_MATCH; SuggestedFixes.qualifyType(getCheckState(state), builder, symbol.getEnclosingElement()) + ".";
@Override protected Choice<Unifier> defaultAction(Tree node, Unifier unifier) { Symbol symbol = ASTHelpers.getSymbol(node); if (symbol != null) { return classIdent() .unify(symbol.getEnclosingElement(), unifier) .thenChoose(unifications(getName(), symbol.getSimpleName())) .thenChoose(unifications(memberType(), symbol.asType())); } return Choice.none(); } }
private boolean isAmbientAnnotatedDeclaration(Symbol symbol) { if (symbol == null) { return false; } if (hasAnnotationType(symbol, JSweetConfig.ANNOTATION_AMBIENT)) { return true; } else { return isAmbientAnnotatedDeclaration(symbol.getEnclosingElement()); } }
public void visitIdent(JCIdent var) { if (var.sym != null && (var.sym instanceof VarSymbol)) { VarSymbol varSymbol = (VarSymbol) var.sym; if (varSymbol.getEnclosingElement() instanceof MethodSymbol && varSymbol.getEnclosingElement() .getEnclosingElement() == getParent(JCClassDecl.class).sym) { finalVars.add((VarSymbol) var.sym); } } } }.visitClassDef(newClass.def);
private void getRootRelativeJavaName(StringBuilder sb, Symbol symbol) { if (!isRootPackage(symbol)) { if (sb.length() > 0 && !"".equals(symbol.toString())) { sb.insert(0, "."); } String name = symbol.getSimpleName().toString(); sb.insert(0, name); symbol = (symbol instanceof PackageSymbol) ? ((PackageSymbol) symbol).owner : symbol.getEnclosingElement(); if (symbol != null) { getRootRelativeJavaName(sb, symbol); } } }
@Override public void visitApply(JCMethodInvocation invocation) { // TODO: same for static variables if (invocation.meth instanceof JCIdent && JSweetConfig.TS_STRICT_MODE_KEYWORDS.contains(invocation.meth.toString().toLowerCase())) { PackageSymbol invocationPackage = (PackageSymbol) ((JCIdent) invocation.meth).sym .getEnclosingElement().getEnclosingElement(); String rootRelativeInvocationPackageName = getRootRelativeName(invocationPackage); if (rootRelativeInvocationPackageName.indexOf('.') == -1) { super.visitApply(invocation); return; } String targetRootPackageName = rootRelativeInvocationPackageName.substring(0, rootRelativeInvocationPackageName.indexOf('.')); String pathToReachRootPackage = Util.getRelativePath( "/" + compilationUnit.packge.getQualifiedName().toString().replace('.', '/'), "/" + targetRootPackageName); if (pathToReachRootPackage == null) { super.visitApply(invocation); return; } File moduleFile = new File(new File(pathToReachRootPackage), JSweetConfig.MODULE_FILE_NAME); if (!invocationPackage.toString().equals(compilationUnit.packge.getSimpleName().toString())) { useModule(false, invocationPackage, invocation, targetRootPackageName, moduleFile.getPath().replace('\\', '/'), null); } } super.visitApply(invocation); }
/** * Tells if the given symbol is ambient (part of a def.* package or within an * <code>@Ambient</code>-annotated scope). */ public boolean isAmbientDeclaration(Symbol symbol) { if (symbol instanceof TypeSymbol ? symbol.getQualifiedName().toString().startsWith(JSweetConfig.LIBS_PACKAGE + ".") : symbol.getEnclosingElement().getQualifiedName().toString() .startsWith(JSweetConfig.LIBS_PACKAGE + ".")) { return true; } else { return isAmbientAnnotatedDeclaration(symbol); } }
private void getRootRelativeName(Map<Symbol, String> nameMapping, StringBuilder sb, Symbol symbol) { if (useModules && symbol instanceof PackageSymbol && !symbol.toString().startsWith(JSweetConfig.LIBS_PACKAGE + ".")) { return; } if (!isRootPackage(symbol)) { if (sb.length() > 0 && !"".equals(symbol.toString())) { sb.insert(0, "."); } String name = symbol.getSimpleName().toString(); if (nameMapping != null && nameMapping.containsKey(symbol)) { name = nameMapping.get(symbol); } else { if (hasAnnotationType(symbol, JSweetConfig.ANNOTATION_NAME)) { String originalName = getAnnotationValue(symbol, JSweetConfig.ANNOTATION_NAME, String.class, null); if (!isBlank(originalName)) { name = originalName; } } } sb.insert(0, name); symbol = (symbol instanceof PackageSymbol) ? ((PackageSymbol) symbol).owner : symbol.getEnclosingElement(); if (symbol != null) { getRootRelativeName(nameMapping, sb, symbol); } } }
if (symbol.getEnclosingElement() != null) { signature = symbol.getEnclosingElement().getQualifiedName().toString() + "." + signature;
.equals(identifier.sym.getEnclosingElement().getSimpleName().toString())) { String pathToModulePackage = Util.getRelativePath(compilationUnit.packge, identifier.sym.getEnclosingElement()); if (pathToModulePackage == null) { return; if (!identifier.sym.getEnclosingElement() .equals(compilationUnit.packge.getSimpleName().toString())) { useModule(false, (PackageSymbol) identifier.sym.getEnclosingElement(), identifier, JSweetConfig.GLOBALS_PACKAGE_NAME, moduleFile.getPath().replace('\\', '/'), null);
while (i >= 0 && !(s instanceof PackageSymbol)) { qualifiedName = namePath[i--] + ("".equals(qualifiedName) ? "" : "." + qualifiedName); s = s.getEnclosingElement();
if (!(symbol instanceof TypeSymbol) && symbol.getEnclosingElement() != null) { signature = symbol.getEnclosingElement().getQualifiedName().toString() + "." + signature;
/** * Gets the top-level package enclosing the given symbol. The top-level package * is the one that is enclosed within a root package (see * <code>jsweet.lang.Root</code>) or the one in the default (unnamed) package. */ public PackageSymbol getTopLevelPackage(Symbol symbol) { if ((symbol instanceof PackageSymbol) && isRootPackage(symbol)) { return null; } Symbol parent = (symbol instanceof PackageSymbol) ? ((PackageSymbol) symbol).owner : symbol.getEnclosingElement(); if (parent != null && isRootPackage(parent)) { if (symbol instanceof PackageSymbol) { return (PackageSymbol) symbol; } else { return null; } } else { if (parent == null || (parent instanceof PackageSymbol && StringUtils.isBlank(parent.getSimpleName()))) { if (symbol instanceof PackageSymbol) { return (PackageSymbol) symbol; } else { return null; } } else { return getTopLevelPackage(parent); } } }
JCFieldAccess qualified = (JCFieldAccess) importDecl.qualid; if (qualified.sym instanceof ClassSymbol && qualified.sym.getEnclosingElement() instanceof ClassSymbol) { return null;
@Override public void visitSelect(JCTree.JCFieldAccess jcFieldAccess) { Symbol symbol = jcFieldAccess.sym; if (symbol.getEnclosingElement() != null && symbol.getEnclosingElement().getEnclosingElement() != null && symbol.getEnclosingElement().getEnclosingElement().enclClass() != null) { try { int value = (Integer) requireNonNull(((Symbol.VarSymbol) symbol).getConstantValue()); resourceIds.put(value, new Id(value, symbol)); } catch (Exception ignored) { } } }
.getTree().meth).sym.getEnclosingElement().getQualifiedName().toString(); if (context.getBaseThrowables().contains(superClassName)) {