diff --git a/build.gradle b/build.gradle index d39db03..6e6220c 100644 --- a/build.gradle +++ b/build.gradle @@ -49,8 +49,22 @@ dependencies { compileOnly(libs.forgespi) implementation(libs.nashorn) compileOnly(libs.nulls) + + + annotationProcessor(implementation('org.bsc.processor:java2ts-processor:1.3.1')) + + // there are here because for some reason, java2ts decides to load the classes directly + // instead of using the built-in AP feature to do proper checking + annotationProcessor(libs.bundles.asm) + annotationProcessor('org.ow2.asm:asm-util:7.3.1') // for processor + // TODO automate moving files from build/generated/sources/annotationProcessor/java/main/j2ts to resources out + // also automate doing ASMAPI class. you can't exactly load the class while compiling the class + // and also the `declare namespace Java { export function type(s: "class.name"): class.name; }` stuff, I just used some regex + } + + jar { manifest { attributes([ diff --git a/src/main/java/net/minecraftforge/coremod/package-info.java b/src/main/java/net/minecraftforge/coremod/package-info.java new file mode 100644 index 0000000..d26fa90 --- /dev/null +++ b/src/main/java/net/minecraftforge/coremod/package-info.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) Forge Development LLC + * SPDX-License-Identifier: LGPL-2.1-only + */ +@Java2TS( + name = "asm", declare = { + @Type(value = org.objectweb.asm.tree.AbstractInsnNode.class, export = true), + @Type(value = org.objectweb.asm.tree.FieldInsnNode.class, export = true), + @Type(value = org.objectweb.asm.tree.FrameNode.class, export = true), + @Type(value = org.objectweb.asm.tree.IincInsnNode.class, export = true), + @Type(value = org.objectweb.asm.tree.InsnNode.class, export = true), + @Type(value = org.objectweb.asm.tree.IntInsnNode.class, export = true), + @Type(value = org.objectweb.asm.tree.InsnList.class, export = true), + @Type(value = org.objectweb.asm.tree.InvokeDynamicInsnNode.class, export = true), + @Type(value = org.objectweb.asm.tree.JumpInsnNode.class, export = true), + @Type(value = org.objectweb.asm.tree.LabelNode.class, export = true), + @Type(value = org.objectweb.asm.tree.LdcInsnNode.class, export = true), + @Type(value = org.objectweb.asm.tree.LineNumberNode.class, export = true), + @Type(value = org.objectweb.asm.tree.LocalVariableAnnotationNode.class, export = true), + @Type(value = org.objectweb.asm.tree.LocalVariableNode.class, export = true), + @Type(value = org.objectweb.asm.tree.LookupSwitchInsnNode.class, export = true), + @Type(value = org.objectweb.asm.tree.MethodInsnNode.class, export = true), + @Type(value = org.objectweb.asm.tree.MultiANewArrayInsnNode.class, export = true), + @Type(value = org.objectweb.asm.tree.TableSwitchInsnNode.class, export = true), + @Type(value = org.objectweb.asm.tree.TryCatchBlockNode.class, export = true), + @Type(value = org.objectweb.asm.tree.TypeAnnotationNode.class, export = true), + @Type(value = org.objectweb.asm.tree.TypeInsnNode.class, export = true), + @Type(value = org.objectweb.asm.tree.VarInsnNode.class, export = true), + + // Adding new fields to classes + @Type(value = org.objectweb.asm.tree.FieldNode.class, export = true), + + // Adding new methods to classes + @Type(value = org.objectweb.asm.tree.MethodNode.class, export = true), + @Type(value = org.objectweb.asm.tree.ClassNode.class, export = true), + @Type(value = org.objectweb.asm.tree.ParameterNode.class, export = true), + + @Type(value = org.objectweb.asm.Attribute.class, export = true), + @Type(value = org.objectweb.asm.Handle.class, export = true), + @Type(value = org.objectweb.asm.Label.class, export = true), + @Type(value = org.objectweb.asm.Type.class, export = true), + @Type(value = org.objectweb.asm.TypePath.class, export = true), + @Type(value = org.objectweb.asm.TypeReference.class, export = true), + + + @Type(value = org.objectweb.asm.util.ASMifier.class, export = true), + @Type(value = org.objectweb.asm.util.ASMifierSupport.class, export = true), + @Type(value = org.objectweb.asm.util.CheckAnnotationAdapter.class, export = true), + @Type(value = org.objectweb.asm.util.CheckClassAdapter.class, export = true), + @Type(value = org.objectweb.asm.util.CheckFieldAdapter.class, export = true), + @Type(value = org.objectweb.asm.util.CheckMethodAdapter.class, export = true), + @Type(value = org.objectweb.asm.util.CheckModuleAdapter.class, export = true), + @Type(value = org.objectweb.asm.util.CheckRecordComponentAdapter.class, export = true), + @Type(value = org.objectweb.asm.util.CheckSignatureAdapter.class, export = true), + @Type(value = org.objectweb.asm.util.Printer.class, export = true), + @Type(value = org.objectweb.asm.util.Textifier.class, export = true), + @Type(value = org.objectweb.asm.util.TextifierSupport.class, export = true), + @Type(value = org.objectweb.asm.util.TraceAnnotationVisitor.class, export = true), + @Type(value = org.objectweb.asm.util.TraceClassVisitor.class, export = true), + @Type(value = org.objectweb.asm.util.TraceFieldVisitor.class, export = true), + @Type(value = org.objectweb.asm.util.TraceMethodVisitor.class, export = true), + @Type(value = org.objectweb.asm.util.TraceModuleVisitor.class, export = true), + // @Type(value=org.objectweb.asm.util.TraceRecordComponentVisitor.class, export=true), + @Type(value = org.objectweb.asm.util.TraceSignatureVisitor.class, export = true), +} +) +package net.minecraftforge.coremod; + +import org.bsc.processor.annotation.Java2TS; +import org.bsc.processor.annotation.Type; \ No newline at end of file diff --git a/src/main/resources/asm-types.ts b/src/main/resources/asm-types.ts new file mode 100644 index 0000000..3ae7013 --- /dev/null +++ b/src/main/resources/asm-types.ts @@ -0,0 +1,714 @@ +/* + * Project: java2typescript - https://github.com/bsorrentino/java2typescript + * + * Author: bsorrentino + * + * TYPESCRIPT EXPORTED DECLARATIONS + * + */ +/// + +interface ASMifierStatic { + + readonly class:any; + new( ):org.objectweb.asm.util.ASMifier; + main( arg0:[string] ):void; + appendString( arg0:any /*java.lang.StringBuilder*/, arg1:string ):void; +} + +export const ASMifier: ASMifierStatic = Java.type("org.objectweb.asm.util.ASMifier"); + + +interface ASMifierSupportStatic { + + readonly class:any; +} + +export const ASMifierSupport: ASMifierSupportStatic = Java.type("org.objectweb.asm.util.ASMifierSupport"); + + +interface AbstractInsnNodeStatic { + + readonly class:any; +} + +export const AbstractInsnNode: AbstractInsnNodeStatic = Java.type("org.objectweb.asm.tree.AbstractInsnNode"); + + +interface AttributeStatic { + + readonly class:any; + write( arg0:org.objectweb.asm.Attribute, arg1:any /*org.objectweb.asm.ClassWriter*/, arg2:bytearray, arg3:int, arg4:int, arg5:int ):bytearray; + read( arg0:org.objectweb.asm.Attribute, arg1:any /*org.objectweb.asm.ClassReader*/, arg2:int, arg3:int, arg4:chararray, arg5:int, arg6:[org.objectweb.asm.Label] ):org.objectweb.asm.Attribute; + readLabel( arg0:any /*org.objectweb.asm.ClassReader*/, arg1:int, arg2:[org.objectweb.asm.Label] ):org.objectweb.asm.Label; +} + +export const Attribute: AttributeStatic = Java.type("org.objectweb.asm.Attribute"); + + +interface CheckAnnotationAdapterStatic { + + readonly class:any; + new( arg0:any /*org.objectweb.asm.AnnotationVisitor*/ ):org.objectweb.asm.util.CheckAnnotationAdapter; +} + +export const CheckAnnotationAdapter: CheckAnnotationAdapterStatic = Java.type("org.objectweb.asm.util.CheckAnnotationAdapter"); + + +interface CheckClassAdapterStatic { + + readonly class:any; + new( arg0:any /*org.objectweb.asm.ClassVisitor*/, arg1:boolean ):org.objectweb.asm.util.CheckClassAdapter; + new( arg0:any /*org.objectweb.asm.ClassVisitor*/ ):org.objectweb.asm.util.CheckClassAdapter; + checkClassSignature( arg0:string ):void; + checkFieldSignature( arg0:string ):void; + checkMethodSignature( arg0:string ):void; + main( arg0:[string] ):void; + verify( arg0:any /*org.objectweb.asm.ClassReader*/, arg1:boolean, arg2:any /*java.io.PrintWriter*/ ):void; + verify( arg0:any /*org.objectweb.asm.ClassReader*/, arg1:any /*java.lang.ClassLoader*/, arg2:boolean, arg3:any /*java.io.PrintWriter*/ ):void; +} + +export const CheckClassAdapter: CheckClassAdapterStatic = Java.type("org.objectweb.asm.util.CheckClassAdapter"); + + +interface CheckFieldAdapterStatic { + + readonly class:any; + new( arg0:any /*org.objectweb.asm.FieldVisitor*/ ):org.objectweb.asm.util.CheckFieldAdapter; +} + +export const CheckFieldAdapter: CheckFieldAdapterStatic = Java.type("org.objectweb.asm.util.CheckFieldAdapter"); + + +interface CheckMethodAdapterStatic { + + readonly class:any; + new( arg0:int, arg1:string, arg2:string, arg3:any /*org.objectweb.asm.MethodVisitor*/, arg4:java.util.Map ):org.objectweb.asm.util.CheckMethodAdapter; + new( arg0:any /*org.objectweb.asm.MethodVisitor*/ ):org.objectweb.asm.util.CheckMethodAdapter; + new( arg0:any /*org.objectweb.asm.MethodVisitor*/, arg1:java.util.Map ):org.objectweb.asm.util.CheckMethodAdapter; +} + +export const CheckMethodAdapter: CheckMethodAdapterStatic = Java.type("org.objectweb.asm.util.CheckMethodAdapter"); + + +interface CheckModuleAdapterStatic { + + readonly class:any; + new( arg0:any /*org.objectweb.asm.ModuleVisitor*/, arg1:boolean ):org.objectweb.asm.util.CheckModuleAdapter; +} + +export const CheckModuleAdapter: CheckModuleAdapterStatic = Java.type("org.objectweb.asm.util.CheckModuleAdapter"); + + +interface CheckRecordComponentAdapterStatic { + + readonly class:any; + new( arg0:any /*org.objectweb.asm.RecordComponentVisitor*/ ):org.objectweb.asm.util.CheckRecordComponentAdapter; +} + +export const CheckRecordComponentAdapter: CheckRecordComponentAdapterStatic = Java.type("org.objectweb.asm.util.CheckRecordComponentAdapter"); + + +interface CheckSignatureAdapterStatic { + + readonly class:any; + new( arg0:int, arg1:any /*org.objectweb.asm.signature.SignatureVisitor*/ ):org.objectweb.asm.util.CheckSignatureAdapter; +} + +export const CheckSignatureAdapter: CheckSignatureAdapterStatic = Java.type("org.objectweb.asm.util.CheckSignatureAdapter"); + + +interface ClassNodeStatic { + + readonly class:any; + new( ):org.objectweb.asm.tree.ClassNode; + new( arg0:int ):org.objectweb.asm.tree.ClassNode; +} + +export const ClassNode: ClassNodeStatic = Java.type("org.objectweb.asm.tree.ClassNode"); + + +interface CollectionsStatic { + + readonly class:any; + checkedCollection( arg0:java.util.Collection, arg1:java.lang.Class ):java.util.Collection; + checkedList( arg0:java.util.List, arg1:java.lang.Class ):java.util.List; + checkedNavigableSet( arg0:any /*java.util.NavigableSet*/, arg1:java.lang.Class ):any /*java.util.NavigableSet*/; + emptyNavigableSet( ):any /*java.util.NavigableSet*/; + checkedQueue( arg0:any /*java.util.Queue*/, arg1:java.lang.Class ):any /*java.util.Queue*/; + checkedSet( arg0:java.util.Set, arg1:java.lang.Class ):java.util.Set; + newSetFromMap( arg0:java.util.Map ):java.util.Set; + checkedSortedSet( arg0:any /*java.util.SortedSet*/, arg1:java.lang.Class ):any /*java.util.SortedSet*/; + emptySortedSet( ):any /*java.util.SortedSet*/; + checkedMap( arg0:java.util.Map, arg1:java.lang.Class, arg2:java.lang.Class ):java.util.Map; + singletonMap( arg0:K, arg1:V ):java.util.Map; + synchronizedMap( arg0:java.util.Map ):java.util.Map; + unmodifiableMap( arg0:java.util.Map ):java.util.Map; + checkedNavigableMap( arg0:any /*java.util.NavigableMap*/, arg1:java.lang.Class, arg2:java.lang.Class ):any /*java.util.NavigableMap*/; + synchronizedNavigableMap( arg0:any /*java.util.NavigableMap*/ ):any /*java.util.NavigableMap*/; + unmodifiableNavigableMap( arg0:any /*java.util.NavigableMap*/ ):any /*java.util.NavigableMap*/; + checkedSortedMap( arg0:any /*java.util.SortedMap*/, arg1:java.lang.Class, arg2:java.lang.Class ):any /*java.util.SortedMap*/; + synchronizedSortedMap( arg0:any /*java.util.SortedMap*/ ):any /*java.util.SortedMap*/; + unmodifiableSortedMap( arg0:any /*java.util.SortedMap*/ ):any /*java.util.SortedMap*/; + sort( arg0:java.util.List ):void; + max( arg0:java.util.Collection ):T; + min( arg0:java.util.Collection ):T; + max( arg0:java.util.Collection, arg1:any /*java.util.Comparator*/ ):T; + min( arg0:java.util.Collection, arg1:any /*java.util.Comparator*/ ):T; + addAll( arg0:java.util.Collection, ...arg1:T[] ):boolean; + replaceAll( arg0:java.util.List, arg1:T, arg2:T ):boolean; + binarySearch( arg0:java.util.List, arg1:T, arg2:any /*java.util.Comparator*/ ):int; + binarySearch( arg0:java.util.List>, arg1:T ):int; + list( arg0:any /*java.util.Enumeration*/ ):any /*java.util.ArrayList*/; + synchronizedCollection( arg0:java.util.Collection ):java.util.Collection; + unmodifiableCollection( arg0:java.util.Collection ):java.util.Collection; + reverseOrder( ):any /*java.util.Comparator*/; + reverseOrder( arg0:any /*java.util.Comparator*/ ):any /*java.util.Comparator*/; + emptyEnumeration( ):any /*java.util.Enumeration*/; + enumeration( arg0:java.util.Collection ):any /*java.util.Enumeration*/; + emptyIterator( ):java.util.Iterator; + nCopies( arg0:int, arg1:T ):java.util.List; + singletonList( arg0:T ):java.util.List; + synchronizedList( arg0:java.util.List ):java.util.List; + unmodifiableList( arg0:java.util.List ):java.util.List; + emptyListIterator( ):any /*java.util.ListIterator*/; + synchronizedNavigableSet( arg0:any /*java.util.NavigableSet*/ ):any /*java.util.NavigableSet*/; + unmodifiableNavigableSet( arg0:any /*java.util.NavigableSet*/ ):any /*java.util.NavigableSet*/; + asLifoQueue( arg0:any /*java.util.Deque*/ ):any /*java.util.Queue*/; + singleton( arg0:T ):java.util.Set; + synchronizedSet( arg0:java.util.Set ):java.util.Set; + unmodifiableSet( arg0:java.util.Set ):java.util.Set; + synchronizedSortedSet( arg0:any /*java.util.SortedSet*/ ):any /*java.util.SortedSet*/; + unmodifiableSortedSet( arg0:any /*java.util.SortedSet*/ ):any /*java.util.SortedSet*/; + copy( arg0:java.util.List, arg1:java.util.List ):void; + fill( arg0:java.util.List, arg1:T ):void; + sort( arg0:java.util.List, arg1:any /*java.util.Comparator*/ ):void; + disjoint( arg0:java.util.Collection, arg1:java.util.Collection ):boolean; + emptyMap( ):java.util.Map; + emptyNavigableMap( ):any /*java.util.NavigableMap*/; + emptySortedMap( ):any /*java.util.SortedMap*/; + emptyList( ):java.util.List; + emptySet( ):java.util.Set; + frequency( arg0:java.util.Collection, arg1:any /*java.lang.Object*/ ):int; + indexOfSubList( arg0:java.util.List, arg1:java.util.List ):int; + lastIndexOfSubList( arg0:java.util.List, arg1:java.util.List ):int; + reverse( arg0:java.util.List ):void; + rotate( arg0:java.util.List, arg1:int ):void; + shuffle( arg0:java.util.List ):void; + shuffle( arg0:java.util.List, arg1:any /*java.util.Random*/ ):void; + swap( arg0:java.util.List, arg1:int, arg2:int ):void; +} + +export const Collections: CollectionsStatic = Java.type("java.util.Collections"); + + +interface CollectorsStatic { + + readonly class:any; + collectingAndThen( arg0:any /*java.util.stream.Collector*/, arg1:Func ):any /*java.util.stream.Collector*/; + filtering( arg0:Predicate, arg1:any /*java.util.stream.Collector*/ ):any /*java.util.stream.Collector*/; + toCollection( arg0:Supplier ):any /*java.util.stream.Collector*/; + partitioningBy( arg0:Predicate, arg1:any /*java.util.stream.Collector*/ ):any /*java.util.stream.Collector*/; + groupingByConcurrent( arg0:Func, arg1:Supplier, arg2:any /*java.util.stream.Collector*/ ):any /*java.util.stream.Collector*/; + groupingBy( arg0:Func, arg1:any /*java.util.stream.Collector*/ ):any /*java.util.stream.Collector*/; + groupingByConcurrent( arg0:Func, arg1:any /*java.util.stream.Collector*/ ):any /*java.util.stream.Collector*/; + groupingBy( arg0:Func, arg1:Supplier, arg2:any /*java.util.stream.Collector*/ ):any /*java.util.stream.Collector*/; + toMap( arg0:Func, arg1:Func, arg2:BinaryOperator, arg3:Supplier ):any /*java.util.stream.Collector*/; + toConcurrentMap( arg0:Func, arg1:Func, arg2:BinaryOperator, arg3:Supplier ):any /*java.util.stream.Collector*/; + toMap( arg0:Func, arg1:Func ):any /*java.util.stream.Collector*/; + toMap( arg0:Func, arg1:Func, arg2:BinaryOperator ):any /*java.util.stream.Collector*/; + toUnmodifiableMap( arg0:Func, arg1:Func ):any /*java.util.stream.Collector*/; + toUnmodifiableMap( arg0:Func, arg1:Func, arg2:BinaryOperator ):any /*java.util.stream.Collector*/; + toConcurrentMap( arg0:Func, arg1:Func ):any /*java.util.stream.Collector*/; + toConcurrentMap( arg0:Func, arg1:Func, arg2:BinaryOperator ):any /*java.util.stream.Collector*/; + groupingBy( arg0:Func ):any /*java.util.stream.Collector*/; + groupingByConcurrent( arg0:Func ):any /*java.util.stream.Collector*/; + teeing( arg0:any /*java.util.stream.Collector*/, arg1:any /*java.util.stream.Collector*/, arg2:BiFunction ):any /*java.util.stream.Collector*/; + flatMapping( arg0:Func>, arg1:any /*java.util.stream.Collector*/ ):any /*java.util.stream.Collector*/; + mapping( arg0:Func, arg1:any /*java.util.stream.Collector*/ ):any /*java.util.stream.Collector*/; + reducing( arg0:U, arg1:Func, arg2:BinaryOperator ):any /*java.util.stream.Collector*/; + reducing( arg0:T, arg1:BinaryOperator ):any /*java.util.stream.Collector*/; + averagingDouble( arg0:any /*java.util.function.ToDoubleFunction*/ ):any /*java.util.stream.Collector*/; + averagingInt( arg0:any /*java.util.function.ToIntFunction*/ ):any /*java.util.stream.Collector*/; + averagingLong( arg0:any /*java.util.function.ToLongFunction*/ ):any /*java.util.stream.Collector*/; + summingDouble( arg0:any /*java.util.function.ToDoubleFunction*/ ):any /*java.util.stream.Collector*/; + summingInt( arg0:any /*java.util.function.ToIntFunction*/ ):any /*java.util.stream.Collector*/; + counting( ):any /*java.util.stream.Collector*/; + summingLong( arg0:any /*java.util.function.ToLongFunction*/ ):any /*java.util.stream.Collector*/; + summarizingDouble( arg0:any /*java.util.function.ToDoubleFunction*/ ):any /*java.util.stream.Collector*/; + summarizingInt( arg0:any /*java.util.function.ToIntFunction*/ ):any /*java.util.stream.Collector*/; + toList( ):any /*java.util.stream.Collector*/; + toUnmodifiableList( ):any /*java.util.stream.Collector*/; + summarizingLong( arg0:any /*java.util.function.ToLongFunction*/ ):any /*java.util.stream.Collector*/; + partitioningBy( arg0:Predicate ):any /*java.util.stream.Collector*/; + maxBy( arg0:any /*java.util.Comparator*/ ):any /*java.util.stream.Collector*/; + minBy( arg0:any /*java.util.Comparator*/ ):any /*java.util.stream.Collector*/; + reducing( arg0:BinaryOperator ):any /*java.util.stream.Collector*/; + toSet( ):any /*java.util.stream.Collector*/; + toUnmodifiableSet( ):any /*java.util.stream.Collector*/; + joining( ):any /*java.util.stream.Collector*/; + joining( arg0:any /*java.lang.CharSequence*/ ):any /*java.util.stream.Collector*/; + joining( arg0:any /*java.lang.CharSequence*/, arg1:any /*java.lang.CharSequence*/, arg2:any /*java.lang.CharSequence*/ ):any /*java.util.stream.Collector*/; +} + +export const Collectors: CollectorsStatic = Java.type("java.util.stream.Collectors"); + + +interface FieldInsnNodeStatic { + + readonly class:any; + new( arg0:int, arg1:string, arg2:string, arg3:string ):org.objectweb.asm.tree.FieldInsnNode; +} + +export const FieldInsnNode: FieldInsnNodeStatic = Java.type("org.objectweb.asm.tree.FieldInsnNode"); + + +interface FieldNodeStatic { + + readonly class:any; + new( arg0:int, arg1:string, arg2:string, arg3:string, arg4:any /*java.lang.Object*/ ):org.objectweb.asm.tree.FieldNode; + new( arg0:int, arg1:int, arg2:string, arg3:string, arg4:string, arg5:any /*java.lang.Object*/ ):org.objectweb.asm.tree.FieldNode; +} + +export const FieldNode: FieldNodeStatic = Java.type("org.objectweb.asm.tree.FieldNode"); + + +interface FrameNodeStatic { + + readonly class:any; + new( arg0:int, arg1:int, arg2:[any /*java.lang.Object*/], arg3:int, arg4:[any /*java.lang.Object*/] ):org.objectweb.asm.tree.FrameNode; +} + +export const FrameNode: FrameNodeStatic = Java.type("org.objectweb.asm.tree.FrameNode"); + + +interface HandleStatic { + + readonly class:any; + new( arg0:int, arg1:string, arg2:string, arg3:string ):org.objectweb.asm.Handle; + new( arg0:int, arg1:string, arg2:string, arg3:string, arg4:boolean ):org.objectweb.asm.Handle; +} + +export const Handle: HandleStatic = Java.type("org.objectweb.asm.Handle"); + + +interface IincInsnNodeStatic { + + readonly class:any; + new( arg0:int, arg1:int ):org.objectweb.asm.tree.IincInsnNode; +} + +export const IincInsnNode: IincInsnNodeStatic = Java.type("org.objectweb.asm.tree.IincInsnNode"); + + +interface InsnListStatic { + + readonly class:any; + new( ):org.objectweb.asm.tree.InsnList; +} + +export const InsnList: InsnListStatic = Java.type("org.objectweb.asm.tree.InsnList"); + + +interface InsnNodeStatic { + + readonly class:any; + new( arg0:int ):org.objectweb.asm.tree.InsnNode; +} + +export const InsnNode: InsnNodeStatic = Java.type("org.objectweb.asm.tree.InsnNode"); + + +interface IntInsnNodeStatic { + + readonly class:any; + new( arg0:int, arg1:int ):org.objectweb.asm.tree.IntInsnNode; +} + +export const IntInsnNode: IntInsnNodeStatic = Java.type("org.objectweb.asm.tree.IntInsnNode"); + + +interface InvokeDynamicInsnNodeStatic { + + readonly class:any; + new( arg0:string, arg1:string, arg2:org.objectweb.asm.Handle, ...arg3:any /*java.lang.Object*/[] ):org.objectweb.asm.tree.InvokeDynamicInsnNode; +} + +export const InvokeDynamicInsnNode: InvokeDynamicInsnNodeStatic = Java.type("org.objectweb.asm.tree.InvokeDynamicInsnNode"); + + +interface IterableStatic { + + readonly class:any; + new( arg0:java.lang.Iterable ):java.lang.Iterable; +} + +export const Iterable: IterableStatic = Java.type("java.lang.Iterable"); + + +interface JumpInsnNodeStatic { + + readonly class:any; + new( arg0:int, arg1:org.objectweb.asm.tree.LabelNode ):org.objectweb.asm.tree.JumpInsnNode; +} + +export const JumpInsnNode: JumpInsnNodeStatic = Java.type("org.objectweb.asm.tree.JumpInsnNode"); + + +interface LabelNodeStatic { + + readonly class:any; + new( ):org.objectweb.asm.tree.LabelNode; + new( arg0:org.objectweb.asm.Label ):org.objectweb.asm.tree.LabelNode; +} + +export const LabelNode: LabelNodeStatic = Java.type("org.objectweb.asm.tree.LabelNode"); + + +interface LabelStatic { + + readonly class:any; + new( ):org.objectweb.asm.Label; +} + +export const Label: LabelStatic = Java.type("org.objectweb.asm.Label"); + + +interface LdcInsnNodeStatic { + + readonly class:any; + new( arg0:any /*java.lang.Object*/ ):org.objectweb.asm.tree.LdcInsnNode; +} + +export const LdcInsnNode: LdcInsnNodeStatic = Java.type("org.objectweb.asm.tree.LdcInsnNode"); + + +interface LineNumberNodeStatic { + + readonly class:any; + new( arg0:int, arg1:org.objectweb.asm.tree.LabelNode ):org.objectweb.asm.tree.LineNumberNode; +} + +export const LineNumberNode: LineNumberNodeStatic = Java.type("org.objectweb.asm.tree.LineNumberNode"); + + +interface LocalVariableAnnotationNodeStatic { + + readonly class:any; + new( arg0:int, arg1:org.objectweb.asm.TypePath, arg2:[org.objectweb.asm.tree.LabelNode], arg3:[org.objectweb.asm.tree.LabelNode], arg4:[int], arg5:string ):org.objectweb.asm.tree.LocalVariableAnnotationNode; + new( arg0:int, arg1:int, arg2:org.objectweb.asm.TypePath, arg3:[org.objectweb.asm.tree.LabelNode], arg4:[org.objectweb.asm.tree.LabelNode], arg5:[int], arg6:string ):org.objectweb.asm.tree.LocalVariableAnnotationNode; +} + +export const LocalVariableAnnotationNode: LocalVariableAnnotationNodeStatic = Java.type("org.objectweb.asm.tree.LocalVariableAnnotationNode"); + + +interface LocalVariableNodeStatic { + + readonly class:any; + new( arg0:string, arg1:string, arg2:string, arg3:org.objectweb.asm.tree.LabelNode, arg4:org.objectweb.asm.tree.LabelNode, arg5:int ):org.objectweb.asm.tree.LocalVariableNode; +} + +export const LocalVariableNode: LocalVariableNodeStatic = Java.type("org.objectweb.asm.tree.LocalVariableNode"); + + +interface LookupSwitchInsnNodeStatic { + + readonly class:any; + new( arg0:org.objectweb.asm.tree.LabelNode, arg1:[int], arg2:[org.objectweb.asm.tree.LabelNode] ):org.objectweb.asm.tree.LookupSwitchInsnNode; +} + +export const LookupSwitchInsnNode: LookupSwitchInsnNodeStatic = Java.type("org.objectweb.asm.tree.LookupSwitchInsnNode"); + + +interface MethodInsnNodeStatic { + + readonly class:any; + new( arg0:int, arg1:string, arg2:string, arg3:string ):org.objectweb.asm.tree.MethodInsnNode; + new( arg0:int, arg1:string, arg2:string, arg3:string, arg4:boolean ):org.objectweb.asm.tree.MethodInsnNode; +} + +export const MethodInsnNode: MethodInsnNodeStatic = Java.type("org.objectweb.asm.tree.MethodInsnNode"); + + +interface MethodNodeStatic { + + readonly class:any; + new( ):org.objectweb.asm.tree.MethodNode; + new( arg0:int, arg1:int, arg2:string, arg3:string, arg4:string, arg5:[string] ):org.objectweb.asm.tree.MethodNode; + new( arg0:int ):org.objectweb.asm.tree.MethodNode; + new( arg0:int, arg1:string, arg2:string, arg3:string, arg4:[string] ):org.objectweb.asm.tree.MethodNode; +} + +export const MethodNode: MethodNodeStatic = Java.type("org.objectweb.asm.tree.MethodNode"); + + +interface MultiANewArrayInsnNodeStatic { + + readonly class:any; + new( arg0:string, arg1:int ):org.objectweb.asm.tree.MultiANewArrayInsnNode; +} + +export const MultiANewArrayInsnNode: MultiANewArrayInsnNodeStatic = Java.type("org.objectweb.asm.tree.MultiANewArrayInsnNode"); + + +interface OptionalStatic { + + readonly class:any; + empty( ):java.util.Optional; + of( arg0:T ):java.util.Optional; + ofNullable( arg0:T ):java.util.Optional; +} + +export const Optional: OptionalStatic = Java.type("java.util.Optional"); + + +interface ParameterNodeStatic { + + readonly class:any; + new( arg0:string, arg1:int ):org.objectweb.asm.tree.ParameterNode; +} + +export const ParameterNode: ParameterNodeStatic = Java.type("org.objectweb.asm.tree.ParameterNode"); + + +interface PrinterStatic { + + readonly class:any; + appendString( arg0:any /*java.lang.StringBuilder*/, arg1:string ):void; +} + +export const Printer: PrinterStatic = Java.type("org.objectweb.asm.util.Printer"); + + +interface StreamStatic { + + readonly class:any; + builder( ):any /*java.util.stream.Stream$Builder*/; + concat( arg0:java.util.stream.Stream, arg1:java.util.stream.Stream ):java.util.stream.Stream; + empty( ):java.util.stream.Stream; + generate( arg0:Supplier ):java.util.stream.Stream; + iterate( arg0:T, arg1:Predicate, arg2:UnaryOperator ):java.util.stream.Stream; + iterate( arg0:T, arg1:UnaryOperator ):java.util.stream.Stream; + of( arg0:T ):java.util.stream.Stream; + of( ...arg0:T[] ):java.util.stream.Stream; + ofNullable( arg0:T ):java.util.stream.Stream; +} + +export const Stream: StreamStatic = Java.type("java.util.stream.Stream"); + + +interface StringStatic { + + readonly class:any; + new( arg0:any /*java.lang.StringBuffer*/ ):string; + new( arg0:any /*java.lang.StringBuilder*/ ):string; + new( arg0:bytearray, arg1:int, arg2:int, arg3:any /*java.nio.charset.Charset*/ ):string; + new( arg0:bytearray, arg1:string ):string; + new( arg0:bytearray, arg1:any /*java.nio.charset.Charset*/ ):string; + new( arg0:bytearray, arg1:int, arg2:int ):string; + new( arg0:bytearray ):string; + new( arg0:chararray, arg1:int, arg2:int ):string; + new( arg0:chararray ):string; + new( arg0:string ):string; + new( ):string; + new( arg0:bytearray, arg1:int, arg2:int, arg3:string ):string; + new( arg0:bytearray, arg1:int ):string; + new( arg0:bytearray, arg1:int, arg2:int, arg3:int ):string; + new( arg0:[int], arg1:int, arg2:int ):string; + copyValueOf( arg0:chararray ):string; + copyValueOf( arg0:chararray, arg1:int, arg2:int ):string; + format( arg0:string, ...arg1:any /*java.lang.Object*/[] ):string; + format( arg0:any /*java.util.Locale*/, arg1:string, ...arg2:any /*java.lang.Object*/[] ):string; + join( arg0:any /*java.lang.CharSequence*/, ...arg1:any /*java.lang.CharSequence*/[] ):string; + join( arg0:any /*java.lang.CharSequence*/, arg1:java.lang.Iterable ):string; + valueOf( arg0:boolean ):string; + valueOf( arg0:any /*char*/ ):string; + valueOf( arg0:chararray ):string; + valueOf( arg0:chararray, arg1:int, arg2:int ):string; + valueOf( arg0:double ):string; + valueOf( arg0:float ):string; + valueOf( arg0:int ):string; + valueOf( arg0:any /*java.lang.Object*/ ):string; + valueOf( arg0:long ):string; +} + +export const String: StringStatic = Java.type("java.lang.String"); + + +interface TableSwitchInsnNodeStatic { + + readonly class:any; + new( arg0:int, arg1:int, arg2:org.objectweb.asm.tree.LabelNode, ...arg3:org.objectweb.asm.tree.LabelNode[] ):org.objectweb.asm.tree.TableSwitchInsnNode; +} + +export const TableSwitchInsnNode: TableSwitchInsnNodeStatic = Java.type("org.objectweb.asm.tree.TableSwitchInsnNode"); + + +interface TextifierStatic { + + readonly class:any; + new( ):org.objectweb.asm.util.Textifier; + appendString( arg0:any /*java.lang.StringBuilder*/, arg1:string ):void; + main( arg0:[string] ):void; +} + +export const Textifier: TextifierStatic = Java.type("org.objectweb.asm.util.Textifier"); + + +interface TextifierSupportStatic { + + readonly class:any; +} + +export const TextifierSupport: TextifierSupportStatic = Java.type("org.objectweb.asm.util.TextifierSupport"); + + +interface TraceAnnotationVisitorStatic { + + readonly class:any; + new( arg0:org.objectweb.asm.util.Printer ):org.objectweb.asm.util.TraceAnnotationVisitor; + new( arg0:any /*org.objectweb.asm.AnnotationVisitor*/, arg1:org.objectweb.asm.util.Printer ):org.objectweb.asm.util.TraceAnnotationVisitor; +} + +export const TraceAnnotationVisitor: TraceAnnotationVisitorStatic = Java.type("org.objectweb.asm.util.TraceAnnotationVisitor"); + + +interface TraceClassVisitorStatic { + + readonly class:any; + new( arg0:any /*org.objectweb.asm.ClassVisitor*/, arg1:org.objectweb.asm.util.Printer, arg2:any /*java.io.PrintWriter*/ ):org.objectweb.asm.util.TraceClassVisitor; + new( arg0:any /*org.objectweb.asm.ClassVisitor*/, arg1:any /*java.io.PrintWriter*/ ):org.objectweb.asm.util.TraceClassVisitor; + new( arg0:any /*java.io.PrintWriter*/ ):org.objectweb.asm.util.TraceClassVisitor; +} + +export const TraceClassVisitor: TraceClassVisitorStatic = Java.type("org.objectweb.asm.util.TraceClassVisitor"); + + +interface TraceFieldVisitorStatic { + + readonly class:any; + new( arg0:org.objectweb.asm.util.Printer ):org.objectweb.asm.util.TraceFieldVisitor; + new( arg0:any /*org.objectweb.asm.FieldVisitor*/, arg1:org.objectweb.asm.util.Printer ):org.objectweb.asm.util.TraceFieldVisitor; +} + +export const TraceFieldVisitor: TraceFieldVisitorStatic = Java.type("org.objectweb.asm.util.TraceFieldVisitor"); + + +interface TraceMethodVisitorStatic { + + readonly class:any; + new( arg0:org.objectweb.asm.util.Printer ):org.objectweb.asm.util.TraceMethodVisitor; + new( arg0:any /*org.objectweb.asm.MethodVisitor*/, arg1:org.objectweb.asm.util.Printer ):org.objectweb.asm.util.TraceMethodVisitor; +} + +export const TraceMethodVisitor: TraceMethodVisitorStatic = Java.type("org.objectweb.asm.util.TraceMethodVisitor"); + + +interface TraceModuleVisitorStatic { + + readonly class:any; + new( arg0:org.objectweb.asm.util.Printer ):org.objectweb.asm.util.TraceModuleVisitor; + new( arg0:any /*org.objectweb.asm.ModuleVisitor*/, arg1:org.objectweb.asm.util.Printer ):org.objectweb.asm.util.TraceModuleVisitor; +} + +export const TraceModuleVisitor: TraceModuleVisitorStatic = Java.type("org.objectweb.asm.util.TraceModuleVisitor"); + + +interface TraceSignatureVisitorStatic { + + readonly class:any; + new( arg0:int ):org.objectweb.asm.util.TraceSignatureVisitor; +} + +export const TraceSignatureVisitor: TraceSignatureVisitorStatic = Java.type("org.objectweb.asm.util.TraceSignatureVisitor"); + + +interface TryCatchBlockNodeStatic { + + readonly class:any; + new( arg0:org.objectweb.asm.tree.LabelNode, arg1:org.objectweb.asm.tree.LabelNode, arg2:org.objectweb.asm.tree.LabelNode, arg3:string ):org.objectweb.asm.tree.TryCatchBlockNode; +} + +export const TryCatchBlockNode: TryCatchBlockNodeStatic = Java.type("org.objectweb.asm.tree.TryCatchBlockNode"); + + +interface TypeAnnotationNodeStatic { + + readonly class:any; + new( arg0:int, arg1:org.objectweb.asm.TypePath, arg2:string ):org.objectweb.asm.tree.TypeAnnotationNode; + new( arg0:int, arg1:int, arg2:org.objectweb.asm.TypePath, arg3:string ):org.objectweb.asm.tree.TypeAnnotationNode; +} + +export const TypeAnnotationNode: TypeAnnotationNodeStatic = Java.type("org.objectweb.asm.tree.TypeAnnotationNode"); + + +interface TypeInsnNodeStatic { + + readonly class:any; + new( arg0:int, arg1:string ):org.objectweb.asm.tree.TypeInsnNode; +} + +export const TypeInsnNode: TypeInsnNodeStatic = Java.type("org.objectweb.asm.tree.TypeInsnNode"); + + +interface TypePathStatic { + + readonly class:any; + fromString( arg0:string ):org.objectweb.asm.TypePath; +} + +export const TypePath: TypePathStatic = Java.type("org.objectweb.asm.TypePath"); + + +interface TypeReferenceStatic { + + readonly class:any; + new( arg0:int ):org.objectweb.asm.TypeReference; + newExceptionReference( arg0:int ):org.objectweb.asm.TypeReference; + newFormalParameterReference( arg0:int ):org.objectweb.asm.TypeReference; + newSuperTypeReference( arg0:int ):org.objectweb.asm.TypeReference; + newTryCatchReference( arg0:int ):org.objectweb.asm.TypeReference; + newTypeArgumentReference( arg0:int, arg1:int ):org.objectweb.asm.TypeReference; + newTypeParameterBoundReference( arg0:int, arg1:int, arg2:int ):org.objectweb.asm.TypeReference; + newTypeParameterReference( arg0:int, arg1:int ):org.objectweb.asm.TypeReference; + newTypeReference( arg0:int ):org.objectweb.asm.TypeReference; +} + +export const TypeReference: TypeReferenceStatic = Java.type("org.objectweb.asm.TypeReference"); + + +interface TypeStatic { + + readonly class:any; + getArgumentCount( arg0:string ):int; + getArgumentsAndReturnSizes( arg0:string ):int; + getConstructorDescriptor( arg0:any /*java.lang.reflect.Constructor*/ ):string; + getDescriptor( arg0:java.lang.Class ):string; + getInternalName( arg0:java.lang.Class ):string; + getMethodDescriptor( arg0:any /*java.lang.reflect.Method*/ ):string; + getMethodDescriptor( arg0:org.objectweb.asm.Type, ...arg1:org.objectweb.asm.Type[] ):string; + getMethodType( arg0:string ):org.objectweb.asm.Type; + getMethodType( arg0:org.objectweb.asm.Type, ...arg1:org.objectweb.asm.Type[] ):org.objectweb.asm.Type; + getObjectType( arg0:string ):org.objectweb.asm.Type; + getReturnType( arg0:string ):org.objectweb.asm.Type; + getReturnType( arg0:any /*java.lang.reflect.Method*/ ):org.objectweb.asm.Type; + getType( arg0:java.lang.Class ):org.objectweb.asm.Type; + getType( arg0:string ):org.objectweb.asm.Type; + getType( arg0:any /*java.lang.reflect.Constructor*/ ):org.objectweb.asm.Type; + getType( arg0:any /*java.lang.reflect.Method*/ ):org.objectweb.asm.Type; + getArgumentTypes( arg0:string ):[org.objectweb.asm.Type]; + getArgumentTypes( arg0:any /*java.lang.reflect.Method*/ ):[org.objectweb.asm.Type]; +} + +export const Type: TypeStatic = Java.type("org.objectweb.asm.Type"); + + +interface VarInsnNodeStatic { + + readonly class:any; + new( arg0:int, arg1:int ):org.objectweb.asm.tree.VarInsnNode; +} + +export const VarInsnNode: VarInsnNodeStatic = Java.type("org.objectweb.asm.tree.VarInsnNode"); + + diff --git a/src/main/resources/asm.d.ts b/src/main/resources/asm.d.ts new file mode 100644 index 0000000..7992a27 --- /dev/null +++ b/src/main/resources/asm.d.ts @@ -0,0 +1,404 @@ +declare interface _AbstractInsnNode { + opcode: number +} + +declare interface _LdcInsnNode extends _AbstractInsnNode { + new(constant: any) + cst: any +} + +declare interface _VarInsnNode extends _AbstractInsnNode { + new(opcode: number, varIdx: number) + "var": number +} + +declare interface _InsnNode extends _AbstractInsnNode { + new(opcode: number) +} + +declare interface _MethodInsnNode extends _AbstractInsnNode { + new(opcode: number, owner: string, name: string, descriptor: string, isInterface?: boolean) + owner: string, + name: string, + desc: string, + itf: boolean +} + +declare interface _TypeInsnNode extends _AbstractInsnNode { + new(opcode: number, type: string) + desc: string +} + +declare interface _InsnList { + new() + + get(i: number): AbstractInsnNode + + add(insn: AbstractInsnNode | _InsnList) + + remove(insn: AbstractInsnNode) + + removeAll(mark: boolean) + + getFirst(): AbstractInsnNode + + getLast(): AbstractInsnNode + + size(): number + + clear(): void + + resetLabels(): void + + contains(node: AbstractInsnNode): boolean + + indexOf(insnNode: AbstractInsnNode): number + + toArray(): AbstractInsnNode[] + + set(oldInsnNode: AbstractInsnNode, newInsnNode: AbstractInsnNode): void + + insert(insnNode: AbstractInsnNode, otherNode?: AbstractInsnNode | _InsnList): void + + insertBefore(insnNode: AbstractInsnNode, otherNode: AbstractInsnNode | _InsnList): void + + +} + +declare interface _Opcodes { + ASM4: number + ASM5: number + ASM6: number + ASM7: number + ASM8: number + ASM9: number + + + + SOURCE_DEPRECATED: number + SOURCE_MASK: number + + // Java ClassFile versions (the minor version is stored in the 16 most significant bits, and the + // major version in the 16 least significant bits). + + V1_1: number + V1_2: number + V1_3: number + V1_4: number + V1_5: number + V1_6: number + V1_7: number + V1_8: number + V9: number + V10: number + V11: number + V12: number + V13: number + V14: number + V15: number + V16: number + V17: number + V18: number + V19: number + V20: number + V21: number + V22: number + V23: number + + /** + * Version flag indicating that the class is using 'preview' features. + * + *

{@code version & V_PREVIEW == V_PREVIEW} tests if a version is flagged with {@code + * V_PREVIEW}. + */ + V_PREVIEW: number + + // Access flags values, defined in + // - https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.1-200-E.1 + // - https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.5-200-A.1 + // - https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.6-200-A.1 + // - https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.25 + + ACC_PUBLIC: number + ACC_PRIVATE: number + ACC_PROTECTED: number + ACC_STATIC: number + ACC_FINAL: number + ACC_SUPER: number + ACC_SYNCHRONIZED: number + ACC_OPEN: number + ACC_TRANSITIVE: number + ACC_VOLATILE: number + ACC_BRIDGE: number + ACC_STATIC_PHASE: number + ACC_VARARGS: number + ACC_TRANSIENT: number + ACC_NATIVE: number + ACC_INTERFACE: number + ACC_ABSTRACT: number + ACC_STRICT: number + ACC_SYNTHETIC: number + ACC_ANNOTATION: number + ACC_ENUM: number + ACC_MANDATED: number + ACC_MODULE: number + + // ASM specific access flags. + // WARNING: the 16 least significant bits must NOT be used, to avoid conflicts with standard + // access flags, and also to make sure that these flags are automatically filtered out when + // written in class files (because access flags are stored using 16 bits only). + + ACC_RECORD: number + ACC_DEPRECATED: number + + // Possible values for the type operand of the NEWARRAY instruction. + // See https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-6.html#jvms-6.5.newarray. + + T_BOOLEAN: number + T_CHAR: number + T_FLOAT: number + T_DOUBLE: number + T_BYTE: number + T_SHORT: number + T_INT: number + T_LONG: number + + // Possible values for the reference_kind field of CONSTANT_MethodHandle_info structures. + // See https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.4.8. + + H_GETFIELD: number + H_GETSTATIC: number + H_PUTFIELD: number + H_PUTSTATIC: number + H_INVOKEVIRTUAL: number + H_INVOKESTATIC: number + H_INVOKESPECIAL: number + H_NEWINVOKESPECIAL: number + H_INVOKEINTERFACE: number + + // ASM specific stack map frame types, used in {@link ClassVisitor#visitFrame}. + + /** An expanded frame. See {@link ClassReader#EXPAND_FRAMES}. */ + F_NEW: number + + /** A compressed frame with complete frame data. */ + F_FULL: number + + /** + * A compressed frame where locals are the same as the locals in the previous frame, except that + * additional 1-3 locals are defined, and with an empty stack. + */ + F_APPEND: number + + /** + * A compressed frame where locals are the same as the locals in the previous frame, except that + * the last 1-3 locals are absent and with an empty stack. + */ + F_CHOP: number + + /** + * A compressed frame with exactly the same locals as the previous frame and with an empty stack. + */ + F_SAME: number + + /** + * A compressed frame with exactly the same locals as the previous frame and with a single value + * on the stack. + */ + F_SAME1: number + + // Standard stack map frame element types, used in {@link ClassVisitor#visitFrame}. + + TOP: number + INTEGER: number + FLOAT: number + DOUBLE: number + LONG: number + NULL: number + UNINITIALIZED_THIS: number + + // The JVM opcode values (with the MethodVisitor method name used to visit them in comment, and + // where '-' means 'same method name as on the previous line'). + // See https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-6.html. + + NOP: number + ACONST_NULL: number + ICONST_M1: number + ICONST_0: number + ICONST_1: number + ICONST_2: number + ICONST_3: number + ICONST_4: number + ICONST_5: number + LCONST_0: number + LCONST_1: number + FCONST_0: number + FCONST_1: number + FCONST_2: number + DCONST_0: number + DCONST_1: number + BIPUSH: number + SIPUSH: number + LDC: number + ILOAD: number + LLOAD: number + FLOAD: number + DLOAD: number + ALOAD: number + IALOAD: number + LALOAD: number + FALOAD: number + DALOAD: number + AALOAD: number + BALOAD: number + CALOAD: number + SALOAD: number + ISTORE: number + LSTORE: number + FSTORE: number + DSTORE: number + ASTORE: number + IASTORE: number + LASTORE: number + FASTORE: number + DASTORE: number + AASTORE: number + BASTORE: number + CASTORE: number + SASTORE: number + POP: number + POP2: number + DUP: number + DUP_X1: number + DUP_X2: number + DUP2: number + DUP2_X1: number + DUP2_X2: number + SWAP: number + IADD: number + LADD: number + FADD: number + DADD: number + ISUB: number + LSUB: number + FSUB: number + DSUB: number + IMUL: number + LMUL: number + FMUL: number + DMUL: number + IDIV: number + LDIV: number + FDIV: number + DDIV: number + IREM: number + LREM: number + FREM: number + DREM: number + INEG: number + LNEG: number + FNEG: number + DNEG: number + ISHL: number + LSHL: number + ISHR: number + LSHR: number + IUSHR: number + LUSHR: number + IAND: number + LAND: number + IOR: number + LOR: number + IXOR: number + LXOR: number + IINC: number + I2L: number + I2F: number + I2D: number + L2I: number + L2F: number + L2D: number + F2I: number + F2L: number + F2D: number + D2I: number + D2L: number + D2F: number + I2B: number + I2C: number + I2S: number + LCMP: number + FCMPL: number + FCMPG: number + DCMPL: number + DCMPG: number + IFEQ: number + IFNE: number + IFLT: number + IFGE: number + IFGT: number + IFLE: number + IF_ICMPEQ: number + IF_ICMPNE: number + IF_ICMPLT: number + IF_ICMPGE: number + IF_ICMPGT: number + IF_ICMPLE: number + IF_ACMPEQ: number + IF_ACMPNE: number + GOTO: number + JSR: number + RET: number + TABLESWITCH: number + LOOKUPSWITCH: number + IRETURN: number + LRETURN: number + FRETURN: number + DRETURN: number + ARETURN: number + RETURN: number + GETSTATIC: number + PUTSTATIC: number + GETFIELD: number + PUTFIELD: number + INVOKEVIRTUAL: number + INVOKESPECIAL: number + INVOKESTATIC: number + INVOKEINTERFACE: number + INVOKEDYNAMIC: number + NEW: number + NEWARRAY: number + ANEWARRAY: number + ARRAYLENGTH: number + ATHROW: number + CHECKCAST: number + INSTANCEOF: number + MONITORENTER: number + MONITOREXIT: number + MULTIANEWARRAY: number + IFNULL: number + IFNONNULL: number +} + +declare interface Java { + type(name: 'org.objectweb.asm.tree.InsnList'): _InsnList + + type(name: 'org.objectweb.asm.tree.AbstractInsnNode'): _AbstractInsnNode + + type(name: 'org.objectweb.asm.tree.InsnNode'): _InsnNode + + type(name: 'org.objectweb.asm.tree.LdcInsnNode'): _LdcInsnNode + + type(name: 'org.objectweb.asm.tree.MethodInsnNode'): _MethodInsnNode + + type(name: 'org.objectweb.asm.tree.VarInsnNode'): _VarInsnNode + + type(name: 'org.objectweb.asm.tree.MethodNode'): _MethodNode + + type(name: 'org.objectweb.asm.tree.TypeInsnNode'): _TypeInsnNode + + type(name: 'org.objectweb.asm.Opcodes'): _Opcodes +} + + + diff --git a/src/main/resources/asmapi.d.ts b/src/main/resources/asmapi.d.ts new file mode 100644 index 0000000..85d3fe8 --- /dev/null +++ b/src/main/resources/asmapi.d.ts @@ -0,0 +1,206 @@ +import MethodType = ASMAPI.MethodType; +import InsertMode = ASMAPI.InsertMode; + +type MethodNode = any +type MethodInsnNode = any +type AbstractInsnNode = any +type ClassNode = any +type FieldNode = any +type InsnList = any + + + + +declare interface ASMAPI { + + /** + * Helper to construct a new empty MethodNode. + */ + getMethodNode(): MethodNode + + /** + * Add a MethodInsnNode to the beginning of the target MethodNode's instructions list. + * @param node + * @param methodCall + */ + appendMethodCall(node: MethodNode, methodCall: MethodInsnNode): void + + + + + /** + * Helper to build a MethodInsnNode. + * @param ownerName The name of the owner, from bytecode. + * @param methodName The method name, from bytecode. + * @param methodDescriptor The method descriptor, from bytecode. + * @param type The type of the method to be invoked. + */ + buildMethodCall(ownerName: String, methodName: String, methodDescriptor: String, type: MethodType): MethodInsnNode + + /** + * Convert a method name from SRG to deobfuscated. + * @param name The SRG name of a method. + */ + mapMethod(name: String): String + + /** + * Convert a field name from SRG to deobfuscated. + * @param name The SRG name of a field. + */ + mapField(name: String): String + + /** + * Checks if the given JVM property (or if the property prepended with {@code "coremod."}) is {@code true}. + * + * @param propertyName the property to check + * @return true if the property is true + */ + getSystemPropertyFlag(propertyName: String): boolean + + + + /** + * Finds the first instruction with matching opcode + * + * @param method the method to search in + * @param opCode the opcode to search for + * @return the found instruction node or null if none matched + */ + findFirstInstruction(method: MethodNode, opCode: number): AbstractInsnNode + + /** + * Finds the first instruction with matching opcode after the given start index + * + * @param method the method to search in + * @param opCode the opcode to search for + * @param startIndex the index to start search after (inclusive) + * @return the found instruction node or null if none matched after the given index + */ + findFirstInstructionAfter(method: MethodNode, opCode: number, startIndex: number): AbstractInsnNode ; + + /** + * Finds the first instruction with matching opcode before the given index in reverse search + * + * @param method the method to search in + * @param opCode the opcode to search for + * @param startIndex the index at which to start searching (inclusive) + * @return the found instruction node or null if none matched before the given startIndex + */ + findFirstInstructionBefore(method: MethodNode, opCode: number, startIndex: number): AbstractInsnNode; + + /** + * Finds the first method call in the given method matching the given type, owner, name and descriptor + * + * @param method the method to search in + * @param type the type of method call to search for + * @param owner the method call's owner to search for + * @param name the method call's name + * @param descriptor the method call's descriptor + * @return the found method call node or null if none matched + */ + findFirstMethodCall(method: MethodNode, type: MethodType, owner: String, name: String, descriptor: String): MethodInsnNode + + /** + * Finds the first method call in the given method matching the given type, owner, name and descriptor + * after the instruction given index + * + * @param method the method to search in + * @param type the type of method call to search for + * @param owner the method call's owner to search for + * @param name the method call's name + * @param descriptor the method call's descriptor + * @param startIndex the index after which to start searching (inclusive) + * @return the found method call node, null if none matched after the given index + */ + findFirstMethodCallAfter(method: MethodNode, type: MethodType, owner: String, name: String, descriptor: String, startIndex: number): MethodInsnNode; + + /** + * Finds the first method call in the given method matching the given type, owner, name and descriptor + * before the given index in reverse search + * + * @param method the method to search in + * @param type the type of method call to search for + * @param owner the method call's owner to search for + * @param name the method call's name + * @param descriptor the method call's descriptor + * @param startIndex the index at which to start searching (inclusive) + * @return the found method call node or null if none matched before the given startIndex + */ + findFirstMethodCallBefore(method: MethodNode, type: MethodType, owner: String, name: String, descriptor: String, startIndex: number): MethodInsnNode; + + /** + * Inserts/replaces a list after/before first {@link MethodInsnNode} that matches the parameters of these functions in the method provided. + * Only the first node matching is targeted, all other matches are ignored. + * @param method The method where you want to find the node + * @param type The type of the old method node. + * @param owner The owner of the old method node. + * @param name The name of the old method node. You may want to use {@link #mapMethod(String)} if this is a srg name + * @param desc The desc of the old method node. + * @param list The list that should be inserted + * @param mode How the given code should be inserted + * @return True if the node was found, false otherwise + */ + insertInsnList(method: MethodNode, type: MethodType, owner: String, name: String, desc: String, list: InsnList, mode: InsertMode): boolean; + + /** + * Builds a new {@link InsnList} out of the specified AbstractInsnNodes + * @param nodes The nodes you want to add + * @return A new list with the nodes + */ + listOf(...nodes: AbstractInsnNode): InsnList + + /** + * Rewrites accesses to a specific field in the given class to a method-call. + * + * The field specified by fieldName must be private and non-static. + * The method-call the field-access is redirected to does not take any parameters and returns an object of the + * same type as the field. + * If no methodName is passed, any method matching the described signature will be used as callable method. + * + * @param classNode the class to rewrite the accesses in + * @param fieldName the field accesses should be redirected to + * @param methodName the name of the method to redirect accesses through, + * or null if any method with matching signature should be applicable + */ + redirectFieldToMethod(classNode: ClassNode, fieldName: String, methodName: String): void + + loadFile(file: String): boolean + + /** + * Load a JSON file as an object. + * @param file Path to the file, from the resources directory/root of the jar. + */ + loadData(file: String): T + + log(level: String, message: String, ...args: any): void + + classNodeToString(node: ClassNode): String + + fieldNodeToString(node: FieldNode): String + + methodNodeToString(node: MethodNode): String +} + +declare namespace ASMAPI { + namespace MethodType { + const VIRTUAL: MethodType + const SPECIAL: MethodType + const STATIC: MethodType + const INTERFACE: MethodType + const DYNAMIC: MethodType + } + + interface MethodType { + toOpcode(): number; + } + + enum InsertMode { + REMOVE_ORIGINAL, + INSERT_BEFORE, + INSERT_AFTER + } +} + +declare interface Java { + type(name: 'net.minecraftforge.coremod.api.ASMAPI'): ASMAPI +} diff --git a/src/main/resources/index.d.ts b/src/main/resources/index.d.ts new file mode 100644 index 0000000..bbe8141 --- /dev/null +++ b/src/main/resources/index.d.ts @@ -0,0 +1,117 @@ +/// + +/** + * org.objectweb.asm.tree.ClassNode + */ +type ClassNode = any; + +/** + * org.objectweb.asm.tree.MethodNode + */ +type MethodNode = any; + +/** + * org.objectweb.asm.tree.FieldNode + */ +type FieldNode = any; + + +declare interface MultiClassTarget { + "type": "CLASS" + + /** + * A function returning a list of class names to target. + * @param self This object. + */ + "names": (self: MultiClassTarget) => string[] +} + +declare interface SingleClassTarget { + "type": "CLASS" + + /** + * String representing the class name to target. + * String must contain the fully qualified name of the class. (e.g. "net.minecraft.world.level.Block") + */ + "name": string +} + +declare interface ClassTransformer { + /** + * The target discriminator. + */ + "target": SingleClassTarget | MultiClassTarget, + /** + * Function to transform the class. Must return its input. + * ClassNode: org.objectweb.asm.tree.ClassNode. + */ + "transformer": ((classNode: ClassNode) => ClassNode) +} + +declare interface MethodTransformer { + /** + * The target discriminator. + */ + "target": { + "type": "METHOD", + /** + * The fully qualified name of the target class. (e.g. "net.minecraft.world.level.Block") + */ + "class": string, + + /** + * The SRG name of the target method, if obfuscated. (e.g. Block.byName -> m_49814_) + * (Will be remapped by FML using ASMAPI.mapMethod when evaluated.) + * + * If the target is NOT an obfuscated class or inherited method, then this should be the normal method name. + */ + "methodName": string, + + /** + * The target method's descriptor/signature. [e.g. "(Lnet/minecraft/world/item/Item;)Lnet/minecraft/world/level/block/Block;"] + */ + "methodDesc": string + }, + /** + * Function to transform the method. Must return the input. + * MethodNode: org.objectweb.asm.tree.MethodNode. + */ + "transformer": ((methodNode: MethodNode) => MethodNode) +} + +declare interface FieldTransformer { + /** + * The target discriminator. + */ + "target": { + "type": "METHOD", + + /** + * The fully qualified name of the target class. (e.g. "net.minecraft.world.level.Block") + */ + "class": string, + + /** + * The SRG name of the target field, if obfuscated. (e.g. Block#descriptionId -> f_49787_) + * + * If the target is NOT an obfuscated class or inherited field, then this should be the normal field name. + */ + "fieldName": string, + }, + /** + * Function to transform the field. Must return the input. + */ + "transformer": ((fieldNode: FieldNode) => FieldNode) +} + +/** + * Contains the declared transformers for this file, in the form "{ 'TransformerName': }" + */ +declare interface CoreModInitializer { + [transformerName: string]: ClassTransformer | MethodTransformer | FieldTransformer +} + +/** + * Entry point to the coremod script. + */ +declare function initializeCoreMod(): CoreModInitializer;