Java Code Examples for com.strobel.assembler.metadata.MethodReference#getErasedSignature()
The following examples show how to use
com.strobel.assembler.metadata.MethodReference#getErasedSignature() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MethodTranslator.java From j2objc with Apache License 2.0 | 5 votes |
private ExecutableElement findMethod(String name, TypeMirror type, MethodReference methodDef) { TypeElement typeElement = (TypeElement) parserEnv.typeUtilities().asElement(type); String signature = methodDef.getSignature(); String erasedSignature = methodDef.getErasedSignature(); for (Element e : typeElement.getEnclosedElements()) { if (e.getKind() == ElementKind.METHOD && e.getSimpleName().contentEquals(name)) { String sig = typeUtil.getReferenceSignature((ExecutableElement) e); if (sig.equals(signature) || sig.equals(erasedSignature)) { return (ExecutableElement) e; } } } throw new AssertionError("failed method lookup: " + type + " " + name + signature); }
Example 2
Source File: MethodTranslator.java From j2objc with Apache License 2.0 | 5 votes |
private ExecutableElement findConstructor(TypeElement type, MethodReference methodDef) { String signature = methodDef.getSignature(); String erasedSignature = methodDef.getErasedSignature(); for (Element e : type.getEnclosedElements()) { if (e.getKind() == ElementKind.CONSTRUCTOR) { String sig = typeUtil.getReferenceSignature((ExecutableElement) e); if (sig.equals(signature) || sig.equals(erasedSignature)) { return (ExecutableElement) e; } } } throw new AssertionError("failed constructor lookup: " + type.getQualifiedName() + signature); }
Example 3
Source File: Methods.java From huntbugs with Apache License 2.0 | 4 votes |
public static boolean isSideEffectFree(MethodReference mr) { if(isPure(mr)) return true; if(isEqualsMethod(mr) || isHashCodeMethod(mr)) return true; TypeReference tr = mr.getDeclaringType(); String sig = mr.getErasedSignature(); String name = mr.getName(); if(name.equals("toString") && sig.equals("()Ljava/lang/String;")) return true; switch(tr.getInternalName()) { case "java/util/Arrays": return name.equals("hashCode") || name.equals("equals") || name.equals("toString") || name.equals("binarySearch") || name.equals("stream") || name.equals("spliterator") || name.startsWith("deep") || name.startsWith("copyOf") || name.equals("asList"); case "java/lang/Object": return mr.isConstructor(); case "java/util/Collections": return name.equals("min") || name.equals("max") || name.startsWith("unmodifiable") || name.startsWith("synchronized") || name.startsWith("empty"); } if(Types.isCollection(tr)) { if(name.equals("contains") && sig.equals("(Ljava/lang/Object;)Z")) return true; if(name.equals("containsAll") && sig.equals("(Ljava/util/Collection;)Z")) return true; if(name.equals("isEmpty") && sig.equals("()Z")) return true; if(name.equals("size") && sig.equals("()I")) return true; if(Types.isInstance(tr, "java/util/List")) { if (name.equals("get") && sig.equals("(I)Ljava/lang/Object;") || name.equals("subList") && sig.equals("(II)Ljava/util/List;")) return true; } return false; } if(Types.isInstance(tr, "java/util/Map")) { if ((name.equals("containsKey") || name.equals("containsValue")) && sig.equals("(Ljava/lang/Object;)Z")) return true; if (name.equals("get") && sig.equals("(Ljava/lang/Object;)Ljava/lang/Object;")) return true; } return Types.isSideEffectFreeType(tr); }