List of usage examples for org.objectweb.asm.commons Remapper mapMethodDesc
public String mapMethodDesc(final String methodDescriptor)
From source file:com.wolvereness.overmapped.MembersSubRoutine.java
License:Open Source License
private static String parseDescription(final Remapper inverseMapper, final MutableSignature mutableSignature, final String unresolvedDescription) { return unresolvedDescription != null ? mutableSignature.update("", "", unresolvedDescription).isMethod() ? inverseMapper.mapMethodDesc(unresolvedDescription) : inverseMapper.mapDesc(unresolvedDescription) : null; }
From source file:net.minecrell.quartz.launch.mappings.Mappings.java
License:MIT License
protected Mappings(List<ClassNode> mappingClasses) { requireNonNull(mappingClasses, "mappingClasses"); if (mappingClasses.isEmpty()) { this.classes = ImmutableBiMap.of(); this.methods = ImmutableTable.of(); this.fields = ImmutableTable.of(); this.constructors = ImmutableMultimap.of(); this.accessMappings = ImmutableTable.of(); return;//w w w . java2 s .c om } ImmutableBiMap.Builder<String, String> classes = ImmutableBiMap.builder(); for (ClassNode classNode : mappingClasses) { ParsedAnnotation annotation = MappingsParser.getAnnotation(classNode, MAPPING); checkState(annotation != null, "Class %s is missing the @Mapping annotation", classNode.name); String mapping = annotation.getString("value", ""); if (!mapping.isEmpty()) { classes.put(mapping, classNode.name); } } this.classes = classes.build(); // We need to remap the descriptors of the fields and methods, use ASM for convenience Remapper remapper = new Remapper() { @Override public String map(String className) { return unmap(className); } }; // Load field, method and access mappings ImmutableTable.Builder<String, String, String> methods = ImmutableTable.builder(); ImmutableTable.Builder<String, String, String> fields = ImmutableTable.builder(); ImmutableMultimap.Builder<String, MethodNode> constructors = ImmutableMultimap.builder(); ImmutableTable.Builder<String, String, AccessMapping> accessMappings = ImmutableTable.builder(); for (ClassNode classNode : mappingClasses) { String className = classNode.name.replace('/', '.'); String internalName = unmap(classNode.name); ParsedAnnotation annotation = MappingsParser.getAnnotation(classNode, ACCESSIBLE); if (annotation != null) { accessMappings.put(className, "", AccessMapping.of(classNode)); } for (MethodNode methodNode : classNode.methods) { Map<String, ParsedAnnotation> annotations = MappingsParser.getAnnotations(methodNode); annotation = annotations.get(CONSTRUCTOR); if (annotation != null) { // Generate constructor call code Methods.visitConstructor(methodNode, classNode.name); constructors.put(className, methodNode); continue; } // TODO: Validation annotation = annotations.get(MAPPING); if (annotation != null) { String mapping = annotation.getString("value", ""); if (!mapping.isEmpty()) { methods.put(internalName, mapping + remapper.mapMethodDesc(methodNode.desc), methodNode.name); } } annotation = annotations.get(ACCESSIBLE); if (annotation != null) { accessMappings.put(className, methodNode.name + methodNode.desc, AccessMapping.of(methodNode)); } } for (FieldNode fieldNode : classNode.fields) { Map<String, ParsedAnnotation> annotations = MappingsParser.getAnnotations(fieldNode); // TODO: Validation annotation = annotations.get(MAPPING); if (annotation != null) { String mapping = annotation.getString("value", ""); if (!mapping.isEmpty()) { fields.put(internalName, mapping + ':' + remapper.mapDesc(fieldNode.desc), fieldNode.name); } } annotation = annotations.get(ACCESSIBLE); if (annotation != null) { accessMappings.put(className, fieldNode.name, AccessMapping.of(fieldNode)); } } } this.methods = methods.build(); this.fields = fields.build(); this.constructors = constructors.build(); this.accessMappings = accessMappings.build(); }
From source file:net.minecrell.quartz.mappings.processor.MappingsGeneratorProcessor.java
License:Open Source License
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { if (roundEnv.processingOver()) { return false; }/*from w w w.j ava2s . co m*/ List<TypeElement> mappingClasses = new ArrayList<>(); for (Element element : roundEnv.getElementsAnnotatedWith(Mapping.class)) { if (element instanceof TypeElement) { mappingClasses.add((TypeElement) element); } } if (mappingClasses.isEmpty()) { return true; } try { FileObject file = this.processingEnv.getFiler().getResource(StandardLocation.CLASS_OUTPUT, "", "mappings.json"); Map<String, MappedClass> mappings; try (Reader reader = file.openReader(false)) { mappings = Mappings.read(reader); } catch (IOException ignored) { mappings = new HashMap<>(); } ClassMapper classMappings = createMapper(mappingClasses); // We need to remap the descriptors of the fields and methods, use ASM for convenience Remapper unmapper = classMappings.createUnmapper(); for (TypeElement mappingClass : mappingClasses) { String internalName = getInternalName(mappingClass); Mapping annotation = mappingClass.getAnnotation(Mapping.class); String mappedName = annotation.value(); if (mappedName.isEmpty()) { mappedName = internalName; } MappedClass mapping = new MappedClass(mappedName); Accessible accessible = mappingClass.getAnnotation(Accessible.class); if (accessible != null) { mapping.getAccess().put("", parseAccessible(accessible)); } for (Element element : mappingClass.getEnclosedElements()) { accessible = element.getAnnotation(Accessible.class); Constructor constructor = element.getAnnotation(Constructor.class); if (constructor != null) { if (accessible != null) { String constructorDesc = getDescriptor((ExecutableElement) element); mapping.getAccess().put("<init>" + constructorDesc, parseAccessible(accessible)); } continue; } annotation = element.getAnnotation(Mapping.class); if (annotation == null) { continue; } mappedName = annotation.value(); checkArgument(!mappedName.isEmpty(), "Mapping detection is not supported yet"); switch (element.getKind()) { case METHOD: ExecutableElement method = (ExecutableElement) element; String methodName = method.getSimpleName().toString(); String methodDesc = getDescriptor(method); mapping.getMethods().put(mappedName + unmapper.mapMethodDesc(methodDesc), methodName); if (accessible != null) { mapping.getAccess().put(methodName + methodDesc, parseAccessible(accessible)); } break; case FIELD: case ENUM_CONSTANT: VariableElement field = (VariableElement) element; String fieldName = field.getSimpleName().toString(); mapping.getFields().put(mappedName + ':' + unmapper.mapDesc(getDescriptor(field)), fieldName); if (accessible != null) { mapping.getAccess().put(fieldName, parseAccessible(accessible)); } break; default: } } mappings.put(internalName, mapping); } // Generate JSON output file = this.processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", "mappings.json"); try (Writer writer = file.openWriter()) { Mappings.write(writer, mappings); } return true; } catch (IOException e) { this.processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, ExceptionUtils.getStackTrace(e)); throw new RuntimeException("Failed to create mappings.json", e); } }
From source file:nl.hardijzer.fw.chainsrg.Method.java
License:Open Source License
public static Map<Method, Method> chainMethods(Map<Method, Method> a, Map<Method, Method> b, Remapper btoa, Remapper btoc) { Map<Method, Method> c = new TreeMap<Method, Method>(); for (Method mFrom : a.keySet()) { Method mToA = a.get(mFrom); Method mToB = b.get(mToA); if (mToB != null) { //We have a mapping from a to b, and b to c, so yay! b.remove(mToA);//w w w . j a va 2 s .c o m c.put(mFrom, mToB); } else { //We only have a mapping from a to b, so we need to add b to c (descriptor only) c.put(mFrom, new Method(mToA.name, btoc.mapMethodDesc(mToA.desc))); } } for (Method mFrom : b.keySet()) { //We only have a mapping from b to c, to we need to add a to b (descriptor only) c.put(new Method(mFrom.name, btoa.mapMethodDesc(mFrom.desc)), b.get(mFrom)); } return c; }
From source file:nova.core.wrapper.mc.forge.v17.asm.lib.ObfMapping.java
License:Open Source License
public ObfMapping map(Remapper mapper) { if (isMethod()) { s_name = mapper.mapMethodName(s_owner, s_name, s_desc); } else if (isField()) { s_name = mapper.mapFieldName(s_owner, s_name, s_desc); }//from w ww .j a v a2 s. com s_owner = mapper.mapType(s_owner); if (isMethod()) { s_desc = mapper.mapMethodDesc(s_desc); } else if (s_desc.length() > 0) { s_desc = mapper.mapDesc(s_desc); } return this; }