|
| 1 | +/* |
| 2 | + * Copyright (c) 2008, 2019 Emmanuel Dupuy. |
| 3 | + * This project is distributed under the GPLv3 license. |
| 4 | + * This is a Copyleft license that gives the user the right to use, |
| 5 | + * copy and modify the code freely for non-commercial purposes. |
| 6 | + */ |
| 7 | + |
| 8 | +package org.jd.core.v1.service.converter.classfiletojavasyntax.util; |
| 9 | + |
| 10 | +import org.jd.core.v1.model.javasyntax.expression.*; |
| 11 | +import org.jd.core.v1.model.javasyntax.type.*; |
| 12 | +import org.jd.core.v1.service.converter.classfiletojavasyntax.model.javasyntax.expression.*; |
| 13 | + |
| 14 | +public abstract class AbstractTypeParametersToTypeArgumentsBinder { |
| 15 | + public abstract ClassFileConstructorInvocationExpression newConstructorInvocationExpression( |
| 16 | + int lineNumber, ObjectType objectType, String descriptor, |
| 17 | + TypeMaker.MethodTypes methodTypes, BaseExpression parameters); |
| 18 | + |
| 19 | + public abstract ClassFileSuperConstructorInvocationExpression newSuperConstructorInvocationExpression( |
| 20 | + int lineNumber, ObjectType objectType, String descriptor, |
| 21 | + TypeMaker.MethodTypes methodTypes, BaseExpression parameters); |
| 22 | + |
| 23 | + public abstract ClassFileMethodInvocationExpression newMethodInvocationExpression( |
| 24 | + int lineNumber, Expression expression, ObjectType objectType, String name, String descriptor, |
| 25 | + TypeMaker.MethodTypes methodTypes, BaseExpression parameters); |
| 26 | + |
| 27 | + public abstract FieldReferenceExpression newFieldReferenceExpression( |
| 28 | + int lineNumber, Type type, Expression expression, ObjectType objectType, String name, String descriptor); |
| 29 | + |
| 30 | + public abstract void bindParameterTypesWithArgumentTypes(Type type, Expression expression); |
| 31 | + |
| 32 | + public void updateNewExpression(ClassFileNewExpression ne, String descriptor, TypeMaker.MethodTypes methodTypes, BaseExpression parameters) { |
| 33 | + ne.set(descriptor, clone(methodTypes.parameterTypes), parameters); |
| 34 | + } |
| 35 | + |
| 36 | + public static void staticBindParameterTypesWithArgumentTypes(Type type, Expression expression) { |
| 37 | + if (expression.isMethodInvocationExpression()) { |
| 38 | + ClassFileMethodInvocationExpression mie = (ClassFileMethodInvocationExpression)expression; |
| 39 | + AbstractTypeParametersToTypeArgumentsBinder binder = mie.getBinder(); |
| 40 | + |
| 41 | + if (binder != null) { |
| 42 | + binder.bindParameterTypesWithArgumentTypes(type, mie); |
| 43 | + } |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + protected static BaseType clone(BaseType parameterTypes) { |
| 48 | + if ((parameterTypes != null) && parameterTypes.isList()) { |
| 49 | + switch (parameterTypes.size()) { |
| 50 | + case 0: parameterTypes = null; break; |
| 51 | + case 1: parameterTypes = parameterTypes.getFirst(); break; |
| 52 | + default: parameterTypes = new Types(parameterTypes.getList()); break; |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + return parameterTypes; |
| 57 | + } |
| 58 | +} |
0 commit comments