@Override public Object visit(ASTImportDeclaration node, Object data) { if (node.isStatic()) { return data; } String img = node.jjtGetChild(0).getImage(); if (img.startsWith(IMPORT_JAVA_LANG)) { if (!IMPORT_JAVA_LANG.equals(img)) { if (img.indexOf('.', IMPORT_JAVA_LANG.length() + 1) != -1 || node.isImportOnDemand()) { // Importing from a subpackage / inner class return data; } } addViolation(data, node); } return data; } }
String strPackage = anImportDeclaration.getPackageName(); if (anImportDeclaration.isStatic()) { if (anImportDeclaration.isImportOnDemand()) { importOnDemandStaticClasses.add(JavaTypeDefinition.forClass(loadClass(strPackage))); } else { // not import on-demand if (anImportDeclaration.isImportOnDemand()) { importedOnDemand.add(strPackage); } else { // not import on-demand
private boolean isAvoidingConflict(final AbstractJavaTypeNode node, final String name, final ASTImportDeclaration firstMatch) { if (firstMatch.isImportOnDemand() && firstMatch.isStatic()) { final String methodCalled = name.substring(name.indexOf('.') + 1); if (importDeclaration.isImportOnDemand()) { if (firstMatch.isImportOnDemand() && !firstMatch.isStatic()) { for (ASTImportDeclaration importDeclaration : imports) { if (importDeclaration != firstMatch // NOPMD && !importDeclaration.isStatic() && !importDeclaration.isImportOnDemand()) { if (!firstMatch.isImportOnDemand() && !firstMatch.isStatic()) { String fqnName = name.substring(0, name.lastIndexOf('.')); if (!fqnName.equals(importName) && !firstMatch.isStatic() && !firstMatch.isImportOnDemand() && nameParts.length > 1 && nameParts[nameParts.length - 2].equals(importUnqualified)) { return true;
@Override public Object visit(ASTImportDeclaration node, Object data) { if (node.isImportOnDemand()) { ASTName importedType = (ASTName) node.jjtGetChild(0); imports.add(new ImportWrapper(importedType.getImage(), null, node, node.getType(), node.isStatic())); } else { if (!node.isImportOnDemand()) { ASTName importedType = (ASTName) node.jjtGetChild(0); String className; if (isQualifiedName(importedType)) { int lastDot = importedType.getImage().lastIndexOf('.') + 1; className = importedType.getImage().substring(lastDot); } else { className = importedType.getImage(); } imports.add(new ImportWrapper(importedType.getImage(), className, node)); } } return data; }
/** * Configures the type resolution for the symbol table. * * @param imports * the import declarations */ public void configureImports(final List<ASTImportDeclaration> imports) { for (ASTImportDeclaration i : imports) { if (i.isImportOnDemand()) { types.addImport(i.getImportedName() + ".*"); } else { types.addImport(i.getImportedName()); } } }
if (!importDeclaration.isImportOnDemand()) { String[] nameParts = name.split("\\."); if (importDeclaration.isStatic()) { if (importDeclaration.isImportOnDemand()) { } else if (!importDeclaration.isImportOnDemand()) { String importStr = firstMatch.getImportedName() + (firstMatch.isImportOnDemand() ? ".*" : ""); String type = firstMatch.isStatic() ? "static " : "";
@Override public Object visit(ASTImportDeclaration node, Object data) { ImportWrapper wrapper = new ImportWrapper(node.getImportedName(), node.getImportedName(), node.getImportedNameNode(), node.isStatic() && node.isImportOnDemand()); // blahhhh... this really wants to be ASTImportDeclaration to be // polymorphic... if (node.isImportOnDemand()) { if (importOnDemandImports.contains(wrapper)) { addViolation(data, node.getImportedNameNode(), node.getImportedNameNode().getImage()); } else { importOnDemandImports.add(wrapper); } } else { if (singleTypeImports.contains(wrapper)) { addViolation(data, node.getImportedNameNode(), node.getImportedNameNode().getImage()); } else { singleTypeImports.add(wrapper); } } return data; }
if (((ASTImportDeclaration) node).isImportOnDemand()) { extras.add("on demand");
@Override public Object visit(ASTImportDeclaration node, Object data) { String importPackage = node.getPackageName(); // Check each restricted package for (String pkg : getRestrictedPackages()) { // Is this import restricted? Use the deepest sub-package which // restricts this import. if (isContainingPackage(pkg, importPackage)) { // Is this source in a sub-package of restricted package? if (pkg.equals(thisPackage) || isContainingPackage(pkg, thisPackage)) { // Valid usage break; } else { // On demand imports automatically fail because they include // everything if (node.isImportOnDemand()) { addViolation(data, node, new Object[] { node.getImportedName(), pkg }); break; } else { if (!isAllowedClass(node)) { addViolation(data, node, new Object[] { node.getImportedName(), pkg }); break; } } } } } return data; }
/** * If the outer class wasn't found then we'll get in here */ private void populateImports(ASTCompilationUnit node) { List<ASTImportDeclaration> theImportDeclarations = node.findChildrenOfType(ASTImportDeclaration.class); importedClasses.putAll(JAVA_LANG); // go through the imports for (ASTImportDeclaration anImportDeclaration : theImportDeclarations) { String strPackage = anImportDeclaration.getPackageName(); if (anImportDeclaration.isImportOnDemand()) { importedOnDemand.add(strPackage); } else if (!anImportDeclaration.isImportOnDemand()) { String strName = anImportDeclaration.getImportedName(); importedClasses.put(strName, strName); importedClasses.put(strName.substring(strPackage.length() + 1), strName); } } }
@Override public Object visit(ASTImportDeclaration node, Object data) { if (node.isStatic()) { return data; } String img = node.jjtGetChild(0).getImage(); if (img.startsWith(IMPORT_JAVA_LANG)) { if (!IMPORT_JAVA_LANG.equals(img)) { if (img.indexOf('.', IMPORT_JAVA_LANG.length() + 1) != -1 || node.isImportOnDemand()) { // Importing from a subpackage / inner class return data; } } addViolation(data, node); } return data; } }
String strPackage = anImportDeclaration.getPackageName(); if (anImportDeclaration.isStatic()) { if (anImportDeclaration.isImportOnDemand()) { importOnDemandStaticClasses.add(JavaTypeDefinition.forClass(loadClass(strPackage))); } else { // not import on-demand if (anImportDeclaration.isImportOnDemand()) { importedOnDemand.add(strPackage); } else { // not import on-demand
private boolean isAvoidingConflict(final AbstractJavaTypeNode node, final String name, final ASTImportDeclaration firstMatch) { if (firstMatch.isImportOnDemand() && firstMatch.isStatic()) { final String methodCalled = name.substring(name.indexOf('.') + 1); if (importDeclaration.isImportOnDemand()) { if (firstMatch.isImportOnDemand() && !firstMatch.isStatic()) { for (ASTImportDeclaration importDeclaration : imports) { if (importDeclaration != firstMatch // NOPMD && !importDeclaration.isStatic() && !importDeclaration.isImportOnDemand()) { if (!firstMatch.isImportOnDemand() && !firstMatch.isStatic()) { String fqnName = name.substring(0, name.lastIndexOf('.')); if (!fqnName.equals(importName) && !firstMatch.isStatic() && !firstMatch.isImportOnDemand() && nameParts.length > 1 && nameParts[nameParts.length - 2].equals(importUnqualified)) { return true;
@Override public Object visit(ASTImportDeclaration node, Object data) { if (node.isImportOnDemand()) { ASTName importedType = (ASTName) node.jjtGetChild(0); imports.add(new ImportWrapper(importedType.getImage(), null, node, node.getType(), node.isStatic())); } else { if (!node.isImportOnDemand()) { ASTName importedType = (ASTName) node.jjtGetChild(0); String className; if (isQualifiedName(importedType)) { int lastDot = importedType.getImage().lastIndexOf('.') + 1; className = importedType.getImage().substring(lastDot); } else { className = importedType.getImage(); } imports.add(new ImportWrapper(importedType.getImage(), className, node)); } } return data; }
/** * Configures the type resolution for the symbol table. * * @param imports * the import declarations */ public void configureImports(final List<ASTImportDeclaration> imports) { for (ASTImportDeclaration i : imports) { if (i.isImportOnDemand()) { types.addImport(i.getImportedName() + ".*"); } else { types.addImport(i.getImportedName()); } } }
@Override public Object visit(ASTImportDeclaration node, Object data) { ImportWrapper wrapper = new ImportWrapper(node.getImportedName(), node.getImportedName(), node.getImportedNameNode(), node.isStatic() && node.isImportOnDemand()); // blahhhh... this really wants to be ASTImportDeclaration to be // polymorphic... if (node.isImportOnDemand()) { if (importOnDemandImports.contains(wrapper)) { addViolation(data, node.getImportedNameNode(), node.getImportedNameNode().getImage()); } else { importOnDemandImports.add(wrapper); } } else { if (singleTypeImports.contains(wrapper)) { addViolation(data, node.getImportedNameNode(), node.getImportedNameNode().getImage()); } else { singleTypeImports.add(wrapper); } } return data; }
if (!importDeclaration.isImportOnDemand()) { String[] nameParts = name.split("\\."); if (importDeclaration.isStatic()) { if (importDeclaration.isImportOnDemand()) { } else if (!importDeclaration.isImportOnDemand()) { String importStr = firstMatch.getImportedName() + (firstMatch.isImportOnDemand() ? ".*" : ""); String type = firstMatch.isStatic() ? "static " : "";
if (((ASTImportDeclaration) node).isImportOnDemand()) { extras.add("on demand");
@Override public Object visit(ASTImportDeclaration node, Object data) { String importPackage = node.getPackageName(); // Check each restricted package for (String pkg : getRestrictedPackages()) { // Is this import restricted? Use the deepest sub-package which // restricts this import. if (isContainingPackage(pkg, importPackage)) { // Is this source in a sub-package of restricted package? if (pkg.equals(thisPackage) || isContainingPackage(pkg, thisPackage)) { // Valid usage break; } else { // On demand imports automatically fail because they include // everything if (node.isImportOnDemand()) { addViolation(data, node, new Object[] { node.getImportedName(), pkg }); break; } else { if (!isAllowedClass(node)) { addViolation(data, node, new Object[] { node.getImportedName(), pkg }); break; } } } } } return data; }