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 189521 Details for
Bug 337868
[compiler][model] incomplete support for package-info.java when using SearchableEnvironment
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
tests and proposed fixes
Bug_337868_v1.patch (text/plain), 12.69 KB, created by
Stephan Herrmann
on 2011-02-22 13:00:16 EST
(
hide
)
Description:
tests and proposed fixes
Filename:
MIME Type:
Creator:
Stephan Herrmann
Created:
2011-02-22 13:00:16 EST
Size:
12.69 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: compiler/org/eclipse/jdt/internal/compiler/Compiler.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/Compiler.java,v >retrieving revision 1.117 >diff -u -r1.117 Compiler.java >--- compiler/org/eclipse/jdt/internal/compiler/Compiler.java 16 Nov 2010 14:08:54 -0000 1.117 >+++ compiler/org/eclipse/jdt/internal/compiler/Compiler.java 22 Feb 2011 17:56:55 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2010 IBM Corporation and others. >+ * Copyright (c) 2000, 2011 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -352,6 +352,9 @@ > ICompilationUnit sourceUnit, > CompilationUnitDeclaration parsedUnit) { > >+ if (this.unitsToProcess == null) >+ return; // not collecting units >+ > // append the unit to the list of ones to process later on > int size = this.unitsToProcess.length; > if (this.totalUnits == size) >@@ -876,8 +879,18 @@ > // build and record parsed units > this.parseThreshold = 0; // will request a full parse > beginToCompile(new ICompilationUnit[] { sourceUnit }); >- // process all units (some more could be injected in the loop by the lookup environment) >- unit = this.unitsToProcess[0]; >+ // find the right unit from what was injected via accept(ICompilationUnit,..): >+ for (int i=0; i<this.totalUnits; i++) { >+ if ( this.unitsToProcess[i] != null >+ && this.unitsToProcess[i].compilationResult.compilationUnit == sourceUnit) >+ { >+ unit = this.unitsToProcess[i]; >+ break; >+ } >+ } >+ if (unit == null) >+ unit = this.unitsToProcess[0]; // fall back to old behavior >+ > } else { > // initial type binding creation > this.lookupEnvironment.buildTypeBindings(unit, null /*no access restriction*/); >Index: compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java,v >retrieving revision 1.112 >diff -u -r1.112 LookupEnvironment.java >--- compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java 16 Feb 2011 07:56:50 -0000 1.112 >+++ compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java 22 Feb 2011 17:56:58 -0000 >@@ -24,6 +24,7 @@ > import org.eclipse.jdt.internal.compiler.env.*; > import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; > import org.eclipse.jdt.internal.compiler.impl.ITypeRequestor; >+import org.eclipse.jdt.internal.compiler.problem.AbortCompilation; > import org.eclipse.jdt.internal.compiler.problem.ProblemReporter; > import org.eclipse.jdt.internal.compiler.util.HashtableOfPackage; > import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable; >@@ -136,7 +137,13 @@ > this.typeRequestor.accept(answer.getBinaryType(), packageBinding, answer.getAccessRestriction()); > } else if (answer.isCompilationUnit()) { > // the type was found as a .java file, try to build it then search the cache >- this.typeRequestor.accept(answer.getCompilationUnit(), answer.getAccessRestriction()); >+ try { >+ this.typeRequestor.accept(answer.getCompilationUnit(), answer.getAccessRestriction()); >+ } catch (AbortCompilation abort) { >+ if (CharOperation.equals(name, TypeConstants.PACKAGE_INFO_NAME)) >+ return null; // silently, requestor may not be able to handle compilation units (HierarchyResolver) >+ throw abort; >+ } > } else if (answer.isSourceType()) { > // the type was found as a source model > this.typeRequestor.accept(answer.getSourceTypes(), packageBinding, answer.getAccessRestriction()); >Index: model/org/eclipse/jdt/internal/core/SearchableEnvironment.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SearchableEnvironment.java,v >retrieving revision 1.77 >diff -u -r1.77 SearchableEnvironment.java >--- model/org/eclipse/jdt/internal/core/SearchableEnvironment.java 9 Jul 2009 10:31:38 -0000 1.77 >+++ model/org/eclipse/jdt/internal/core/SearchableEnvironment.java 22 Feb 2011 17:56:58 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2009 IBM Corporation and others. >+ * Copyright (c) 2000, 2011 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -22,6 +22,7 @@ > import org.eclipse.jdt.internal.compiler.env.INameEnvironment; > import org.eclipse.jdt.internal.compiler.env.ISourceType; > import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer; >+import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; > import org.eclipse.jdt.internal.core.search.BasicSearchEngine; > import org.eclipse.jdt.internal.core.search.IRestrictedAccessConstructorRequestor; > import org.eclipse.jdt.internal.core.search.IRestrictedAccessTypeRequestor; >@@ -134,8 +135,13 @@ > sourceTypes[index++] = otherType; > } > return new NameEnvironmentAnswer(sourceTypes, answer.restriction); >- } catch (JavaModelException npe) { >- // fall back to using owner >+ } catch (JavaModelException jme) { >+ if (String.valueOf(TypeConstants.PACKAGE_INFO_NAME).equals(typeName)) { >+ // in case of package-info.java the type doesn't exist in the model, >+ // but the CU may still help in order to fetch package level annotations. >+ return new NameEnvironmentAnswer((ICompilationUnit)answer.type.getParent(), answer.restriction); >+ } >+ // no usable answer > } > } > } >#P org.eclipse.jdt.core.tests.model >Index: src/org/eclipse/jdt/core/tests/model/CompilationUnitTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompilationUnitTests.java,v >retrieving revision 1.72 >diff -u -r1.72 CompilationUnitTests.java >--- src/org/eclipse/jdt/core/tests/model/CompilationUnitTests.java 20 Jul 2010 20:23:18 -0000 1.72 >+++ src/org/eclipse/jdt/core/tests/model/CompilationUnitTests.java 22 Feb 2011 17:57:04 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2010 IBM Corporation and others. >+ * Copyright (c) 2000, 2011 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -23,6 +23,9 @@ > import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.IProgressMonitor; > import org.eclipse.jdt.core.*; >+import org.eclipse.jdt.core.compiler.IProblem; >+import org.eclipse.jdt.core.dom.AST; >+import org.eclipse.jdt.core.dom.ASTParser; > import org.eclipse.jdt.core.dom.rewrite.ImportRewrite; > import org.eclipse.jdt.internal.core.Buffer; > import org.eclipse.jdt.internal.core.CompilationUnit; >@@ -478,6 +481,46 @@ > } > > /* >+ * Bug 337868 - [compiler][model] incomplete support for package-info.java when using SearchableEnvironment >+ * Ensure that package level annotation is evaluated during AST creation. >+ */ >+public void testDeprecatedFlag10() throws CoreException { >+ createFolder("/P/src/p2"); >+ >+ createFile( >+ "/P/src/p2/package-info.java", >+ "@java.lang.Deprecated package p2;\n" >+ ); >+ >+ // workaround for missing type in jclMin: >+ createFolder("/P/src/java/lang"); >+ createFile( >+ "/P/src/java/lang/Deprecated.java", >+ "package java.lang;\n" + >+ "@Retention(RetentionPolicy.RUNTIME)\n" + >+ "public @interface Deprecated {\n" + >+ "}\n" >+ ); >+ >+ createFile("/P/src/p2/C.java", >+ "package p2;\n" + >+ "public class C {}\n"); >+ >+ createFile("/P/src/p/D.java", >+ "package p;\n" + >+ "public class D extends p2.C {}\n"); >+ ICompilationUnit cuD = getCompilationUnit("/P/src/p/D.java"); >+ >+ ASTParser parser = ASTParser.newParser(AST.JLS3); >+ parser.setProject(this.testProject); >+ parser.setSource(cuD); >+ parser.setResolveBindings(true); >+ org.eclipse.jdt.core.dom.CompilationUnit cuAST = (org.eclipse.jdt.core.dom.CompilationUnit) parser.createAST(null); >+ IProblem[] problems = cuAST.getProblems(); >+ assertEquals("Should have 1 problem", 1, problems.length); >+ assertEquals("Should have a deprecation warning", "The type C is deprecated", problems[0].getMessage()); >+} >+/* > * Ensures that the primary type of a cu can be found. > */ > public void testFindPrimaryType1() throws JavaModelException { >Index: src/org/eclipse/jdt/core/tests/model/ReconcilerTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests.java,v >retrieving revision 1.165 >diff -u -r1.165 ReconcilerTests.java >--- src/org/eclipse/jdt/core/tests/model/ReconcilerTests.java 21 Feb 2011 00:53:28 -0000 1.165 >+++ src/org/eclipse/jdt/core/tests/model/ReconcilerTests.java 22 Feb 2011 17:57:11 -0000 >@@ -772,6 +772,40 @@ > annotation.discardWorkingCopy(); > } > } >+ >+/* >+ * Bug 337868 - [compiler][model] incomplete support for package-info.java when using SearchableEnvironment >+ * Ensures that an annotated package-info.java doesn't confuse the reconciler. >+ */ >+public void testAnnotations6() throws CoreException { >+ >+ createFolder("/Reconciler15/src/p1"); >+ >+ createFile("/Reconciler15/src/p1/package-info.java", "@java.lang.Deprecated package p1;"); >+ createFile("/Reconciler15/src/p1/C.java", >+ "package p1;\n" + >+ "public class C {\n" + >+ " static class Y extends C {}\n" + >+ "}" >+ ); >+ ICompilationUnit myWC = getCompilationUnit("/Reconciler15/src/p1/C.java").getWorkingCopy(this.wcOwner, null); >+ org.eclipse.jdt.core.dom.CompilationUnit unit = myWC.reconcile(AST.JLS3, true, this.wcOwner, null); >+ assertProblems( >+ "Unexpected problems", >+ "----------\n" + >+ "----------\n" + >+ "----------\n" + >+ "----------\n" >+ ); >+ assertASTNodeEquals( >+ "Unexpected ast", >+ "package p1;\n" + >+ "public class C {\n" + >+ "static class Y extends C {\n" + >+ " }\n" + >+ "}\n", >+ unit); >+} > /* > * Ensures that the AST broadcasted during a reconcile operation is correct. > * (case of a working copy being reconciled with changes, creating AST and no problem detection) >Index: src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java,v >retrieving revision 1.98 >diff -u -r1.98 TypeHierarchyTests.java >--- src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java 29 Nov 2010 13:17:22 -0000 1.98 >+++ src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java 22 Feb 2011 17:57:14 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2010 IBM Corporation and others. >+ * Copyright (c) 2000, 2011 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -2518,4 +2518,40 @@ > deleteProject("P2"); > } > } >+// Bug 337868 - [compiler][model] incomplete support for package-info.java when using SearchableEnvironment >+// Ensure that package-info doesn't cause AbortCompilation from the HierarchyResolver. >+public void testPackageInfo01() throws CoreException { >+ try { >+ createJavaProject("P", new String[] {"src"}, new String[] {"JCL_LIB"}, new String[0], "bin"); >+ >+ createFolder("/P/src/p"); >+ createFile( >+ "/P/src/p/package-info.java", >+ "/** Doc comment*/ package p;\n" >+ ); >+ createFile( >+ "/P/src/p/A.java", >+ "package p;\n" + >+ "public class A {\n" + >+ "}\n" >+ ); >+ createFile( >+ "/P/src/p/C.java", >+ "package p;\n" + >+ "public class C extends A {\n" + >+ " void foo() {\n" + >+ " class Bar extends C {}\n" + >+ " }\n" + >+ "}\n" >+ ); >+ ICompilationUnit cu = getCompilationUnit("/P/src/p/C.java"); >+ IType type = cu.getType("C"); >+ IMethod method = type.getMethod("foo", new String[0]); >+ IType local = method.getType("Bar", 1); >+ ITypeHierarchy cHierarchy = type.newTypeHierarchy(null); >+ assertTrue("Local type should be in the hierarchy", cHierarchy.contains(local)); >+ } finally { >+ deleteProject("P"); >+ } >+} > }
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 337868
: 189521 |
189884