List of usage examples for org.objectweb.asm.commons Remapper mapDesc
public String mapDesc(final String descriptor)
From source file:com.wolvereness.overmapped.FlagsSubRoutine.java
License:Open Source License
@Override public void invoke(final OverMapped instance, final Map<String, ByteClass> classes, final Multimap<String, String> depends, final Multimap<String, String> rdepends, final BiMap<String, String> nameMaps, final BiMap<String, String> inverseNameMaps, final BiMap<Signature, Signature> signatureMaps, final BiMap<Signature, Signature> inverseSignatureMaps, final Remapper inverseMapper, final MutableSignature signature, final Set<String> searchCache, final Map<Signature, Integer> flags, final Map<?, ?> map) throws ClassCastException, NullPointerException, MojoFailureException { final Object flagMaps = map.get(tag); if (!(flagMaps instanceof Map)) return;// w w w.j a v a 2 s . com for (final Map.Entry<?, ?> flagMap : ((Map<?, ?>) flagMaps).entrySet()) { final String qualifiedName = SubRoutine.asType(flagMap.getKey(), "`%4$s' points from a %2$s `%1$s', expected a %5$s, in `%3$s'", false, flagMaps, flagMap, String.class); final Integer flag = SubRoutine.asType(flagMap.getValue(), "Expected a value `%4$s'->%5$s in %3%s, got %2$s `%1$s'", false, flagMaps, qualifiedName, Integer.class); final int firstSpace = qualifiedName.indexOf(' '); final int finalSpace = qualifiedName.lastIndexOf(' '); if (firstSpace == finalSpace || qualifiedName.indexOf(' ', firstSpace + 1) != finalSpace) throw new MojoFailureException(String.format("Malformed mapping %s", qualifiedName)); final String clazz = qualifiedName.substring(0, firstSpace); final String name = qualifiedName.substring(firstSpace + 1, finalSpace); final String description = qualifiedName.substring(finalSpace + 1); final String unmappedClass = inverseNameMaps.get(clazz); if (unmappedClass == null) { instance.missingAction.actFlag(instance.getLog(), flagMap, signatureMaps); continue; } final String unmappedDescription = inverseMapper.mapDesc(description); final Signature unmappedSignature = inverseSignatureMaps .get(signature.update(unmappedClass, name, unmappedDescription)); if (unmappedSignature == null) { instance.missingAction.actFlag(instance.getLog(), flagMap, signatureMaps); continue; } flags.put(unmappedSignature, flag); } }
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;/*from www .ja v a 2 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; }/* w w w . ja v a 2 s . c o 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: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 va 2s . c o m 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; }