• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2009 The JSR-330 Expert Group
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package org.atinject.tck.auto;
18 
19 import org.atinject.tck.auto.accessories.SpareTire;
20 import org.atinject.tck.auto.accessories.RoundThing;
21 
22 import javax.inject.Inject;
23 import java.util.LinkedHashSet;
24 import java.util.Set;
25 
26 public class Tire extends RoundThing {
27 
28     protected static final FuelTank NEVER_INJECTED = new FuelTank();
29 
30     protected static final Set<String> moreProblems = new LinkedHashSet<String>();
31 
32     FuelTank constructorInjection = NEVER_INJECTED;
33     @Inject FuelTank fieldInjection = NEVER_INJECTED;
34     FuelTank methodInjection = NEVER_INJECTED;
35     @Inject static FuelTank staticFieldInjection = NEVER_INJECTED;
36     static FuelTank staticMethodInjection = NEVER_INJECTED;
37 
38     boolean constructorInjected;
39 
40     protected boolean superPrivateMethodInjected;
41     protected boolean superPackagePrivateMethodInjected;
42     protected boolean superProtectedMethodInjected;
43     protected boolean superPublicMethodInjected;
44     protected boolean subPrivateMethodInjected;
45     protected boolean subPackagePrivateMethodInjected;
46     protected boolean subProtectedMethodInjected;
47     protected boolean subPublicMethodInjected;
48 
49     protected boolean superPrivateMethodForOverrideInjected;
50     protected boolean superPackagePrivateMethodForOverrideInjected;
51     protected boolean subPrivateMethodForOverrideInjected;
52     protected boolean subPackagePrivateMethodForOverrideInjected;
53     protected boolean protectedMethodForOverrideInjected;
54     protected boolean publicMethodForOverrideInjected;
55 
56     public boolean methodInjectedBeforeFields;
57     public boolean subtypeFieldInjectedBeforeSupertypeMethods;
58     public boolean subtypeMethodInjectedBeforeSupertypeMethods;
59     public static boolean staticMethodInjectedBeforeStaticFields;
60     public static boolean subtypeStaticFieldInjectedBeforeSupertypeStaticMethods;
61     public static boolean subtypeStaticMethodInjectedBeforeSupertypeStaticMethods;
62     public boolean similarPrivateMethodInjectedTwice;
63     public boolean similarPackagePrivateMethodInjectedTwice;
64     public boolean overriddenProtectedMethodInjectedTwice;
65     public boolean overriddenPublicMethodInjectedTwice;
66 
Tire(FuelTank constructorInjection)67     @Inject public Tire(FuelTank constructorInjection) {
68         this.constructorInjection = constructorInjection;
69     }
70 
supertypeMethodInjection(FuelTank methodInjection)71     @Inject void supertypeMethodInjection(FuelTank methodInjection) {
72         if (!hasTireBeenFieldInjected()) {
73             methodInjectedBeforeFields = true;
74         }
75         if (hasSpareTireBeenFieldInjected()) {
76             subtypeFieldInjectedBeforeSupertypeMethods = true;
77         }
78         if (hasSpareTireBeenMethodInjected()) {
79             subtypeMethodInjectedBeforeSupertypeMethods = true;
80         }
81         this.methodInjection = methodInjection;
82     }
83 
supertypeStaticMethodInjection(FuelTank methodInjection)84     @Inject static void supertypeStaticMethodInjection(FuelTank methodInjection) {
85         if (!Tire.hasBeenStaticFieldInjected()) {
86             staticMethodInjectedBeforeStaticFields = true;
87         }
88         if (SpareTire.hasBeenStaticFieldInjected()) {
89             subtypeStaticFieldInjectedBeforeSupertypeStaticMethods = true;
90         }
91         if (SpareTire.hasBeenStaticMethodInjected()) {
92             subtypeStaticMethodInjectedBeforeSupertypeStaticMethods = true;
93         }
94         staticMethodInjection = methodInjection;
95     }
96 
injectPrivateMethod()97     @Inject private void injectPrivateMethod() {
98         if (superPrivateMethodInjected) {
99             similarPrivateMethodInjectedTwice = true;
100         }
101         superPrivateMethodInjected = true;
102     }
103 
injectPackagePrivateMethod()104     @Inject void injectPackagePrivateMethod() {
105         if (superPackagePrivateMethodInjected) {
106             similarPackagePrivateMethodInjectedTwice = true;
107         }
108         superPackagePrivateMethodInjected = true;
109     }
110 
injectProtectedMethod()111     @Inject protected void injectProtectedMethod() {
112         if (superProtectedMethodInjected) {
113             overriddenProtectedMethodInjectedTwice = true;
114         }
115         superProtectedMethodInjected = true;
116     }
117 
injectPublicMethod()118     @Inject public void injectPublicMethod() {
119         if (superPublicMethodInjected) {
120             overriddenPublicMethodInjectedTwice = true;
121         }
122         superPublicMethodInjected = true;
123     }
124 
injectPrivateMethodForOverride()125     @Inject private void injectPrivateMethodForOverride() {
126         subPrivateMethodForOverrideInjected = true;
127     }
128 
injectPackagePrivateMethodForOverride()129     @Inject void injectPackagePrivateMethodForOverride() {
130         subPackagePrivateMethodForOverrideInjected = true;
131     }
132 
injectProtectedMethodForOverride()133     @Inject protected void injectProtectedMethodForOverride() {
134         protectedMethodForOverrideInjected = true;
135     }
136 
injectPublicMethodForOverride()137     @Inject public void injectPublicMethodForOverride() {
138         publicMethodForOverrideInjected = true;
139     }
140 
hasTireBeenFieldInjected()141     protected final boolean hasTireBeenFieldInjected() {
142         return fieldInjection != NEVER_INJECTED;
143     }
144 
hasSpareTireBeenFieldInjected()145     protected boolean hasSpareTireBeenFieldInjected() {
146         return false;
147     }
148 
hasTireBeenMethodInjected()149     protected final boolean hasTireBeenMethodInjected() {
150         return methodInjection != NEVER_INJECTED;
151     }
152 
hasBeenStaticFieldInjected()153     protected static boolean hasBeenStaticFieldInjected() {
154         return staticFieldInjection != NEVER_INJECTED;
155     }
156 
hasBeenStaticMethodInjected()157     protected static boolean hasBeenStaticMethodInjected() {
158         return staticMethodInjection != NEVER_INJECTED;
159     }
160 
hasSpareTireBeenMethodInjected()161     protected boolean hasSpareTireBeenMethodInjected() {
162         return false;
163     }
164 
165     boolean packagePrivateMethod2Injected;
166 
injectPackagePrivateMethod2()167     @Inject void injectPackagePrivateMethod2() {
168         packagePrivateMethod2Injected = true;
169     }
170 
171     public boolean packagePrivateMethod3Injected;
172 
injectPackagePrivateMethod3()173     @Inject void injectPackagePrivateMethod3() {
174         packagePrivateMethod3Injected = true;
175     }
176 
177     public boolean packagePrivateMethod4Injected;
178 
injectPackagePrivateMethod4()179     void injectPackagePrivateMethod4() {
180         packagePrivateMethod4Injected = true;
181     }
182 }
183