private MethodDefinition findMethodInType(TypeDefinition typeDef, String uniqueStr) { String[] linkParts = uniqueStr.split("\\|"); if (linkParts.length != 5) return null; String methodName = linkParts[3]; String methodErasedSignature = linkParts[4]; if (methodName.trim().length() <= 0 || methodErasedSignature.trim().length() <= 0) return null; List<MethodDefinition> declaredMethods = typeDef.getDeclaredMethods(); if (declaredMethods == null) return null; boolean isFound = false; for (MethodDefinition declaredMethod : declaredMethods) { isFound = (declaredMethod != null && methodName.equals(declaredMethod.getName())); isFound = (isFound && methodErasedSignature.equals(declaredMethod.getErasedSignature())); if (isFound) { if (declaredMethod.isSynthetic() && !settings.getShowSyntheticMembers()) { return null; } else { return declaredMethod; } } } return null; }
@Override public String toString() { return mainMethod.getDeclaringType() + "." + mainMethod; } }
if (method.isTypeInitializer()) { modifiers = Collections.singleton(Modifier.STATIC); else if (method.getDeclaringType().isInterface()) { modifiers = Collections.emptySet(); modifiers = Flags.asModifierSet(scrubAccessModifiers(method.getFlags() & Flags.MethodFlags)); astMethod.setName(method.getName()); astMethod.getParameters().addAll(createParameters(method.getParameters())); astMethod.getTypeParameters().addAll(createTypeParameters(method.getGenericParameters())); astMethod.setReturnType(convertType(method.getReturnType())); astMethod.putUserData(Keys.METHOD_DEFINITION, method); astMethod.putUserData(Keys.MEMBER_REFERENCE, method); for (final TypeDefinition declaredType : method.getDeclaredTypes()) { if (!declaredType.isAnonymous()) { astMethod.getDeclaredTypes().add(createType(declaredType)); if (!method.getDeclaringType().isInterface() || method.isTypeInitializer() || method.isDefault()) { astMethod.setBody(createMethodBody(method, astMethod.getParameters())); for (final TypeReference thrownType : method.getThrownTypes()) { astMethod.addChild(convertType(thrownType), Roles.THROWN_TYPE); for (final CustomAnnotation annotation : method.getAnnotations()) { astMethod.getAnnotations().add(createAnnotation(annotation)); method.getSourceAttributes()
public StringBuilder appendErasedDescription(final StringBuilder sb) { if (hasGenericParameters() && !isGenericDefinition()) { final MethodDefinition definition = resolve(); if (definition != null) { return definition.appendErasedDescription(sb); } } for (final javax.lang.model.element.Modifier modifier : Flags.asModifierSet(getModifiers() & ~Flags.ACC_VARARGS)) { sb.append(modifier.toString()); sb.append(' '); } final List<ParameterDefinition> parameterTypes = getParameters(); StringBuilder s = getReturnType().appendErasedDescription(sb); s.append(' '); s.append(getName()); s.append('('); for (int i = 0, n = parameterTypes.size(); i < n; ++i) { if (i != 0) { s.append(", "); } s = parameterTypes.get(i).getParameterType().appendErasedDescription(s); } s.append(')'); return s; }
private static boolean isSwitchMapMethod(final MethodReference method) { if (method == null) { return false; } final MethodDefinition definition = method instanceof MethodDefinition ? (MethodDefinition) method : method.resolve(); return definition != null && definition.isSynthetic() && definition.isStatic() && definition.isPackagePrivate() && StringUtilities.startsWith(definition.getName(), "$SWITCH_TABLE$") && MetadataResolver.areEquivalent(BuiltinTypes.Integer.makeArrayType(), definition.getReturnType()); }
if (!includeBridgeMethods && method.isBridgeMethod()) { continue; final String key = (includeOverriddenMethods ? method.getFullName() : method.getName()) + ":" + method.getErasedSignature();
private void writeMethodHeader(final MethodDefinition method, final ITextOutput output) { if (method.isTypeInitializer()) { output.writeKeyword("static"); return; if (!method.getDeclaringType().isInterface()) { for (final Modifier modifier : Flags.asModifierSet(method.getFlags() & Flags.MethodFlags)) { output.writeKeyword(modifier.toString()); output.write(' '); if (!method.isTypeInitializer()) { DecompilerHelpers.writeType(output, method.getReturnType(), NameSyntax.TYPE_NAME); output.write(' '); if (method.isConstructor()) { output.writeReference(method.getDeclaringType().getName(), method.getDeclaringType()); output.writeReference(method.getName(), method); final List<ParameterDefinition> parameters = method.getParameters();
@Override public boolean equals(final Object obj) { if (obj instanceof MethodDefinition) { final MethodDefinition other = (MethodDefinition) obj; return StringUtilities.equals(getName(), other.getName()) && StringUtilities.equals(getErasedSignature(), other.getErasedSignature()) && typeNamesMatch(getDeclaringType(), other.getDeclaringType()); } return false; }
public static MethodDefinition resolveToBridge(MethodDefinition md) { if (md.isBridgeMethod()) { return md; } for (MethodDefinition candidate : md.getDeclaringType().getDeclaredMethods()) { if (candidate.getName().equals(md.getName()) && candidate.isBridgeMethod()) { List<ParameterDefinition> params = candidate.getParameters(); if (params.size() == md.getParameters().size()) { MethodBody body = candidate.getBody(); if (body != null) { for (Instruction instr : body.getInstructions()) { if (instr.getOperandCount() == 1) { Object operand = instr.getOperand(0); if (operand instanceof MethodReference) { MethodReference mr = (MethodReference) operand; if (mr.getName().equals(md.getName()) && mr.getErasedSignature().equals(md .getErasedSignature()) && mr.getDeclaringType().isEquivalentTo(md .getDeclaringType())) { return candidate; } } } } } } } } return md; }
@Override public boolean test(final MethodDefinition m) { return m.isConstructor() && !m.isSynthetic() && !StringUtilities.equals(m.getErasedSignature(), method.getErasedSignature()); } }
private ConstructorDeclaration createConstructor(final MethodDefinition method) { final ConstructorDeclaration astMethod = new ConstructorDeclaration(); EntityDeclaration.setModifiers( astMethod, Flags.asModifierSet(scrubAccessModifiers(method.getFlags() & Flags.ConstructorFlags)) ); astMethod.setName(method.getDeclaringType().getName()); astMethod.getParameters().addAll(createParameters(method.getParameters())); astMethod.getTypeParameters().addAll(createTypeParameters(method.getGenericParameters())); astMethod.setBody(createMethodBody(method, astMethod.getParameters())); astMethod.putUserData(Keys.METHOD_DEFINITION, method); astMethod.putUserData(Keys.MEMBER_REFERENCE, method); for (final CustomAnnotation annotation : method.getAnnotations()) { astMethod.getAnnotations().add(createAnnotation(annotation)); } for (final TypeReference thrownType : method.getThrownTypes()) { astMethod.addChild(convertType(thrownType), Roles.THROWN_TYPE); } return astMethod; }
private ConstructorDeclaration createConstructor(final MethodDefinition method) { final ConstructorDeclaration astMethod = new ConstructorDeclaration(); EntityDeclaration.setModifiers( astMethod, Flags.asModifierSet(scrubAccessModifiers(method.getFlags() & Flags.ConstructorFlags)) ); astMethod.setName(method.getDeclaringType().getName()); astMethod.getParameters().addAll(createParameters(method.getParameters())); astMethod.setBody(createMethodBody(method, astMethod.getParameters())); astMethod.putUserData(Keys.METHOD_DEFINITION, method); astMethod.putUserData(Keys.MEMBER_REFERENCE, method); for (final TypeReference thrownType : method.getThrownTypes()) { astMethod.addChild(convertType(thrownType), Roles.THROWN_TYPE); } return astMethod; }
static boolean isClassMethodCandidate(final MethodDefinition m) { return m != null && m.isSynthetic() && m.isStatic() && m.isPackagePrivate() && m.getParameters().size() == 1 && CommonTypeReferences.Class.isEquivalentTo(m.getReturnType()) && CommonTypeReferences.String.isEquivalentTo(m.getParameters().get(0).getParameterType()); }
method.isPublic() && method.isStatic()) { switch (method.getName()) { case "values": { if (method.getParameters().isEmpty() && MetadataResolver.areEquivalent(currentType.makeArrayType(), method.getReturnType())) { if (currentType.equals(method.getReturnType().resolve()) && method.getParameters().size() == 1) { final ParameterDefinition pd = method.getParameters().get(0);
@AstVisitor(nodes = AstNodes.ROOT) public void checkSameAsConstructor(Block root, MethodDefinition md, TypeDefinition td, MethodContext mc) { if (md.getName().equals(td.getSimpleName()) && md.getReturnType().isVoid() && !md.isDeprecated()) { int priority = 0; if (root.getBody().isEmpty()) { priority += 20; } else if (root.getBody().size() == 1 && Nodes.isOp(root.getBody().get(0), AstCode.AThrow)) { priority += 40; } if (td.getDeclaredMethods().stream().anyMatch( m -> m.isConstructor() && m.getErasedSignature().equals(md.getErasedSignature()))) { priority += 10; } mc.report("BadNameOfMethodSameAsConstructor", priority); } }
@MethodVisitor public boolean check(MethodDefinition md, TypeDefinition td) { if(md.isSynthetic()) return false; if(md.getName().equals("compare") && md.getParameters().size() == 2 && md.getReturnType().getSimpleType() == JvmType.Integer && Types.isInstance(td, "java/util/Comparator")) return true; if(md.getName().equals("compareTo") && md.getParameters().size() == 1 && md.getReturnType().getSimpleType() == JvmType.Integer && Types.isInstance(td, "java/lang/Comparable")) return true; return false; }
public static boolean isMain(MethodDefinition md) { return md.getName().equals("main") && md.isPublic() && md.isStatic() && md.getErasedSignature().startsWith("([Ljava/lang/String;)"); }
public boolean checkMethod(MethodDefinition md) { if(!md.getReturnType().isArray() && !TYPE_TO_WARNING.containsKey(md.getReturnType().getInternalName())) return false; if(md.getName().equals("getName") && md.getReturnType().getSignature().equals("[B") && md.getParameters().size() == 1 && Types.isInstance(md.getDeclaringType(), "java/sql/ResultSet")) return false; return true; }
private boolean areMethodsEquivalent(final MethodReference m1, final MethodDefinition m2) { if (m1 == m2) { return true; } //noinspection SimplifiableIfStatement if (m1 == null || m2 == null) { return false; } return StringUtilities.equals(m1.getFullName(), m2.getFullName()) && StringUtilities.equals(m1.getErasedSignature(), m2.getErasedSignature()); } }
@SuppressWarnings("ConstantConditions") public MethodBody readBody() { try { return readBodyCore(); } catch (final Throwable t) { throw new MethodBodyParseException( format( "An error occurred while parsing the bytecode of method '%s:%s'.", _methodDefinition.getFullName(), _methodDefinition.getSignature() ), t); } }