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 22704 Details for
Bug 76266
[plan][compiler] Access restriction should also apply to inherited members
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Tests - part added, part aligned according to the fix side effects - model
org.eclipse.jdt.core.tests.model_07.txt (text/plain), 19.39 KB, created by
Maxime Daniel
on 2005-06-09 11:37:47 EDT
(
hide
)
Description:
Tests - part added, part aligned according to the fix side effects - model
Filename:
MIME Type:
Creator:
Maxime Daniel
Created:
2005-06-09 11:37:47 EDT
Size:
19.39 KB
patch
obsolete
>Index: src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java,v >retrieving revision 1.141 >diff -u -r1.141 AbstractJavaModelTests.java >--- src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java 8 Jun 2005 09:03:20 -0000 1.141 >+++ src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java 9 Jun 2005 14:35:46 -0000 >@@ -52,7 +52,7 @@ > public static class ProblemRequestor implements IProblemRequestor { > public StringBuffer problems; > public int problemCount; >- private char[] unitSource; >+ protected char[] unitSource; > public ProblemRequestor() { > initialize(null); > } >Index: src/org/eclipse/jdt/core/tests/model/AllJavaModelTests.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AllJavaModelTests.java,v >retrieving revision 1.61 >diff -u -r1.61 AllJavaModelTests.java >--- src/org/eclipse/jdt/core/tests/model/AllJavaModelTests.java 6 May 2005 10:59:38 -0000 1.61 >+++ src/org/eclipse/jdt/core/tests/model/AllJavaModelTests.java 9 Jun 2005 14:35:46 -0000 >@@ -125,6 +125,9 @@ > // Inclusion patterns tests > InclusionPatternsTests.class, > >+ // Access restrictions tests >+ AccessRestrictionsTests.class, >+ > // Signature tests > SignatureTests.class, > >Index: src/org/eclipse/jdt/core/tests/model/ModifyingResourceTests.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ModifyingResourceTests.java,v >retrieving revision 1.39 >diff -u -r1.39 ModifyingResourceTests.java >--- src/org/eclipse/jdt/core/tests/model/ModifyingResourceTests.java 15 Apr 2005 08:27:55 -0000 1.39 >+++ src/org/eclipse/jdt/core/tests/model/ModifyingResourceTests.java 9 Jun 2005 14:35:46 -0000 >@@ -295,12 +295,20 @@ > for (int j = 0; j < ruleCount; j++) { > String rule = tokenizer.nextToken(); > int kind; >- if (rule.charAt(0) == '+') { >- kind = IAccessRule.K_ACCESSIBLE; >- } else { >- kind = IAccessRule.K_NON_ACCESSIBLE; >- nonAccessibleRules++; >+ switch (rule.charAt(0)) { >+ case '+': >+ kind = IAccessRule.K_ACCESSIBLE; >+ break; >+ case '~': >+ kind = IAccessRule.K_DISCOURAGED; >+ break; >+ case '-': >+ default: // TODO consider forbidding unspecified rule start; this one tolerates >+ // shortcuts that only specify a path matching pattern >+ kind = IAccessRule.K_NON_ACCESSIBLE; >+ break; > } >+ nonAccessibleRules++; > accessRules[j] = JavaCore.newAccessRule(new Path(rule.substring(1)), kind); > } > >Index: src/org/eclipse/jdt/core/tests/model/ReconcilerTests.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests.java,v >retrieving revision 1.65 >diff -u -r1.65 ReconcilerTests.java >--- src/org/eclipse/jdt/core/tests/model/ReconcilerTests.java 8 Jun 2005 09:03:20 -0000 1.65 >+++ src/org/eclipse/jdt/core/tests/model/ReconcilerTests.java 9 Jun 2005 14:35:47 -0000 >@@ -1804,15 +1804,10 @@ > "----------\n" + > "1. WARNING in /Reconciler15/src/Y.java (at line 1)\n" + > " public class Y extends X {\n" + >- " ^\n" + >- "The constructor X() is deprecated\n" + >- "----------\n" + >- "2. WARNING in /Reconciler15/src/Y.java (at line 1)\n" + >- " public class Y extends X {\n" + > " ^\n" + > "The type X is deprecated\n" + > "----------\n" + >- "3. ERROR in /Reconciler15/src/Y.java (at line 4)\n" + >+ "2. ERROR in /Reconciler15/src/Y.java (at line 4)\n" + > " Zork z;\n" + > " ^^^^\n" + > "Zork cannot be resolved to a type\n" + >Index: src/org/eclipse/jdt/core/tests/model/AccessRestrictionsTests.java >=================================================================== >RCS file: src/org/eclipse/jdt/core/tests/model/AccessRestrictionsTests.java >diff -N src/org/eclipse/jdt/core/tests/model/AccessRestrictionsTests.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jdt/core/tests/model/AccessRestrictionsTests.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,483 @@ >+/******************************************************************************* >+ * Copyright (c) 2000, 2005 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 >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.jdt.core.tests.model; >+ >+ >+import junit.framework.Test; >+ >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.jdt.core.*; >+import org.eclipse.jdt.core.compiler.IProblem; >+ >+public class AccessRestrictionsTests extends ModifyingResourceTests { >+ static class ProblemRequestor extends AbstractJavaModelTests.ProblemRequestor { >+ ProblemRequestor (String source) { >+ if (source != null) >+ unitSource = source.toCharArray(); >+ } >+ ProblemRequestor() { >+ } >+ public void acceptProblem(IProblem problem) { >+ super.acceptProblem(problem); >+ } >+ } >+ >+ protected ProblemRequestor problemRequestor; >+ >+ public AccessRestrictionsTests(String name) { >+ super(name); >+ } >+ >+ // Use this static initializer to specify subset for tests >+ // All specified tests which do not belong to the class are skipped... >+ static { >+ // Names of tests to run, like "testXXX" >+ //TESTS_NAMES = new String[] { "test004" }; >+ // Numbers of tests to run: "test<number>" will be run for each number of this array >+ //TESTS_NUMBERS = new int[] { 1 }; >+ // Range numbers of tests to run: all tests between "test<first>" and "test<last>" will be run for { first, last } >+ //TESTS_RANGE = new int[] { 16, -1 }; >+ } >+ >+ public static Test suite() { >+ return buildTestSuite(AccessRestrictionsTests.class); >+ } >+ >+ protected void assertProblems(String message, String expected) { >+ assertProblems(message, expected, this.problemRequestor); >+ } >+ >+/* >+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=76266 >+ * Ensures that a problem is created for a reference to a member of a type that is not >+ * accessible in a prereq project, even though it is accessed through an intermediate >+ * accessible mother class. >+ * Checking methods. >+ */ >+public void test001() throws CoreException { >+ ICompilationUnit x1 = null, x2 = null, y = null, z = null; >+ try { >+ WorkingCopyOwner owner = new WorkingCopyOwner(){}; >+ createJavaProject( >+ "P1", >+ new String[] {"src"}, >+ new String[] {"JCL_LIB"}, >+ "bin"); >+ this.problemRequestor = new ProblemRequestor(); >+ x1 = getWorkingCopy( >+ "/P1/src/p/X1.java", >+ "package p;\n" + >+ "public class X1 {\n" + >+ " void foo() {\n" + >+ " }\n" + >+ "}", >+ owner, >+ this.problemRequestor); >+ assertProblems( >+ "Unexpected problems", >+ "----------\n----------\n----------\n----------\n" >+ ); >+ this.problemRequestor = new ProblemRequestor(); >+ x2 = getWorkingCopy( >+ "/P1/src/p/X2.java", >+ "package p;\n" + >+ "public class X2 extends X1 {\n" + >+ " void bar() {\n" + >+ " }\n" + >+ "}", owner, >+ this.problemRequestor); >+ assertProblems( >+ "Unexpected problems", >+ "----------\n----------\n----------\n----------\n" >+ ); >+ IJavaProject p2 = createJavaProject("P2", new String[] {"src"}, >+ new String[] {"JCL_LIB"}, "bin"); >+ IClasspathEntry[] classpath = p2.getRawClasspath(); >+ int length = classpath.length; >+ System.arraycopy(classpath, 0, classpath = new IClasspathEntry[length+1], 0, length); >+ classpath[length] = createSourceEntry("P2", "/P1", "-p/X1"); >+ p2.setRawClasspath(classpath, null); >+ // check the most basic case >+ String src = >+ "package p;\n" + >+ "public class Z extends X1 {\n" + >+ "}"; >+ this.problemRequestor = new ProblemRequestor(src); >+ z = getWorkingCopy( >+ "/P2/src/p/Z.java", >+ src, >+ owner, >+ this.problemRequestor); >+ assertProblems( >+ "Unexpected problems value", >+ "----------\n----------\n----------\n" + >+ "1. ERROR in /P2/src/p/Z.java (at line 2)\n" + >+ " public class Z extends X1 {\n" + >+ " ^^\n" + >+ "Access restriction: The type X1 is not accessible due to restriction on required project P1\n" + >+ "----------\n" >+ ); >+ // check the specifics of this test case >+ src = >+ "package p;\n" + >+ "public class Y extends X2 {\n" + >+ " void foobar() {\n" + >+ " foo(); // accesses X1.foo, should trigger an error\n" + >+ " bar(); // accesses X2.bar, OK\n" + >+ " }\n" + >+ "}"; >+ this.problemRequestor = new ProblemRequestor(src); >+ y = getWorkingCopy( >+ "/P2/src/p/Y.java", >+ src, >+ owner, >+ this.problemRequestor); >+ assertProblems( >+ "Unexpected problems value", >+ "----------\n" + >+ "----------\n" + >+ "----------\n" + >+ "1. ERROR in /P2/src/p/Y.java (at line 4)\n" + >+ " foo(); // accesses X1.foo, should trigger an error\n" + >+ " ^^^^^\n" + >+ "Access restriction: The method foo() from the type X1 is not accessible due to restriction on required project P1\n" + >+ "----------\n" >+ ); >+ } finally { >+ if (x1 != null) >+ x1.discardWorkingCopy(); >+ if (x2 != null) >+ x2.discardWorkingCopy(); >+ if (y != null) >+ y.discardWorkingCopy(); >+ if (z != null) >+ z.discardWorkingCopy(); >+ deleteProjects(new String[] {"P1", "P2"}); >+ } >+} >+ >+/* >+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=76266 >+ * Ensures that a problem is created for a reference to a member of a type that is not >+ * accessible in a prereq project, even though it is accessed through an intermediate >+ * accessible mother class. >+ * Checking members. >+ */ >+public void test002() throws CoreException { >+ ICompilationUnit x1 = null, x2 = null, y = null, z = null; >+ try { >+ WorkingCopyOwner owner = new WorkingCopyOwner(){}; >+ createJavaProject( >+ "P1", >+ new String[] {"src"}, >+ new String[] {"JCL_LIB"}, >+ "bin"); >+ this.problemRequestor = new ProblemRequestor(); >+ x1 = getWorkingCopy( >+ "/P1/src/p/X1.java", >+ "package p;\n" + >+ "public class X1 {\n" + >+ " int m1;\n" + >+ "}", >+ owner, >+ this.problemRequestor); >+ assertProblems( >+ "Unexpected problems", >+ "----------\n----------\n----------\n----------\n" >+ ); >+ this.problemRequestor = new ProblemRequestor(); >+ x2 = getWorkingCopy( >+ "/P1/src/p/X2.java", >+ "package p;\n" + >+ "public class X2 extends X1 {\n" + >+ " char m2;\n" + >+ "}", >+ owner, >+ this.problemRequestor); >+ assertProblems( >+ "Unexpected problems", >+ "----------\n----------\n----------\n----------\n" >+ ); >+ IJavaProject p2 = createJavaProject("P2", new String[] {"src"}, >+ new String[] {"JCL_LIB"}, "bin"); >+ IClasspathEntry[] classpath = p2.getRawClasspath(); >+ int length = classpath.length; >+ System.arraycopy(classpath, 0, classpath = new IClasspathEntry[length+1], 0, length); >+ classpath[length] = createSourceEntry("P2", "/P1", "-p/X1"); >+ p2.setRawClasspath(classpath, null); >+ // check the most basic case >+ String src = >+ "package p;\n" + >+ "public class Z extends X1 {\n" + >+ "}"; >+ this.problemRequestor = new ProblemRequestor(src); >+ z = getWorkingCopy( >+ "/P2/src/p/Z.java", >+ src, >+ owner, >+ this.problemRequestor); >+ assertProblems( >+ "Unexpected problems value", >+ "----------\n----------\n----------\n" + >+ "1. ERROR in /P2/src/p/Z.java (at line 2)\n" + >+ " public class Z extends X1 {\n" + >+ " ^^\n" + >+ "Access restriction: The type X1 is not accessible due to restriction on required project P1\n" + >+ "----------\n" >+ ); >+ // check the specifics of this test case >+ src = >+ "package p;\n" + >+ "public class Y extends X2 {\n" + >+ " void foobar() {\n" + >+ " int l1 = m1; // accesses X1.m1, should trigger an error\n" + >+ " char l2 = m2; // accesses X2.m2, OK\n" + >+ " }\n" + >+ "}"; >+ this.problemRequestor = new ProblemRequestor(src); >+ y = getWorkingCopy( >+ "/P2/src/p/Y.java", >+ src, >+ owner, >+ this.problemRequestor); >+ assertProblems( >+ "Unexpected problems value", >+ "----------\n" + >+ "----------\n" + >+ "----------\n" + >+ "1. ERROR in /P2/src/p/Y.java (at line 4)\n" + >+ " int l1 = m1; // accesses X1.m1, should trigger an error\n" + >+ " ^^\n" + >+ "Access restriction: The field m1 from the type X1 is not accessible due to restriction on required project P1\n" + >+ "----------\n" >+ ); >+ } finally { >+ if (x1 != null) >+ x1.discardWorkingCopy(); >+ if (x2 != null) >+ x2.discardWorkingCopy(); >+ if (y != null) >+ y.discardWorkingCopy(); >+ if (z != null) >+ z.discardWorkingCopy(); >+ deleteProjects(new String[] {"P1", "P2"}); >+ } >+} >+ >+/* >+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=76266 >+ * Ensures that a problem is created for a reference to a member of a type that is not >+ * accessible in a prereq project, even though it is accessed through an intermediate >+ * accessible mother class. >+ * Checking member types. >+ */ >+public void test003() throws CoreException { >+ ICompilationUnit x1 = null, x2 = null, y = null, z = null; >+ try { >+ WorkingCopyOwner owner = new WorkingCopyOwner(){}; >+ createJavaProject( >+ "P1", >+ new String[] {"src"}, >+ new String[] {"JCL_LIB"}, >+ "bin"); >+ this.problemRequestor = new ProblemRequestor(); >+ x1 = getWorkingCopy( >+ "/P1/src/p/X1.java", >+ "package p;\n" + >+ "public class X1 {\n" + >+ " class C1 {\n" + >+ " protected C1 (int dummy) {}\n" + >+ " protected void foo() {}\n" + >+ " }\n" + >+ " interface I1 {}\n" + >+ "}", >+ owner, >+ this.problemRequestor); >+ assertProblems( >+ "Unexpected problems", >+ "----------\n----------\n----------\n----------\n" >+ ); >+ this.problemRequestor = new ProblemRequestor(); >+ x2 = getWorkingCopy( >+ "/P1/src/p/X2.java", >+ "package p;\n" + >+ "public class X2 extends X1 {\n" + >+ " class C2 {}\n" + >+ " interface I2 {}\n" + >+ "}", >+ owner, >+ this.problemRequestor); >+ assertProblems( >+ "Unexpected problems", >+ "----------\n----------\n----------\n----------\n" >+ ); >+ IJavaProject p2 = createJavaProject("P2", new String[] {"src"}, >+ new String[] {"JCL_LIB"}, "bin"); >+ IClasspathEntry[] classpath = p2.getRawClasspath(); >+ int length = classpath.length; >+ System.arraycopy(classpath, 0, classpath = new IClasspathEntry[length+1], 0, length); >+ classpath[length] = createSourceEntry("P2", "/P1", "-p/X1"); >+ p2.setRawClasspath(classpath, null); >+ // check the most basic case >+ String src = >+ "package p;\n" + >+ "public class Z extends X1 {\n" + >+ "}"; >+ this.problemRequestor = new ProblemRequestor(src); >+ z = getWorkingCopy( >+ "/P2/src/p/Z.java", >+ src, >+ owner, >+ this.problemRequestor); >+ assertProblems( >+ "Unexpected problems value", >+ "----------\n----------\n----------\n" + >+ "1. ERROR in /P2/src/p/Z.java (at line 2)\n" + >+ " public class Z extends X1 {\n" + >+ " ^^\n" + >+ "Access restriction: The type X1 is not accessible due to restriction on required project P1\n" + >+ "----------\n" >+ ); >+ // check the specifics of this test case >+ src = >+ "package p;\n" + >+ "public class Y extends X2 {\n" + >+ " class C3a extends C1 { // error\n" + >+ " C3a() {\n" + >+ " super(0);\n" + >+ " foo(); // error\n" + >+ " }\n" + >+ " }\n" + >+ " class C3c extends C2 implements I2 {}\n" + >+ " void foobar() {\n" + >+ " C1 m1 = // error\n" + >+ " new C1(0); // error\n" + >+ " C2 m2 = new C2();\n" + >+ " }\n" + >+ "}"; >+ this.problemRequestor = new ProblemRequestor(src); >+ y = getWorkingCopy( >+ "/P2/src/p/Y.java", >+ src, >+ owner, >+ this.problemRequestor); >+ assertProblems( >+ "Unexpected problems value", >+ "----------\n" + >+ "----------\n" + >+ "----------\n" + >+ "1. ERROR in /P2/src/p/Y.java (at line 3)\n" + >+ " class C3a extends C1 { // error\n" + >+ " ^^\n" + >+ "Access restriction: The type X1.C1 is not accessible due to restriction on required project P1\n" + >+ "----------\n" + >+ "2. ERROR in /P2/src/p/Y.java (at line 5)\n" + >+ " super(0);\n" + >+ " ^^^^^^^^\n" + >+ "Access restriction: The constructor X1.C1(int) is not accessible due to restriction on required project P1\n" + >+ "----------\n" + >+ "3. ERROR in /P2/src/p/Y.java (at line 6)\n" + >+ " foo(); // error\n" + >+ " ^^^^^\n" + >+ "Access restriction: The method foo() from the type X1.C1 is not accessible due to restriction on required project P1\n" + >+ "----------\n" + >+ "4. ERROR in /P2/src/p/Y.java (at line 11)\n" + >+ " C1 m1 = // error\n" + >+ " ^^\n" + >+ "Access restriction: The type X1.C1 is not accessible due to restriction on required project P1\n" + >+ "----------\n" + >+ "5. ERROR in /P2/src/p/Y.java (at line 12)\n" + >+ " new C1(0); // error\n" + >+ " ^^^^^^^^^\n" + >+ "Access restriction: The constructor X1.C1(int) is not accessible due to restriction on required project P1\n" + >+ "----------\n" + >+ "6. ERROR in /P2/src/p/Y.java (at line 12)\n" + >+ " new C1(0); // error\n" + >+ " ^^\n" + >+ "Access restriction: The type X1.C1 is not accessible due to restriction on required project P1\n" + >+ "----------\n" >+ ); >+ } finally { >+ if (x1 != null) >+ x1.discardWorkingCopy(); >+ if (x2 != null) >+ x2.discardWorkingCopy(); >+ if (y != null) >+ y.discardWorkingCopy(); >+ if (z != null) >+ z.discardWorkingCopy(); >+ deleteProjects(new String[] {"P1", "P2"}); >+ } >+} >+ >+/* >+ * Discouraged access message - type via discouraged rule. >+ */ >+public void test004() throws CoreException { >+ ICompilationUnit x1 = null, z = null; >+ try { >+ WorkingCopyOwner owner = new WorkingCopyOwner(){}; >+ createJavaProject( >+ "P1", >+ new String[] {"src"}, >+ new String[] {"JCL_LIB"}, >+ "bin"); >+ this.problemRequestor = new ProblemRequestor(); >+ x1 = getWorkingCopy( >+ "/P1/src/p/X1.java", >+ "package p;\n" + >+ "public class X1 {\n" + >+ " class C1 {}\n" + >+ " interface I1 {}\n" + >+ "}", >+ owner, >+ this.problemRequestor); >+ assertProblems( >+ "Unexpected problems", >+ "----------\n----------\n----------\n----------\n" >+ ); >+ IJavaProject p2 = createJavaProject("P2", new String[] {"src"}, >+ new String[] {"JCL_LIB"}, "bin"); >+ IClasspathEntry[] classpath = p2.getRawClasspath(); >+ int length = classpath.length; >+ System.arraycopy(classpath, 0, classpath = new IClasspathEntry[length+1], 0, length); >+ classpath[length] = createSourceEntry("P2", "/P1", "~p/X1"); >+ p2.setRawClasspath(classpath, null); >+ String src = >+ "package p;\n" + >+ "public class Z extends X1 {\n" + >+ "}"; >+ this.problemRequestor = new ProblemRequestor(src); >+ z = getWorkingCopy( >+ "/P2/src/p/Z.java", >+ src, >+ owner, >+ this.problemRequestor); >+ assertProblems( >+ "Unexpected problems value", >+ "----------\n" + >+ "----------\n" + >+ "----------\n" + >+ "1. WARNING in /P2/src/p/Z.java (at line 2)\n" + >+ " public class Z extends X1 {\n" + >+ " ^^\n" + >+ "Discouraged access: The type X1 is not accessible due to restriction on required project P1\n" + >+ "----------\n" >+ ); >+ } finally { >+ if (x1 != null) >+ x1.discardWorkingCopy(); >+ if (z != null) >+ z.discardWorkingCopy(); >+ deleteProjects(new String[] {"P1", "P2"}); >+ } >+} >+}
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 76266
:
22702
|
22703
|
22704
|
32416