String importActualName = this.importName;
if (onDemand) {
importActualName = this.importName.substring(0, this.importName.length() - 2);
}
while (imports.hasNext()) {
ImportDeclaration importDeclaration = (ImportDeclaration) imports.next();
if (importActualName.equals(importDeclaration.getName().getFullyQualifiedName())
&& (onDemand == importDeclaration.isOnDemand())
&& (Flags.isStatic(this.flags) == importDeclaration.isStatic())) {
this.creationOccurred = false;
return null;
}
}
AST ast = this.cuAST.getAST();
ImportDeclaration importDeclaration = ast.newImportDeclaration();
importDeclaration.setStatic(Flags.isStatic(this.flags));
// split import name into individual fragments, checking for on demand imports
char[][] charFragments = CharOperation.splitOn('.', importActualName.toCharArray(), 0, importActualName.length());
int length = charFragments.length;
String[] strFragments = new String[length];
for (int i = 0; i < length; i++) {
strFragments[i] = String.valueOf(charFragments[i]);
}
Name name = ast.newName(strFragments);
importDeclaration.setName(name);
if (onDemand) importDeclaration.setOnDemand(true);
return importDeclaration;
}