### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java,v retrieving revision 1.33 diff -u -r1.33 BatchCompilerTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java 16 Jan 2006 13:59:15 -0000 1.33 +++ src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java 23 Jan 2006 09:24:46 -0000 @@ -27,8 +27,8 @@ static { // TESTS_NAMES = new String[] { "test000" }; -// TESTS_NUMBERS = new int[] { 27 }; -// TESTS_RANGE = new int[] { 11, -1 }; +// TESTS_NUMBERS = new int[] { 1 }; +// TESTS_RANGE = new int[] { 1, -1 }; } public BatchCompilerTest(String name) { super(name); @@ -1537,13 +1537,13 @@ " (at line 5)\n" + " Warn warn;\n" + " ^^^^\n" + - "Discouraged access: Warn\n" + - "----------\n" + - "2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java\n" + - " (at line 6)\n" + - " KO ko;\n" + - " ^^\n" + - "Access restriction: KO\n" + + "Discouraged access: The type Warn is not accessible due to restriction on classpath entry ---OUTPUT_DIR_PLACEHOLDER---/p1\n" + + "----------\n" + + "2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java\n" + + " (at line 6)\n" + + " KO ko;\n" + + " ^^\n" + + "Access restriction: The type KO is not accessible due to restriction on classpath entry ---OUTPUT_DIR_PLACEHOLDER---\n" + "----------\n" + "3. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/X.java\n" + " (at line 7)\n" + @@ -2108,7 +2108,7 @@ " (at line 2)\n" + " public class Y extends p.X {\n" + " ^^^\n" + - "Discouraged access: X\n" + + "Discouraged access: The type X is not accessible due to restriction on classpath entry ---OUTPUT_DIR_PLACEHOLDER---/bin1\n" + "----------\n" + "1 problem (1 warning)", false); @@ -2189,30 +2189,222 @@ " (at line 3)\n" + " X x1;\n" + " ^\n" + - "Discouraged access: X\n" + + "Discouraged access: The type X is not accessible due to restriction on classpath entry ---OUTPUT_DIR_PLACEHOLDER---/bin1\n" + "----------\n" + "2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/src2/Y.java\n" + " (at line 4)\n" + " X x2 = new X();\n" + " ^\n" + - "Discouraged access: X\n" + + "Discouraged access: The type X is not accessible due to restriction on classpath entry ---OUTPUT_DIR_PLACEHOLDER---/bin1\n" + "----------\n" + "3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/src2/Y.java\n" + " (at line 4)\n" + " X x2 = new X();\n" + " ^^^^^^^^^^^^^^^\n" + - "Discouraged access: X()\n" + + "Discouraged access: The constructor X() is not accessible due to restriction on classpath entry ---OUTPUT_DIR_PLACEHOLDER---/bin1\n" + "----------\n" + "4. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/src2/Y.java\n" + " (at line 4)\n" + " X x2 = new X();\n" + " ^\n" + - "Discouraged access: X\n" + + "Discouraged access: The type X is not accessible due to restriction on classpath entry ---OUTPUT_DIR_PLACEHOLDER---/bin1\n" + "----------\n" + "4 problems (4 warnings)", false); } +// check we get appropriate combination of access rules +public void test040(){ + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "/** */\n" + + "public class X {\n" + + "}", + "p/Z.java", + "package p;\n" + + "/** */\n" + + "public class Z {\n" + + "}" + }, + "\"" + OUTPUT_DIR + File.separator + "p" + File.separator + "X.java\"" + + " \"" + OUTPUT_DIR + File.separator + "p" + File.separator + "Z.java\"" + + " -1.5 -g -preserveAllLocals" + + " -nowarn" + + " -proceedOnError -referenceInfo -d \"" + OUTPUT_DIR + "\"", + "", + "", + true); + this.runConformTest( + new String[] { + "Y.java", + "/** */\n" + + "public class Y {\n" + + " p.X x;\n" + + " p.Z z;\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "Y.java\"" + + " -1.5 -g -preserveAllLocals" + + " -cp \"" + OUTPUT_DIR + "[+p/X" + File.pathSeparator + "-p/*]\"" + + " -warn:+deprecation,syntheticAccess,uselessTypeCheck,unsafe,finalBound,unusedLocal" + + " -proceedOnError -referenceInfo -d \"" + OUTPUT_DIR + "\"", + "", + "----------\n" + + "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/Y.java\n" + + " (at line 4)\n" + + " p.Z z;\n" + + " ^^^\n" + + "Access restriction: The type Z is not accessible due to restriction on classpath entry ---OUTPUT_DIR_PLACEHOLDER---\n" + + "----------\n" + + "1 problem (1 warning)", + false); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=124533 +// turn off discouraged references warnings +public void test041(){ + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "/** */\n" + + "public class X {\n" + + "}", + "p/Z.java", + "package p;\n" + + "/** */\n" + + "public class Z {\n" + + "}" + }, + "\"" + OUTPUT_DIR + File.separator + "p" + File.separator + "X.java\"" + + " \"" + OUTPUT_DIR + File.separator + "p" + File.separator + "Z.java\"" + + " -1.5 -g -preserveAllLocals" + + " -nowarn" + + " -proceedOnError -referenceInfo -d \"" + OUTPUT_DIR + "\"", + "", + "", + true); + this.runConformTest( + new String[] { + "Y.java", + "/** */\n" + + "public class Y {\n" + + " p.X x;\n" + + " p.Z z;\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "Y.java\"" + + " -1.5 -g -preserveAllLocals" + + " -cp \"" + OUTPUT_DIR + "[~p/X" + File.pathSeparator + "-p/*]\"" + + " -warn:-discouraged -warn:+deprecation,syntheticAccess,uselessTypeCheck,unsafe,finalBound,unusedLocal" + + " -proceedOnError -referenceInfo -d \"" + OUTPUT_DIR + "\"", + "", + "----------\n" + + "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/Y.java\n" + + " (at line 4)\n" + + " p.Z z;\n" + + " ^^^\n" + + "Access restriction: The type Z is not accessible due to restriction on classpath entry ---OUTPUT_DIR_PLACEHOLDER---\n" + + "----------\n" + + "1 problem (1 warning)", + false); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=124533 +// turn off discouraged references warnings +public void test042(){ + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "/** */\n" + + "public class X {\n" + + "}", + "p/Z.java", + "package p;\n" + + "/** */\n" + + "public class Z {\n" + + "}" + }, + "\"" + OUTPUT_DIR + File.separator + "p" + File.separator + "X.java\"" + + " \"" + OUTPUT_DIR + File.separator + "p" + File.separator + "Z.java\"" + + " -1.5 -g -preserveAllLocals" + + " -nowarn" + + " -proceedOnError -referenceInfo -d \"" + OUTPUT_DIR + "\"", + "", + "", + true); + this.runConformTest( + new String[] { + "Y.java", + "/** */\n" + + "public class Y {\n" + + " p.X x;\n" + + " p.Z z;\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "Y.java\"" + + " -1.5 -g -preserveAllLocals" + + " -cp \"" + OUTPUT_DIR + "[~p/X" + File.pathSeparator + "-p/*]\"" + + " -warn:-forbidden -warn:+deprecation,syntheticAccess,uselessTypeCheck,unsafe,finalBound,unusedLocal" + + " -proceedOnError -referenceInfo -d \"" + OUTPUT_DIR + "\"", + "", + "----------\n" + + "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/Y.java\n" + + " (at line 3)\n" + + " p.X x;\n" + + " ^^^\n" + + "Discouraged access: The type X is not accessible due to restriction on classpath entry ---OUTPUT_DIR_PLACEHOLDER---\n" + + "----------\n" + + "1 problem (1 warning)", + false); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=124533 +// turn off discouraged references warnings +public void test043(){ + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "/** */\n" + + "public class X {\n" + + "}", + "p/Z.java", + "package p;\n" + + "/** */\n" + + "public class Z {\n" + + "}" + }, + "\"" + OUTPUT_DIR + File.separator + "p" + File.separator + "X.java\"" + + " \"" + OUTPUT_DIR + File.separator + "p" + File.separator + "Z.java\"" + + " -1.5 -g -preserveAllLocals" + + " -nowarn" + + " -proceedOnError -referenceInfo -d \"" + OUTPUT_DIR + "\"", + "", + "", + true); + this.runConformTest( + new String[] { + "Y.java", + "/** */\n" + + "public class Y {\n" + + " p.X x;\n" + + " p.Z z;\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "Y.java\"" + + " -1.5 -g -preserveAllLocals" + + " -cp \"" + OUTPUT_DIR + "[~p/X" + File.pathSeparator + "-p/*]\"" + + " -warn:-discouraged,forbidden -warn:+deprecation,syntheticAccess,uselessTypeCheck,unsafe,finalBound,unusedLocal" + + " -proceedOnError -referenceInfo -d \"" + OUTPUT_DIR + "\"", + "", + "", + false); +} + public static Class testClass() { return BatchCompilerTest.class; } #P org.eclipse.jdt.core Index: batch/org/eclipse/jdt/internal/compiler/batch/messages.properties =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/messages.properties,v retrieving revision 1.488 diff -u -r1.488 messages.properties --- batch/org/eclipse/jdt/internal/compiler/batch/messages.properties 17 Jan 2006 14:31:47 -0000 1.488 +++ batch/org/eclipse/jdt/internal/compiler/batch/messages.properties 23 Jan 2006 09:24:50 -0000 @@ -96,15 +96,15 @@ \ -cp -classpath \n\ \ specify location for application classes and sources. Each\n\ \ directory or file can specify access rules for types between\n\ -\ ''['' and '']'' (e.g. [-X.java] to deny access to type X)\n\ +\ ''['' and '']'' (e.g. [-X] to forbid access to type X, [~X] to\n\ +\ discourage access to type X, [+p/X:-p/*] to forbid access to all\n\ +\ types in package p but allow access to p/X)\n\ \ -bootclasspath \n\ \ specify location for system classes. Each directory or file can\n\ -\ specify access rules for types between ''['' and '']'' (e.g. [-X.java]\n\ -\ to deny access to type X)\n\ +\ specify access rules for types between ''['' and '']''\n\ \ -sourcepath \n\ \ specify location for application sources. Each directory can\n\ -\ specify access rules for types between ''['' and '']'' (e.g. [-X.java]\n\ -\ to deny access to type X)\n\ +\ specify access rules for types between ''['' and '']''\n\ \ -extdirs \n\ \ specify location for extension zip/jar files\n\ \ -d destination directory (if omitted, no directory is created)\n\ @@ -136,11 +136,13 @@ \ constructorName + method with constructor name\n\ \ dep-ann missing @Deprecated annotation\n\ \ deprecation + deprecation outside deprecated code\n\ +\ discouraged + use of types matching a discouraged access rule\n\ \ emptyBlock undocumented empty block\n\ \ enumSwitch incomplete enum switch\n\ \ fieldHiding field hiding another variable\n\ \ finalBound type parameter with final bound\n\ \ finally + finally block not completing normally\n\ +\ forbidden + use of types matching a forbidden access rule\n\ \ hiding macro for fieldHiding, localHiding, typeHiding and maskedCatchBlock\n\ \ incomplete-switch same as enumSwitch\n\ \ indirectStatic indirect reference to static member\n\ @@ -214,3 +216,10 @@ \ -v -version print compiler version\n\ \ -showversion print compiler version and continue\n +# templates +### access restrictions +template.restrictedAccess.type = The type {0} is not accessible due to restriction on classpath entry {1} +template.restrictedAccess.constructor = The constructor {0} is not accessible due to restriction on classpath entry {1} +template.restrictedAccess.field = The field {0} from the type {1} is not accessible due to restriction on classpath entry {2} +template.restrictedAccess.method = The method {0} from the type {1} is not accessible due to restriction on classpath entry {2} + Index: batch/org/eclipse/jdt/internal/compiler/batch/Main.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java,v retrieving revision 1.225 diff -u -r1.225 Main.java --- batch/org/eclipse/jdt/internal/compiler/batch/Main.java 17 Jan 2006 18:44:23 -0000 1.225 +++ batch/org/eclipse/jdt/internal/compiler/batch/Main.java 23 Jan 2006 09:24:50 -0000 @@ -1920,6 +1920,14 @@ this.options.put( CompilerOptions.OPTION_ReportParameterAssignment, isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); + } else if (token.equals("discouraged")) { //$NON-NLS-1$ + this.options.put( + CompilerOptions.OPTION_ReportDiscouragedReference, + isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); + } else if (token.equals("forbidden")) { //$NON-NLS-1$ + this.options.put( + CompilerOptions.OPTION_ReportForbiddenReference, + isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); } else { throw new InvalidInputException(Main.bind("configure.invalidWarning", token)); //$NON-NLS-1$ } @@ -2546,7 +2554,20 @@ } } if (rulesOK) { - AccessRuleSet accessRuleSet = new AccessRuleSet(accessRules); + String templates[] = new String[AccessRuleSet.MESSAGE_TEMPLATES_LENGTH]; + templates[0] = Main.bind( + "template.restrictedAccess.type", //$NON-NLS-1$ + new String[] {"{0}", currentClasspathName}); //$NON-NLS-1$ + templates[1] = Main.bind( + "template.restrictedAccess.constructor", //$NON-NLS-1$ + new String[] {"{0}", currentClasspathName}); //$NON-NLS-1$ + templates[2] = Main.bind( + "template.restrictedAccess.method", //$NON-NLS-1$ + new String[] {"{0}", "{1}", currentClasspathName}); //$NON-NLS-1$ //$NON-NLS-2$ + templates[3] = Main.bind( + "template.restrictedAccess.field", //$NON-NLS-1$ + new String[] {"{0}", "{1}", currentClasspathName}); //$NON-NLS-1$ //$NON-NLS-2$ + AccessRuleSet accessRuleSet = new AccessRuleSet(accessRules, templates); FileSystem.Classpath currentClasspath = FileSystem .getClasspath(currentClasspathName, customEncoding, 0, accessRuleSet); Index: model/org/eclipse/jdt/internal/core/builder/State.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/State.java,v retrieving revision 1.53 diff -u -r1.53 State.java --- model/org/eclipse/jdt/internal/core/builder/State.java 5 Jan 2006 16:59:12 -0000 1.53 +++ model/org/eclipse/jdt/internal/core/builder/State.java 23 Jan 2006 09:24:51 -0000 @@ -334,8 +334,7 @@ for (int i = 0; i < AccessRuleSet.MESSAGE_TEMPLATES_LENGTH; i++) { messageTemplates[i] = in.readUTF(); } - AccessRuleSet accessRuleSet = new AccessRuleSet(accessRules); - accessRuleSet.messageTemplates = messageTemplates; + AccessRuleSet accessRuleSet = new AccessRuleSet(accessRules, messageTemplates); return accessRuleSet; } Index: search/org/eclipse/jdt/internal/core/search/JavaSearchScope.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/JavaSearchScope.java,v retrieving revision 1.45 diff -u -r1.45 JavaSearchScope.java --- search/org/eclipse/jdt/internal/core/search/JavaSearchScope.java 17 Aug 2005 09:20:48 -0000 1.45 +++ search/org/eclipse/jdt/internal/core/search/JavaSearchScope.java 23 Jan 2006 09:24:51 -0000 @@ -51,7 +51,7 @@ private int threshold; private IPath[] enclosingProjectsAndJars; - public final static AccessRuleSet NOT_ENCLOSED = new AccessRuleSet(null); + public final static AccessRuleSet NOT_ENCLOSED = new AccessRuleSet(null, null); public JavaSearchScope() { this(5); Index: model/org/eclipse/jdt/internal/core/ClasspathEntry.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClasspathEntry.java,v retrieving revision 1.87 diff -u -r1.87 ClasspathEntry.java --- model/org/eclipse/jdt/internal/core/ClasspathEntry.java 18 Jan 2006 12:28:02 -0000 1.87 +++ model/org/eclipse/jdt/internal/core/ClasspathEntry.java 23 Jan 2006 09:24:51 -0000 @@ -218,12 +218,15 @@ this.inclusionPatterns = inclusionPatterns; this.exclusionPatterns = exclusionPatterns; - AccessRuleSet ruleSet = createAccessRuleSet(accessRules); - if (ruleSet != null) { - // compute message template - ruleSet.messageTemplates = getMessageTemplates(); - } - this.accessRuleSet = ruleSet; + int length; + if (accessRules != null && (length = accessRules.length) > 0) { + AccessRule[] rules = new AccessRule[length]; + System.arraycopy(accessRules, 0, rules, 0, length); + this.accessRuleSet = new AccessRuleSet(rules, getMessageTemplates()); + } +// else { -- implicit! +// this.accessRuleSet = null; +// } this.combineAccessRules = combineAccessRules; this.extraAttributes = extraAttributes; @@ -239,15 +242,7 @@ this.specificOutputLocation = specificOutputLocation; this.isExported = isExported; } - - private static AccessRuleSet createAccessRuleSet(IAccessRule[] accessRules) { - int length = accessRules == null ? 0 : accessRules.length; - if (length == 0) return null; - AccessRule[] rules = new AccessRule[length]; - System.arraycopy(accessRules, 0, rules, 0, length); - return new AccessRuleSet(rules); - } - + public boolean combineAccessRules() { return this.combineAccessRules; } Index: compiler/org/eclipse/jdt/internal/compiler/env/AccessRuleSet.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/env/AccessRuleSet.java,v retrieving revision 1.10 diff -u -r1.10 AccessRuleSet.java --- compiler/org/eclipse/jdt/internal/compiler/env/AccessRuleSet.java 17 Jan 2006 09:35:51 -0000 1.10 +++ compiler/org/eclipse/jdt/internal/compiler/env/AccessRuleSet.java 23 Jan 2006 09:24:50 -0000 @@ -22,20 +22,15 @@ public String[] messageTemplates; public static final int MESSAGE_TEMPLATES_LENGTH = 4; - - public AccessRuleSet(AccessRule[] accessRules) { - this(accessRules, null); - } - /** * Make a new set of access rules. * @param accessRules the access rules to be contained by the new set * @param messageTemplates a Sting[4] array specifying the messages for type, * constructor, method and field access violation; each should contain as many * placeholders as expected by the respective access violation message (that is, - * one for type and constructor, two for method and field). + * one for type and constructor, two for method and field); replaced by a + * default value if null. */ - // TODO (maxime) move to better support public AccessRuleSet(AccessRule[] accessRules, String[] messageTemplates) { this.accessRules = accessRules; if (messageTemplates != null && messageTemplates.length == MESSAGE_TEMPLATES_LENGTH)