private ASTImportDeclaration findFirstMatch(List<ASTImportDeclaration> imports) { // first search only static imports ASTImportDeclaration result = null; for (ASTImportDeclaration importDeclaration : imports) { if (importDeclaration.isStatic()) { result = importDeclaration; break; } } // then search all non-static, if needed if (result == null) { for (ASTImportDeclaration importDeclaration : imports) { if (!importDeclaration.isStatic()) { result = importDeclaration; break; } } } return result; }
@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; } }
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 (!Objects.equals(importDeclaration, firstMatch) && importDeclaration.isStatic()) { if (declarationMatches(firstMatch, importDeclaration.getImportedName())) { 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;
if (anImportDeclaration.isStatic()) { if (anImportDeclaration.isImportOnDemand()) { importOnDemandStaticClasses.add(JavaTypeDefinition.forClass(loadClass(strPackage)));
@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; }
extras.add("on demand"); if (((ASTImportDeclaration) node).isStatic()) { extras.add("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; }
private ASTImportDeclaration findFirstMatch(List<ASTImportDeclaration> imports) { // first search only static imports ASTImportDeclaration result = null; for (ASTImportDeclaration importDeclaration : imports) { if (importDeclaration.isStatic()) { result = importDeclaration; break; } } // then search all non-static, if needed if (result == null) { for (ASTImportDeclaration importDeclaration : imports) { if (!importDeclaration.isStatic()) { result = importDeclaration; break; } } } return result; }
@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; } }
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 (!Objects.equals(importDeclaration, firstMatch) && importDeclaration.isStatic()) { if (declarationMatches(firstMatch, importDeclaration.getImportedName())) { 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;
if (anImportDeclaration.isStatic()) { if (anImportDeclaration.isImportOnDemand()) { importOnDemandStaticClasses.add(JavaTypeDefinition.forClass(loadClass(strPackage)));
@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; }
extras.add("on demand"); if (((ASTImportDeclaration) node).isStatic()) { extras.add("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; }