/** * This method is used to check if the declaring type has been already imported, or if it is local * In both case we do not want to import it, even in FQN mode. * @param declaringType * @return true if it is local or imported */ private boolean declaringTypeIsLocalOrImported(CtTypeReference declaringType) { if (declaringType != null) { boolean isInCollision = isTypeInCollision(declaringType, false); if (!isInCollision) { boolean importSuccess = addClassImport(declaringType); if (importSuccess) { return true; } } boolean importedInClassImports = isImportedInClassImports(declaringType); boolean inJavaLang = classNamePresentInJavaLang(declaringType); if (importedInClassImports || inJavaLang) { return true; } while (declaringType != null) { if (declaringType.equals(targetType)) { return true; } declaringType = declaringType.getDeclaringType(); } } return false; }
@Override public <T> void visitCtTypeReference(CtTypeReference<T> reference) { if (!(reference instanceof CtArrayTypeReference)) { CtTypeReference typeReference; if (reference.getDeclaringType() == null) { typeReference = reference; } else { typeReference = reference.getAccessType(); } if (!typeReference.equals(reference)) { if (this.isAlreadyInUsedImport(reference)) { super.visitCtTypeReference(reference); return; } } if (!this.isTypeInCollision(typeReference, false)) { this.addClassImport(typeReference); } } super.visitCtTypeReference(reference); }