protected boolean isImportedInMethodImports(CtExecutableReference<?> ref) { if (this.isAlreadyInUsedImport(ref)) { return true; } if (!(ref.isImplicit()) && methodImports.containsKey(ref.getSimpleName())) { CtExecutableReference<?> exist = methodImports.get(ref.getSimpleName()); return getSignature(exist).equals(getSignature(ref)); } return false; }
protected boolean isImportedInFieldImports(CtFieldReference<?> ref) { if (this.isAlreadyInUsedImport(ref)) { return true; } if (!(ref.isImplicit()) && fieldImports.containsKey(ref.getSimpleName())) { CtFieldReference<?> exist = fieldImports.get(ref.getSimpleName()); try { if (exist.getFieldDeclaration() != null && exist.getFieldDeclaration().equals(ref.getFieldDeclaration())) { return true; } // in some rare cases we could not access to the field, then we do not import it. } catch (SpoonClassNotFoundException notfound) { return false; } } 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); }
protected boolean isImportedInClassImports(CtTypeReference<?> ref) { if (this.isAlreadyInUsedImport(ref)) { return true; } if (targetType != null) { CtPackageReference pack = targetType.getPackage(); // we consider that if a class belongs to java.lang or the same package than the actual class // then it is imported by default if (pack != null && ref.getPackage() != null && !ref.getPackage().isUnnamedPackage()) { // ignore java.lang package if (!"java.lang".equals(ref.getPackage().getSimpleName())) { // ignore type in same package if (ref.getPackage().getSimpleName() .equals(pack.getSimpleName())) { return true; } } } } if (ref.equals(targetType)) { return true; } if (!(ref.isImplicit()) && classImports.containsKey(ref.getSimpleName())) { CtTypeReference<?> exist = classImports.get(ref.getSimpleName()); return exist.getQualifiedName().equals(ref.getQualifiedName()); } return false; }