Lines 537-543
Link Here
|
537 |
int numberOfImports = numberOfStatements + 1; |
537 |
int numberOfImports = numberOfStatements + 1; |
538 |
for (int i = 0; i < numberOfStatements; i++) { |
538 |
for (int i = 0; i < numberOfStatements; i++) { |
539 |
ImportReference importReference = referenceContext.imports[i]; |
539 |
ImportReference importReference = referenceContext.imports[i]; |
540 |
if (((importReference.bits & ASTNode.OnDemand) != 0) && CharOperation.equals(JAVA_LANG, importReference.tokens) && !importReference.isStatic()) { |
540 |
if (((importReference.bits & ASTNode.OnDemand) != 0) && CharOperation.equals(JAVA_LANG, importReference.tokens)) { |
541 |
numberOfImports--; |
541 |
numberOfImports--; |
542 |
break; |
542 |
break; |
543 |
} |
543 |
} |
Lines 553-559
Link Here
|
553 |
// skip duplicates or imports of the current package |
553 |
// skip duplicates or imports of the current package |
554 |
for (int j = 0; j < index; j++) { |
554 |
for (int j = 0; j < index; j++) { |
555 |
ImportBinding resolved = resolvedImports[j]; |
555 |
ImportBinding resolved = resolvedImports[j]; |
556 |
if (resolved.onDemand == ((importReference.bits & ASTNode.OnDemand) != 0) && resolved.isStatic() == importReference.isStatic()) |
556 |
if (resolved.onDemand == ((importReference.bits & ASTNode.OnDemand) != 0)) |
557 |
if (CharOperation.equals(compoundName, resolvedImports[j].compoundName)) |
557 |
if (CharOperation.equals(compoundName, resolvedImports[j].compoundName)) |
558 |
continue nextImport; |
558 |
continue nextImport; |
559 |
} |
559 |
} |
Lines 563-569
Link Here
|
563 |
continue nextImport; |
563 |
continue nextImport; |
564 |
|
564 |
|
565 |
Binding importBinding = findImport(compoundName, compoundName.length); |
565 |
Binding importBinding = findImport(compoundName, compoundName.length); |
566 |
if (!importBinding.isValidBinding() || (importReference.isStatic() && importBinding instanceof PackageBinding)) |
566 |
if (!importBinding.isValidBinding()) |
567 |
continue nextImport; // we report all problems in faultInImports() |
567 |
continue nextImport; // we report all problems in faultInImports() |
568 |
resolvedImports[index++] = new ImportBinding(compoundName, true, importBinding, importReference); |
568 |
resolvedImports[index++] = new ImportBinding(compoundName, true, importBinding, importReference); |
569 |
} else { |
569 |
} else { |
Lines 722-728
Link Here
|
722 |
int numberOfImports = numberOfStatements + defaultImports.length; |
722 |
int numberOfImports = numberOfStatements + defaultImports.length; |
723 |
for (int i = 0; i < numberOfStatements; i++) { |
723 |
for (int i = 0; i < numberOfStatements; i++) { |
724 |
ImportReference importReference = referenceContext.imports[i]; |
724 |
ImportReference importReference = referenceContext.imports[i]; |
725 |
if (((importReference.bits & ASTNode.OnDemand) != 0) && CharOperation.equals(JAVA_LANG, importReference.tokens) && !importReference.isStatic()) { |
725 |
if (((importReference.bits & ASTNode.OnDemand) != 0) && CharOperation.equals(JAVA_LANG, importReference.tokens)) { |
726 |
numberOfImports--; |
726 |
numberOfImports--; |
727 |
break; |
727 |
break; |
728 |
} |
728 |
} |
Lines 741-747
Link Here
|
741 |
// skip duplicates or imports of the current package |
741 |
// skip duplicates or imports of the current package |
742 |
for (int j = 0; j < index; j++) { |
742 |
for (int j = 0; j < index; j++) { |
743 |
ImportBinding resolved = resolvedImports[j]; |
743 |
ImportBinding resolved = resolvedImports[j]; |
744 |
if (resolved.onDemand == ((importReference.bits & ASTNode.OnDemand) != 0) && resolved.isStatic() == importReference.isStatic()) { |
744 |
if (resolved.onDemand == ((importReference.bits & ASTNode.OnDemand) != 0)) { |
745 |
if (CharOperation.equals(compoundName, resolved.compoundName)) { |
745 |
if (CharOperation.equals(compoundName, resolved.compoundName)) { |
746 |
problemReporter().unusedImport(importReference); // since skipped, must be reported now |
746 |
problemReporter().unusedImport(importReference); // since skipped, must be reported now |
747 |
continue nextImport; |
747 |
continue nextImport; |
Lines 759-771
Link Here
|
759 |
problemReporter().importProblem(importReference, importBinding); |
759 |
problemReporter().importProblem(importReference, importBinding); |
760 |
continue nextImport; |
760 |
continue nextImport; |
761 |
} |
761 |
} |
762 |
if (importReference.isStatic() && importBinding instanceof PackageBinding) { |
|
|
763 |
problemReporter().cannotImportPackage(importReference); |
764 |
continue nextImport; |
765 |
} |
766 |
resolvedImports[index++] = new ImportBinding(compoundName, true, importBinding, importReference); |
762 |
resolvedImports[index++] = new ImportBinding(compoundName, true, importBinding, importReference); |
767 |
} else { |
763 |
} else { |
768 |
Binding importBinding = findSingleImport(compoundName, importReference.isStatic()); |
764 |
Binding importBinding = findSingleImport(compoundName); |
769 |
if (!importBinding.isValidBinding()) { |
765 |
if (!importBinding.isValidBinding()) { |
770 |
problemReporter().importProblem(importReference, importBinding); |
766 |
problemReporter().importProblem(importReference, importBinding); |
771 |
continue nextImport; |
767 |
continue nextImport; |
Lines 802-819
Link Here
|
802 |
continue nextImport; |
798 |
continue nextImport; |
803 |
} |
799 |
} |
804 |
typesBySimpleNames.put(compoundName[compoundName.length - 1], referenceBinding); |
800 |
typesBySimpleNames.put(compoundName[compoundName.length - 1], referenceBinding); |
805 |
} else if (importBinding instanceof FieldBinding) { |
801 |
} |
806 |
for (int j = 0; j < index; j++) { |
|
|
807 |
ImportBinding resolved = resolvedImports[j]; |
808 |
// find other static fields with the same name |
809 |
if (resolved.isStatic() && resolved.resolvedImport instanceof FieldBinding && importBinding != resolved.resolvedImport) { |
810 |
if (CharOperation.equals(compoundName[compoundName.length - 1], resolved.compoundName[resolved.compoundName.length - 1])) { |
811 |
problemReporter().duplicateImport(importReference); |
812 |
continue nextImport; |
813 |
} |
814 |
} |
815 |
} |
816 |
} |
817 |
resolvedImports[index++] = conflictingType == null |
802 |
resolvedImports[index++] = conflictingType == null |
818 |
? new ImportBinding(compoundName, false, importBinding, importReference) |
803 |
? new ImportBinding(compoundName, false, importBinding, importReference) |
819 |
: new ImportConflictBinding(compoundName, importBinding, conflictingType, importReference); |
804 |
: new ImportConflictBinding(compoundName, importBinding, conflictingType, importReference); |
Lines 842-852
Link Here
|
842 |
} |
827 |
} |
843 |
|
828 |
|
844 |
//this API is for code assist purpose |
829 |
//this API is for code assist purpose |
845 |
public Binding findImport(char[][] compoundName, boolean findStaticImports, boolean onDemand) { |
830 |
public Binding findImport(char[][] compoundName, boolean onDemand) { |
846 |
if(onDemand) { |
831 |
if(onDemand) { |
847 |
return findImport(compoundName, compoundName.length); |
832 |
return findImport(compoundName, compoundName.length); |
848 |
} else { |
833 |
} else { |
849 |
return findSingleImport(compoundName, findStaticImports); |
834 |
return findSingleImport(compoundName); |
850 |
} |
835 |
} |
851 |
} |
836 |
} |
852 |
|
837 |
|
Lines 901-907
Link Here
|
901 |
return new ProblemReferenceBinding(compoundName, type, ProblemReasons.NotVisible); |
886 |
return new ProblemReferenceBinding(compoundName, type, ProblemReasons.NotVisible); |
902 |
return type; |
887 |
return type; |
903 |
} |
888 |
} |
904 |
private Binding findSingleImport(char[][] compoundName, boolean findStaticImports) { |
889 |
private Binding findSingleImport(char[][] compoundName) { |
905 |
if (compoundName.length == 1) { |
890 |
if (compoundName.length == 1) { |
906 |
// findType records the reference |
891 |
// findType records the reference |
907 |
// the name cannot be a package |
892 |
// the name cannot be a package |
Lines 913-954
Link Here
|
913 |
return typeBinding; |
898 |
return typeBinding; |
914 |
} |
899 |
} |
915 |
|
900 |
|
916 |
if (findStaticImports) |
|
|
917 |
return findSingleStaticImport(compoundName); |
918 |
return findImport(compoundName, compoundName.length); |
901 |
return findImport(compoundName, compoundName.length); |
919 |
} |
902 |
} |
920 |
private Binding findSingleStaticImport(char[][] compoundName) { |
903 |
|
921 |
Binding binding = findImport(compoundName, compoundName.length - 1); |
|
|
922 |
if (!binding.isValidBinding()) return binding; |
923 |
|
924 |
char[] name = compoundName[compoundName.length - 1]; |
925 |
if (binding instanceof PackageBinding) { |
926 |
Binding temp = ((PackageBinding) binding).getTypeOrPackage(name, Binding.TYPE | Binding.PACKAGE); |
927 |
if (temp != null && temp instanceof ReferenceBinding) // must resolve to a member type or field, not a top level type |
928 |
return new ProblemReferenceBinding(compoundName, (ReferenceBinding) temp, ProblemReasons.InvalidTypeForStaticImport); |
929 |
return binding; // cannot be a package, error is caught in sender |
930 |
} |
931 |
|
932 |
// look to see if its a static field first |
933 |
ReferenceBinding type = (ReferenceBinding) binding; |
934 |
FieldBinding field = findField(type, name, null, true); |
935 |
if (field != null && field.isValidBinding() && field.isStatic() && field.canBeSeenBy(type, null, this)) |
936 |
return field; |
937 |
|
938 |
// look to see if there is a static method with the same selector |
939 |
MethodBinding method = findStaticMethod(type, name); |
940 |
if (method != null) return method; |
941 |
|
942 |
type = findMemberType(name, type); |
943 |
if (type == null || !type.isStatic()) { |
944 |
if (field != null && !field.isValidBinding() && field.problemId() != ProblemReasons.NotFound) |
945 |
return field; |
946 |
return new ProblemReferenceBinding(compoundName, type, ProblemReasons.NotFound); |
947 |
} |
948 |
if (!type.canBeSeenBy(environment.defaultPackage)) |
949 |
return new ProblemReferenceBinding(compoundName, type, ProblemReasons.NotVisible); |
950 |
return type; |
951 |
} |
952 |
MethodBinding findStaticMethod(ReferenceBinding currentType, char[] selector) { |
904 |
MethodBinding findStaticMethod(ReferenceBinding currentType, char[] selector) { |
953 |
if (!currentType.canBeSeenBy(this)) |
905 |
if (!currentType.canBeSeenBy(this)) |
954 |
return null; |
906 |
return null; |
Lines 1026-1035
Link Here
|
1026 |
return defaultImports ; |
978 |
return defaultImports ; |
1027 |
} |
979 |
} |
1028 |
// NOT Public API |
980 |
// NOT Public API |
1029 |
public final Binding getImport(char[][] compoundName, boolean onDemand, boolean isStaticImport) { |
981 |
public final Binding getImport(char[][] compoundName, boolean onDemand) { |
1030 |
if (onDemand) |
982 |
if (onDemand) |
1031 |
return findImport(compoundName, compoundName.length); |
983 |
return findImport(compoundName, compoundName.length); |
1032 |
return findSingleImport(compoundName, isStaticImport); |
984 |
return findSingleImport(compoundName); |
1033 |
} |
985 |
} |
1034 |
|
986 |
|
1035 |
public int nextCaptureID() { |
987 |
public int nextCaptureID() { |
Lines 1151-1157
Link Here
|
1151 |
} |
1103 |
} |
1152 |
Binding resolveSingleImport(ImportBinding importBinding) { |
1104 |
Binding resolveSingleImport(ImportBinding importBinding) { |
1153 |
if (importBinding.resolvedImport == null) { |
1105 |
if (importBinding.resolvedImport == null) { |
1154 |
importBinding.resolvedImport = findSingleImport(importBinding.compoundName, importBinding.isStatic()); |
1106 |
importBinding.resolvedImport = findSingleImport(importBinding.compoundName); |
1155 |
if (!importBinding.resolvedImport.isValidBinding() || importBinding.resolvedImport instanceof PackageBinding) { |
1107 |
if (!importBinding.resolvedImport.isValidBinding() || importBinding.resolvedImport instanceof PackageBinding) { |
1156 |
if (this.imports != null) { |
1108 |
if (this.imports != null) { |
1157 |
ImportBinding[] newImports = new ImportBinding[imports.length - 1]; |
1109 |
ImportBinding[] newImports = new ImportBinding[imports.length - 1]; |