コード例 #1
0
 /**
  * Gets the full class name.
  *
  * @param string the string
  * @return the full class name
  */
 private String getFullClassName(String string) {
   List<ImportDeclaration> importDeclarations = cu.getImports();
   for (ImportDeclaration importDeclaration : importDeclarations) {
     if (importDeclaration.isAsterisk()) {
       String collectionPackage = importDeclaration.getName().toString();
       if (collectionPackage.equals("java.util")) {
         if (collectionLibraries.contains(string)) {
           return collectionPackage + "." + string;
         }
       }
     }
     if (importDeclaration.getName().getName().equals(string)) {
       return importDeclaration.getName().toString();
     }
   }
   String classFullName = "";
   if (cu.getPackage() != null) {
     classFullName += cu.getPackage().getName().toString() + ".";
   }
   classFullName += string;
   return classFullName;
 }
コード例 #2
0
 /**
  * Checks if is instance of collection.
  *
  * @param variableName the variable name
  * @return true, if is instance of collection
  */
 private boolean isInstanceOfCollection(NameExpr variableName) {
   boolean isCollection = false;
   String variableType = getVariableType(variableName.getName());
   if (variableType == null) {
     return isCollection;
   }
   boolean isFoundPackage = false;
   for (ImportDeclaration declaration : cu.getImports()) {
     if (!declaration.isStatic()) {
       NameExpr expr = declaration.getName();
       if (!expr.getName().equals(variableType)) {
         continue;
       }
       isFoundPackage = true;
       StringBuffer sb = new StringBuffer(expr.getName());
       expr = ((QualifiedNameExpr) expr).getQualifier();
       do {
         if (expr == null) {
           break;
         }
         sb.insert(0, expr.getName() + ".");
         if (expr instanceof QualifiedNameExpr) {
           expr = ((QualifiedNameExpr) expr).getQualifier();
         } else {
           break;
         }
       } while (expr != null);
       isCollection = isInstanceOfCollection(sb.toString());
     }
   }
   if (!isFoundPackage) {
     PackageDeclaration declaration = cu.getPackage();
     if (declaration != null) {}
     isCollection = isInstanceOfCollection(variableType);
   }
   return isCollection;
 }