View | Details | Raw Unified | Return to bug 262428
Collapse All | Expand All

(-)src/org/eclipse/wst/jsdt/core/tests/compiler/parser/TestSourceElementRequestor.java (-1 / +1 lines)
Lines 31-37 Link Here
31
/**
31
/**
32
 * acceptImport method comment.
32
 * acceptImport method comment.
33
 */
33
 */
34
public void acceptImport(int declarationStart, int declarationEnd, char[][] tokens, boolean onDemand, int modifiers) {}
34
public void acceptImport(int declarationStart, int declarationEnd, char[][] tokens, boolean onDemand) {}
35
/**
35
/**
36
 * acceptLineSeparatorPositions method comment.
36
 * acceptLineSeparatorPositions method comment.
37
 */
37
 */
(-)src/org/eclipse/wst/jsdt/core/tests/compiler/parser/SourceElementParserTest.java (-3 / +2 lines)
Lines 83-93 Link Here
83
	int declarationStart, 
83
	int declarationStart, 
84
	int declarationEnd, 
84
	int declarationEnd, 
85
	char[][] tokens, 
85
	char[][] tokens, 
86
	boolean onDemand,
86
	boolean onDemand) {
87
	int modifiers) {
88
87
89
	addImport(
88
	addImport(
90
		new SourceImport(declarationStart, declarationEnd, CharOperation.concatWith(tokens, '.'), onDemand, modifiers, source)); 
89
		new SourceImport(declarationStart, declarationEnd, CharOperation.concatWith(tokens, '.'), onDemand, source)); 
91
}
90
}
92
/**
91
/**
93
 * acceptLineSeparatorPositions method comment.
92
 * acceptLineSeparatorPositions method comment.
(-)src/org/eclipse/wst/jsdt/core/tests/compiler/parser/SourceImport.java (-3 lines)
Lines 15-21 Link Here
15
	int declarationSourceEnd;
15
	int declarationSourceEnd;
16
	char[] name;
16
	char[] name;
17
	boolean onDemand;
17
	boolean onDemand;
18
	int modifiers;
19
	char[] source;
18
	char[] source;
20
/**
19
/**
21
 * @param declarationSourceStart int
20
 * @param declarationSourceStart int
Lines 28-41 Link Here
28
	int declarationSourceEnd, 
27
	int declarationSourceEnd, 
29
	char[] name, 
28
	char[] name, 
30
	boolean onDemand,
29
	boolean onDemand,
31
	int modifiers,
32
	char[] source) {
30
	char[] source) {
33
31
34
	this.declarationSourceStart = declarationSourceStart;
32
	this.declarationSourceStart = declarationSourceStart;
35
	this.declarationSourceEnd = declarationSourceEnd; 
33
	this.declarationSourceEnd = declarationSourceEnd; 
36
	this.name = name;
34
	this.name = name;
37
	this.onDemand = onDemand;
35
	this.onDemand = onDemand;
38
	this.modifiers = modifiers;
39
	this.source = source;
36
	this.source = source;
40
}
37
}
41
/**
38
/**
(-)src/org/eclipse/wst/jsdt/core/tests/compiler/regression/BasicResolveTests.java (+91 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.wst.jsdt.core.tests.compiler.regression;
11
package org.eclipse.wst.jsdt.core.tests.compiler.regression;
12
12
13
import java.util.HashMap;
14
import java.util.Map;
15
13
16
14
public class BasicResolveTests extends AbstractRegressionTest {
17
public class BasicResolveTests extends AbstractRegressionTest {
15
18
Lines 1064-1069 Link Here
1064
				""
1067
				""
1065
		);
1068
		);
1066
	}
1069
	}
1070
	
1071
	/*public void testbug259187()	{	 
1067
1072
1073
		this.runNegativeTest(
1074
				new String[] {
1075
						"X.js",
1076
						"var params = \"some?string\".split('?');\n" +
1077
				        "var base = params.shift();"
1078
				},
1079
				"----------\n" + 
1080
		"1. WARNING in X.js (at line 1)\n" + 
1081
		"	var params = \"some?string\".split(\'?\');\n" + 
1082
		"	             ^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
1083
		"Wrong number of arguments for the function split (), expecting 2 argument(s), but there was 1 \n" + 
1084
		"----------\n"
1085
		);
1086
	}
1087
	
1088
	public void testbug259023()	{	 
1089
		Map custom = new HashMap();
1090
		custom.put("org.eclipse.wst.jsdt.core.compiler.problem.unusedLocal", "error");
1091
		
1092
		this.runNegativeTest(
1093
				new String[] {
1094
						"X.js",
1095
						"var myObject = {\n" +
1096
							"val1: \"test1\",\n" +
1097
							"val2: \"test2\"\n" +
1098
						"};\n" +
1099
						"myObject.val1 = \"test3\";"
1100
				},
1101
				"", null, true, custom
1102
		);
1103
	}
1104
	
1105
	public void testbug259023_2()	{	 
1106
		Map custom = new HashMap();
1107
		custom.put("org.eclipse.wst.jsdt.core.compiler.problem.unusedLocal", "error");
1108
		
1109
		this.runNegativeTest(
1110
				new String[] {
1111
						"X.js",
1112
						"var myObject = \"test3\";\n" +
1113
						"if(myObject == \"test3\") {}"
1114
				},
1115
				"", null, true, custom
1116
		);
1117
	}
1118
	
1119
	public void testbug251374()	{	
1120
		Map custom = new HashMap();
1121
		custom.put("org.eclipse.wst.jsdt.core.compiler.problem.nullReference", "error");
1122
		
1123
		this.runNegativeTest(
1124
				new String[] {
1125
						"X.js",
1126
						"var a = null;\n" +
1127
						"function foo() { a.toString();}\n" +
1128
						"a = 1; foo();"
1129
				},
1130
				"", null, true, custom
1131
		);
1132
	}
1133
	
1134
	public void testChris()	{	 
1135
		Map custom = new HashMap();
1136
		custom.put("org.eclipse.wst.jsdt.core.compiler.problem.unusedLocal", "error");
1137
		this.runNegativeTest(
1138
				new String[] {
1139
						"X.js",
1140
						"var square = function(x) {return x*x;};" +
1141
						"square(2);",
1142
				},
1143
				"", null, true, custom
1144
		);
1145
	}
1146
1147
	public void testChris2()	{	 
1148
		Map custom = new HashMap();
1149
		custom.put("org.eclipse.wst.jsdt.core.compiler.problem.unusedLocal", "error");
1150
		this.runNegativeTest(
1151
				new String[] {
1152
						"X.js",
1153
						"var square = \"chris\";" +
1154
						"square.split(\".\", 1);",
1155
				},
1156
				"", null, true, custom
1157
		);
1158
	}*/
1068
1159
1069
}
1160
}
(-)src/org/eclipse/wst/jsdt/internal/compiler/lookup/ImportBinding.java (-3 / +1 lines)
Lines 33-41 Link Here
33
public final int kind() {
33
public final int kind() {
34
	return IMPORT;
34
	return IMPORT;
35
}
35
}
36
public boolean isStatic() {
36
37
	return this.reference != null && this.reference.isStatic();
38
}
39
public char[] readableName() {
37
public char[] readableName() {
40
	if (onDemand)
38
	if (onDemand)
41
		return CharOperation.concat(CharOperation.concatWith(compoundName, '.'), ".*".toCharArray()); //$NON-NLS-1$
39
		return CharOperation.concat(CharOperation.concatWith(compoundName, '.'), ".*".toCharArray()); //$NON-NLS-1$
(-)src/org/eclipse/wst/jsdt/internal/compiler/lookup/CompilationUnitScope.java (-62 / +14 lines)
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];
(-)src/org/eclipse/wst/jsdt/internal/compiler/lookup/Scope.java (-138 lines)
Lines 1678-1742 Link Here
1678
					problemField = foundField;
1678
					problemField = foundField;
1679
					foundField = null;
1679
					foundField = null;
1680
				}
1680
				}
1681
1682
				if (compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5) {
1683
					// at this point the scope is a compilation unit scope & need to check for imported static fields
1684
					unitScope.faultInImports(); // ensure static imports are resolved
1685
					ImportBinding[] imports = unitScope.imports;
1686
					if (imports != null) {
1687
						// check single static imports
1688
						for (int i = 0, length = imports.length; i < length; i++) {
1689
							ImportBinding importBinding = imports[i];
1690
							if (importBinding.isStatic() && !importBinding.onDemand) {
1691
								if (CharOperation.equals(importBinding.compoundName[importBinding.compoundName.length - 1], name)) {
1692
									if (unitScope.resolveSingleImport(importBinding) != null && importBinding.resolvedImport instanceof FieldBinding) {
1693
										foundField = (FieldBinding) importBinding.resolvedImport;
1694
										ImportReference importReference = importBinding.reference;
1695
										if (importReference != null && needResolve)
1696
											importReference.bits |= ASTNode.Used;
1697
										invocationSite.setActualReceiverType(foundField.declaringClass);
1698
										if (foundField.isValidBinding()) {
1699
											return foundField;
1700
										}
1701
										if (problemField == null)
1702
											problemField = foundField;
1703
									}
1704
								}
1705
							}
1706
						}
1707
						// check on demand imports
1708
						boolean foundInImport = false;
1709
						for (int i = 0, length = imports.length; i < length; i++) {
1710
							ImportBinding importBinding = imports[i];
1711
							if (importBinding.isStatic() && importBinding.onDemand) {
1712
								Binding resolvedImport = importBinding.resolvedImport;
1713
								if (resolvedImport instanceof ReferenceBinding) {
1714
									FieldBinding temp = findField((ReferenceBinding) resolvedImport, name, invocationSite, needResolve);
1715
									if (temp != null) {
1716
										if (!temp.isValidBinding()) {
1717
											if (problemField == null)
1718
												problemField = temp;
1719
										} else if (temp.isStatic()) {
1720
											if (foundField == temp) continue;
1721
											ImportReference importReference = importBinding.reference;
1722
											if (importReference != null && needResolve)
1723
												importReference.bits |= ASTNode.Used;
1724
											if (foundInImport)
1725
												// Answer error binding -- import on demand conflict; name found in two import on demand packages.
1726
												return new ProblemReferenceBinding(name, null, ProblemReasons.Ambiguous);
1727
											foundField = temp;
1728
											foundInImport = true;
1729
										}
1730
									}
1731
								}
1732
							}
1733
						}
1734
						if (foundField != null) {
1735
							invocationSite.setActualReceiverType(foundField.declaringClass);
1736
							return foundField;
1737
						}
1738
					}
1739
				}
1740
			}
1681
			}
1741
1682
1742
			if ( (mask&Binding.METHOD)!=0)
1683
			if ( (mask&Binding.METHOD)!=0)
Lines 2415-2495 Link Here
2415
					return foundProblem; // visible method selectors take precedence
2356
					return foundProblem; // visible method selectors take precedence
2416
				}
2357
				}
2417
			}
2358
			}
2418
2419
			// at this point the scope is a compilation unit scope & need to check for imported static methods
2420
			CompilationUnitScope unitScope = (CompilationUnitScope) scope;
2421
			ImportBinding[] imports = unitScope.imports;
2422
			if (imports != null) {
2423
				ObjectVector visible = null;
2424
				boolean skipOnDemand = false; // set to true when matched static import of method name so stop looking for on demand methods
2425
				for (int i = 0, length = imports.length; i < length; i++) {
2426
					ImportBinding importBinding = imports[i];
2427
					if (importBinding.isStatic()) {
2428
						Binding resolvedImport = importBinding.resolvedImport;
2429
						MethodBinding possible = null;
2430
						if (importBinding.onDemand) {
2431
							if (!skipOnDemand && resolvedImport instanceof ReferenceBinding)
2432
								// answers closest approximation, may not check argumentTypes or visibility
2433
								possible = findMethod((ReferenceBinding) resolvedImport, selector, argumentTypes, invocationSite);
2434
						} else {
2435
							if (resolvedImport instanceof MethodBinding) {
2436
								MethodBinding staticMethod = (MethodBinding) resolvedImport;
2437
								if (CharOperation.equals(staticMethod.selector, selector))
2438
									// answers closest approximation, may not check argumentTypes or visibility
2439
									possible = findMethod(staticMethod.declaringClass, selector, argumentTypes, invocationSite);
2440
							} else if (resolvedImport instanceof FieldBinding) {
2441
								// check to see if there are also methods with the same name
2442
								FieldBinding staticField = (FieldBinding) resolvedImport;
2443
								if (CharOperation.equals(staticField.name, selector)) {
2444
									// must find the importRef's type again since the field can be from an inherited type
2445
									char[][] importName = importBinding.reference.tokens;
2446
									TypeBinding referencedType = getType(importName, importName.length - 1);
2447
									if (referencedType != null)
2448
										// answers closest approximation, may not check argumentTypes or visibility
2449
										possible = findMethod((ReferenceBinding) referencedType, selector, argumentTypes, invocationSite);
2450
								}
2451
							}
2452
						}
2453
						if (possible != null && possible != foundProblem) {
2454
							if (!possible.isValidBinding()) {
2455
								if (foundProblem == null)
2456
									foundProblem = possible; // answer as error case match
2457
							} else if (possible.isStatic()) {
2458
								MethodBinding compatibleMethod = computeCompatibleMethod(possible, argumentTypes, invocationSite);
2459
								if (compatibleMethod != null) {
2460
									if (compatibleMethod.isValidBinding()) {
2461
										if (compatibleMethod.canBeSeenBy(unitScope.getDefaultPackage())) {
2462
											if (visible == null || !visible.contains(compatibleMethod)) {
2463
												ImportReference importReference = importBinding.reference;
2464
												if (importReference != null)
2465
													importReference.bits |= ASTNode.Used;
2466
												if (!skipOnDemand && !importBinding.onDemand) {
2467
													visible = null; // forget previous matches from on demand imports
2468
													skipOnDemand = true;
2469
												}
2470
												if (visible == null)
2471
													visible = new ObjectVector(3);
2472
												visible.add(compatibleMethod);
2473
											}
2474
										} else if (foundProblem == null) {
2475
											foundProblem = new ProblemMethodBinding(compatibleMethod, selector, compatibleMethod.parameters, ProblemReasons.NotVisible);
2476
										}
2477
									} else if (foundProblem == null) {
2478
										foundProblem = compatibleMethod;
2479
									}
2480
								} else if (foundProblem == null) {
2481
									foundProblem = new ProblemMethodBinding(possible, selector, argumentTypes, ProblemReasons.NotFound);
2482
								}
2483
							}
2484
						}
2485
					}
2486
				}
2487
				if (visible != null) {
2488
					MethodBinding[] temp = new MethodBinding[visible.size];
2489
					visible.copyInto(temp);
2490
					foundMethod = mostSpecificMethodBinding(temp, temp.length, argumentTypes, invocationSite, null);
2491
				}
2492
			}
2493
		}
2359
		}
2494
2360
2495
		if (foundMethod != null) {
2361
		if (foundMethod != null) {
Lines 3009-3018 Link Here
3009
						Binding temp = null;
2875
						Binding temp = null;
3010
						if (resolvedImport instanceof PackageBinding) {
2876
						if (resolvedImport instanceof PackageBinding) {
3011
							temp = findBinding(name, mask, (PackageBinding) resolvedImport, currentPackage, false);
2877
							temp = findBinding(name, mask, (PackageBinding) resolvedImport, currentPackage, false);
3012
						} else if (someImport.isStatic()) {
3013
							temp = findMemberType(name, (ReferenceBinding) resolvedImport); // static imports are allowed to see inherited member types
3014
//							if (temp != null && !temp.isStatic())
3015
//								temp = null;
3016
						} else {
2878
						} else {
3017
							temp = findDirectMemberType(name, (ReferenceBinding) resolvedImport);
2879
							temp = findDirectMemberType(name, (ReferenceBinding) resolvedImport);
3018
						}
2880
						}
(-)src/org/eclipse/wst/jsdt/core/dom/DefaultBindingResolver.java (-40 / +19 lines)
Lines 687-737 Link Here
687
			org.eclipse.wst.jsdt.internal.compiler.ast.ASTNode node = (org.eclipse.wst.jsdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(importDeclaration);
687
			org.eclipse.wst.jsdt.internal.compiler.ast.ASTNode node = (org.eclipse.wst.jsdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(importDeclaration);
688
			if (node instanceof ImportReference) {
688
			if (node instanceof ImportReference) {
689
				ImportReference importReference = (ImportReference) node;
689
				ImportReference importReference = (ImportReference) node;
690
				final boolean isStatic = importReference.isStatic();
691
				if ((importReference.bits & org.eclipse.wst.jsdt.internal.compiler.ast.ASTNode.OnDemand) != 0) {
690
				if ((importReference.bits & org.eclipse.wst.jsdt.internal.compiler.ast.ASTNode.OnDemand) != 0) {
692
					Binding binding = this.scope.getImport(CharOperation.subarray(importReference.tokens, 0, importReference.tokens.length), true, isStatic);
691
					Binding binding = this.scope.getImport(CharOperation.subarray(importReference.tokens, 0, importReference.tokens.length), true);
693
					if (binding != null) {
692
					if (binding != null) {
694
						if (isStatic) {
693
						if ((binding.kind() & Binding.PACKAGE) != 0) {
695
							if (binding instanceof org.eclipse.wst.jsdt.internal.compiler.lookup.TypeBinding) {
694
							IPackageBinding packageBinding = this.getPackageBinding((org.eclipse.wst.jsdt.internal.compiler.lookup.PackageBinding) binding);
696
								ITypeBinding typeBinding = this.getTypeBinding((org.eclipse.wst.jsdt.internal.compiler.lookup.TypeBinding) binding);
695
							if (packageBinding == null) {
697
								return typeBinding == null ? null : typeBinding;
696
								return null;
698
							}
697
							}
698
							return packageBinding;
699
						} else {
699
						} else {
700
							if ((binding.kind() & Binding.PACKAGE) != 0) {
700
							// if it is not a package, it has to be a type
701
								IPackageBinding packageBinding = this.getPackageBinding((org.eclipse.wst.jsdt.internal.compiler.lookup.PackageBinding) binding);
701
							ITypeBinding typeBinding = this.getTypeBinding((org.eclipse.wst.jsdt.internal.compiler.lookup.TypeBinding) binding);
702
								if (packageBinding == null) {
702
							if (typeBinding == null) {
703
									return null;
703
								return null;
704
								}
705
								return packageBinding;
706
							} else {
707
								// if it is not a package, it has to be a type
708
								ITypeBinding typeBinding = this.getTypeBinding((org.eclipse.wst.jsdt.internal.compiler.lookup.TypeBinding) binding);
709
								if (typeBinding == null) {
710
									return null;
711
								}
712
								return typeBinding;
713
							}
704
							}
705
							return typeBinding;
714
						}
706
						}
715
					}
707
					}
716
				} else {
708
				} else {
717
					Binding binding = this.scope.getImport(importReference.tokens, false, isStatic);
709
					Binding binding = this.scope.getImport(importReference.tokens, false);
718
					if (binding != null) {
710
					if (binding != null) {
719
						if (isStatic) {
711
						if (binding instanceof org.eclipse.wst.jsdt.internal.compiler.lookup.TypeBinding) {
720
							if (binding instanceof org.eclipse.wst.jsdt.internal.compiler.lookup.TypeBinding) {
712
							ITypeBinding typeBinding = this.getTypeBinding((org.eclipse.wst.jsdt.internal.compiler.lookup.TypeBinding) binding);
721
								ITypeBinding typeBinding = this.getTypeBinding((org.eclipse.wst.jsdt.internal.compiler.lookup.TypeBinding) binding);
713
							return typeBinding == null ? null : typeBinding;
722
								return typeBinding == null ? null : typeBinding;
723
							} else if (binding instanceof FieldBinding) {
724
								IVariableBinding variableBinding = this.getVariableBinding((FieldBinding) binding);
725
								return variableBinding == null ? null : variableBinding;
726
							} else if (binding instanceof org.eclipse.wst.jsdt.internal.compiler.lookup.MethodBinding) {
727
								// it is a type
728
								return this.getMethodBinding((org.eclipse.wst.jsdt.internal.compiler.lookup.MethodBinding)binding);
729
							}
730
						} else {
731
							if (binding instanceof org.eclipse.wst.jsdt.internal.compiler.lookup.TypeBinding) {
732
								ITypeBinding typeBinding = this.getTypeBinding((org.eclipse.wst.jsdt.internal.compiler.lookup.TypeBinding) binding);
733
								return typeBinding == null ? null : typeBinding;
734
							}
735
						}
714
						}
736
					}
715
					}
737
				}
716
				}
Lines 908-920 Link Here
908
				if (this.scope == null) return null;
887
				if (this.scope == null) return null;
909
				if (importReferenceLength == index) {
888
				if (importReferenceLength == index) {
910
					try {
889
					try {
911
						binding = this.scope.getImport(CharOperation.subarray(importReference.tokens, 0, index), (importReference.bits & org.eclipse.wst.jsdt.internal.compiler.ast.ASTNode.OnDemand) != 0, importReference.isStatic());
890
						binding = this.scope.getImport(CharOperation.subarray(importReference.tokens, 0, index), (importReference.bits & org.eclipse.wst.jsdt.internal.compiler.ast.ASTNode.OnDemand) != 0);
912
					} catch (AbortCompilation e) {
891
					} catch (AbortCompilation e) {
913
						// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=53357
892
						// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=53357
914
					}
893
					}
915
				} else {
894
				} else {
916
					try {
895
					try {
917
						binding = this.scope.getImport(CharOperation.subarray(importReference.tokens, 0, index), true, importReference.isStatic());
896
						binding = this.scope.getImport(CharOperation.subarray(importReference.tokens, 0, index), true);
918
					} catch (AbortCompilation e) {
897
					} catch (AbortCompilation e) {
919
						// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=53357
898
						// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=53357
920
					}
899
					}
Lines 1116-1128 Link Here
1116
				if (this.scope == null) return null;
1095
				if (this.scope == null) return null;
1117
				if (importReferenceLength == index) {
1096
				if (importReferenceLength == index) {
1118
					try {
1097
					try {
1119
						binding = this.scope.getImport(CharOperation.subarray(importReference.tokens, 0, index), (importReference.bits & org.eclipse.wst.jsdt.internal.compiler.ast.ASTNode.OnDemand) != 0, importReference.isStatic());
1098
						binding = this.scope.getImport(CharOperation.subarray(importReference.tokens, 0, index), (importReference.bits & org.eclipse.wst.jsdt.internal.compiler.ast.ASTNode.OnDemand) != 0);
1120
					} catch (AbortCompilation e) {
1099
					} catch (AbortCompilation e) {
1121
						// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=53357
1100
						// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=53357
1122
					}
1101
					}
1123
				} else {
1102
				} else {
1124
					try {
1103
					try {
1125
						binding = this.scope.getImport(CharOperation.subarray(importReference.tokens, 0, index), true, importReference.isStatic());
1104
						binding = this.scope.getImport(CharOperation.subarray(importReference.tokens, 0, index), true);
1126
					} catch (AbortCompilation e) {
1105
					} catch (AbortCompilation e) {
1127
						// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=53357
1106
						// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=53357
1128
					}
1107
					}
(-)src/org/eclipse/wst/jsdt/core/dom/BindingComparator.java (-2 / +1 lines)
Lines 97-104 Link Here
97
			}
97
			}
98
			ImportBinding importBinding = (ImportBinding) declaringElement;
98
			ImportBinding importBinding = (ImportBinding) declaringElement;
99
			ImportBinding importBinding2 = (ImportBinding) declaringElement2;
99
			ImportBinding importBinding2 = (ImportBinding) declaringElement2;
100
			return importBinding.isStatic() == importBinding2.isStatic()
100
			return importBinding.onDemand == importBinding2.onDemand
101
				&& importBinding.onDemand == importBinding2.onDemand
102
				&& CharOperation.equals(importBinding.compoundName, importBinding2.compoundName);
101
				&& CharOperation.equals(importBinding.compoundName, importBinding2.compoundName);
103
		}
102
		}
104
		return false;
103
		return false;
(-)src/org/eclipse/wst/jsdt/core/dom/ASTConverter.java (-26 / +2 lines)
Lines 2740-2759 Link Here
2740
		importDeclaration.setSourceRange(importReference.declarationSourceStart, importReference.declarationEnd - importReference.declarationSourceStart + 1);
2740
		importDeclaration.setSourceRange(importReference.declarationSourceStart, importReference.declarationEnd - importReference.declarationSourceStart + 1);
2741
		importDeclaration.setOnDemand(onDemand && !isFile);
2741
		importDeclaration.setOnDemand(onDemand && !isFile);
2742
		importDeclaration.setIsFileImport(isFile);
2742
		importDeclaration.setIsFileImport(isFile);
2743
		int modifiers = importReference.modifiers;
2743
		
2744
		if (modifiers != ClassFileConstants.AccDefault) {
2745
			switch(this.ast.apiLevel) {
2746
				case AST.JLS2_INTERNAL :
2747
					importDeclaration.setFlags(importDeclaration.getFlags() | ASTNode.MALFORMED);
2748
					break;
2749
				case AST.JLS3 :
2750
					if (modifiers == ClassFileConstants.AccStatic) {
2751
						importDeclaration.setStatic(true);
2752
					} else {
2753
						importDeclaration.setFlags(importDeclaration.getFlags() | ASTNode.MALFORMED);
2754
					}
2755
			}
2756
		}
2757
		if (this.resolveBindings) {
2744
		if (this.resolveBindings) {
2758
			recordNodes(importDeclaration, importReference);
2745
			recordNodes(importDeclaration, importReference);
2759
		}
2746
		}
Lines 2781-2798 Link Here
2781
			}
2768
			}
2782
		}
2769
		}
2783
		packageDeclaration.setSourceRange(importReference.declarationSourceStart, importReference.declarationEnd - importReference.declarationSourceStart + 1);
2770
		packageDeclaration.setSourceRange(importReference.declarationSourceStart, importReference.declarationEnd - importReference.declarationSourceStart + 1);
2784
		org.eclipse.wst.jsdt.internal.compiler.ast.Annotation[] annotations = importReference.annotations;
2771
		
2785
		if (annotations != null) {
2786
			switch(this.ast.apiLevel) {
2787
				case AST.JLS2_INTERNAL :
2788
					packageDeclaration.setFlags(packageDeclaration.getFlags() & ASTNode.MALFORMED);
2789
					break;
2790
				case AST.JLS3 :
2791
					for (int i = 0, max = annotations.length; i < max; i++) {
2792
						packageDeclaration.annotations().add(convert(annotations[i]));
2793
					}
2794
			}
2795
		}
2796
		if (this.resolveBindings) {
2772
		if (this.resolveBindings) {
2797
			recordNodes(packageDeclaration, importReference);
2773
			recordNodes(packageDeclaration, importReference);
2798
		}
2774
		}
(-)src/org/eclipse/wst/jsdt/internal/core/search/indexing/SourceIndexerRequestor.java (-1 / +1 lines)
Lines 58-64 Link Here
58
/**
58
/**
59
 * @see ISourceElementRequestor#acceptImport(int, int, char[][], boolean, int)
59
 * @see ISourceElementRequestor#acceptImport(int, int, char[][], boolean, int)
60
 */
60
 */
61
public void acceptImport(int declarationStart, int declarationEnd, char[][] tokens, boolean onDemand, int modifiers) {
61
public void acceptImport(int declarationStart, int declarationEnd, char[][] tokens, boolean onDemand) {
62
	// imports have already been reported while creating the ImportRef node (see SourceElementParser#comsume*ImportDeclarationName() methods)
62
	// imports have already been reported while creating the ImportRef node (see SourceElementParser#comsume*ImportDeclarationName() methods)
63
}
63
}
64
/**
64
/**
(-)src/org/eclipse/wst/jsdt/internal/core/search/indexing/IndexingParser.java (-1 / +1 lines)
Lines 25-31 Link Here
25
public class IndexingParser extends SourceElementParser {
25
public class IndexingParser extends SourceElementParser {
26
	SingleNameReference singleNameReference = new SingleNameReference(CharOperation.NO_CHAR, 0);
26
	SingleNameReference singleNameReference = new SingleNameReference(CharOperation.NO_CHAR, 0);
27
	QualifiedNameReference qualifiedNameReference = new QualifiedNameReference(CharOperation.NO_CHAR_CHAR, new long[0], 0, 0);
27
	QualifiedNameReference qualifiedNameReference = new QualifiedNameReference(CharOperation.NO_CHAR_CHAR, new long[0], 0, 0);
28
	ImportReference importReference = new ImportReference(CharOperation.NO_CHAR_CHAR, new long[1], false, 0);
28
	ImportReference importReference = new ImportReference(CharOperation.NO_CHAR_CHAR, new long[1], false);
29
29
30
	public IndexingParser(ISourceElementRequestor requestor, IProblemFactory problemFactory, CompilerOptions options, boolean reportLocalDeclarations, boolean optimizeStringLiterals, boolean useSourceJavadocParser) {
30
	public IndexingParser(ISourceElementRequestor requestor, IProblemFactory problemFactory, CompilerOptions options, boolean reportLocalDeclarations, boolean optimizeStringLiterals, boolean useSourceJavadocParser) {
31
		super(requestor, problemFactory, options, reportLocalDeclarations,
31
		super(requestor, problemFactory, options, reportLocalDeclarations,
(-)src/org/eclipse/wst/jsdt/internal/codeassist/complete/CompletionParser.java (-10 / +2 lines)
Lines 2802-2811 Link Here
2802
	super.consumeSingleMemberAnnotation();
2802
	super.consumeSingleMemberAnnotation();
2803
	}
2803
	}
2804
}
2804
}
2805
protected void consumeSingleStaticImportDeclarationName() {
2806
	super.consumeSingleStaticImportDeclarationName();
2807
	this.pendingAnnotation = null; // the pending annotation cannot be attached to next nodes
2808
}
2809
protected void consumeSingleTypeImportDeclarationName() {
2805
protected void consumeSingleTypeImportDeclarationName() {
2810
	super.consumeSingleTypeImportDeclarationName();
2806
	super.consumeSingleTypeImportDeclarationName();
2811
	this.pendingAnnotation = null; // the pending annotation cannot be attached to next nodes
2807
	this.pendingAnnotation = null; // the pending annotation cannot be attached to next nodes
Lines 2832-2841 Link Here
2832
		popElement(K_BLOCK_DELIMITER);
2828
		popElement(K_BLOCK_DELIMITER);
2833
	}
2829
	}
2834
}
2830
}
2835
protected void consumeStaticImportOnDemandDeclarationName() {
2836
	super.consumeStaticImportOnDemandDeclarationName();
2837
	this.pendingAnnotation = null; // the pending annotation cannot be attached to next nodes
2838
}
2839
protected void consumeStaticInitializer() {
2831
protected void consumeStaticInitializer() {
2840
	super.consumeStaticInitializer();
2832
	super.consumeStaticInitializer();
2841
	this.pendingAnnotation = null; // the pending annotation cannot be attached to next nodes
2833
	this.pendingAnnotation = null; // the pending annotation cannot be attached to next nodes
Lines 3550-3557 Link Here
3550
	}
3542
	}
3551
}
3543
}
3552
3544
3553
public ImportReference createAssistImportReference(char[][] tokens, long[] positions, int mod){
3545
public ImportReference createAssistImportReference(char[][] tokens, long[] positions){
3554
	return new CompletionOnImportReference(tokens, positions, mod);
3546
	return new CompletionOnImportReference(tokens, positions);
3555
}
3547
}
3556
public ImportReference createAssistPackageReference(char[][] tokens, long[] positions){
3548
public ImportReference createAssistPackageReference(char[][] tokens, long[] positions){
3557
	return new CompletionOnPackageReference(tokens, positions);
3549
	return new CompletionOnPackageReference(tokens, positions);
(-)src/org/eclipse/wst/jsdt/internal/codeassist/complete/CompletionOnImportReference.java (-2 / +2 lines)
Lines 36-43 Link Here
36
36
37
public class CompletionOnImportReference extends ImportReference {
37
public class CompletionOnImportReference extends ImportReference {
38
38
39
public CompletionOnImportReference(char[][] tokens , long[] positions, int modifiers) {
39
public CompletionOnImportReference(char[][] tokens , long[] positions) {
40
	super(tokens, positions, false, modifiers);
40
	super(tokens, positions, false);
41
}
41
}
42
public StringBuffer print(int indent, StringBuffer output, boolean withOnDemand) {
42
public StringBuffer print(int indent, StringBuffer output, boolean withOnDemand) {
43
43
(-)src/org/eclipse/wst/jsdt/internal/codeassist/complete/CompletionOnKeyword2.java (-2 / +1 lines)
Lines 11-23 Link Here
11
package org.eclipse.wst.jsdt.internal.codeassist.complete;
11
package org.eclipse.wst.jsdt.internal.codeassist.complete;
12
12
13
import org.eclipse.wst.jsdt.internal.compiler.ast.ImportReference;
13
import org.eclipse.wst.jsdt.internal.compiler.ast.ImportReference;
14
import org.eclipse.wst.jsdt.internal.compiler.classfmt.ClassFileConstants;
15
14
16
public class CompletionOnKeyword2 extends ImportReference implements CompletionOnKeyword {
15
public class CompletionOnKeyword2 extends ImportReference implements CompletionOnKeyword {
17
	private char[] token;
16
	private char[] token;
18
	private char[][] possibleKeywords;
17
	private char[][] possibleKeywords;
19
	public CompletionOnKeyword2(char[] token, long pos, char[][] possibleKeywords) {
18
	public CompletionOnKeyword2(char[] token, long pos, char[][] possibleKeywords) {
20
		super(new char[][]{token}, new long[]{pos}, false, ClassFileConstants.AccDefault);
19
		super(new char[][]{token}, new long[]{pos}, false);
21
		this.token = token;
20
		this.token = token;
22
		this.possibleKeywords = possibleKeywords;
21
		this.possibleKeywords = possibleKeywords;
23
	}
22
	}
(-)src/org/eclipse/wst/jsdt/internal/codeassist/complete/CompletionOnPackageReference.java (-2 / +1 lines)
Lines 33-43 Link Here
33
 */
33
 */
34
34
35
import org.eclipse.wst.jsdt.internal.compiler.ast.ImportReference;
35
import org.eclipse.wst.jsdt.internal.compiler.ast.ImportReference;
36
import org.eclipse.wst.jsdt.internal.compiler.classfmt.ClassFileConstants;
37
36
38
public class CompletionOnPackageReference extends ImportReference {
37
public class CompletionOnPackageReference extends ImportReference {
39
public CompletionOnPackageReference(char[][] tokens , long[] positions) {
38
public CompletionOnPackageReference(char[][] tokens , long[] positions) {
40
	super(tokens, positions, true, ClassFileConstants.AccDefault);
39
	super(tokens, positions, true);
41
}
40
}
42
public StringBuffer print(int indent, StringBuffer output, boolean withOnDemand) {
41
public StringBuffer print(int indent, StringBuffer output, boolean withOnDemand) {
43
42
(-)src/org/eclipse/wst/jsdt/internal/formatter/CodeFormatterVisitor.java (-5 lines)
Lines 635-644 Link Here
635
		this.scribe.printNextToken(TerminalTokens.TokenNameimport);
635
		this.scribe.printNextToken(TerminalTokens.TokenNameimport);
636
		this.preferences.number_of_empty_lines_to_preserve = this.preferences.blank_lines_between_import_groups;
636
		this.preferences.number_of_empty_lines_to_preserve = this.preferences.blank_lines_between_import_groups;
637
		this.scribe.space();
637
		this.scribe.space();
638
		if (importRef.isStatic()) {
639
			this.scribe.printNextToken(TerminalTokens.TokenNamestatic);
640
			this.scribe.space();
641
		}
642
		if ((importRef.bits & ASTNode.OnDemand) != 0) {
638
		if ((importRef.bits & ASTNode.OnDemand) != 0) {
643
			this.scribe.printQualifiedReference(importRef.sourceEnd);
639
			this.scribe.printQualifiedReference(importRef.sourceEnd);
644
			this.scribe.printNextToken(TerminalTokens.TokenNameDOT);
640
			this.scribe.printNextToken(TerminalTokens.TokenNameDOT);
Lines 3140-3146 Link Here
3140
				this.scribe.printEmptyLines(blankLinesBeforePackage);
3136
				this.scribe.printEmptyLines(blankLinesBeforePackage);
3141
			}
3137
			}
3142
3138
3143
			this.scribe.printModifiers(compilationUnitDeclaration.currentPackage.annotations, this);
3144
			this.scribe.space();
3139
			this.scribe.space();
3145
			// dump the package keyword
3140
			// dump the package keyword
3146
			this.scribe.printNextToken(TerminalTokens.TokenNamepackage);
3141
			this.scribe.printNextToken(TerminalTokens.TokenNamepackage);
(-)src/org/eclipse/wst/jsdt/internal/core/search/matching/TypeReferenceLocator.java (-39 / +1 lines)
Lines 46-52 Link Here
46
import org.eclipse.wst.jsdt.internal.compiler.lookup.ClassScope;
46
import org.eclipse.wst.jsdt.internal.compiler.lookup.ClassScope;
47
import org.eclipse.wst.jsdt.internal.compiler.lookup.FieldBinding;
47
import org.eclipse.wst.jsdt.internal.compiler.lookup.FieldBinding;
48
import org.eclipse.wst.jsdt.internal.compiler.lookup.LocalTypeBinding;
48
import org.eclipse.wst.jsdt.internal.compiler.lookup.LocalTypeBinding;
49
import org.eclipse.wst.jsdt.internal.compiler.lookup.MemberTypeBinding;
50
import org.eclipse.wst.jsdt.internal.compiler.lookup.MethodBinding;
49
import org.eclipse.wst.jsdt.internal.compiler.lookup.MethodBinding;
51
import org.eclipse.wst.jsdt.internal.compiler.lookup.ParameterizedTypeBinding;
50
import org.eclipse.wst.jsdt.internal.compiler.lookup.ParameterizedTypeBinding;
52
import org.eclipse.wst.jsdt.internal.compiler.lookup.ProblemBinding;
51
import org.eclipse.wst.jsdt.internal.compiler.lookup.ProblemBinding;
Lines 184-225 Link Here
184
	}
183
	}
185
	return IMPOSSIBLE_MATCH;
184
	return IMPOSSIBLE_MATCH;
186
}
185
}
187
/* (non-Javadoc)
186
188
 * @see org.eclipse.wst.jsdt.internal.core.search.matching.PatternLocator#matchLevelAndReportImportRef(org.eclipse.wst.jsdt.internal.compiler.ast.ImportReference, org.eclipse.wst.jsdt.internal.compiler.lookup.Binding, org.eclipse.wst.jsdt.internal.core.search.matching.MatchLocator)
189
 */
190
protected void matchLevelAndReportImportRef(ImportReference importRef, Binding binding, MatchLocator locator) throws CoreException {
191
	Binding refBinding = binding;
192
	if (importRef.isStatic()) {
193
		// for static import, binding can be a field binding or a member type binding
194
		// verify that in this case binding is static and use declaring class for fields
195
		if (binding instanceof FieldBinding) {
196
			FieldBinding fieldBinding = (FieldBinding) binding;
197
			if (!fieldBinding.isStatic()) return;
198
			refBinding = fieldBinding.declaringClass;
199
		} else if (binding instanceof MethodBinding) {
200
			MethodBinding methodBinding = (MethodBinding) binding;
201
			if (!methodBinding.isStatic()) return;
202
			refBinding = methodBinding.declaringClass;
203
		} else if (binding instanceof MemberTypeBinding) {
204
			MemberTypeBinding memberBinding = (MemberTypeBinding) binding;
205
			if (!memberBinding.isStatic()) return;
206
		}
207
		// resolve and report
208
		int level = resolveLevel(refBinding);
209
		if (level >= INACCURATE_MATCH) {
210
			matchReportImportRef(
211
				importRef,
212
				binding,
213
				locator.createImportHandle(importRef),
214
				level == ACCURATE_MATCH
215
					? SearchMatch.A_ACCURATE
216
					: SearchMatch.A_INACCURATE,
217
				locator);
218
		}
219
		return;
220
	}
221
	super.matchLevelAndReportImportRef(importRef, refBinding, locator);
222
}
223
protected void matchReportImportRef(ImportReference importRef, Binding binding, IJavaScriptElement element, int accuracy, MatchLocator locator) throws CoreException {
187
protected void matchReportImportRef(ImportReference importRef, Binding binding, IJavaScriptElement element, int accuracy, MatchLocator locator) throws CoreException {
224
	if (this.isDeclarationOfReferencedTypesPattern) {
188
	if (this.isDeclarationOfReferencedTypesPattern) {
225
		if ((element = findElement(element, accuracy)) != null) {
189
		if ((element = findElement(element, accuracy)) != null) {
Lines 255-264 Link Here
255
		typeBinding = (ReferenceBinding) binding;
219
		typeBinding = (ReferenceBinding) binding;
256
	} else if (binding instanceof FieldBinding) { // may happen for static import
220
	} else if (binding instanceof FieldBinding) { // may happen for static import
257
		typeBinding = ((FieldBinding)binding).declaringClass;
221
		typeBinding = ((FieldBinding)binding).declaringClass;
258
		lastButOne = importRef.isStatic() && ((importRef.bits & ASTNode.OnDemand) == 0);
259
	} else if (binding instanceof MethodBinding) { // may happen for static import
222
	} else if (binding instanceof MethodBinding) { // may happen for static import
260
		typeBinding = ((MethodBinding)binding).declaringClass;
223
		typeBinding = ((MethodBinding)binding).declaringClass;
261
		lastButOne = importRef.isStatic() && ((importRef.bits & ASTNode.OnDemand) == 0);
262
	}
224
	}
263
	if (typeBinding != null) {
225
	if (typeBinding != null) {
264
		int lastIndex = importRef.tokens.length - 1;
226
		int lastIndex = importRef.tokens.length - 1;
(-)src/org/eclipse/wst/jsdt/internal/core/search/matching/MethodLocator.java (-18 lines)
Lines 116-136 Link Here
116
}
116
}
117
public int match(ASTNode node, MatchingNodeSet nodeSet) {
117
public int match(ASTNode node, MatchingNodeSet nodeSet) {
118
	int declarationsLevel = IMPOSSIBLE_MATCH;
118
	int declarationsLevel = IMPOSSIBLE_MATCH;
119
	if (this.pattern.findReferences) {
120
		if (node instanceof ImportReference) {
121
			// With static import, we can have static method reference in import reference
122
			ImportReference importRef = (ImportReference) node;
123
			int length = importRef.tokens.length-1;
124
			if (importRef.isStatic() && ((importRef.bits & ASTNode.OnDemand) == 0) && matchesName(this.pattern.selector, importRef.tokens[length])) {
125
				char[][] compoundName = new char[length][];
126
				System.arraycopy(importRef.tokens, 0, compoundName, 0, length);
127
				char[] declaringType = CharOperation.concat(pattern.declaringQualification, pattern.declaringSimpleName, '.');
128
				if (matchesName(declaringType, CharOperation.concatWith(compoundName, '.'))) {
129
					declarationsLevel = ((InternalSearchPattern)this.pattern).mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH;
130
				}
131
			}
132
		}
133
	}
134
	return nodeSet.addMatch(node, declarationsLevel);
119
	return nodeSet.addMatch(node, declarationsLevel);
135
}
120
}
136
//public int match(ConstructorDeclaration node, MatchingNodeSet nodeSet) - SKIP IT
121
//public int match(ConstructorDeclaration node, MatchingNodeSet nodeSet) - SKIP IT
Lines 227-235 Link Here
227
 * Accept to report match of static field on static import
212
 * Accept to report match of static field on static import
228
 */
213
 */
229
protected void matchLevelAndReportImportRef(ImportReference importRef, Binding binding, MatchLocator locator) throws CoreException {
214
protected void matchLevelAndReportImportRef(ImportReference importRef, Binding binding, MatchLocator locator) throws CoreException {
230
	if (importRef.isStatic() && binding instanceof MethodBinding) {
231
		super.matchLevelAndReportImportRef(importRef, binding, locator);
232
	}
233
}
215
}
234
protected int matchMethod(MethodBinding method, boolean skipImpossibleArg) {
216
protected int matchMethod(MethodBinding method, boolean skipImpossibleArg) {
235
	if (!matchesName(this.pattern.selector, method.selector)) return IMPOSSIBLE_MATCH;
217
	if (!matchesName(this.pattern.selector, method.selector)) return IMPOSSIBLE_MATCH;
(-)src/org/eclipse/wst/jsdt/internal/core/search/matching/PackageReferenceLocator.java (-26 lines)
Lines 27-36 Link Here
27
import org.eclipse.wst.jsdt.internal.compiler.ast.TypeReference;
27
import org.eclipse.wst.jsdt.internal.compiler.ast.TypeReference;
28
import org.eclipse.wst.jsdt.internal.compiler.lookup.ArrayBinding;
28
import org.eclipse.wst.jsdt.internal.compiler.lookup.ArrayBinding;
29
import org.eclipse.wst.jsdt.internal.compiler.lookup.Binding;
29
import org.eclipse.wst.jsdt.internal.compiler.lookup.Binding;
30
import org.eclipse.wst.jsdt.internal.compiler.lookup.FieldBinding;
31
import org.eclipse.wst.jsdt.internal.compiler.lookup.ImportBinding;
30
import org.eclipse.wst.jsdt.internal.compiler.lookup.ImportBinding;
32
import org.eclipse.wst.jsdt.internal.compiler.lookup.MemberTypeBinding;
33
import org.eclipse.wst.jsdt.internal.compiler.lookup.MethodBinding;
34
import org.eclipse.wst.jsdt.internal.compiler.lookup.PackageBinding;
31
import org.eclipse.wst.jsdt.internal.compiler.lookup.PackageBinding;
35
import org.eclipse.wst.jsdt.internal.compiler.lookup.ProblemBinding;
32
import org.eclipse.wst.jsdt.internal.compiler.lookup.ProblemBinding;
36
import org.eclipse.wst.jsdt.internal.compiler.lookup.ProblemFieldBinding;
33
import org.eclipse.wst.jsdt.internal.compiler.lookup.ProblemFieldBinding;
Lines 142-170 Link Here
142
	}
139
	}
143
	return IMPOSSIBLE_MATCH;
140
	return IMPOSSIBLE_MATCH;
144
}
141
}
145
/* (non-Javadoc)
146
 * @see org.eclipse.wst.jsdt.internal.core.search.matching.PatternLocator#matchLevelAndReportImportRef(org.eclipse.wst.jsdt.internal.compiler.ast.ImportReference, org.eclipse.wst.jsdt.internal.compiler.lookup.Binding, org.eclipse.wst.jsdt.internal.core.search.matching.MatchLocator)
147
 */
148
protected void matchLevelAndReportImportRef(ImportReference importRef, Binding binding, MatchLocator locator) throws CoreException {
149
	Binding refBinding = binding;
150
	if (importRef.isStatic()) {
151
		// for static import, binding can be a field binding or a member type binding
152
		// verify that in this case binding is static and use declaring class for fields
153
		if (binding instanceof FieldBinding) {
154
			FieldBinding fieldBinding = (FieldBinding) binding;
155
			if (!fieldBinding.isStatic()) return;
156
			refBinding = fieldBinding.declaringClass;
157
		} else if (binding instanceof MethodBinding) {
158
			MethodBinding methodBinding = (MethodBinding) binding;
159
			if (!methodBinding.isStatic()) return;
160
			refBinding = methodBinding.declaringClass;
161
		} else if (binding instanceof MemberTypeBinding) {
162
			MemberTypeBinding memberBinding = (MemberTypeBinding) binding;
163
			if (!memberBinding.isStatic()) return;
164
		}
165
	}
166
	super.matchLevelAndReportImportRef(importRef, refBinding, locator);
167
}
168
protected void matchReportImportRef(ImportReference importRef, Binding binding, IJavaScriptElement element, int accuracy, MatchLocator locator) throws CoreException {
142
protected void matchReportImportRef(ImportReference importRef, Binding binding, IJavaScriptElement element, int accuracy, MatchLocator locator) throws CoreException {
169
	if (binding == null) {
143
	if (binding == null) {
170
		this.matchReportReference(importRef, element, null/*no binding*/, accuracy, locator);
144
		this.matchReportReference(importRef, element, null/*no binding*/, accuracy, locator);
(-)src/org/eclipse/wst/jsdt/internal/core/search/matching/ImportMatchLocatorParser.java (-8 lines)
Lines 17-30 Link Here
17
protected ImportMatchLocatorParser(ProblemReporter problemReporter, MatchLocator locator) {
17
protected ImportMatchLocatorParser(ProblemReporter problemReporter, MatchLocator locator) {
18
	super(problemReporter, locator);
18
	super(problemReporter, locator);
19
}
19
}
20
protected void consumeStaticImportOnDemandDeclarationName() {
21
	super.consumeStaticImportOnDemandDeclarationName();
22
	this.patternLocator.match(this.astStack[this.astPtr], this.nodeSet);
23
}
24
protected void consumeSingleStaticImportDeclarationName() {
25
	super.consumeSingleStaticImportDeclarationName();
26
	this.patternLocator.match(this.astStack[this.astPtr], this.nodeSet);
27
}
28
protected void consumeSingleTypeImportDeclarationName() {
20
protected void consumeSingleTypeImportDeclarationName() {
29
	super.consumeSingleTypeImportDeclarationName();
21
	super.consumeSingleTypeImportDeclarationName();
30
	this.patternLocator.match(this.astStack[this.astPtr], this.nodeSet);
22
	this.patternLocator.match(this.astStack[this.astPtr], this.nodeSet);
(-)src/org/eclipse/wst/jsdt/internal/core/search/matching/MatchLocator.java (-10 / +2 lines)
Lines 2307-2314 Link Here
2307
2307
2308
				ImportReference importRef = (ImportReference) node;
2308
				ImportReference importRef = (ImportReference) node;
2309
				Binding binding = (importRef.bits & ASTNode.OnDemand) != 0
2309
				Binding binding = (importRef.bits & ASTNode.OnDemand) != 0
2310
					? unitScope.getImport(CharOperation.subarray(importRef.tokens, 0, importRef.tokens.length), true, importRef.isStatic())
2310
					? unitScope.getImport(CharOperation.subarray(importRef.tokens, 0, importRef.tokens.length), true)
2311
					: unitScope.getImport(importRef.tokens, false, importRef.isStatic());
2311
					: unitScope.getImport(importRef.tokens, false);
2312
				this.patternLocator.matchLevelAndReportImportRef(importRef, binding, this);
2312
				this.patternLocator.matchLevelAndReportImportRef(importRef, binding, this);
2313
			}
2313
			}
2314
			nodeSet.addMatch(node, this.patternLocator.resolveLevel(node));
2314
			nodeSet.addMatch(node, this.patternLocator.resolveLevel(node));
Lines 2349-2362 Link Here
2349
	}
2349
	}
2350
2350
2351
	if (matchedUnitContainer) {
2351
	if (matchedUnitContainer) {
2352
		ImportReference pkg = unit.currentPackage;
2353
		if (pkg != null && pkg.annotations != null) {
2354
			IJavaScriptElement element = createPackageDeclarationHandle(unit);
2355
			if (element != null) {
2356
				reportMatching(pkg.annotations, element, null, nodeSet, true, encloses(element));
2357
			}
2358
		}
2359
2360
		ImportReference[] imports = unit.imports;
2352
		ImportReference[] imports = unit.imports;
2361
		if (imports != null) {
2353
		if (imports != null) {
2362
			for (int i = 0, l = imports.length; i < l; i++) {
2354
			for (int i = 0, l = imports.length; i < l; i++) {
(-)src/org/eclipse/wst/jsdt/internal/core/search/matching/FieldLocator.java (-19 lines)
Lines 58-79 Link Here
58
}
58
}
59
public int match(ASTNode node, MatchingNodeSet nodeSet) {
59
public int match(ASTNode node, MatchingNodeSet nodeSet) {
60
	int declarationsLevel = IMPOSSIBLE_MATCH;
60
	int declarationsLevel = IMPOSSIBLE_MATCH;
61
	if (this.pattern.findReferences) {
62
		if (node instanceof ImportReference) {
63
			// With static import, we can have static field reference in import reference
64
			ImportReference importRef = (ImportReference) node;
65
			int length = importRef.tokens.length-1;
66
			if (importRef.isStatic() && ((importRef.bits &ASTNode.OnDemand)==0) && matchesName(this.pattern.name, importRef.tokens[length])) {
67
				char[][] compoundName = new char[length][];
68
				System.arraycopy(importRef.tokens, 0, compoundName, 0, length);
69
				FieldPattern fieldPattern = (FieldPattern) this.pattern;
70
				char[] declaringType = CharOperation.concat(fieldPattern.declaringQualification, fieldPattern.declaringSimpleName, '.');
71
				if (matchesName(declaringType, CharOperation.concatWith(compoundName, '.'))) {
72
					declarationsLevel = ((InternalSearchPattern)this.pattern).mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH;
73
				}
74
			}
75
		}
76
	}
77
	return nodeSet.addMatch(node, declarationsLevel);
61
	return nodeSet.addMatch(node, declarationsLevel);
78
}
62
}
79
//public int match(ConstructorDeclaration node, MatchingNodeSet nodeSet) - SKIP IT
63
//public int match(ConstructorDeclaration node, MatchingNodeSet nodeSet) - SKIP IT
Lines 201-209 Link Here
201
 * Accept to report match of static field on static import
185
 * Accept to report match of static field on static import
202
 */
186
 */
203
protected void matchLevelAndReportImportRef(ImportReference importRef, Binding binding, MatchLocator locator) throws CoreException {
187
protected void matchLevelAndReportImportRef(ImportReference importRef, Binding binding, MatchLocator locator) throws CoreException {
204
	if (importRef.isStatic() && binding instanceof FieldBinding) {
205
		super.matchLevelAndReportImportRef(importRef, binding, locator);
206
	}
207
}
188
}
208
protected int matchReference(Reference node, MatchingNodeSet nodeSet, boolean writeOnlyAccess) {
189
protected int matchReference(Reference node, MatchingNodeSet nodeSet, boolean writeOnlyAccess) {
209
	if (node instanceof FieldReference) {
190
	if (node instanceof FieldReference) {
(-)src/org/eclipse/wst/jsdt/internal/core/search/matching/OrLocator.java (-20 lines)
Lines 29-37 Link Here
29
import org.eclipse.wst.jsdt.internal.compiler.ast.TypeDeclaration;
29
import org.eclipse.wst.jsdt.internal.compiler.ast.TypeDeclaration;
30
import org.eclipse.wst.jsdt.internal.compiler.ast.TypeReference;
30
import org.eclipse.wst.jsdt.internal.compiler.ast.TypeReference;
31
import org.eclipse.wst.jsdt.internal.compiler.lookup.Binding;
31
import org.eclipse.wst.jsdt.internal.compiler.lookup.Binding;
32
import org.eclipse.wst.jsdt.internal.compiler.lookup.FieldBinding;
33
import org.eclipse.wst.jsdt.internal.compiler.lookup.MemberTypeBinding;
34
import org.eclipse.wst.jsdt.internal.compiler.lookup.MethodBinding;
35
32
36
public class OrLocator extends PatternLocator {
33
public class OrLocator extends PatternLocator {
37
34
Lines 206-229 Link Here
206
	return result;
203
	return result;
207
}
204
}
208
protected void matchLevelAndReportImportRef(ImportReference importRef, Binding binding, MatchLocator locator) throws CoreException {
205
protected void matchLevelAndReportImportRef(ImportReference importRef, Binding binding, MatchLocator locator) throws CoreException {
209
210
	// for static import, binding can be a field binding or a member type binding
211
	// verify that in this case binding is static and use declaring class for fields
212
	Binding refBinding = binding;
206
	Binding refBinding = binding;
213
	if (importRef.isStatic()) {
214
		if (binding instanceof FieldBinding) {
215
			FieldBinding fieldBinding = (FieldBinding) binding;
216
			if (!fieldBinding.isStatic()) return;
217
			refBinding = fieldBinding.declaringClass;
218
		} else if (binding instanceof MethodBinding) {
219
			MethodBinding methodBinding = (MethodBinding) binding;
220
			if (!methodBinding.isStatic()) return;
221
			refBinding = methodBinding.declaringClass;
222
		} else if (binding instanceof MemberTypeBinding) {
223
			MemberTypeBinding memberBinding = (MemberTypeBinding) binding;
224
			if (!memberBinding.isStatic()) return;
225
		}
226
	}
227
207
228
	// Look for closest pattern
208
	// Look for closest pattern
229
	PatternLocator closestPattern = null;
209
	PatternLocator closestPattern = null;
(-)src/org/eclipse/wst/jsdt/internal/codeassist/select/SelectionOnImportReference.java (-2 / +2 lines)
Lines 33-40 Link Here
33
33
34
public class SelectionOnImportReference extends ImportReference {
34
public class SelectionOnImportReference extends ImportReference {
35
35
36
public SelectionOnImportReference(char[][] tokens , long[] positions, int modifiers) {
36
public SelectionOnImportReference(char[][] tokens , long[] positions) {
37
	super(tokens, positions, false, modifiers);
37
	super(tokens, positions, false);
38
}
38
}
39
public StringBuffer print(int indent, StringBuffer output, boolean withOnDemand) {
39
public StringBuffer print(int indent, StringBuffer output, boolean withOnDemand) {
40
40
(-)src/org/eclipse/wst/jsdt/internal/codeassist/select/SelectionParser.java (-55 / +3 lines)
Lines 913-970 Link Here
913
	singleMemberAnnotation.declarationSourceEnd = this.rParenPos;
913
	singleMemberAnnotation.declarationSourceEnd = this.rParenPos;
914
	pushOnExpressionStack(singleMemberAnnotation);
914
	pushOnExpressionStack(singleMemberAnnotation);
915
}
915
}
916
protected void consumeStaticImportOnDemandDeclarationName() {
917
	// TypeImportOnDemandDeclarationName ::= 'import' 'static' Name '.' '*'
918
	/* push an ImportRef build from the last name
919
	stored in the identifier stack. */
920
921
	int index;
922
923
	/* no need to take action if not inside assist identifiers */
924
	if ((index = indexOfAssistIdentifier()) < 0) {
925
		super.consumeStaticImportOnDemandDeclarationName();
926
		return;
927
	}
928
	/* retrieve identifiers subset and whole positions, the assist node positions
929
		should include the entire replaced source. */
930
	int length = identifierLengthStack[identifierLengthPtr];
931
	char[][] subset = identifierSubSet(index+1); // include the assistIdentifier
932
	identifierLengthPtr--;
933
	identifierPtr -= length;
934
	long[] positions = new long[length];
935
	System.arraycopy(
936
		identifierPositionStack,
937
		identifierPtr + 1,
938
		positions,
939
		0,
940
		length);
941
942
	/* build specific assist node on import statement */
943
	ImportReference reference = this.createAssistImportReference(subset, positions, ClassFileConstants.AccStatic);
944
	reference.bits |= ASTNode.OnDemand;
945
	assistNode = reference;
946
	this.lastCheckPoint = reference.sourceEnd + 1;
947
948
	pushOnAstStack(reference);
949
950
	if (currentToken == TokenNameSEMICOLON){
951
		reference.declarationSourceEnd = scanner.currentPosition - 1;
952
	} else {
953
		reference.declarationSourceEnd = (int) positions[length-1];
954
	}
955
	//endPosition is just before the ;
956
	reference.declarationSourceStart = intStack[intPtr--];
957
	// flush annotations defined prior to import statements
958
	reference.declarationSourceEnd = this.flushCommentsDefinedPriorTo(reference.declarationSourceEnd);
959
960
	// recovery
961
	if (currentElement != null){
962
		lastCheckPoint = reference.declarationSourceEnd+1;
963
		currentElement = currentElement.add(reference, 0);
964
		lastIgnoredToken = -1;
965
		restartRecovery = true; // used to avoid branching back into the regular automaton
966
	}
967
}
968
protected void consumeToken(int token) {
916
protected void consumeToken(int token) {
969
	super.consumeToken(token);
917
	super.consumeToken(token);
970
918
Lines 1009-1015 Link Here
1009
		length);
957
		length);
1010
958
1011
	/* build specific assist node on import statement */
959
	/* build specific assist node on import statement */
1012
	ImportReference reference = this.createAssistImportReference(subset, positions, ClassFileConstants.AccDefault);
960
	ImportReference reference = this.createAssistImportReference(subset, positions);
1013
	reference.bits |= ASTNode.OnDemand;
961
	reference.bits |= ASTNode.OnDemand;
1014
	assistNode = reference;
962
	assistNode = reference;
1015
	this.lastCheckPoint = reference.sourceEnd + 1;
963
	this.lastCheckPoint = reference.sourceEnd + 1;
Lines 1034-1041 Link Here
1034
		restartRecovery = true; // used to avoid branching back into the regular automaton
982
		restartRecovery = true; // used to avoid branching back into the regular automaton
1035
	}
983
	}
1036
}
984
}
1037
public ImportReference createAssistImportReference(char[][] tokens, long[] positions, int mod){
985
public ImportReference createAssistImportReference(char[][] tokens, long[] positions){
1038
	return new SelectionOnImportReference(tokens, positions, mod);
986
	return new SelectionOnImportReference(tokens, positions);
1039
}
987
}
1040
public ImportReference createAssistPackageReference(char[][] tokens, long[] positions){
988
public ImportReference createAssistPackageReference(char[][] tokens, long[] positions){
1041
	return new SelectionOnPackageReference(tokens, positions);
989
	return new SelectionOnPackageReference(tokens, positions);
(-)src/org/eclipse/wst/jsdt/internal/codeassist/select/SelectionOnPackageReference.java (-2 / +1 lines)
Lines 30-40 Link Here
30
 */
30
 */
31
31
32
import org.eclipse.wst.jsdt.internal.compiler.ast.ImportReference;
32
import org.eclipse.wst.jsdt.internal.compiler.ast.ImportReference;
33
import org.eclipse.wst.jsdt.internal.compiler.classfmt.ClassFileConstants;
34
33
35
public class SelectionOnPackageReference extends ImportReference {
34
public class SelectionOnPackageReference extends ImportReference {
36
public SelectionOnPackageReference(char[][] tokens , long[] positions) {
35
public SelectionOnPackageReference(char[][] tokens , long[] positions) {
37
	super(tokens, positions, true, ClassFileConstants.AccDefault);
36
	super(tokens, positions, true);
38
}
37
}
39
public StringBuffer print(int tab, StringBuffer output, boolean withOnDemand) {
38
public StringBuffer print(int tab, StringBuffer output, boolean withOnDemand) {
40
	printIndent(tab, output).append("<SelectOnPackage:"); //$NON-NLS-1$
39
	printIndent(tab, output).append("<SelectOnPackage:"); //$NON-NLS-1$
(-)src/org/eclipse/wst/jsdt/internal/codeassist/select/SelectionOnLocalName.java (-3 / +2 lines)
Lines 15-21 Link Here
15
15
16
public class SelectionOnLocalName extends LocalDeclaration{
16
public class SelectionOnLocalName extends LocalDeclaration{
17
17
18
	public SelectionOnLocalName(char[] name,	int sourceStart, int sourceEnd) {
18
	public SelectionOnLocalName(char[] name, int sourceStart, int sourceEnd) {
19
19
20
		super(name, sourceStart, sourceEnd);
20
		super(name, sourceStart, sourceEnd);
21
	}
21
	}
Lines 30-37 Link Here
30
		printIndent(indent, output);
30
		printIndent(indent, output);
31
		output.append("<SelectionOnLocalName:"); //$NON-NLS-1$
31
		output.append("<SelectionOnLocalName:"); //$NON-NLS-1$
32
		printModifiers(this.modifiers, output);
32
		printModifiers(this.modifiers, output);
33
//		 type.print(0, output).append(' ').append(this.name);
33
		output.append(this.name);
34
		 output.append(this.name);
35
		if (initialization != null) {
34
		if (initialization != null) {
36
			output.append(" = "); //$NON-NLS-1$
35
			output.append(" = "); //$NON-NLS-1$
37
			initialization.printExpression(0, output);
36
			initialization.printExpression(0, output);
(-)src/org/eclipse/wst/jsdt/internal/compiler/SourceElementRequestorAdapter.java (-3 / +2 lines)
Lines 32-45 Link Here
32
	}
32
	}
33
33
34
	/**
34
	/**
35
	 * @see ISourceElementRequestor#acceptImport(int, int, char[][], boolean, int)
35
	 * @see ISourceElementRequestor#acceptImport(int, int, char[][], boolean)
36
	 */
36
	 */
37
	public void acceptImport(
37
	public void acceptImport(
38
		int declarationStart,
38
		int declarationStart,
39
		int declarationEnd,
39
		int declarationEnd,
40
		char[][] tokens,
40
		char[][] tokens,
41
		boolean onDemand,
41
		boolean onDemand) {
42
		int modifiers) {
43
		// default implementation: do nothing
42
		// default implementation: do nothing
44
	}
43
	}
45
44
(-)src/org/eclipse/wst/jsdt/internal/compiler/DocumentElementParser.java (-34 lines)
Lines 972-994 Link Here
972
	}
972
	}
973
	resetModifiers();
973
	resetModifiers();
974
}
974
}
975
protected void consumeSingleStaticImportDeclarationName() {
976
	// SingleTypeImportDeclarationName ::= 'import' 'static' Name
977
978
	/* persisting javadoc positions */
979
	pushOnIntArrayStack(this.getJavaDocPositions());
980
981
	super.consumeSingleStaticImportDeclarationName();
982
	ImportReference importReference = (ImportReference) astStack[astPtr];
983
	requestor.acceptImport(
984
		importReference.declarationSourceStart,
985
		importReference.declarationSourceEnd,
986
		intArrayStack[intArrayPtr--],
987
		CharOperation.concatWith(importReference.getImportName(), '.'),
988
		importReference.sourceStart,
989
		false,
990
		ClassFileConstants.AccStatic);
991
}
992
/*
975
/*
993
 *
976
 *
994
 * INTERNAL USE-ONLY
977
 * INTERNAL USE-ONLY
Lines 1010-1032 Link Here
1010
		false,
993
		false,
1011
		ClassFileConstants.AccDefault);
994
		ClassFileConstants.AccDefault);
1012
}
995
}
1013
protected void consumeStaticImportOnDemandDeclarationName() {
1014
	// SingleTypeImportDeclarationName ::= 'import' 'static' Name '.' '*'
1015
1016
	/* persisting javadoc positions */
1017
	pushOnIntArrayStack(this.getJavaDocPositions());
1018
1019
	super.consumeStaticImportOnDemandDeclarationName();
1020
	ImportReference importReference = (ImportReference) astStack[astPtr];
1021
	requestor.acceptImport(
1022
		importReference.declarationSourceStart,
1023
		importReference.declarationSourceEnd,
1024
		intArrayStack[intArrayPtr--],
1025
		CharOperation.concatWith(importReference.getImportName(), '.'),
1026
		importReference.sourceStart,
1027
		true,
1028
		ClassFileConstants.AccStatic);
1029
}
1030
/*
996
/*
1031
 *
997
 *
1032
 * INTERNAL USE-ONLY
998
 * INTERNAL USE-ONLY
(-)src/org/eclipse/wst/jsdt/internal/compiler/SourceElementParser.java (-107 / +5 lines)
Lines 679-741 Link Here
679
		requestor.acceptMethodReference(TypeConstants.VALUE, 0, member.sourceStart);
679
		requestor.acceptMethodReference(TypeConstants.VALUE, 0, member.sourceStart);
680
	}
680
	}
681
}
681
}
682
protected void consumeSingleStaticImportDeclarationName() {
683
	// SingleTypeImportDeclarationName ::= 'import' 'static' Name
684
	ImportReference impt;
685
	int length;
686
	char[][] tokens = new char[length = this.identifierLengthStack[this.identifierLengthPtr--]][];
687
	this.identifierPtr -= length;
688
	long[] positions = new long[length];
689
	System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length);
690
	System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length);
691
	pushOnAstStack(impt = newImportReference(tokens, positions, false, ClassFileConstants.AccStatic));
692
693
	this.modifiers = ClassFileConstants.AccDefault;
694
	this.modifiersSourceStart = -1; // <-- see comment into modifiersFlag(int)
695
696
	if (this.currentToken == TokenNameSEMICOLON){
697
		impt.declarationSourceEnd = this.scanner.currentPosition - 1;
698
	} else {
699
		impt.declarationSourceEnd = impt.sourceEnd;
700
	}
701
	impt.declarationEnd = impt.declarationSourceEnd;
702
	//this.endPosition is just before the ;
703
	impt.declarationSourceStart = this.intStack[this.intPtr--];
704
705
	if(!this.statementRecoveryActivated &&
706
			this.options.sourceLevel < ClassFileConstants.JDK1_5 &&
707
			this.lastErrorEndPositionBeforeRecovery < this.scanner.currentPosition) {
708
		impt.modifiers = ClassFileConstants.AccDefault; // convert the static import reference to a non-static importe reference
709
		this.problemReporter().invalidUsageOfStaticImports(impt);
710
	}
711
712
	// recovery
713
	if (this.currentElement != null){
714
		this.lastCheckPoint = impt.declarationSourceEnd+1;
715
		this.currentElement = this.currentElement.add(impt, 0);
716
		this.lastIgnoredToken = -1;
717
		this.restartRecovery = true; // used to avoid branching back into the regular automaton
718
	}
719
	if (reportReferenceInfo) {
720
		// Name for static import is TypeName '.' Identifier
721
		// => accept unknown ref on identifier
722
		int tokensLength = impt.tokens.length-1;
723
		int start = (int) (impt.sourcePositions[tokensLength] >>> 32);
724
		char[] last = impt.tokens[tokensLength];
725
		// accept all possible kind for last name, index users will have to select the right one...
726
		// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=86901
727
		requestor.acceptFieldReference(last, start);
728
		requestor.acceptMethodReference(last, 0,start);
729
		requestor.acceptTypeReference(last, start);
730
		// accept type name
731
		if (tokensLength > 0) {
732
			char[][] compoundName = new char[tokensLength][];
733
			System.arraycopy(impt.tokens, 0, compoundName, 0, tokensLength);
734
			int end = (int) impt.sourcePositions[tokensLength-1];
735
			requestor.acceptTypeReference(compoundName, impt.sourceStart, end);
736
		}
737
	}
738
}
739
682
740
protected void consumeSingleTypeImportDeclarationName() {
683
protected void consumeSingleTypeImportDeclarationName() {
741
	// SingleTypeImportDeclarationName ::= 'import' Name
684
	// SingleTypeImportDeclarationName ::= 'import' Name
Lines 749-755 Link Here
749
	long[] positions = new long[length];
692
	long[] positions = new long[length];
750
	System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length);
693
	System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length);
751
	System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length);
694
	System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length);
752
	pushOnAstStack(impt = newImportReference(tokens, positions, false, ClassFileConstants.AccDefault));
695
	pushOnAstStack(impt = newImportReference(tokens, positions, false));
753
696
754
	if (this.currentToken == TokenNameSEMICOLON){
697
	if (this.currentToken == TokenNameSEMICOLON){
755
		impt.declarationSourceEnd = this.scanner.currentPosition - 1;
698
		impt.declarationSourceEnd = this.scanner.currentPosition - 1;
Lines 771-820 Link Here
771
		requestor.acceptTypeReference(impt.tokens, impt.sourceStart, impt.sourceEnd);
714
		requestor.acceptTypeReference(impt.tokens, impt.sourceStart, impt.sourceEnd);
772
	}
715
	}
773
}
716
}
774
protected void consumeStaticImportOnDemandDeclarationName() {
775
	// TypeImportOnDemandDeclarationName ::= 'import' 'static' Name '.' '*'
776
	/* push an ImportRef build from the last name
777
	stored in the identifier stack. */
778
779
	ImportReference impt;
780
	int length;
781
	char[][] tokens = new char[length = this.identifierLengthStack[this.identifierLengthPtr--]][];
782
	this.identifierPtr -= length;
783
	long[] positions = new long[length];
784
	System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length);
785
	System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length);
786
	pushOnAstStack(impt = new ImportReference(tokens, positions, true, ClassFileConstants.AccStatic));
787
788
	this.modifiers = ClassFileConstants.AccDefault;
789
	this.modifiersSourceStart = -1; // <-- see comment into modifiersFlag(int)
790
791
	if (this.currentToken == TokenNameSEMICOLON){
792
		impt.declarationSourceEnd = this.scanner.currentPosition - 1;
793
	} else {
794
		impt.declarationSourceEnd = impt.sourceEnd;
795
	}
796
	impt.declarationEnd = impt.declarationSourceEnd;
797
	//this.endPosition is just before the ;
798
	impt.declarationSourceStart = this.intStack[this.intPtr--];
799
800
	if(!this.statementRecoveryActivated &&
801
			options.sourceLevel < ClassFileConstants.JDK1_5 &&
802
			this.lastErrorEndPositionBeforeRecovery < this.scanner.currentPosition) {
803
		impt.modifiers = ClassFileConstants.AccDefault; // convert the static import reference to a non-static importe reference
804
		this.problemReporter().invalidUsageOfStaticImports(impt);
805
	}
806
807
	// recovery
808
	if (this.currentElement != null){
809
		this.lastCheckPoint = impt.declarationSourceEnd+1;
810
		this.currentElement = this.currentElement.add(impt, 0);
811
		this.lastIgnoredToken = -1;
812
		this.restartRecovery = true; // used to avoid branching back into the regular automaton
813
	}
814
	if (reportReferenceInfo) {
815
		requestor.acceptTypeReference(impt.tokens, impt.sourceStart, impt.sourceEnd);
816
	}
817
}
818
protected void consumeTypeImportOnDemandDeclarationName() {
717
protected void consumeTypeImportOnDemandDeclarationName() {
819
	// TypeImportOnDemandDeclarationName ::= 'import' Name '.' '*'
718
	// TypeImportOnDemandDeclarationName ::= 'import' Name '.' '*'
820
	/* push an ImportRef build from the last name
719
	/* push an ImportRef build from the last name
Lines 827-833 Link Here
827
	long[] positions = new long[length];
726
	long[] positions = new long[length];
828
	System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length);
727
	System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length);
829
	System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length);
728
	System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length);
830
	pushOnAstStack(impt = new ImportReference(tokens, positions, true, ClassFileConstants.AccDefault));
729
	pushOnAstStack(impt = new ImportReference(tokens, positions, true));
831
730
832
	if (this.currentToken == TokenNameSEMICOLON){
731
	if (this.currentToken == TokenNameSEMICOLON){
833
		impt.declarationSourceEnd = this.scanner.currentPosition - 1;
732
		impt.declarationSourceEnd = this.scanner.currentPosition - 1;
Lines 1105-1112 Link Here
1105
	return false;
1004
	return false;
1106
}
1005
}
1107
1006
1108
protected ImportReference newImportReference(char[][] tokens, long[] positions, boolean onDemand, int mod) {
1007
protected ImportReference newImportReference(char[][] tokens, long[] positions, boolean onDemand) {
1109
	return new ImportReference(tokens, positions, onDemand, mod);
1008
	return new ImportReference(tokens, positions, onDemand);
1110
}
1009
}
1111
protected QualifiedNameReference newQualifiedNameReference(char[][] tokens, long[] positions, int sourceStart, int sourceEnd) {
1010
protected QualifiedNameReference newQualifiedNameReference(char[][] tokens, long[] positions, int sourceStart, int sourceEnd) {
1112
	return new QualifiedNameReference(tokens, positions, sourceStart, sourceEnd);
1011
	return new QualifiedNameReference(tokens, positions, sourceStart, sourceEnd);
Lines 1701-1708 Link Here
1701
			importReference.declarationSourceStart,
1600
			importReference.declarationSourceStart,
1702
			importReference.declarationSourceEnd,
1601
			importReference.declarationSourceEnd,
1703
			importReference.tokens,
1602
			importReference.tokens,
1704
			(importReference.bits & ASTNode.OnDemand) != 0,
1603
			(importReference.bits & ASTNode.OnDemand) != 0);
1705
			importReference.modifiers);
1706
	}
1604
	}
1707
}
1605
}
1708
public void notifySourceElementRequestor(TypeDeclaration typeDeclaration, boolean notifyTypePresence, TypeDeclaration declaringType) {
1606
public void notifySourceElementRequestor(TypeDeclaration typeDeclaration, boolean notifyTypePresence, TypeDeclaration declaringType) {
(-)src/org/eclipse/wst/jsdt/internal/compiler/ISourceElementRequestor.java (-3 / +1 lines)
Lines 106-115 Link Here
106
	 * @param onDemand
106
	 * @param onDemand
107
	 *                   set to true if the import is an import on demand (e.g. import
107
	 *                   set to true if the import is an import on demand (e.g. import
108
	 *                   java.io.*). False otherwise.
108
	 *                   java.io.*). False otherwise.
109
	 * @param modifiers
110
	 *                   can be set to static from 1.5 on.
111
	 */
109
	 */
112
	void acceptImport(int declarationStart, int declarationEnd, char[][] tokens, boolean onDemand, int modifiers);
110
	void acceptImport(int declarationStart, int declarationEnd, char[][] tokens, boolean onDemand);
113
111
114
	/*
112
	/*
115
	 * Table of line separator position. This table is passed once at the end of
113
	 * Table of line separator position. This table is passed once at the end of
(-)src/org/eclipse/wst/jsdt/internal/codeassist/CompletionEngine.java (-211 / +6 lines)
Lines 401-407 Link Here
401
	char[] completionToken;
401
	char[] completionToken;
402
	char[] qualifiedCompletionToken;
402
	char[] qualifiedCompletionToken;
403
	boolean resolvingImports = false;
403
	boolean resolvingImports = false;
404
	boolean resolvingStaticImports = false;
405
	boolean insideQualifiedReference = false;
404
	boolean insideQualifiedReference = false;
406
	boolean noProposal = true;
405
	boolean noProposal = true;
407
	CategorizedProblem problem = null;
406
	CategorizedProblem problem = null;
Lines 659-678 Link Here
659
			this.knownTypes.put(fullyQualifiedName, this);
658
			this.knownTypes.put(fullyQualifiedName, this);
660
659
661
			if (this.resolvingImports) {
660
			if (this.resolvingImports) {
662
				char[] completionName;
661
				char[] completionName = CharOperation.concat(fullyQualifiedName, new char[] { ';' });
663
662
				
664
				if(this.resolvingStaticImports) {
665
					if(enclosingTypeNames == null || enclosingTypeNames.length == 0) {
666
						completionName = CharOperation.concat(fullyQualifiedName, new char[] { '.' });
667
					} else if ((modifiers & ClassFileConstants.AccStatic) == 0) {
668
						continue next;
669
					} else {
670
						completionName = CharOperation.concat(fullyQualifiedName, new char[] { ';' });
671
					}
672
				} else {
673
					completionName = CharOperation.concat(fullyQualifiedName, new char[] { ';' });
674
				}
675
676
				int relevance = computeBaseRelevance();
663
				int relevance = computeBaseRelevance();
677
				relevance += computeRelevanceForResolution();
664
				relevance += computeRelevanceForResolution();
678
				relevance += computeRelevanceForInterestingProposal();
665
				relevance += computeRelevanceForInterestingProposal();
Lines 2581-2598 Link Here
2581
										} else {
2568
										} else {
2582
											ReferenceBinding ref = (ReferenceBinding) binding;
2569
											ReferenceBinding ref = (ReferenceBinding) binding;
2583
											if(!this.requestor.isIgnored(CompletionProposal.TYPE_REF)) {
2570
											if(!this.requestor.isIgnored(CompletionProposal.TYPE_REF)) {
2584
												this.findImportsOfMemberTypes(lastToken, ref, importReference.isStatic());
2571
												this.findImportsOfMemberTypes(lastToken, ref);
2585
											}
2586
											if(importReference.isStatic()) {
2587
												if(!this.requestor.isIgnored(CompletionProposal.FIELD_REF)) {
2588
													long positions = importReference.sourcePositions[importReference.sourcePositions.length - 1];
2589
													setSourceRange((int) (positions >>> 32), (int) positions);
2590
													this.findImportsOfStaticFields(lastToken, ref);
2591
													setSourceRange(importReference.sourceStart, importReference.declarationSourceEnd);
2592
												}
2593
												if(!this.requestor.isIgnored(CompletionProposal.METHOD_NAME_REFERENCE)) {
2594
													this.findImportsOfStaticMethods(lastToken, ref);
2595
												}
2596
											}
2572
											}
2597
										}
2573
										}
2598
									}
2574
									}
Lines 4435-4441 Link Here
4435
			importName = CharOperation.concat(importName, new char[]{'.'});
4411
			importName = CharOperation.concat(importName, new char[]{'.'});
4436
4412
4437
		this.resolvingImports = true;
4413
		this.resolvingImports = true;
4438
		this.resolvingStaticImports = importReference.isStatic();
4439
4414
4440
		this.completionToken =  importName;
4415
		this.completionToken =  importName;
4441
		// want to replace the existing .*;
4416
		// want to replace the existing .*;
Lines 4453-4459 Link Here
4453
		}
4428
		}
4454
	}
4429
	}
4455
4430
4456
	private void findImportsOfMemberTypes(char[] typeName,	ReferenceBinding ref, boolean onlyStatic) {
4431
	private void findImportsOfMemberTypes(char[] typeName,	ReferenceBinding ref) {
4457
		ReferenceBinding[] memberTypes = ref.memberTypes();
4432
		ReferenceBinding[] memberTypes = ref.memberTypes();
4458
4433
4459
		int typeLength = typeName.length;
4434
		int typeLength = typeName.length;
Lines 4462-4470 Link Here
4462
			//		if (!wantClasses && memberType.isClass()) continue next;
4437
			//		if (!wantClasses && memberType.isClass()) continue next;
4463
			//		if (!wantInterfaces && memberType.isInterface()) continue next;
4438
			//		if (!wantInterfaces && memberType.isInterface()) continue next;
4464
4439
4465
			if (onlyStatic && !memberType.isStatic())
4466
				continue next;
4467
4468
			if (typeLength > memberType.sourceName.length)
4440
			if (typeLength > memberType.sourceName.length)
4469
				continue next;
4441
				continue next;
4470
4442
Lines 7269-7278 Link Here
7269
			}
7241
			}
7270
		}
7242
		}
7271
7243
7272
		if(!skip && proposeType) {
7273
			this.findTypesFromStaticImports(token, scope, proposeAllMemberTypes, typesFound);
7274
		}
7275
7276
		if (isEmptyPrefix && !this.assistNodeIsAnnotation) {
7244
		if (isEmptyPrefix && !this.assistNodeIsAnnotation) {
7277
			if(proposeType && this.expectedTypesPtr > -1) {
7245
			if(proposeType && this.expectedTypesPtr > -1) {
7278
				next : for (int i = 0; i <= this.expectedTypesPtr; i++) {
7246
				next : for (int i = 0; i <= this.expectedTypesPtr; i++) {
Lines 7540-7630 Link Here
7540
//		}
7508
//		}
7541
	}
7509
	}
7542
7510
7543
	private void findTypesFromStaticImports(char[] token, Scope scope, boolean proposeAllMemberTypes, ObjectVector typesFound) {
7544
		ImportBinding[] importBindings = scope.compilationUnitScope().imports;
7545
		for (int i = 0; i < importBindings.length; i++) {
7546
			ImportBinding importBinding = importBindings[i];
7547
			if(importBinding.isValidBinding() && importBinding.isStatic()) {
7548
				Binding binding = importBinding.resolvedImport;
7549
				if(binding != null && binding.isValidBinding()) {
7550
					if(importBinding.onDemand) {
7551
						if((binding.kind() & Binding.TYPE) != 0) {
7552
							this.findMemberTypes(
7553
									token,
7554
									(ReferenceBinding) binding,
7555
									scope,
7556
									scope.enclosingSourceType(),
7557
									true,
7558
									false,
7559
									true,
7560
									true,
7561
									proposeAllMemberTypes,
7562
									null,
7563
									typesFound);
7564
						}
7565
					} else {
7566
						if ((binding.kind() & Binding.TYPE) != 0) {
7567
							ReferenceBinding typeBinding = (ReferenceBinding) binding;
7568
							int typeLength = token.length;
7569
7570
							if (!typeBinding.isStatic()) continue;
7571
7572
							if (typeLength > typeBinding.sourceName.length)	continue;
7573
7574
							if (!CharOperation.prefixEquals(token, typeBinding.sourceName, false)
7575
									&& !(this.options.camelCaseMatch && CharOperation.camelCaseMatch(token, typeBinding.sourceName)))	continue;
7576
7577
							if (typesFound.contains(typeBinding))  continue;
7578
7579
							typesFound.add(typeBinding);
7580
7581
							if(this.assistNodeIsClass) {
7582
								if(!typeBinding.isClass()) continue;
7583
							} else if(this.assistNodeIsInterface) {
7584
								if(!typeBinding.isInterface() && !typeBinding.isAnnotationType()) continue;
7585
							} else if (this.assistNodeIsAnnotation) {
7586
								if(!typeBinding.isAnnotationType()) continue;
7587
							}
7588
7589
							int relevance = computeBaseRelevance();
7590
							relevance += computeRelevanceForResolution();
7591
							relevance += computeRelevanceForInterestingProposal();
7592
							relevance += computeRelevanceForCaseMatching(token, typeBinding.sourceName);
7593
							relevance += computeRelevanceForExpectingType(typeBinding);
7594
							relevance += computeRelevanceForQualification(false);
7595
							relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE);
7596
7597
							if (typeBinding.isClass()) {
7598
								relevance += computeRelevanceForClass();
7599
								relevance += computeRelevanceForException(typeBinding.sourceName);
7600
							} else if(typeBinding.isEnum()) {
7601
								relevance += computeRelevanceForEnum();
7602
							} else if(typeBinding.isInterface()) {
7603
								relevance += computeRelevanceForInterface();
7604
							}
7605
7606
							this.noProposal = false;
7607
							if(!this.requestor.isIgnored(CompletionProposal.TYPE_REF)) {
7608
								CompletionProposal proposal = this.createProposal(CompletionProposal.TYPE_REF, this.actualCompletionPosition);
7609
								proposal.setDeclarationSignature(typeBinding.qualifiedPackageName());
7610
								proposal.setSignature(getSignature(typeBinding));
7611
								proposal.setPackageName(typeBinding.qualifiedPackageName());
7612
								proposal.setTypeName(typeBinding.qualifiedSourceName());
7613
								proposal.setCompletion(typeBinding.sourceName());
7614
								proposal.setFlags(typeBinding.modifiers);
7615
								proposal.setReplaceRange(this.startPosition - this.offset, this.endPosition - this.offset);
7616
								proposal.setRelevance(relevance);
7617
								this.requestor.accept(proposal);
7618
								if(DEBUG) {
7619
									this.printDebug(proposal);
7620
								}
7621
							}
7622
						}
7623
					}
7624
				}
7625
			}
7626
		}
7627
	}
7628
	private void findVariablesAndMethods(
7511
	private void findVariablesAndMethods(
7629
		char[] token,
7512
		char[] token,
7630
		Scope scope,
7513
		Scope scope,
Lines 7833-7925 Link Here
7833
				currentScope = currentScope.parent;
7716
				currentScope = currentScope.parent;
7834
			}
7717
			}
7835
7718
7836
			// search in static import
7837
			ImportBinding[] importBindings = scope.compilationUnitScope().imports;
7838
			for (int i = 0; i < importBindings.length; i++) {
7839
				ImportBinding importBinding = importBindings[i];
7840
				if(importBinding.isValidBinding() && importBinding.isStatic()) {
7841
					Binding binding = importBinding.resolvedImport;
7842
					if(binding != null && binding.isValidBinding()) {
7843
						if(importBinding.onDemand) {
7844
							if((binding.kind() & Binding.TYPE) != 0) {
7845
								if(proposeField) {
7846
									findFields(
7847
										token,
7848
										(ReferenceBinding)binding,
7849
										scope,
7850
										fieldsFound,
7851
										localsFound,
7852
										true,
7853
										invocationSite,
7854
										invocationScope,
7855
										true,
7856
										false,
7857
										null,
7858
										null,
7859
										null,
7860
										false);
7861
								}
7862
								if(proposeMethod && !insideAnnotationAttribute) {
7863
									findMethods(
7864
										token,
7865
										null,
7866
										null,
7867
										(ReferenceBinding)binding,
7868
										scope,
7869
										methodsFound,
7870
										true,
7871
										false,
7872
										false,
7873
										invocationSite,
7874
										invocationScope,
7875
										true,
7876
										false,
7877
										false,
7878
										null,
7879
										null,
7880
										null,
7881
										false);
7882
								}
7883
							}
7884
						} else {
7885
							if ((binding.kind() & Binding.FIELD) != 0) {
7886
								if(proposeField) {
7887
										findFields(
7888
												token,
7889
												new FieldBinding[]{(FieldBinding)binding},
7890
												scope,
7891
												fieldsFound,
7892
												localsFound,
7893
												true,
7894
												((FieldBinding)binding).declaringClass,
7895
												invocationSite,
7896
												invocationScope,
7897
												true,
7898
												false,
7899
												null,
7900
												null,
7901
												null,
7902
												false);
7903
								}
7904
							} else if ((binding.kind() & Binding.METHOD) != 0) {
7905
								if(proposeMethod && !insideAnnotationAttribute) {
7906
									MethodBinding methodBinding = (MethodBinding)binding;
7907
									if(CharOperation.prefixEquals(token, methodBinding.selector))
7908
7909
									findLocalMethodsOfStaticImports(
7910
											methodBinding.selector,
7911
											methodBinding.declaringClass.methods(),
7912
											scope,
7913
											methodsFound,
7914
											methodBinding.declaringClass,
7915
											invocationSite);
7916
								}
7917
							}
7918
						}
7919
					}
7920
				}
7921
			}
7922
7923
			if (this.assistNodeInJavadoc == 0) {
7719
			if (this.assistNodeInJavadoc == 0) {
7924
				// search in favorites import
7720
				// search in favorites import
7925
				findFieldsAndMethodsFromFavorites(
7721
				findFieldsAndMethodsFromFavorites(
Lines 8367-8376 Link Here
8367
				new ImportReference(
8163
				new ImportReference(
8368
						compoundName,
8164
						compoundName,
8369
						new long[compoundName.length],
8165
						new long[compoundName.length],
8370
						onDemand,
8166
						onDemand);
8371
						isStatic ? ClassFileConstants.AccStatic : ClassFileConstants.AccDefault);
8372
8167
8373
			Binding importBinding = this.unitScope.findImport(compoundName, isStatic, onDemand);
8168
			Binding importBinding = this.unitScope.findImport(compoundName, onDemand);
8374
8169
8375
			if (!importBinding.isValidBinding()) {
8170
			if (!importBinding.isValidBinding()) {
8376
				continue next;
8171
				continue next;
(-)src/org/eclipse/wst/jsdt/internal/codeassist/SelectionEngine.java (-9 / +2 lines)
Lines 810-820 Link Here
810
									Binding binding = this.unitScope.getTypeOrPackage(qualifierTokens);
810
									Binding binding = this.unitScope.getTypeOrPackage(qualifierTokens);
811
									if(binding != null && binding instanceof ReferenceBinding) {
811
									if(binding != null && binding instanceof ReferenceBinding) {
812
										ReferenceBinding ref = (ReferenceBinding) binding;
812
										ReferenceBinding ref = (ReferenceBinding) binding;
813
										selectMemberTypeFromImport(parsedUnit, lastToken, ref, importReference.isStatic());
813
										selectMemberTypeFromImport(parsedUnit, lastToken, ref);
814
										if(importReference.isStatic()) {
815
											selectStaticFieldFromStaticImport(parsedUnit, lastToken, ref);
816
											selectStaticMethodFromStaticImport(parsedUnit, lastToken, ref);
817
										}
818
									}
814
									}
819
								}
815
								}
820
							}
816
							}
Lines 897-903 Link Here
897
		}
893
		}
898
	}
894
	}
899
895
900
	private void selectMemberTypeFromImport(CompilationUnitDeclaration parsedUnit, char[] lastToken, ReferenceBinding ref, boolean staticOnly) {
896
	private void selectMemberTypeFromImport(CompilationUnitDeclaration parsedUnit, char[] lastToken, ReferenceBinding ref) {
901
		int fieldLength = lastToken.length;
897
		int fieldLength = lastToken.length;
902
		ReferenceBinding[] memberTypes = ref.memberTypes();
898
		ReferenceBinding[] memberTypes = ref.memberTypes();
903
		next : for (int j = 0; j < memberTypes.length; j++) {
899
		next : for (int j = 0; j < memberTypes.length; j++) {
Lines 906-914 Link Here
906
			if (fieldLength > memberType.sourceName.length)
902
			if (fieldLength > memberType.sourceName.length)
907
				continue next;
903
				continue next;
908
904
909
			if (staticOnly && !memberType.isStatic())
910
				continue next;
911
912
			if (!CharOperation.equals(lastToken, memberType.sourceName, true))
905
			if (!CharOperation.equals(lastToken, memberType.sourceName, true))
913
				continue next;
906
				continue next;
914
907
(-)src/org/eclipse/wst/jsdt/internal/codeassist/impl/AssistParser.java (-115 / +4 lines)
Lines 19-25 Link Here
19
import org.eclipse.wst.jsdt.internal.compiler.ast.AbstractMethodDeclaration;
19
import org.eclipse.wst.jsdt.internal.compiler.ast.AbstractMethodDeclaration;
20
import org.eclipse.wst.jsdt.internal.compiler.ast.AbstractVariableDeclaration;
20
import org.eclipse.wst.jsdt.internal.compiler.ast.AbstractVariableDeclaration;
21
import org.eclipse.wst.jsdt.internal.compiler.ast.AllocationExpression;
21
import org.eclipse.wst.jsdt.internal.compiler.ast.AllocationExpression;
22
import org.eclipse.wst.jsdt.internal.compiler.ast.Annotation;
23
import org.eclipse.wst.jsdt.internal.compiler.ast.Block;
22
import org.eclipse.wst.jsdt.internal.compiler.ast.Block;
24
import org.eclipse.wst.jsdt.internal.compiler.ast.CompilationUnitDeclaration;
23
import org.eclipse.wst.jsdt.internal.compiler.ast.CompilationUnitDeclaration;
25
import org.eclipse.wst.jsdt.internal.compiler.ast.ConstructorDeclaration;
24
import org.eclipse.wst.jsdt.internal.compiler.ast.ConstructorDeclaration;
Lines 547-561 Link Here
547
	this.intPtr--; // we don't need the modifiers start
546
	this.intPtr--; // we don't need the modifiers start
548
	this.intPtr--; // we don't need the package modifiers
547
	this.intPtr--; // we don't need the package modifiers
549
	ImportReference reference = this.createAssistPackageReference(subset, positions);
548
	ImportReference reference = this.createAssistPackageReference(subset, positions);
550
	// consume annotations
549
551
	if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
552
		System.arraycopy(
553
			this.expressionStack,
554
			(this.expressionPtr -= length) + 1,
555
			reference.annotations = new Annotation[length],
556
			0,
557
			length);
558
	}
559
	/* build specific assist node on package statement */
550
	/* build specific assist node on package statement */
560
	assistNode = reference;
551
	assistNode = reference;
561
	this.lastCheckPoint = reference.sourceEnd + 1;
552
	this.lastCheckPoint = reference.sourceEnd + 1;
Lines 585-641 Link Here
585
		popElement(K_FIELD_INITIALIZER_DELIMITER);
576
		popElement(K_FIELD_INITIALIZER_DELIMITER);
586
	}
577
	}
587
}
578
}
588
protected void consumeSingleStaticImportDeclarationName() {
589
	// SingleTypeImportDeclarationName ::= 'import' 'static' Name
590
	/* push an ImportRef build from the last name
591
	stored in the identifier stack. */
592
579
593
	int index;
594
595
	/* no need to take action if not inside assist identifiers */
596
	if ((index = indexOfAssistIdentifier()) < 0) {
597
		super.consumeSingleStaticImportDeclarationName();
598
		return;
599
	}
600
	/* retrieve identifiers subset and whole positions, the assist node positions
601
		should include the entire replaced source. */
602
	int length = identifierLengthStack[identifierLengthPtr];
603
	char[][] subset = identifierSubSet(index+1); // include the assistIdentifier
604
	identifierLengthPtr--;
605
	identifierPtr -= length;
606
	long[] positions = new long[length];
607
	System.arraycopy(
608
		identifierPositionStack,
609
		identifierPtr + 1,
610
		positions,
611
		0,
612
		length);
613
614
	/* build specific assist node on import statement */
615
	ImportReference reference = this.createAssistImportReference(subset, positions, ClassFileConstants.AccStatic);
616
	assistNode = reference;
617
	this.lastCheckPoint = reference.sourceEnd + 1;
618
619
	pushOnAstStack(reference);
620
621
	if (currentToken == TokenNameSEMICOLON){
622
		reference.declarationSourceEnd = scanner.currentPosition - 1;
623
	} else {
624
		reference.declarationSourceEnd = (int) positions[length-1];
625
	}
626
	//endPosition is just before the ;
627
	reference.declarationSourceStart = intStack[intPtr--];
628
	// flush annotations defined prior to import statements
629
	reference.declarationSourceEnd = this.flushCommentsDefinedPriorTo(reference.declarationSourceEnd);
630
631
	// recovery
632
	if (currentElement != null){
633
		lastCheckPoint = reference.declarationSourceEnd+1;
634
		currentElement = currentElement.add(reference, 0);
635
		lastIgnoredToken = -1;
636
		restartRecovery = true; // used to avoid branching back into the regular automaton
637
	}
638
}
639
protected void consumeSingleTypeImportDeclarationName() {
580
protected void consumeSingleTypeImportDeclarationName() {
640
	// SingleTypeImportDeclarationName ::= 'import' Name
581
	// SingleTypeImportDeclarationName ::= 'import' Name
641
	/* push an ImportRef build from the last name
582
	/* push an ImportRef build from the last name
Lines 663-669 Link Here
663
		length);
604
		length);
664
605
665
	/* build specific assist node on import statement */
606
	/* build specific assist node on import statement */
666
	ImportReference reference = this.createAssistImportReference(subset, positions, ClassFileConstants.AccDefault);
607
	ImportReference reference = this.createAssistImportReference(subset, positions);
667
	assistNode = reference;
608
	assistNode = reference;
668
	this.lastCheckPoint = reference.sourceEnd + 1;
609
	this.lastCheckPoint = reference.sourceEnd + 1;
669
610
Lines 687-744 Link Here
687
		restartRecovery = true; // used to avoid branching back into the regular automaton
628
		restartRecovery = true; // used to avoid branching back into the regular automaton
688
	}
629
	}
689
}
630
}
690
protected void consumeStaticImportOnDemandDeclarationName() {
691
	// TypeImportOnDemandDeclarationName ::= 'import' 'static' Name '.' '*'
692
	/* push an ImportRef build from the last name
693
	stored in the identifier stack. */
694
695
	int index;
696
697
	/* no need to take action if not inside assist identifiers */
698
	if ((index = indexOfAssistIdentifier()) < 0) {
699
		super.consumeStaticImportOnDemandDeclarationName();
700
		return;
701
	}
702
	/* retrieve identifiers subset and whole positions, the assist node positions
703
		should include the entire replaced source. */
704
	int length = identifierLengthStack[identifierLengthPtr];
705
	char[][] subset = identifierSubSet(index+1); // include the assistIdentifier
706
	identifierLengthPtr--;
707
	identifierPtr -= length;
708
	long[] positions = new long[length];
709
	System.arraycopy(
710
		identifierPositionStack,
711
		identifierPtr + 1,
712
		positions,
713
		0,
714
		length);
715
716
	/* build specific assist node on import statement */
717
	ImportReference reference = this.createAssistImportReference(subset, positions, ClassFileConstants.AccStatic);
718
	reference.bits |= ASTNode.OnDemand;
719
	assistNode = reference;
720
	this.lastCheckPoint = reference.sourceEnd + 1;
721
722
	pushOnAstStack(reference);
723
724
	if (currentToken == TokenNameSEMICOLON){
725
		reference.declarationSourceEnd = scanner.currentPosition - 1;
726
	} else {
727
		reference.declarationSourceEnd = (int) positions[length-1];
728
	}
729
	//endPosition is just before the ;
730
	reference.declarationSourceStart = intStack[intPtr--];
731
	// flush annotations defined prior to import statements
732
	reference.declarationSourceEnd = this.flushCommentsDefinedPriorTo(reference.declarationSourceEnd);
733
734
	// recovery
735
	if (currentElement != null){
736
		lastCheckPoint = reference.declarationSourceEnd+1;
737
		currentElement = currentElement.add(reference, 0);
738
		lastIgnoredToken = -1;
739
		restartRecovery = true; // used to avoid branching back into the regular automaton
740
	}
741
}
742
protected void consumeStaticInitializer() {
631
protected void consumeStaticInitializer() {
743
	super.consumeStaticInitializer();
632
	super.consumeStaticInitializer();
744
	popElement(K_METHOD_DELIMITER);
633
	popElement(K_METHOD_DELIMITER);
Lines 820-826 Link Here
820
		length);
709
		length);
821
710
822
	/* build specific assist node on import statement */
711
	/* build specific assist node on import statement */
823
	ImportReference reference = this.createAssistImportReference(subset, positions, ClassFileConstants.AccDefault);
712
	ImportReference reference = this.createAssistImportReference(subset, positions);
824
	reference.bits |= ASTNode.OnDemand;
713
	reference.bits |= ASTNode.OnDemand;
825
	assistNode = reference;
714
	assistNode = reference;
826
	this.lastCheckPoint = reference.sourceEnd + 1;
715
	this.lastCheckPoint = reference.sourceEnd + 1;
Lines 845-851 Link Here
845
		restartRecovery = true; // used to avoid branching back into the regular automaton
734
		restartRecovery = true; // used to avoid branching back into the regular automaton
846
	}
735
	}
847
}
736
}
848
public abstract ImportReference createAssistImportReference(char[][] tokens, long[] positions, int mod);
737
public abstract ImportReference createAssistImportReference(char[][] tokens, long[] positions);
849
public abstract ImportReference createAssistPackageReference(char[][] tokens, long[] positions);
738
public abstract ImportReference createAssistPackageReference(char[][] tokens, long[] positions);
850
public abstract NameReference createQualifiedAssistNameReference(char[][] previousIdentifiers, char[] assistName, long[] positions);
739
public abstract NameReference createQualifiedAssistNameReference(char[][] previousIdentifiers, char[] assistName, long[] positions);
851
public abstract TypeReference createQualifiedAssistTypeReference(char[][] previousIdentifiers, char[] assistName, long[] positions);
740
public abstract TypeReference createQualifiedAssistTypeReference(char[][] previousIdentifiers, char[] assistName, long[] positions);
(-)src/org/eclipse/wst/jsdt/internal/codeassist/impl/Engine.java (-11 / +2 lines)
Lines 20-26 Link Here
20
import org.eclipse.wst.jsdt.internal.compiler.ast.FieldDeclaration;
20
import org.eclipse.wst.jsdt.internal.compiler.ast.FieldDeclaration;
21
import org.eclipse.wst.jsdt.internal.compiler.ast.Initializer;
21
import org.eclipse.wst.jsdt.internal.compiler.ast.Initializer;
22
import org.eclipse.wst.jsdt.internal.compiler.ast.TypeDeclaration;
22
import org.eclipse.wst.jsdt.internal.compiler.ast.TypeDeclaration;
23
import org.eclipse.wst.jsdt.internal.compiler.classfmt.ClassFileConstants;
24
import org.eclipse.wst.jsdt.internal.compiler.env.AccessRestriction;
23
import org.eclipse.wst.jsdt.internal.compiler.env.AccessRestriction;
25
import org.eclipse.wst.jsdt.internal.compiler.env.IBinaryType;
24
import org.eclipse.wst.jsdt.internal.compiler.env.IBinaryType;
26
import org.eclipse.wst.jsdt.internal.compiler.env.ICompilationUnit;
25
import org.eclipse.wst.jsdt.internal.compiler.env.ICompilationUnit;
Lines 207-227 Link Here
207
									'.');
206
									'.');
208
					}
207
					}
209
					if(CharOperation.equals(fullyQualifiedEnclosingTypeName, importFlatName)) {
208
					if(CharOperation.equals(fullyQualifiedEnclosingTypeName, importFlatName)) {
210
						if(importBinding.isStatic()) {
209
						isFound = true;
211
							isFound = (modifiers & ClassFileConstants.AccStatic) != 0;
212
						} else {
213
							isFound = true;
214
						}
215
					}
210
					}
216
				}
211
				}
217
			} else {
212
			} else {
218
				if(enclosingTypeNames == null || enclosingTypeNames.length == 0) {
213
				if(enclosingTypeNames == null || enclosingTypeNames.length == 0) {
219
					if(CharOperation.equals(packageName, importFlatName)) {
214
					if(CharOperation.equals(packageName, importFlatName)) {
220
						if(importBinding.isStatic()) {
215
						isFound = true;
221
							isFound = (modifiers & ClassFileConstants.AccStatic) != 0;
222
						} else {
223
							isFound = true;
224
						}
225
					}
216
					}
226
				}
217
				}
227
			}
218
			}
(-)src/org/eclipse/wst/jsdt/internal/compiler/ast/Argument.java (-13 / +2 lines)
Lines 27-34 Link Here
27
public class Argument extends LocalDeclaration implements IArgument {
27
public class Argument extends LocalDeclaration implements IArgument {
28
28
29
	public char [] comment;
29
	public char [] comment;
30
	// prefix for setter method (to recognize special hiding argument)
31
//	private final static char[] SET = "set".toCharArray(); //$NON-NLS-1$
32
30
33
	public Argument(char[] name, long posNom, TypeReference tr, int modifiers) {
31
	public Argument(char[] name, long posNom, TypeReference tr, int modifiers) {
34
32
Lines 163-193 Link Here
163
	public void traverse(ASTVisitor visitor, BlockScope scope) {
161
	public void traverse(ASTVisitor visitor, BlockScope scope) {
164
162
165
		if (visitor.visit(this, scope)) {
163
		if (visitor.visit(this, scope)) {
166
			if (this.annotations != null) {
167
				int annotationsLength = this.annotations.length;
168
				for (int i = 0; i < annotationsLength; i++)
169
					this.annotations[i].traverse(visitor, scope);
170
			}
171
			if (type != null)
164
			if (type != null)
172
				type.traverse(visitor, scope);
165
				type.traverse(visitor, scope);
173
		}
166
		}
174
		visitor.endVisit(this, scope);
167
		visitor.endVisit(this, scope);
175
	}
168
	}
169
	
176
	public void traverse(ASTVisitor visitor, ClassScope scope) {
170
	public void traverse(ASTVisitor visitor, ClassScope scope) {
177
171
178
		if (visitor.visit(this, scope)) {
172
		if (visitor.visit(this, scope)) {
179
			if (this.annotations != null) {
180
				int annotationsLength = this.annotations.length;
181
				for (int i = 0; i < annotationsLength; i++)
182
					this.annotations[i].traverse(visitor, scope);
183
			}
184
			if (type != null)
173
			if (type != null)
185
				type.traverse(visitor, scope);
174
				type.traverse(visitor, scope);
186
		}
175
		}
187
		visitor.endVisit(this, scope);
176
		visitor.endVisit(this, scope);
188
	}
177
	}
178
	
189
	public int getASTType() {
179
	public int getASTType() {
190
		return IASTNode.ARGUMENT;
180
		return IASTNode.ARGUMENT;
191
	
192
	}
181
	}
193
}
182
}
(-)src/org/eclipse/wst/jsdt/internal/compiler/ast/ImportReference.java (-28 / +20 lines)
Lines 10-20 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.wst.jsdt.internal.compiler.ast;
11
package org.eclipse.wst.jsdt.internal.compiler.ast;
12
12
13
import org.eclipse.wst.jsdt.core.ast.IASTNode;
14
import org.eclipse.wst.jsdt.core.ast.IImportReference;
13
import org.eclipse.wst.jsdt.core.ast.IImportReference;
15
import org.eclipse.wst.jsdt.core.compiler.CharOperation;
14
import org.eclipse.wst.jsdt.core.compiler.CharOperation;
16
import org.eclipse.wst.jsdt.internal.compiler.ASTVisitor;
15
import org.eclipse.wst.jsdt.internal.compiler.ASTVisitor;
17
import org.eclipse.wst.jsdt.internal.compiler.classfmt.ClassFileConstants;
18
import org.eclipse.wst.jsdt.internal.compiler.lookup.CompilationUnitScope;
16
import org.eclipse.wst.jsdt.internal.compiler.lookup.CompilationUnitScope;
19
17
20
public class ImportReference extends ASTNode implements IImportReference {
18
public class ImportReference extends ASTNode implements IImportReference {
Lines 24-49 Link Here
24
	public int declarationEnd; // doesn't include an potential trailing comment
22
	public int declarationEnd; // doesn't include an potential trailing comment
25
	public int declarationSourceStart;
23
	public int declarationSourceStart;
26
	public int declarationSourceEnd;
24
	public int declarationSourceEnd;
27
	public int modifiers; // 1.5 addition for static imports
28
	public Annotation[] annotations;
29
25
30
	public ImportReference(
26
	public ImportReference(
31
			char[][] tokens,
27
			char[][] tokens, long[] sourcePositions, boolean onDemand) {
32
			long[] sourcePositions,
33
			boolean onDemand,
34
			int modifiers) {
35
28
36
		this.tokens = tokens;
29
		this.tokens = tokens;
37
		this.sourcePositions = sourcePositions;
30
		this.sourcePositions = sourcePositions;
38
		if (onDemand) {
31
		if (onDemand) {
39
				this.bits |= ASTNode.OnDemand;
32
			this.bits |= ASTNode.OnDemand;
40
		}
33
		}
34
		
41
		this.sourceEnd = (int) (sourcePositions[sourcePositions.length-1] & 0x00000000FFFFFFFF);
35
		this.sourceEnd = (int) (sourcePositions[sourcePositions.length-1] & 0x00000000FFFFFFFF);
42
		this.sourceStart = (int) (sourcePositions[0] >>> 32);
36
		this.sourceStart = (int) (sourcePositions[0] >>> 32);
43
		this.modifiers = modifiers;
44
	}
37
	}
45
38
46
47
	public ImportReference(		// for internal imports
39
	public ImportReference(		// for internal imports
48
			char[] name, int startPosition, int endPosition, int nameStartPosition) {
40
			char[] name, int startPosition, int endPosition, int nameStartPosition) {
49
41
Lines 58-80 Link Here
58
		this.bits |= ASTNode.OnDemand;
50
		this.bits |= ASTNode.OnDemand;
59
		this.declarationSourceStart=this.sourceStart = startPosition;
51
		this.declarationSourceStart=this.sourceStart = startPosition;
60
		this.declarationSourceEnd=this.declarationEnd=this.sourceEnd = endPosition;
52
		this.declarationSourceEnd=this.declarationEnd=this.sourceEnd = endPosition;
61
		this.modifiers = ClassFileConstants.AccDefault;
62
	}
63
64
	public boolean isStatic() {
65
		return (this.modifiers & ClassFileConstants.AccStatic) != 0;
66
	}
53
	}
67
54
68
	/**
55
	/**
69
	 * @return char[][]
56
	 * @return char[][]
70
	 */
57
	 */
71
	public char[][] getImportName() {
58
	public char[][] getImportName() {
72
73
		return tokens;
59
		return tokens;
74
	}
60
	}
75
61
76
	public StringBuffer print(int indent, StringBuffer output) {
62
	public StringBuffer print(int indent, StringBuffer output) {
77
78
		return print(indent, output, true);
63
		return print(indent, output, true);
79
	}
64
	}
80
65
Lines 91-113 Link Here
91
		return output;
76
		return output;
92
	}
77
	}
93
78
79
	/**
80
	 * Traverse the node
81
	 * @param visitor
82
	 * @param scope
83
	 */
94
	public void traverse(ASTVisitor visitor, CompilationUnitScope scope) {
84
	public void traverse(ASTVisitor visitor, CompilationUnitScope scope) {
95
		// annotations are traversed during the compilation unit traversal using a class scope
96
		visitor.visit(this, scope);
85
		visitor.visit(this, scope);
97
		visitor.endVisit(this, scope);
86
		visitor.endVisit(this, scope);
98
	}
87
	}
99
	public int getASTType() {
100
		return IASTNode.IMPORT_REFERENCE;
101
	
88
	
102
	}
89
	/**
103
	public boolean isInternal()
90
	 * Returns true if this is an internal import.
104
	{
91
	 * @return true if an internal import.
105
	  return (this.bits&ASTNode.IsFileImport)!=0;
92
	 */
93
	public boolean isInternal() {
94
	  return (this.bits & ASTNode.IsFileImport) != 0;
106
	}
95
	}
107
	
96
	
108
	public boolean isFileImport()
97
	/**
109
	{
98
	 * Returns true if this is a file import.
110
	  return (this.bits&ASTNode.IsFileImport)!=0;
99
	 * @return true if a file import.
100
	 */
101
	public boolean isFileImport() {
102
	  return (this.bits & ASTNode.IsFileImport) != 0;
111
	}
103
	}
112
104
113
}
105
}
(-)src/org/eclipse/wst/jsdt/internal/compiler/ast/CompilationUnitDeclaration.java (-15 / +1 lines)
Lines 314-322 Link Here
314
					continue;
314
					continue;
315
				printIndent(indent, output).append("import "); //$NON-NLS-1$
315
				printIndent(indent, output).append("import "); //$NON-NLS-1$
316
				ImportReference currentImport = imports[i];
316
				ImportReference currentImport = imports[i];
317
				if (currentImport.isStatic()) {
318
					output.append("static "); //$NON-NLS-1$
319
				}
320
				currentImport.print(0, output).append(";\n"); //$NON-NLS-1$
317
				currentImport.print(0, output).append(";\n"); //$NON-NLS-1$
321
			}
318
			}
322
319
Lines 407-415 Link Here
407
				this.javadoc.resolve(this.scope);
404
				this.javadoc.resolve(this.scope);
408
    		}
405
    		}
409
		}
406
		}
410
		if (this.currentPackage != null && this.currentPackage.annotations != null && !isPackageInfo) {
407
411
			scope.problemReporter().invalidFileNameForPackageAnnotations(this.currentPackage.annotations[0]);
412
		}
413
		try {
408
		try {
414
			if (types != null) {
409
			if (types != null) {
415
				for (int i = startingTypeIndex, count = types.length; i < count; i++) {
410
				for (int i = startingTypeIndex, count = types.length; i < count; i++) {
Lines 590-604 Link Here
590
					if (this.javadoc != null) {
585
					if (this.javadoc != null) {
591
						this.javadoc.traverse(visitor, methodScope);
586
						this.javadoc.traverse(visitor, methodScope);
592
					}
587
					}
593
					if (this.currentPackage != null) {
594
					final Annotation[] annotations = this.currentPackage.annotations;
595
					if (annotations != null) {
596
						int annotationsLength = annotations.length;
597
						for (int i = 0; i < annotationsLength; i++) {
598
							annotations[i].traverse(visitor, methodScope);
599
						}
600
					}
601
					}
602
				}
588
				}
603
589
604
//				if (currentPackage != null) {
590
//				if (currentPackage != null) {
(-)src/org/eclipse/wst/jsdt/internal/compiler/parser/SourceTypeConverter.java (-7 / +4 lines)
Lines 169-175 Link Here
169
		if (packageName.length > 0)
169
		if (packageName.length > 0)
170
			// if its null then it is defined in the default package
170
			// if its null then it is defined in the default package
171
			this.unit.currentPackage =
171
			this.unit.currentPackage =
172
				createImportReference(packageName, start, end, false, ClassFileConstants.AccDefault);
172
				createImportReference(packageName, start, end, false);
173
		IImportDeclaration[] importDeclarations = topLevelTypeInfo.getHandle().getJavaScriptUnit().getImports();
173
		IImportDeclaration[] importDeclarations = topLevelTypeInfo.getHandle().getJavaScriptUnit().getImports();
174
		int importCount = importDeclarations.length;
174
		int importCount = importDeclarations.length;
175
		this.unit.imports = new ImportReference[importCount];
175
		this.unit.imports = new ImportReference[importCount];
Lines 181-188 Link Here
181
				Util.splitOn('.', nameWithoutStar, 0, nameWithoutStar.length()),
181
				Util.splitOn('.', nameWithoutStar, 0, nameWithoutStar.length()),
182
				sourceImport.getDeclarationSourceStart(),
182
				sourceImport.getDeclarationSourceStart(),
183
				sourceImport.getDeclarationSourceEnd(),
183
				sourceImport.getDeclarationSourceEnd(),
184
				importDeclaration.isOnDemand(),
184
				importDeclaration.isOnDemand());
185
				sourceImport.getModifiers());
186
		}
185
		}
187
		/* convert type(s) */
186
		/* convert type(s) */
188
		try {
187
		try {
Lines 668-675 Link Here
668
		String[] importName,
667
		String[] importName,
669
		int start,
668
		int start,
670
		int end,
669
		int end,
671
		boolean onDemand,
670
		boolean onDemand) {
672
		int modifiers) {
673
671
674
		int length = importName.length;
672
		int length = importName.length;
675
		long[] positions = new long[length];
673
		long[] positions = new long[length];
Lines 682-689 Link Here
682
		return new ImportReference(
680
		return new ImportReference(
683
			qImportName,
681
			qImportName,
684
			positions,
682
			positions,
685
			onDemand,
683
			onDemand);
686
			modifiers);
687
	}
684
	}
688
685
689
	private TypeParameter createTypeParameter(char[] typeParameterName, char[][] typeParameterBounds, int start, int end) {
686
	private TypeParameter createTypeParameter(char[] typeParameterName, char[][] typeParameterBounds, int start, int end) {
(-)src/org/eclipse/wst/jsdt/internal/compiler/parser/Parser.java (-91 / +4 lines)
Lines 4985-4991 Link Here
4985
		0,
4985
		0,
4986
		length);
4986
		length);
4987
4987
4988
	impt = new ImportReference(tokens, positions, true, ClassFileConstants.AccDefault);
4988
	impt = new ImportReference(tokens, positions, true);
4989
	this.compilationUnit.currentPackage = impt;
4989
	this.compilationUnit.currentPackage = impt;
4990
4990
4991
	if (this.currentToken == TokenNameSEMICOLON){
4991
	if (this.currentToken == TokenNameSEMICOLON){
Lines 5028-5045 Link Here
5028
		length);
5028
		length);
5029
5029
5030
	int packageModifiersSourceStart = this.intStack[this.intPtr--]; // we don't need the modifiers start
5030
	int packageModifiersSourceStart = this.intStack[this.intPtr--]; // we don't need the modifiers start
5031
	int packageModifiers = this.intStack[this.intPtr--];
5032
5031
5033
	impt = new ImportReference(tokens, positions, true, packageModifiers);
5032
	impt = new ImportReference(tokens, positions, true);
5034
	this.compilationUnit.currentPackage = impt;
5033
	this.compilationUnit.currentPackage = impt;
5035
	// consume annotations
5034
	// consume annotations
5036
	if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
5035
	if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
5037
		System.arraycopy(
5038
			this.expressionStack,
5039
			(this.expressionPtr -= length) + 1,
5040
			impt.annotations = new Annotation[length],
5041
			0,
5042
			length);
5043
		impt.declarationSourceStart = packageModifiersSourceStart;
5036
		impt.declarationSourceStart = packageModifiersSourceStart;
5044
		intPtr--; // we don't need the position of the 'package keyword
5037
		intPtr--; // we don't need the position of the 'package keyword
5045
	} else {
5038
	} else {
Lines 6496-6542 Link Here
6496
	}
6489
	}
6497
	this.recordStringLiterals = true;
6490
	this.recordStringLiterals = true;
6498
}
6491
}
6499
protected void consumeSingleStaticImportDeclarationName() {
6500
	// SingleTypeImportDeclarationName ::= 'import' 'static' Name
6501
	/* push an ImportRef build from the last name
6502
	stored in the identifier stack. */
6503
6492
6504
	ImportReference impt;
6505
	int length;
6506
	char[][] tokens = new char[length = this.identifierLengthStack[this.identifierLengthPtr--]][];
6507
	this.identifierPtr -= length;
6508
	long[] positions = new long[length];
6509
	System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length);
6510
	System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length);
6511
	pushOnAstStack(impt = new ImportReference(tokens, positions, false, ClassFileConstants.AccStatic));
6512
6513
	this.modifiers = ClassFileConstants.AccDefault;
6514
	this.modifiersSourceStart = -1; // <-- see comment into modifiersFlag(int)
6515
6516
	if (this.currentToken == TokenNameSEMICOLON){
6517
		impt.declarationSourceEnd = this.scanner.currentPosition - 1;
6518
	} else {
6519
		impt.declarationSourceEnd = impt.sourceEnd;
6520
	}
6521
	impt.declarationEnd = impt.declarationSourceEnd;
6522
	//this.endPosition is just before the ;
6523
	impt.declarationSourceStart = this.intStack[this.intPtr--];
6524
6525
	if(!this.statementRecoveryActivated &&
6526
			this.options.sourceLevel < ClassFileConstants.JDK1_5 &&
6527
			this.lastErrorEndPositionBeforeRecovery < this.scanner.currentPosition) {
6528
		impt.modifiers = ClassFileConstants.AccDefault; // convert the static import reference to a non-static importe reference
6529
		this.problemReporter().invalidUsageOfStaticImports(impt);
6530
	}
6531
6532
	// recovery
6533
	if (this.currentElement != null){
6534
		this.lastCheckPoint = impt.declarationSourceEnd+1;
6535
		this.currentElement = this.currentElement.add(impt, 0);
6536
		this.lastIgnoredToken = -1;
6537
		this.restartRecovery = true; // used to avoid branching back into the regular automaton
6538
	}
6539
}
6540
protected void consumeSingleTypeImportDeclarationName() {
6493
protected void consumeSingleTypeImportDeclarationName() {
6541
	// SingleTypeImportDeclarationName ::= 'import' Name
6494
	// SingleTypeImportDeclarationName ::= 'import' Name
6542
	/* push an ImportRef build from the last name
6495
	/* push an ImportRef build from the last name
Lines 6549-6555 Link Here
6549
	long[] positions = new long[length];
6502
	long[] positions = new long[length];
6550
	System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length);
6503
	System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length);
6551
	System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length);
6504
	System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length);
6552
	pushOnAstStack(impt = new ImportReference(tokens, positions, false, ClassFileConstants.AccDefault));
6505
	pushOnAstStack(impt = new ImportReference(tokens, positions, false));
6553
6506
6554
	if (this.currentToken == TokenNameSEMICOLON){
6507
	if (this.currentToken == TokenNameSEMICOLON){
6555
		impt.declarationSourceEnd = this.scanner.currentPosition - 1;
6508
		impt.declarationSourceEnd = this.scanner.currentPosition - 1;
Lines 6855-6901 Link Here
6855
			this.intStack[this.intPtr--],
6808
			this.intStack[this.intPtr--],
6856
			this.endStatementPosition);
6809
			this.endStatementPosition);
6857
}
6810
}
6858
protected void consumeStaticImportOnDemandDeclarationName() {
6859
	// TypeImportOnDemandDeclarationName ::= 'import' 'static' Name '.' '*'
6860
	/* push an ImportRef build from the last name
6861
	stored in the identifier stack. */
6862
6863
	ImportReference impt;
6864
	int length;
6865
	char[][] tokens = new char[length = this.identifierLengthStack[this.identifierLengthPtr--]][];
6866
	this.identifierPtr -= length;
6867
	long[] positions = new long[length];
6868
	System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length);
6869
	System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length);
6870
	pushOnAstStack(impt = new ImportReference(tokens, positions, true, ClassFileConstants.AccStatic));
6871
6872
	this.modifiers = ClassFileConstants.AccDefault;
6873
	this.modifiersSourceStart = -1; // <-- see comment into modifiersFlag(int)
6874
6875
	if (this.currentToken == TokenNameSEMICOLON){
6876
		impt.declarationSourceEnd = this.scanner.currentPosition - 1;
6877
	} else {
6878
		impt.declarationSourceEnd = impt.sourceEnd;
6879
	}
6880
	impt.declarationEnd = impt.declarationSourceEnd;
6881
	//this.endPosition is just before the ;
6882
	impt.declarationSourceStart = this.intStack[this.intPtr--];
6883
6884
	if(!this.statementRecoveryActivated &&
6885
			options.sourceLevel < ClassFileConstants.JDK1_5 &&
6886
			this.lastErrorEndPositionBeforeRecovery < this.scanner.currentPosition) {
6887
		impt.modifiers = ClassFileConstants.AccDefault; // convert the static import reference to a non-static importe reference
6888
		this.problemReporter().invalidUsageOfStaticImports(impt);
6889
	}
6890
6811
6891
	// recovery
6892
	if (this.currentElement != null){
6893
		this.lastCheckPoint = impt.declarationSourceEnd+1;
6894
		this.currentElement = this.currentElement.add(impt, 0);
6895
		this.lastIgnoredToken = -1;
6896
		this.restartRecovery = true; // used to avoid branching back into the regular automaton
6897
	}
6898
}
6899
protected void consumeStaticInitializer() {
6812
protected void consumeStaticInitializer() {
6900
	// StaticInitializer ::=  StaticOnly Block
6813
	// StaticInitializer ::=  StaticOnly Block
6901
	//push an Initializer
6814
	//push an Initializer
Lines 7374-7380 Link Here
7374
	long[] positions = new long[length];
7287
	long[] positions = new long[length];
7375
	System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length);
7288
	System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length);
7376
	System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length);
7289
	System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length);
7377
	pushOnAstStack(impt = new ImportReference(tokens, positions, true, ClassFileConstants.AccDefault));
7290
	pushOnAstStack(impt = new ImportReference(tokens, positions, true));
7378
7291
7379
	if (this.currentToken == TokenNameSEMICOLON){
7292
	if (this.currentToken == TokenNameSEMICOLON){
7380
		impt.declarationSourceEnd = this.scanner.currentPosition - 1;
7293
		impt.declarationSourceEnd = this.scanner.currentPosition - 1;
(-)src/org/eclipse/wst/jsdt/internal/core/CompilationUnitStructureRequestor.java (-2 / +1 lines)
Lines 112-118 Link Here
112
/**
112
/**
113
 * @see ISourceElementRequestor
113
 * @see ISourceElementRequestor
114
 */
114
 */
115
public void acceptImport(int declarationStart, int declarationEnd, char[][] tokens, boolean onDemand, int modifiers) {
115
public void acceptImport(int declarationStart, int declarationEnd, char[][] tokens, boolean onDemand) {
116
	JavaElement parentHandle= (JavaElement) this.handleStack.peek();
116
	JavaElement parentHandle= (JavaElement) this.handleStack.peek();
117
	if (!(parentHandle.getElementType() == IJavaScriptElement.JAVASCRIPT_UNIT)) {
117
	if (!(parentHandle.getElementType() == IJavaScriptElement.JAVASCRIPT_UNIT)) {
118
		Assert.isTrue(false); // Should not happen
118
		Assert.isTrue(false); // Should not happen
Lines 135-141 Link Here
135
	ImportDeclarationElementInfo info = new ImportDeclarationElementInfo();
135
	ImportDeclarationElementInfo info = new ImportDeclarationElementInfo();
136
	info.setSourceRangeStart(declarationStart);
136
	info.setSourceRangeStart(declarationStart);
137
	info.setSourceRangeEnd(declarationEnd);
137
	info.setSourceRangeEnd(declarationEnd);
138
	info.setFlags(modifiers);
139
138
140
	addToChildren(this.importContainerInfo, handle);
139
	addToChildren(this.importContainerInfo, handle);
141
	this.newElements.put(handle, info);
140
	this.newElements.put(handle, info);
(-)src/org/eclipse/wst/jsdt/internal/core/SourceMapper.java (-2 / +1 lines)
Lines 224-231 Link Here
224
			int declarationStart,
224
			int declarationStart,
225
			int declarationEnd,
225
			int declarationEnd,
226
			char[][] tokens,
226
			char[][] tokens,
227
			boolean onDemand,
227
			boolean onDemand) {
228
			int modifiers) {
229
		char[][] imports = (char[][]) this.importsTable.get(this.binaryType);
228
		char[][] imports = (char[][]) this.importsTable.get(this.binaryType);
230
		int importsCounter;
229
		int importsCounter;
231
		if (imports == null) {
230
		if (imports == null) {
(-)src/org/eclipse/wst/jsdt/internal/core/BinaryTypeConverter.java (-1 / +1 lines)
Lines 50-56 Link Here
50
		char[][] packageName = Util.toCharArrays(pkg.names);
50
		char[][] packageName = Util.toCharArrays(pkg.names);
51
51
52
		if (packageName.length > 0) {
52
		if (packageName.length > 0) {
53
			compilationUnit.currentPackage = new ImportReference(packageName, new long[]{0}, false, ClassFileConstants.AccDefault);
53
			compilationUnit.currentPackage = new ImportReference(packageName, new long[]{0}, false);
54
		}
54
		}
55
55
56
		/* convert type */
56
		/* convert type */

Return to bug 262428