@@ -38,7 +38,7 @@ class JcUnknownClass(override var classpath: JcClasspath, name: String) : JcVirt
3838}
3939
4040class JcUnknownMethod (
41- enclosingClass : JcUnknownClass ,
41+ enclosingClass : JcClassOrInterface ,
4242 name : String ,
4343 description : String ,
4444 returnType : TypeName ,
@@ -51,17 +51,17 @@ class JcUnknownMethod(
5151) {
5252
5353 companion object {
54- fun method (type : JcUnknownClass , name : String , description : String ): JcMethod {
54+ fun method (type : JcClassOrInterface , name : String , description : String ): JcMethod {
5555 val methodType = Type .getMethodType(description)
5656 val returnType = TypeNameImpl (methodType.returnType.className.jcdbName())
5757 val paramsType = methodType.argumentTypes.map { TypeNameImpl (it.className.jcdbName()) }
5858 return JcUnknownMethod (type, name, description, returnType, paramsType)
5959 }
6060
61- fun typedMethod (type : JcUnknownType , name : String , description : String ): JcTypedMethod {
61+ fun typedMethod (type : JcClassType , name : String , description : String ): JcTypedMethod {
6262 return JcTypedMethodImpl (
6363 type,
64- method(type.jcClass as JcUnknownClass , name, description),
64+ method(type.jcClass, name, description),
6565 JcSubstitutor .empty
6666 )
6767 }
@@ -72,15 +72,15 @@ class JcUnknownMethod(
7272 }
7373}
7474
75- class JcUnknownField (enclosingClass : JcUnknownClass , name : String , type : TypeName ) :
75+ class JcUnknownField (enclosingClass : JcClassOrInterface , name : String , type : TypeName ) :
7676 JcVirtualFieldImpl (name, type = type) {
7777
7878 companion object {
7979
8080 fun typedField (type : JcClassType , name : String , fieldType : TypeName ): JcTypedField {
8181 return JcTypedFieldImpl (
8282 type,
83- JcUnknownField (type.jcClass as JcUnknownClass , name, fieldType),
83+ JcUnknownField (type.jcClass, name, fieldType),
8484 JcSubstitutor .empty
8585 )
8686 }
@@ -136,4 +136,42 @@ object UnknownClasses : JcClasspathExtFeature {
136136 }
137137}
138138
139+ /* *
140+ * Used for mocking of methods and fields refs that doesn't exist in code base of classpath
141+ * ```
142+ * class Bar {
143+ *
144+ * int x = 0;
145+ *
146+ * public void run() {
147+ * System.out.println("Hello world");
148+ * }
149+ * }
150+ *
151+ * class Foo extends Bar {
152+ *
153+ * Bar f = new Bar();
154+ *
155+ * public void call() {
156+ * System.out.println(f.y);
157+ * f.runSomething();
158+ * }
159+ * }
160+ * ```
161+ *
162+ * 3-address representation of bytecode for Foo class can't resolve `Bar#y` field and `Bar#runSomething`
163+ * method by default. With this feature such methods and fields will be resolved as JcUnknownField and JcUnknownMethod
164+ */
165+ object UnknownClassMethodsAndFields : JcLookupExtFeature {
166+
167+ override fun lookup (clazz : JcClassOrInterface ): JcLookup <JcField , JcMethod > {
168+ return JcUnknownClassLookup (clazz)
169+ }
170+
171+ override fun lookup (type : JcClassType ): JcLookup <JcTypedField , JcTypedMethod > {
172+ return JcUnknownTypeLookup (type)
173+ }
174+ }
175+
176+
139177val JcClasspath .isResolveAllToUnknown: Boolean get() = isInstalled(UnknownClasses )
0 commit comments