Lines 53-58
Link Here
|
53 |
private final int staticImportOnDemandThreshold; |
53 |
private final int staticImportOnDemandThreshold; |
54 |
|
54 |
|
55 |
private boolean filterImplicitImports; |
55 |
private boolean filterImplicitImports; |
|
|
56 |
private boolean mainTypeTypesAreImplicitImports; |
56 |
private boolean findAmbiguousImports; |
57 |
private boolean findAmbiguousImports; |
57 |
|
58 |
|
58 |
private int flags= 0; |
59 |
private int flags= 0; |
Lines 68-73
Link Here
|
68 |
this.staticImportOnDemandThreshold= staticThreshold; |
69 |
this.staticImportOnDemandThreshold= staticThreshold; |
69 |
|
70 |
|
70 |
this.filterImplicitImports= true; |
71 |
this.filterImplicitImports= true; |
|
|
72 |
this.mainTypeTypesAreImplicitImports= true; |
71 |
this.findAmbiguousImports= true; //!restoreExistingImports; |
73 |
this.findAmbiguousImports= true; //!restoreExistingImports; |
72 |
|
74 |
|
73 |
this.packageEntries= new ArrayList(20); |
75 |
this.packageEntries= new ArrayList(20); |
Lines 238-255
Link Here
|
238 |
} |
240 |
} |
239 |
|
241 |
|
240 |
/** |
242 |
/** |
241 |
* Sets that implicit imports (types in default package, CU- package and |
243 |
* Specifies that implicit imports (for types in <code>java.lang</code>, types in the same package as the rewrite |
242 |
* 'java.lang') should not be created. Note that this is a heuristic filter and can |
244 |
* compilation unit and types in the compilation unit's main type) should not be created, except if necessary to |
243 |
* lead to missing imports, e.g. in cases where a type is forced to be specified |
245 |
* resolve an on-demand import conflict. |
244 |
* due to a name conflict. |
246 |
* <p> |
245 |
* By default, the filter is enabled. |
247 |
* The filter is enabled by default. |
246 |
* @param filterImplicitImports The filterImplicitImports to set |
248 |
* </p> |
|
|
249 |
* <p> |
250 |
* Note: {@link #setMainTypeTypesAreImplicitImports(boolean)} can be used to stop filtering types in the compilation |
251 |
* unit's main type. |
252 |
* </p> |
253 |
* |
254 |
* @param filterImplicitImports |
255 |
* if <code>true</code>, implicit imports will be filtered |
256 |
* |
257 |
* @see #setMainTypeTypesAreImplicitImports(boolean) |
247 |
*/ |
258 |
*/ |
248 |
public void setFilterImplicitImports(boolean filterImplicitImports) { |
259 |
public void setFilterImplicitImports(boolean filterImplicitImports) { |
249 |
this.filterImplicitImports= filterImplicitImports; |
260 |
this.filterImplicitImports= filterImplicitImports; |
250 |
} |
261 |
} |
251 |
|
262 |
|
252 |
/** |
263 |
/** |
|
|
264 |
* Sets whether types in the compilation unit's main type are considered as implicit imports when |
265 |
* {@link #setFilterImplicitImports(boolean)} is enabled. By default, the option is enabled, i.e. types in the |
266 |
* compilation unit's main type are considered as implicit imports. |
267 |
* |
268 |
* @param mainTypeTypesAreImplicitImports |
269 |
* the mainTypeTypesAreImplicitImports to set |
270 |
* |
271 |
* @see #setFilterImplicitImports(boolean) |
272 |
* @since 3.6 |
273 |
*/ |
274 |
public void setMainTypeTypesAreImplicitImports(boolean mainTypeTypesAreImplicitImports) { |
275 |
this.mainTypeTypesAreImplicitImports= mainTypeTypesAreImplicitImports; |
276 |
} |
277 |
|
278 |
/** |
253 |
* When set searches for imports that can not be folded into on-demand |
279 |
* When set searches for imports that can not be folded into on-demand |
254 |
* imports but must be specified explicitly |
280 |
* imports but must be specified explicitly |
255 |
* @param findAmbiguousImports The new value |
281 |
* @param findAmbiguousImports The new value |
Lines 385-398
Link Here
|
385 |
return bestMatch; |
411 |
return bestMatch; |
386 |
} |
412 |
} |
387 |
|
413 |
|
388 |
private static boolean isImplicitImport(String qualifier, ICompilationUnit cu) { |
414 |
private boolean isImplicitImport(String qualifier) { |
389 |
if (JAVA_LANG.equals(qualifier)) { |
415 |
if (JAVA_LANG.equals(qualifier)) { |
390 |
return true; |
416 |
return true; |
391 |
} |
417 |
} |
|
|
418 |
ICompilationUnit cu= this.compilationUnit; |
392 |
String packageName= cu.getParent().getElementName(); |
419 |
String packageName= cu.getParent().getElementName(); |
393 |
if (qualifier.equals(packageName)) { |
420 |
if (qualifier.equals(packageName)) { |
394 |
return true; |
421 |
return true; |
395 |
} |
422 |
} |
|
|
423 |
|
424 |
if (!this.mainTypeTypesAreImplicitImports) { |
425 |
return false; |
426 |
} |
427 |
|
396 |
String mainTypeName= JavaCore.removeJavaLikeExtension(cu.getElementName()); |
428 |
String mainTypeName= JavaCore.removeJavaLikeExtension(cu.getElementName()); |
397 |
if (packageName.length() == 0) { |
429 |
if (packageName.length() == 0) { |
398 |
return qualifier.equals(mainTypeName); |
430 |
return qualifier.equals(mainTypeName); |
Lines 524-530
Link Here
|
524 |
PackageEntry pack= (PackageEntry) this.packageEntries.get(i); |
556 |
PackageEntry pack= (PackageEntry) this.packageEntries.get(i); |
525 |
int nImports= pack.getNumberOfImports(); |
557 |
int nImports= pack.getNumberOfImports(); |
526 |
|
558 |
|
527 |
if (this.filterImplicitImports && !pack.isStatic() && isImplicitImport(pack.getName(), this.compilationUnit)) { |
559 |
if (this.filterImplicitImports && !pack.isStatic() && isImplicitImport(pack.getName())) { |
528 |
pack.removeAllNew(onDemandConflicts); |
560 |
pack.removeAllNew(onDemandConflicts); |
529 |
nImports= pack.getNumberOfImports(); |
561 |
nImports= pack.getNumberOfImports(); |
530 |
} |
562 |
} |