Path: blob/master/test/functional/Jsr292/src/examples/PackageExamples.java
6004 views
/*******************************************************************************1* Copyright (c) 2001, 2018 IBM Corp. and others2*3* This program and the accompanying materials are made available under4* the terms of the Eclipse Public License 2.0 which accompanies this5* distribution and is available at https://www.eclipse.org/legal/epl-2.0/6* or the Apache License, Version 2.0 which accompanies this distribution and7* is available at https://www.apache.org/licenses/LICENSE-2.0.8*9* This Source Code may also be made available under the following10* Secondary Licenses when the conditions for such availability set11* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12* General Public License, version 2 with the GNU Classpath13* Exception [1] and GNU General Public License, version 2 with the14* OpenJDK Assembly Exception [2].15*16* [1] https://www.gnu.org/software/classpath/license.html17* [2] http://openjdk.java.net/legal/assembly-exception.html18*19* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception20*******************************************************************************/21package examples;2223import java.lang.invoke.MethodHandles;24import java.lang.invoke.MethodHandles.Lookup;2526/**27* All the fields, constructors and methods in this class are used by test cases that require fields, methods, and constructors of28* various behavior from a class in a different package than that of the test class.29*30* @author mesbah31*32*/33public class PackageExamples {3435public static Lookup getLookup() {36return MethodHandles.lookup();37}3839public static Lookup getPublicLookup() {40return MethodHandles.publicLookup();41}4243final protected String finalProtectedMethod() { return "finalProtectedMethod"; }4445protected static String protectedMethod () { return "protectedMethod"; }4647/* default */ static String defaultMethod() { return "defaultMethod"; }4849public int nonStaticPublicField;50public static int staticPublicField;5152private int nonStaticPrivateField;53private static int staticPrivateField;5455protected int nonStaticProtectedField;5657public int addPublic(int a, int b){return a+b;}58private int addPrivate(int a, int b){return a+b;}5960public static int addPublicStatic (int a,int b) {return a+b;}61private static int addPrivateStatic (int a,int b) {return a+b;}6263protected static int addProtectedStatic(int a,int b) {return a+b;}6465public PackageExamples(){66super();67}6869public PackageExamples(int a, int b){70this.nonStaticPublicField = a + b;71}727374public class CrossPackageInnerClass{75public int addPublicInner(int a, int b){ return a+b; }76public Lookup getLookup() { return MethodHandles.lookup(); }7778public class CrossPackageInnerClass2_Nested_Level2 {79public Lookup getLookup() {80return MethodHandles.lookup();81}82public int addPublicInner_level2(int a, int b){ return a+b; }83}84}8586public int getLength(String[] o){87return o.length;88}8990public static int getLengthStatic(String[] o){91return o.length;92}9394public int addPublicVariableArity(int... n){95int sum = 0 ;96for ( int i = 0 ; i < n.length ; i++ ){97sum += n[i];98}99return sum;100}101102public static int addPublicStaticVariableArity(int... n){103int sum = 0 ;104for ( int i = 0 ; i < n.length ; i++ ){105sum += n[i];106}107return sum;108}109110protected int addProtected(int a, int b) {return a+b;}111}112113114