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; }
public static MethodDefinition findMethod(TypeDefinition td, MemberInfo mi) { if(td == null) return null; for(MethodDefinition decl : td.getDeclaredMethods()) { if(decl.getName().equals(mi.getName())) { String sig1 = decl.getErasedSignature(); String sig2 = mi.getSignature(); if(sig1 == sig2) return decl; if(sig1.substring(0, sig1.indexOf(')')).equals(sig2.substring(0, sig2.indexOf(')')))) return decl; } } return null; }
public MethodDefinition resolve(final MethodReference method) { final TypeDefinition resolvedType = this.resolve(); if (resolvedType != null) { return MetadataResolver.getMethod(resolvedType.getDeclaredMethods(), method); } return null; }
public MethodDefinition resolve(final MethodReference method) { final TypeDefinition resolvedType = this.resolve(); if (resolvedType != null) { return MetadataResolver.getMethod(resolvedType.getDeclaredMethods(), method); } return null; }
public MethodDefinition resolve(final MethodReference method) { final TypeDefinition resolvedType = this.resolve(); if (resolvedType != null) { return MetadataResolver.getMethod(resolvedType.getDeclaredMethods(), method); } return null; }
private static MethodDefinition findReplacement(String name, TypeDefinition target) { for (MethodDefinition md : target.getDeclaredMethods()) { if (!md.isPublic() || !md.getSignature().equals("()V")) continue; if (name.equals("wait") && md.getName().equals("await")) return md; if (name.equals("notify") && (md.getName().equals("signal") || md.getName().equals("countDown"))) return md; if (name.equals("notifyAll") && (md.getName().equals("signalAll") || md.getName().equals("countDown"))) return md; } return null; } }
private static Integer findFirstLineNumber(final TypeDefinition type) { int minLineNumber = Integer.MAX_VALUE; for (final MethodDefinition method : type.getDeclaredMethods()) { final LineNumberTableAttribute attribute = SourceAttribute.find(AttributeNames.LineNumberTable, method.getSourceAttributes()); if (attribute != null && !attribute.getEntries().isEmpty()) { final int firstLineNumber = attribute.getEntries().get(0).getLineNumber(); if (firstLineNumber < minLineNumber) { minLineNumber = firstLineNumber; } } } return minLineNumber; }
private static Integer findFirstLineNumber(final TypeDefinition type) { int minLineNumber = Integer.MAX_VALUE; for (final MethodDefinition method : type.getDeclaredMethods()) { final LineNumberTableAttribute attribute = SourceAttribute.find(AttributeNames.LineNumberTable, method.getSourceAttributes()); if (attribute != null && !attribute.getEntries().isEmpty()) { final int firstLineNumber = attribute.getEntries().get(0).getLineNumber(); if (firstLineNumber < minLineNumber) { minLineNumber = firstLineNumber; } } } return minLineNumber; }
private static Integer findFirstLineNumber(final TypeDefinition type) { int minLineNumber = Integer.MAX_VALUE; for (final MethodDefinition method : type.getDeclaredMethods()) { final LineNumberTableAttribute attribute = SourceAttribute.find(AttributeNames.LineNumberTable, method.getSourceAttributes()); if (attribute != null && !attribute.getEntries().isEmpty()) { final int firstLineNumber = attribute.getEntries().get(0).getLineNumber(); if (firstLineNumber < minLineNumber) { minLineNumber = firstLineNumber; } } } return minLineNumber; }
@Override protected void visitType(TypeDefinition td) { TypeReference tr = td.getDeclaringType(); if(tr == null) return; TypeDefinition outer = tr.resolve(); if(outer == null || !outer.isAnonymous()) return; for(MethodDefinition md : td.getDeclaredMethods()) { extractCalls(md, mr -> { mis.add(new MemberInfo(mr)); return true; }); } }
@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); } }
private static MethodDefinition getSuperfinalizer(TypeDefinition type) { TypeDefinition superType = type.getBaseType().resolve(); if (superType == null || Types.isObject(superType)) return null; for (MethodDefinition child : superType.getDeclaredMethods()) { if (isFinalizer(child)) return child; } return getSuperfinalizer(superType); } }
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 protected void visitType(TypeDefinition td) { for (MethodDefinition md : td.getDeclaredMethods()) { MethodData mdata = getMethodData(md); if (md.isFinal() || td.isFinal() || md.isStatic() || md.isPrivate()) { mdata.flags |= METHOD_FINAL; } visitMethod(mdata, md); for (MethodDefinition superMethod : Methods.findSuperMethods(md)) { getMethodData(superMethod).addSubMethod(mdata); } } }
private void addTypeMembers(final TypeDeclaration astType, final TypeDefinition type) { for (final FieldDefinition field : type.getDeclaredFields()) { astType.addChild(createField(field), Roles.TYPE_MEMBER); } for (final MethodDefinition method : type.getDeclaredMethods()) { if (method.isConstructor()) { astType.addChild(createConstructor(method), Roles.TYPE_MEMBER); } else { astType.addChild(createMethod(method), Roles.TYPE_MEMBER); } } final List<TypeDefinition> nestedTypes = new ArrayList<>(); for (final TypeDefinition nestedType : type.getDeclaredTypes()) { final TypeReference declaringType = nestedType.getDeclaringType(); if (!nestedType.isLocalClass() && type.isEquivalentTo(declaringType)) { if (nestedType.isAnonymous()) { _typeDeclarations.put(type.getInternalName(), new SoftReference<>(astType)); } else { nestedTypes.add(nestedType); } } } sortNestedTypes(nestedTypes); for (final TypeDefinition nestedType : nestedTypes) { astType.addChild(createTypeNoCache(nestedType), Roles.TYPE_MEMBER); } }
final MethodDefinition getMethod(final TypeDefinition declaringType, final MethodReference reference) { TypeDefinition type = declaringType; MethodDefinition method = getMethod(type.getDeclaredMethods(), reference); if (method != null) { return method; } final TypeReference baseType = declaringType.getBaseType(); if (baseType != null) { type = baseType.resolve(); if (type != null) { method = getMethod(type, reference); if (method != null) { return method; } } } for (final TypeReference interfaceType : declaringType.getExplicitInterfaces()) { type = interfaceType.resolve(); if (type != null) { method = getMethod(type, reference); if (method != null) { return method; } } } return null; }
@Nullable private MethodDefinition tryLocateClassMethodOutOfScope(final TypeDefinition currentType) { final TypeDefinition enclosingType = MetadataHelper.getOutermostEnclosingType(currentType); if (enclosingType == null) { return null; } final AstBuilder builder = _context.getUserData(Keys.AST_BUILDER); for (final MethodDefinition m : enclosingType.getDeclaredMethods()) { if (ClassMethodLocator.isClassMethodCandidate(m)) { final MethodBody body = m.getBody(); if (body != null && body.getCodeSize() <= CANDIDATE_MAX_CODE_SIZE) { final MethodDeclaration method = builder.createMethod(m); if (ClassMethodLocator.PATTERN.matches(method)) { return m; } } } } return null; }
final MethodDefinition getMethod(final TypeDefinition declaringType, final MethodReference reference) { TypeDefinition type = declaringType; MethodDefinition method = getMethod(type.getDeclaredMethods(), reference); if (method != null) { return method; } final TypeReference baseType = declaringType.getBaseType(); if (baseType != null) { type = baseType.resolve(); if (type != null) { method = getMethod(type, reference); if (method != null) { return method; } } } for (final TypeReference interfaceType : declaringType.getExplicitInterfaces()) { type = interfaceType.resolve(); if (type != null) { method = getMethod(type, reference); if (method != null) { return method; } } } return null; }
@Override public TypeDecompilationResults decompileType(final TypeDefinition type, final ITextOutput output, final DecompilationOptions options) { writeTypeHeader(type, output); output.writeLine(" {"); output.indent(); try { boolean first = true; for (final MethodDefinition method : type.getDeclaredMethods()) { if (!first) { output.writeLine(); } else { first = false; } decompileMethod(method, output, options); } if (!options.getSettings().getExcludeNestedTypes()) { for (final TypeDefinition innerType : type.getDeclaredTypes()) { output.writeLine(); decompileType(innerType, output, options); } } } finally { output.unindent(); output.writeLine("}"); } return new TypeDecompilationResults( null /*no line number mapping*/); }
@Override public TypeDecompilationResults decompileType(final TypeDefinition type, final ITextOutput output, final DecompilationOptions options) { writeTypeHeader(type, output); output.writeLine(" {"); output.indent(); try { boolean first = true; for (final MethodDefinition method : type.getDeclaredMethods()) { if (!first) { output.writeLine(); } else { first = false; } decompileMethod(method, output, options); } if (!options.getSettings().getExcludeNestedTypes()) { for (final TypeDefinition innerType : type.getDeclaredTypes()) { output.writeLine(); decompileType(innerType, output, options); } } } finally { output.unindent(); output.writeLine("}"); } return new TypeDecompilationResults( null /*no line number mapping*/); }