Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 153947 Details for
Bug 296998
Unused imports should not prevent execution
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
patch for ImportReference as ReferenceContext
bug_296998_patch1.txt (text/plain), 14.00 KB, created by
Stephan Herrmann
on 2009-12-07 13:40:23 EST
(
hide
)
Description:
patch for ImportReference as ReferenceContext
Filename:
MIME Type:
Creator:
Stephan Herrmann
Created:
2009-12-07 13:40:23 EST
Size:
14.00 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: compiler/org/eclipse/jdt/internal/compiler/ast/ImportReference.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ImportReference.java,v >retrieving revision 1.36 >diff -u -r1.36 ImportReference.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/ImportReference.java 7 Mar 2009 01:08:07 -0000 1.36 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/ImportReference.java 7 Dec 2009 18:14:43 -0000 >@@ -10,11 +10,14 @@ > *******************************************************************************/ > package org.eclipse.jdt.internal.compiler.ast; > >+import org.eclipse.jdt.core.compiler.CategorizedProblem; > import org.eclipse.jdt.internal.compiler.ASTVisitor; >+import org.eclipse.jdt.internal.compiler.CompilationResult; > import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; >+import org.eclipse.jdt.internal.compiler.impl.ReferenceContext; > import org.eclipse.jdt.internal.compiler.lookup.*; > >-public class ImportReference extends ASTNode { >+public class ImportReference extends ASTNode implements ReferenceContext { > > public char[][] tokens; > public long[] sourcePositions; //each entry is using the code : (start<<32) + end >@@ -23,12 +26,23 @@ > public int declarationSourceEnd; > public int modifiers; // 1.5 addition for static imports > public Annotation[] annotations; >+ public boolean ignoreFurtherInvestigation; >+ public CompilationUnitDeclaration declaringCompilationUnit; > > public ImportReference( > char[][] tokens, > long[] sourcePositions, > boolean onDemand, > int modifiers) { >+ this(tokens, sourcePositions, onDemand, modifiers, null); >+ } >+ >+ public ImportReference( >+ char[][] tokens, >+ long[] sourcePositions, >+ boolean onDemand, >+ int modifiers, >+ CompilationUnitDeclaration compilationUnit) { > > this.tokens = tokens; > this.sourcePositions = sourcePositions; >@@ -38,6 +52,7 @@ > this.sourceEnd = (int) (sourcePositions[sourcePositions.length-1] & 0x00000000FFFFFFFF); > this.sourceStart = (int) (sourcePositions[0] >>> 32); > this.modifiers = modifiers; >+ this.declaringCompilationUnit = compilationUnit; > } > > public boolean isStatic() { >@@ -75,4 +90,22 @@ > visitor.visit(this, scope); > visitor.endVisit(this, scope); > } >+ >+ public void abort(int abortLevel, CategorizedProblem problem) { >+ // note: must only be called on true import references which indeed have a non-null declaringCompilationUnit >+ this.declaringCompilationUnit.abort(abortLevel, problem); >+ } >+ >+ public CompilationResult compilationResult() { >+ // note: must only be called on true import references which indeed have a non-null declaringCompilationUnit >+ return this.declaringCompilationUnit.compilationResult(); >+ } >+ >+ public boolean hasErrors() { >+ return !this.ignoreFurtherInvestigation; >+ } >+ >+ public void tagAsHavingErrors() { >+ this.ignoreFurtherInvestigation = true; >+ } > } >Index: compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java,v >retrieving revision 1.410 >diff -u -r1.410 Parser.java >--- compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java 27 Nov 2009 17:51:16 -0000 1.410 >+++ compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java 7 Dec 2009 18:15:00 -0000 >@@ -6871,7 +6871,7 @@ > long[] positions = new long[length]; > System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length); > System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length); >- pushOnAstStack(impt = new ImportReference(tokens, positions, false, ClassFileConstants.AccStatic)); >+ pushOnAstStack(impt = new ImportReference(tokens, positions, false, ClassFileConstants.AccStatic, this.compilationUnit)); > > this.modifiers = ClassFileConstants.AccDefault; > this.modifiersSourceStart = -1; // <-- see comment into modifiersFlag(int) >@@ -6912,7 +6912,7 @@ > long[] positions = new long[length]; > System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length); > System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length); >- pushOnAstStack(impt = new ImportReference(tokens, positions, false, ClassFileConstants.AccDefault)); >+ pushOnAstStack(impt = new ImportReference(tokens, positions, false, ClassFileConstants.AccDefault, this.compilationUnit)); > > if (this.currentToken == TokenNameSEMICOLON){ > impt.declarationSourceEnd = this.scanner.currentPosition - 1; >@@ -7254,7 +7254,7 @@ > long[] positions = new long[length]; > System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length); > System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length); >- pushOnAstStack(impt = new ImportReference(tokens, positions, true, ClassFileConstants.AccStatic)); >+ pushOnAstStack(impt = new ImportReference(tokens, positions, true, ClassFileConstants.AccStatic, this.compilationUnit)); > > this.modifiers = ClassFileConstants.AccDefault; > this.modifiersSourceStart = -1; // <-- see comment into modifiersFlag(int) >@@ -7757,7 +7757,7 @@ > long[] positions = new long[length]; > System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length); > System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length); >- pushOnAstStack(impt = new ImportReference(tokens, positions, true, ClassFileConstants.AccDefault)); >+ pushOnAstStack(impt = new ImportReference(tokens, positions, true, ClassFileConstants.AccDefault, this.compilationUnit)); > > if (this.currentToken == TokenNameSEMICOLON){ > impt.declarationSourceEnd = this.scanner.currentPosition - 1; >Index: compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java,v >retrieving revision 1.402 >diff -u -r1.402 ProblemReporter.java >--- compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java 23 Nov 2009 16:45:35 -0000 1.402 >+++ compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java 7 Dec 2009 18:15:12 -0000 >@@ -7089,6 +7089,8 @@ > } > } > public void unusedImport(ImportReference importRef) { >+ if (importRef.declaringCompilationUnit != null) >+ this.referenceContext = importRef; > int severity = computeSeverity(IProblem.UnusedImport); > if (severity == ProblemSeverities.Ignore) return; > String[] arguments = new String[] { CharOperation.toString(importRef.tokens) }; >Index: model/org/eclipse/jdt/internal/compiler/SourceElementParser.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/compiler/SourceElementParser.java,v >retrieving revision 1.90 >diff -u -r1.90 SourceElementParser.java >--- model/org/eclipse/jdt/internal/compiler/SourceElementParser.java 28 Apr 2009 16:53:03 -0000 1.90 >+++ model/org/eclipse/jdt/internal/compiler/SourceElementParser.java 7 Dec 2009 18:15:14 -0000 >@@ -629,7 +629,7 @@ > long[] positions = new long[length]; > System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length); > System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length); >- pushOnAstStack(impt = new ImportReference(tokens, positions, true, ClassFileConstants.AccStatic)); >+ pushOnAstStack(impt = new ImportReference(tokens, positions, true, ClassFileConstants.AccStatic, this.compilationUnit)); > > this.modifiers = ClassFileConstants.AccDefault; > this.modifiersSourceStart = -1; // <-- see comment into modifiersFlag(int) >@@ -673,7 +673,7 @@ > long[] positions = new long[length]; > System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length); > System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length); >- pushOnAstStack(impt = new ImportReference(tokens, positions, true, ClassFileConstants.AccDefault)); >+ pushOnAstStack(impt = new ImportReference(tokens, positions, true, ClassFileConstants.AccDefault, this.compilationUnit)); > > if (this.currentToken == TokenNameSEMICOLON){ > impt.declarationSourceEnd = this.scanner.currentPosition - 1; >@@ -886,7 +886,7 @@ > return ref; > } > protected ImportReference newImportReference(char[][] tokens, long[] positions, boolean onDemand, int mod) { >- return new ImportReference(tokens, positions, onDemand, mod); >+ return new ImportReference(tokens, positions, onDemand, mod, this.compilationUnit); > } > protected QualifiedNameReference newQualifiedNameReference(char[][] tokens, long[] positions, int sourceStart, int sourceEnd) { > return new QualifiedNameReference(tokens, positions, sourceStart, sourceEnd); >Index: model/org/eclipse/jdt/internal/compiler/parser/SourceTypeConverter.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/compiler/parser/SourceTypeConverter.java,v >retrieving revision 1.65 >diff -u -r1.65 SourceTypeConverter.java >--- model/org/eclipse/jdt/internal/compiler/parser/SourceTypeConverter.java 17 Aug 2009 18:56:17 -0000 1.65 >+++ model/org/eclipse/jdt/internal/compiler/parser/SourceTypeConverter.java 7 Dec 2009 18:15:15 -0000 >@@ -129,7 +129,7 @@ > if (packageName.length > 0) > // if its null then it is defined in the default package > this.unit.currentPackage = >- createImportReference(packageName, start, end, false, ClassFileConstants.AccDefault); >+ createImportReference(packageName, start, end, false, ClassFileConstants.AccDefault, null); > IImportDeclaration[] importDeclarations = topLevelTypeInfo.getHandle().getCompilationUnit().getImports(); > int importCount = importDeclarations.length; > this.unit.imports = new ImportReference[importCount]; >@@ -142,7 +142,8 @@ > sourceImport.getDeclarationSourceStart(), > sourceImport.getDeclarationSourceEnd(), > importDeclaration.isOnDemand(), >- sourceImport.getModifiers()); >+ sourceImport.getModifiers(), >+ this.unit); > } > /* convert type(s) */ > try { >Index: model/org/eclipse/jdt/internal/compiler/parser/TypeConverter.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/compiler/parser/TypeConverter.java,v >retrieving revision 1.4 >diff -u -r1.4 TypeConverter.java >--- model/org/eclipse/jdt/internal/compiler/parser/TypeConverter.java 9 Sep 2008 14:53:17 -0000 1.4 >+++ model/org/eclipse/jdt/internal/compiler/parser/TypeConverter.java 7 Dec 2009 18:15:16 -0000 >@@ -17,6 +17,7 @@ > import org.eclipse.jdt.internal.compiler.ast.ASTNode; > import org.eclipse.jdt.internal.compiler.ast.ArrayQualifiedTypeReference; > import org.eclipse.jdt.internal.compiler.ast.ArrayTypeReference; >+import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; > import org.eclipse.jdt.internal.compiler.ast.ImportReference; > import org.eclipse.jdt.internal.compiler.ast.ParameterizedQualifiedTypeReference; > import org.eclipse.jdt.internal.compiler.ast.ParameterizedSingleTypeReference; >@@ -61,7 +62,8 @@ > int start, > int end, > boolean onDemand, >- int modifiers) { >+ int modifiers, >+ CompilationUnitDeclaration compilationUnit) { > > int length = importName.length; > long[] positions = new long[length]; >@@ -75,7 +77,8 @@ > qImportName, > positions, > onDemand, >- modifiers); >+ modifiers, >+ compilationUnit); > } > > protected TypeParameter createTypeParameter(char[] typeParameterName, char[][] typeParameterBounds, int start, int end) { >#P org.eclipse.jdt.core.tests.compiler >Index: src/org/eclipse/jdt/core/tests/compiler/regression/StaticImportTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/StaticImportTest.java,v >retrieving revision 1.75 >diff -u -r1.75 StaticImportTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/StaticImportTest.java 27 Aug 2009 15:26:58 -0000 1.75 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/StaticImportTest.java 7 Dec 2009 18:15:22 -0000 >@@ -10,6 +10,10 @@ > *******************************************************************************/ > package org.eclipse.jdt.core.tests.compiler.regression; > >+import java.util.Map; >+ >+import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; >+ > import junit.framework.Test; > > public class StaticImportTest extends AbstractComparableTest { >@@ -17,7 +21,7 @@ > // Static initializer to specify tests subset using TESTS_* static variables > // All specified tests which do not belong to the class are skipped... > static { >-// TESTS_NAMES = new String[] { "test036" }; >+// TESTS_NAMES = new String[] { "test075" }; > // TESTS_NUMBERS = new int[] { 46 }; > // TESTS_RANGE = new int[] { 169, 180 }; > } >@@ -2490,7 +2494,7 @@ > "----------\n"); > } > //https://bugs.eclipse.org/bugs/show_bug.cgi?id=256375 >- public void testONLY_073() { >+ public void test073() { > this.runNegativeTest( > new String[] { > "test/Outer.java", >@@ -2532,6 +2536,33 @@ > "}\n", > }, > ""); >- } >+ } >+ >+ public void test075() { >+ Map options = getCompilerOptions(); >+ options.put(CompilerOptions.OPTION_ReportUnusedImport, CompilerOptions.ERROR); >+ this.runNegativeTest( >+ true /* flush output directory */, >+ new String[] { >+ "test/ImportBug.java", >+ "package test;\n" + >+ "import java.util.List;\n" + >+ "public class ImportBug {\n" + >+ " public static void main(String[] args) {\n" + >+ " System.out.print(\"SUCCESS\");\n" + >+ " }\n" + >+ "}" >+ }, >+ null /* no class libraries */, >+ options, >+ "----------\n" + >+ "1. ERROR in test\\ImportBug.java (at line 2)\n" + >+ " import java.util.List;\n" + >+ " ^^^^^^^^^^^^^^\n" + >+ "The import java.util.List is never used\n" + >+ "----------\n", >+ "SUCCESS", >+ null, >+ JavacTestOptions.DEFAULT /* default javac test options */); >+ } > } >-
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 296998
: 153947 |
154493
|
154812