@Override public boolean visit(final ImportDeclaration node) { final String qName = node.getName().getFullyQualifiedName(); final String imprt = node.toString().trim(); if (!node.isStatic()) { if (imprt.endsWith(".*;") && qName.matches(pattern)) wildcardImports.add(qName); } else { if (imprt.endsWith(".*;") && qName.matches(pattern)) wildcardMethodImports.add(qName); } return false; }
@Override public boolean visit(final ImportDeclaration node) { final String qName = node.getName().getFullyQualifiedName(); final String imprt = node.toString().trim(); if (!node.isStatic()) { if (!imprt.endsWith(".*;") && qName.matches(pattern)) fqImports.add(qName); } else { if (!imprt.endsWith(".*;") && qName.matches(pattern)) { final String name = qName.substring(qName.lastIndexOf('.') + 1); if (Character.isLowerCase(name.charAt(0))) fqMethodImports.add(qName); } } return false; }
private void processImport(ImportDeclaration node) { String name = node.getName().toString(); if (node.isOnDemand()) { state.getWildcardImports().add(name); String[] resolvedNames = this.wildcardImportResolver.resolve(name); for (String resolvedName : resolvedNames) { processImport(resolvedName, ResolutionStatus.RESOLVED, compilationUnit.getLineNumber(node.getName().getStartPosition()), compilationUnit.getColumnNumber(node.getName().getStartPosition()), node.getName().getLength(), node.toString().trim()); } /* * Also, register the wildcard itself so that we can have rules that match against wildcard imports, event if we do not know what classes * may be contained in that wildcard */ processImport(name + ".*", ResolutionStatus.RESOLVED, compilationUnit.getLineNumber(node.getName().getStartPosition()), compilationUnit.getColumnNumber(node.getName().getStartPosition()), node.getName().getLength(), node.toString().trim()); } else { String clzName = StringUtils.substringAfterLast(name, "."); state.getClassNameLookedUp().add(clzName); state.getClassNameToFQCN().put(clzName, name); ResolutionStatus status = node.resolveBinding() != null ? ResolutionStatus.RESOLVED : ResolutionStatus.RECOVERED; processImport(name, status, compilationUnit.getLineNumber(node.getName().getStartPosition()), compilationUnit.getColumnNumber(node.getName().getStartPosition()), node.getName().getLength(), node.toString().trim()); } }