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

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/ast/ImportReference.java (-1 / +34 lines)
Lines 10-20 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.ast;
11
package org.eclipse.jdt.internal.compiler.ast;
12
12
13
import org.eclipse.jdt.core.compiler.CategorizedProblem;
13
import org.eclipse.jdt.internal.compiler.ASTVisitor;
14
import org.eclipse.jdt.internal.compiler.ASTVisitor;
15
import org.eclipse.jdt.internal.compiler.CompilationResult;
14
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
16
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
17
import org.eclipse.jdt.internal.compiler.impl.ReferenceContext;
15
import org.eclipse.jdt.internal.compiler.lookup.*;
18
import org.eclipse.jdt.internal.compiler.lookup.*;
16
19
17
public class ImportReference extends ASTNode {
20
public class ImportReference extends ASTNode implements ReferenceContext {
18
21
19
	public char[][] tokens;
22
	public char[][] tokens;
20
	public long[] sourcePositions; //each entry is using the code : (start<<32) + end
23
	public long[] sourcePositions; //each entry is using the code : (start<<32) + end
Lines 23-34 Link Here
23
	public int declarationSourceEnd;
26
	public int declarationSourceEnd;
24
	public int modifiers; // 1.5 addition for static imports
27
	public int modifiers; // 1.5 addition for static imports
25
	public Annotation[] annotations;
28
	public Annotation[] annotations;
29
	public boolean ignoreFurtherInvestigation;
30
	public CompilationUnitDeclaration declaringCompilationUnit;
26
31
27
	public ImportReference(
32
	public ImportReference(
28
			char[][] tokens,
33
			char[][] tokens,
29
			long[] sourcePositions,
34
			long[] sourcePositions,
30
			boolean onDemand,
35
			boolean onDemand,
31
			int modifiers) {
36
			int modifiers) {
37
		this(tokens, sourcePositions, onDemand, modifiers, null);
38
	}
39
	
40
	public ImportReference(
41
			char[][] tokens,
42
			long[] sourcePositions,
43
			boolean onDemand,
44
			int modifiers,
45
			CompilationUnitDeclaration compilationUnit) {
32
46
33
		this.tokens = tokens;
47
		this.tokens = tokens;
34
		this.sourcePositions = sourcePositions;
48
		this.sourcePositions = sourcePositions;
Lines 38-43 Link Here
38
		this.sourceEnd = (int) (sourcePositions[sourcePositions.length-1] & 0x00000000FFFFFFFF);
52
		this.sourceEnd = (int) (sourcePositions[sourcePositions.length-1] & 0x00000000FFFFFFFF);
39
		this.sourceStart = (int) (sourcePositions[0] >>> 32);
53
		this.sourceStart = (int) (sourcePositions[0] >>> 32);
40
		this.modifiers = modifiers;
54
		this.modifiers = modifiers;
55
		this.declaringCompilationUnit = compilationUnit;
41
	}
56
	}
42
57
43
	public boolean isStatic() {
58
	public boolean isStatic() {
Lines 75-78 Link Here
75
		visitor.visit(this, scope);
90
		visitor.visit(this, scope);
76
		visitor.endVisit(this, scope);
91
		visitor.endVisit(this, scope);
77
	}
92
	}
93
94
	public void abort(int abortLevel, CategorizedProblem problem) {
95
		// note: must only be called on true import references which indeed have a non-null declaringCompilationUnit
96
		this.declaringCompilationUnit.abort(abortLevel, problem);
97
	}
98
99
	public CompilationResult compilationResult() {
100
		// note: must only be called on true import references which indeed have a non-null declaringCompilationUnit
101
		return this.declaringCompilationUnit.compilationResult();
102
	}
103
104
	public boolean hasErrors() {
105
		return !this.ignoreFurtherInvestigation;
106
	}
107
108
	public void tagAsHavingErrors() {
109
		this.ignoreFurtherInvestigation = true;		
110
	}
78
}
111
}
(-)compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java (-4 / +4 lines)
Lines 6871-6877 Link Here
6871
	long[] positions = new long[length];
6871
	long[] positions = new long[length];
6872
	System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length);
6872
	System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length);
6873
	System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length);
6873
	System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length);
6874
	pushOnAstStack(impt = new ImportReference(tokens, positions, false, ClassFileConstants.AccStatic));
6874
	pushOnAstStack(impt = new ImportReference(tokens, positions, false, ClassFileConstants.AccStatic, this.compilationUnit));
6875
6875
6876
	this.modifiers = ClassFileConstants.AccDefault;
6876
	this.modifiers = ClassFileConstants.AccDefault;
6877
	this.modifiersSourceStart = -1; // <-- see comment into modifiersFlag(int)
6877
	this.modifiersSourceStart = -1; // <-- see comment into modifiersFlag(int)
Lines 6912-6918 Link Here
6912
	long[] positions = new long[length];
6912
	long[] positions = new long[length];
6913
	System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length);
6913
	System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length);
6914
	System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length);
6914
	System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length);
6915
	pushOnAstStack(impt = new ImportReference(tokens, positions, false, ClassFileConstants.AccDefault));
6915
	pushOnAstStack(impt = new ImportReference(tokens, positions, false, ClassFileConstants.AccDefault, this.compilationUnit));
6916
6916
6917
	if (this.currentToken == TokenNameSEMICOLON){
6917
	if (this.currentToken == TokenNameSEMICOLON){
6918
		impt.declarationSourceEnd = this.scanner.currentPosition - 1;
6918
		impt.declarationSourceEnd = this.scanner.currentPosition - 1;
Lines 7254-7260 Link Here
7254
	long[] positions = new long[length];
7254
	long[] positions = new long[length];
7255
	System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length);
7255
	System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length);
7256
	System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length);
7256
	System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length);
7257
	pushOnAstStack(impt = new ImportReference(tokens, positions, true, ClassFileConstants.AccStatic));
7257
	pushOnAstStack(impt = new ImportReference(tokens, positions, true, ClassFileConstants.AccStatic, this.compilationUnit));
7258
7258
7259
	this.modifiers = ClassFileConstants.AccDefault;
7259
	this.modifiers = ClassFileConstants.AccDefault;
7260
	this.modifiersSourceStart = -1; // <-- see comment into modifiersFlag(int)
7260
	this.modifiersSourceStart = -1; // <-- see comment into modifiersFlag(int)
Lines 7757-7763 Link Here
7757
	long[] positions = new long[length];
7757
	long[] positions = new long[length];
7758
	System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length);
7758
	System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length);
7759
	System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length);
7759
	System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length);
7760
	pushOnAstStack(impt = new ImportReference(tokens, positions, true, ClassFileConstants.AccDefault));
7760
	pushOnAstStack(impt = new ImportReference(tokens, positions, true, ClassFileConstants.AccDefault, this.compilationUnit));
7761
7761
7762
	if (this.currentToken == TokenNameSEMICOLON){
7762
	if (this.currentToken == TokenNameSEMICOLON){
7763
		impt.declarationSourceEnd = this.scanner.currentPosition - 1;
7763
		impt.declarationSourceEnd = this.scanner.currentPosition - 1;
(-)compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java (+2 lines)
Lines 7089-7094 Link Here
7089
	}
7089
	}
7090
}
7090
}
7091
public void unusedImport(ImportReference importRef) {
7091
public void unusedImport(ImportReference importRef) {
7092
	if (importRef.declaringCompilationUnit != null)
7093
		this.referenceContext = importRef;
7092
	int severity = computeSeverity(IProblem.UnusedImport);
7094
	int severity = computeSeverity(IProblem.UnusedImport);
7093
	if (severity == ProblemSeverities.Ignore) return;
7095
	if (severity == ProblemSeverities.Ignore) return;
7094
	String[] arguments = new String[] { CharOperation.toString(importRef.tokens) };
7096
	String[] arguments = new String[] { CharOperation.toString(importRef.tokens) };
(-)model/org/eclipse/jdt/internal/compiler/SourceElementParser.java (-3 / +3 lines)
Lines 629-635 Link Here
629
	long[] positions = new long[length];
629
	long[] positions = new long[length];
630
	System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length);
630
	System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length);
631
	System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length);
631
	System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length);
632
	pushOnAstStack(impt = new ImportReference(tokens, positions, true, ClassFileConstants.AccStatic));
632
	pushOnAstStack(impt = new ImportReference(tokens, positions, true, ClassFileConstants.AccStatic, this.compilationUnit));
633
633
634
	this.modifiers = ClassFileConstants.AccDefault;
634
	this.modifiers = ClassFileConstants.AccDefault;
635
	this.modifiersSourceStart = -1; // <-- see comment into modifiersFlag(int)
635
	this.modifiersSourceStart = -1; // <-- see comment into modifiersFlag(int)
Lines 673-679 Link Here
673
	long[] positions = new long[length];
673
	long[] positions = new long[length];
674
	System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length);
674
	System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length);
675
	System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length);
675
	System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length);
676
	pushOnAstStack(impt = new ImportReference(tokens, positions, true, ClassFileConstants.AccDefault));
676
	pushOnAstStack(impt = new ImportReference(tokens, positions, true, ClassFileConstants.AccDefault, this.compilationUnit));
677
677
678
	if (this.currentToken == TokenNameSEMICOLON){
678
	if (this.currentToken == TokenNameSEMICOLON){
679
		impt.declarationSourceEnd = this.scanner.currentPosition - 1;
679
		impt.declarationSourceEnd = this.scanner.currentPosition - 1;
Lines 886-892 Link Here
886
	return ref;
886
	return ref;
887
}
887
}
888
protected ImportReference newImportReference(char[][] tokens, long[] positions, boolean onDemand, int mod) {
888
protected ImportReference newImportReference(char[][] tokens, long[] positions, boolean onDemand, int mod) {
889
	return new ImportReference(tokens, positions, onDemand, mod);
889
	return new ImportReference(tokens, positions, onDemand, mod, this.compilationUnit);
890
}
890
}
891
protected QualifiedNameReference newQualifiedNameReference(char[][] tokens, long[] positions, int sourceStart, int sourceEnd) {
891
protected QualifiedNameReference newQualifiedNameReference(char[][] tokens, long[] positions, int sourceStart, int sourceEnd) {
892
	return new QualifiedNameReference(tokens, positions, sourceStart, sourceEnd);
892
	return new QualifiedNameReference(tokens, positions, sourceStart, sourceEnd);
(-)model/org/eclipse/jdt/internal/compiler/parser/SourceTypeConverter.java (-2 / +3 lines)
Lines 129-135 Link Here
129
		if (packageName.length > 0)
129
		if (packageName.length > 0)
130
			// if its null then it is defined in the default package
130
			// if its null then it is defined in the default package
131
			this.unit.currentPackage =
131
			this.unit.currentPackage =
132
				createImportReference(packageName, start, end, false, ClassFileConstants.AccDefault);
132
				createImportReference(packageName, start, end, false, ClassFileConstants.AccDefault, null);
133
		IImportDeclaration[] importDeclarations = topLevelTypeInfo.getHandle().getCompilationUnit().getImports();
133
		IImportDeclaration[] importDeclarations = topLevelTypeInfo.getHandle().getCompilationUnit().getImports();
134
		int importCount = importDeclarations.length;
134
		int importCount = importDeclarations.length;
135
		this.unit.imports = new ImportReference[importCount];
135
		this.unit.imports = new ImportReference[importCount];
Lines 142-148 Link Here
142
				sourceImport.getDeclarationSourceStart(),
142
				sourceImport.getDeclarationSourceStart(),
143
				sourceImport.getDeclarationSourceEnd(),
143
				sourceImport.getDeclarationSourceEnd(),
144
				importDeclaration.isOnDemand(),
144
				importDeclaration.isOnDemand(),
145
				sourceImport.getModifiers());
145
				sourceImport.getModifiers(),
146
				this.unit);
146
		}
147
		}
147
		/* convert type(s) */
148
		/* convert type(s) */
148
		try {
149
		try {
(-)model/org/eclipse/jdt/internal/compiler/parser/TypeConverter.java (-2 / +5 lines)
Lines 17-22 Link Here
17
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
17
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
18
import org.eclipse.jdt.internal.compiler.ast.ArrayQualifiedTypeReference;
18
import org.eclipse.jdt.internal.compiler.ast.ArrayQualifiedTypeReference;
19
import org.eclipse.jdt.internal.compiler.ast.ArrayTypeReference;
19
import org.eclipse.jdt.internal.compiler.ast.ArrayTypeReference;
20
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
20
import org.eclipse.jdt.internal.compiler.ast.ImportReference;
21
import org.eclipse.jdt.internal.compiler.ast.ImportReference;
21
import org.eclipse.jdt.internal.compiler.ast.ParameterizedQualifiedTypeReference;
22
import org.eclipse.jdt.internal.compiler.ast.ParameterizedQualifiedTypeReference;
22
import org.eclipse.jdt.internal.compiler.ast.ParameterizedSingleTypeReference;
23
import org.eclipse.jdt.internal.compiler.ast.ParameterizedSingleTypeReference;
Lines 61-67 Link Here
61
		int start,
62
		int start,
62
		int end,
63
		int end,
63
		boolean onDemand,
64
		boolean onDemand,
64
		int modifiers) {
65
		int modifiers,
66
		CompilationUnitDeclaration compilationUnit) {
65
67
66
		int length = importName.length;
68
		int length = importName.length;
67
		long[] positions = new long[length];
69
		long[] positions = new long[length];
Lines 75-81 Link Here
75
			qImportName,
77
			qImportName,
76
			positions,
78
			positions,
77
			onDemand,
79
			onDemand,
78
			modifiers);
80
			modifiers,
81
			compilationUnit);
79
	}
82
	}
80
83
81
	protected TypeParameter createTypeParameter(char[] typeParameterName, char[][] typeParameterBounds, int start, int end) {
84
	protected TypeParameter createTypeParameter(char[] typeParameterName, char[][] typeParameterBounds, int start, int end) {
(-)src/org/eclipse/jdt/core/tests/compiler/regression/StaticImportTest.java (-4 / +35 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.core.tests.compiler.regression;
11
package org.eclipse.jdt.core.tests.compiler.regression;
12
12
13
import java.util.Map;
14
15
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
16
13
import junit.framework.Test;
17
import junit.framework.Test;
14
18
15
public class StaticImportTest extends AbstractComparableTest {
19
public class StaticImportTest extends AbstractComparableTest {
Lines 17-23 Link Here
17
	// Static initializer to specify tests subset using TESTS_* static variables
21
	// Static initializer to specify tests subset using TESTS_* static variables
18
	// All specified tests which do not belong to the class are skipped...
22
	// All specified tests which do not belong to the class are skipped...
19
	static {
23
	static {
20
//		TESTS_NAMES = new String[] { "test036" };
24
//		TESTS_NAMES = new String[] { "test075" };
21
//		TESTS_NUMBERS = new int[] { 46 };
25
//		TESTS_NUMBERS = new int[] { 46 };
22
//		TESTS_RANGE = new int[] { 169, 180 };
26
//		TESTS_RANGE = new int[] { 169, 180 };
23
	}
27
	}
Lines 2490-2496 Link Here
2490
			"----------\n");
2494
			"----------\n");
2491
	}	
2495
	}	
2492
	//https://bugs.eclipse.org/bugs/show_bug.cgi?id=256375
2496
	//https://bugs.eclipse.org/bugs/show_bug.cgi?id=256375
2493
	public void testONLY_073() {
2497
	public void test073() {
2494
		this.runNegativeTest(
2498
		this.runNegativeTest(
2495
			new String[] {
2499
			new String[] {
2496
				"test/Outer.java",
2500
				"test/Outer.java",
Lines 2532-2537 Link Here
2532
				"}\n",
2536
				"}\n",
2533
			},
2537
			},
2534
			"");
2538
			"");
2535
	}		
2539
	}
2540
	
2541
	public void test075() {
2542
		Map options = getCompilerOptions();
2543
		options.put(CompilerOptions.OPTION_ReportUnusedImport, CompilerOptions.ERROR);
2544
		this.runNegativeTest(
2545
				true /* flush output directory */,
2546
				new String[] {
2547
						"test/ImportBug.java",
2548
						"package test;\n" +
2549
						"import java.util.List;\n" +
2550
						"public class ImportBug {\n" +
2551
						"	public static void main(String[] args) {\n" +
2552
						"		System.out.print(\"SUCCESS\");\n" +
2553
						"	}\n" +
2554
						"}"
2555
				},
2556
				null /* no class libraries */,
2557
				options, 
2558
				"----------\n" + 
2559
				"1. ERROR in test\\ImportBug.java (at line 2)\n" + 
2560
				"	import java.util.List;\n" + 
2561
				"	       ^^^^^^^^^^^^^^\n" + 
2562
				"The import java.util.List is never used\n" + 
2563
				"----------\n", 
2564
				"SUCCESS", 
2565
				null, 
2566
				JavacTestOptions.DEFAULT /* default javac test options */);
2567
	}
2536
}
2568
}
2537

Return to bug 296998