View | Details | Raw Unified | Return to bug 143684 | Differences between
and this patch

Collapse All | Expand All

(-)model/org/eclipse/jdt/internal/core/CompilationUnit.java (-2 / +1 lines)
Lines 372-379 Link Here
372
 * @since 3.0
372
 * @since 3.0
373
 */
373
 */
374
public IImportDeclaration createImport(String importName, IJavaElement sibling, int flags, IProgressMonitor monitor) throws JavaModelException {
374
public IImportDeclaration createImport(String importName, IJavaElement sibling, int flags, IProgressMonitor monitor) throws JavaModelException {
375
	// TODO (jerome) - consult flags to create static imports
375
	CreateImportOperation op = new CreateImportOperation(importName, this, flags);
376
	CreateImportOperation op = new CreateImportOperation(importName, this);
377
	if (sibling != null) {
376
	if (sibling != null) {
378
		op.createBefore(sibling);
377
		op.createBefore(sibling);
379
	}
378
	}
(-)model/org/eclipse/jdt/internal/core/CreateImportOperation.java (-4 / +18 lines)
Lines 13-18 Link Here
13
import java.util.Iterator;
13
import java.util.Iterator;
14
14
15
import org.eclipse.core.runtime.IStatus;
15
import org.eclipse.core.runtime.IStatus;
16
import org.eclipse.jdt.core.Flags;
16
import org.eclipse.jdt.core.ICompilationUnit;
17
import org.eclipse.jdt.core.ICompilationUnit;
17
import org.eclipse.jdt.core.IImportDeclaration;
18
import org.eclipse.jdt.core.IImportDeclaration;
18
import org.eclipse.jdt.core.IJavaElement;
19
import org.eclipse.jdt.core.IJavaElement;
Lines 56-61 Link Here
56
	 * The name of the import to be created.
57
	 * The name of the import to be created.
57
	 */
58
	 */
58
	protected String importName;
59
	protected String importName;
60
	protected int flags;
61
59
/**
62
/**
60
 * When executed, this operation will add an import to the given compilation unit.
63
 * When executed, this operation will add an import to the given compilation unit.
61
 */
64
 */
Lines 63-78 Link Here
63
	super(parentElement);
66
	super(parentElement);
64
	this.importName = importName;
67
	this.importName = importName;
65
}
68
}
69
public CreateImportOperation(String importName, ICompilationUnit parentElement, int flags) {
70
	super(parentElement);
71
	this.importName = importName;
72
	this.flags = flags;
73
}
66
protected StructuralPropertyDescriptor getChildPropertyDescriptor(ASTNode parent) {
74
protected StructuralPropertyDescriptor getChildPropertyDescriptor(ASTNode parent) {
67
	return CompilationUnit.IMPORTS_PROPERTY;
75
	return CompilationUnit.IMPORTS_PROPERTY;
68
}
76
}
69
protected ASTNode generateElementAST(ASTRewrite rewriter, IDocument document, ICompilationUnit cu) throws JavaModelException {
77
protected ASTNode generateElementAST(ASTRewrite rewriter, IDocument document, ICompilationUnit cu) throws JavaModelException {
70
	// ensure no duplicate
78
	// ensure no duplicate
71
	Iterator imports = this.cuAST.imports().iterator();
79
	Iterator imports = this.cuAST.imports().iterator();
80
	boolean onDemand = this.importName.endsWith(".*"); //$NON-NLS-1$
81
	String importActualName = this.importName;
82
	if (onDemand) {
83
		importActualName = this.importName.substring(0, this.importName.length() - 2);
84
	}
72
	while (imports.hasNext()) {
85
	while (imports.hasNext()) {
73
		ImportDeclaration importDeclaration = (ImportDeclaration) imports.next();
86
		ImportDeclaration importDeclaration = (ImportDeclaration) imports.next();
74
		if (this.importName.equals(importDeclaration.getName().getFullyQualifiedName())) {
87
		if (importActualName.equals(importDeclaration.getName().getFullyQualifiedName())
75
			//no new import was generated
88
				&& (onDemand == importDeclaration.isOnDemand())
89
				&& (Flags.isStatic(this.flags) == importDeclaration.isStatic())) {
76
			this.creationOccurred = false;
90
			this.creationOccurred = false;
77
			return null;
91
			return null;
78
		}
92
		}
Lines 80-88 Link Here
80
	
94
	
81
	AST ast = this.cuAST.getAST();
95
	AST ast = this.cuAST.getAST();
82
	ImportDeclaration importDeclaration = ast.newImportDeclaration();
96
	ImportDeclaration importDeclaration = ast.newImportDeclaration();
97
	importDeclaration.setStatic(Flags.isStatic(this.flags));
83
	// split import name into individual fragments, checking for on demand imports
98
	// split import name into individual fragments, checking for on demand imports
84
	boolean onDemand = this.importName.endsWith("*"); //$NON-NLS-1$
99
	char[][] charFragments = CharOperation.splitOn('.', importActualName.toCharArray(), 0, importActualName.length());
85
	char[][] charFragments = CharOperation.splitOn('.', this.importName.toCharArray(), 0, onDemand ? this.importName.length()-2 : this.importName.length());
86
	int length = charFragments.length;
100
	int length = charFragments.length;
87
	String[] strFragments = new String[length];
101
	String[] strFragments = new String[length];
88
	for (int i = 0; i < length; i++) {
102
	for (int i = 0; i < length; i++) {

Return to bug 143684