001: /* ***** BEGIN LICENSE BLOCK *****
002: * Version: MPL 1.1/GPL 2.0
003: *
004: * The contents of this file are subject to the Mozilla Public License Version
005: * 1.1 (the "License"); you may not use this file except in compliance with
006: * the License. You may obtain a copy of the License at
007: * http://www.mozilla.org/MPL/
008: *
009: * Software distributed under the License is distributed on an "AS IS" basis,
010: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
011: * for the specific language governing rights and limitations under the
012: * License.
013: *
014: * The Original Code is Rhino code, released May 6, 1999.
015: *
016: * The Initial Developer of the Original Code is
017: * Netscape Communications Corporation.
018: * Portions created by the Initial Developer are Copyright (C) 1997-1999
019: * the Initial Developer. All Rights Reserved.
020: *
021: * Contributor(s):
022: * Attila Szegedi
023: * David P. Caldwell <inonit@inonit.com>
024: *
025: * Alternatively, the contents of this file may be used under the terms of
026: * the GNU General Public License Version 2 or later (the "GPL"), in which
027: * case the provisions of the GPL are applicable instead of those above. If
028: * you wish to allow use of your version of this file only under the terms of
029: * the GPL and not to allow others to use your version of this file under the
030: * MPL, indicate your decision by deleting the provisions above and replacing
031: * them with the notice and other provisions required by the GPL. If you do
032: * not delete the provisions above, a recipient may use your version of this
033: * file under either the MPL or the GPL.
034: *
035: * ***** END LICENSE BLOCK ***** */
036:
037: package org.mozilla.javascript.tests;
038:
039: /**
040: * A class with private/protected/package private members, to test the Rhino
041: * feature Context.FEATURE_ENHANCED_JAVA_ACCESS, that allows bypassing Java
042: * member access restrictions.
043: * @author Donna Malayeri
044: */
045:
046: public class PrivateAccessClass {
047: private PrivateAccessClass() {
048: }
049:
050: PrivateAccessClass(String s) {
051: }
052:
053: private PrivateAccessClass(int x) {
054: }
055:
056: protected PrivateAccessClass(int x, String s) {
057: }
058:
059: private static class PrivateNestedClass {
060: private PrivateNestedClass() {
061: }
062:
063: int packagePrivateInt = 0;
064: private int privateInt = 1;
065: protected int protectedInt = 2;
066: }
067:
068: static int staticPackagePrivateInt = 0;
069: private static int staticPrivateInt = 1;
070: protected static int staticProtectedInt = 2;
071:
072: String packagePrivateString = "package private";
073: private String privateString = "private";
074: protected String protectedString = "protected";
075:
076: static int staticPackagePrivateMethod() {
077: return 0;
078: }
079:
080: static private int staticPrivateMethod() {
081: return 1;
082: }
083:
084: static protected int staticProtectedMethod() {
085: return 2;
086: }
087:
088: int packagePrivateMethod() {
089: return 3;
090: }
091:
092: private int privateMethod() {
093: return 4;
094: }
095:
096: protected int protectedMethod() {
097: return 5;
098: }
099:
100: /*
101: * Suppress warnings about unused private members.
102: */
103: public int referenceToPrivateMembers() {
104: PrivateAccessClass pac = new PrivateAccessClass();
105: PrivateAccessClass pac2 = new PrivateAccessClass(2);
106: PrivateNestedClass pnc = new PrivateNestedClass();
107: System.out.println(privateString);
108: return pnc.privateInt + staticPrivateInt
109: + staticPrivateMethod() + pac.privateMethod();
110: }
111: }
|