Reduce size of a Kotlin program that uses lightweight reflection

This commit is contained in:
Alexey Andreev 2019-12-03 20:57:24 +03:00
parent fed75ef0cf
commit 4b3a8e757b
2 changed files with 40 additions and 7 deletions

View File

@ -121,14 +121,22 @@ public class ClassForNameTransformer implements ClassHolderTransformer {
representative = program.variableAt(nameRepresentatives[nameIndex]);
} else if (constant != null) {
if (hierarchy.getClassSource().get(constant) == null || !filterClassName(constant)) {
continue;
InvokeInstruction invokeException = new InvokeInstruction();
invokeException.setType(InvocationType.SPECIAL);
invokeException.setMethod(new MethodReference(ExceptionHelpers.class, "classNotFound",
Class.class));
invokeException.setReceiver(program.createVariable());
invokeException.setLocation(invoke.getLocation());
invoke.insertPrevious(invokeException);
representative = invokeException.getReceiver();
} else {
ClassConstantInstruction classConstant = new ClassConstantInstruction();
classConstant.setConstant(ValueType.object(constant));
classConstant.setReceiver(program.createVariable());
classConstant.setLocation(invoke.getLocation());
invoke.insertPrevious(classConstant);
representative = classConstant.getReceiver();
}
ClassConstantInstruction classConstant = new ClassConstantInstruction();
classConstant.setConstant(ValueType.object(constant));
classConstant.setReceiver(program.createVariable());
classConstant.setLocation(invoke.getLocation());
invoke.insertPrevious(classConstant);
representative = classConstant.getReceiver();
} else {
continue;
}

View File

@ -0,0 +1,25 @@
/*
* Copyright 2019 Alexey Andreev.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.classlib.impl;
public class ExceptionHelpers {
private ExceptionHelpers() {
}
public static Class<?> classNotFound() throws ClassNotFoundException {
throw new ClassNotFoundException();
}
}