Java Code Examples for org.apache.bcel.generic.Type#getArgumentTypes()
The following examples show how to use
org.apache.bcel.generic.Type#getArgumentTypes() .
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: ObligationFactory.java From spotbugs with GNU Lesser General Public License v2.1 | 6 votes |
/** * Get array of Obligation types corresponding to the parameters of the * given method. * * @param xmethod * a method * @return array of Obligation types for each of the method's parameters; a * null element means the corresponding parameter is not an * Obligation type */ public Obligation[] getParameterObligationTypes(XMethod xmethod) { Type[] paramTypes = Type.getArgumentTypes(xmethod.getSignature()); Obligation[] result = new Obligation[paramTypes.length]; for (int i = 0; i < paramTypes.length; i++) { if (!(paramTypes[i] instanceof ObjectType)) { continue; } try { result[i] = getObligationByType((ObjectType) paramTypes[i]); } catch (ClassNotFoundException e) { Global.getAnalysisCache().getErrorLogger().reportMissingClass(e); } } return result; }
Example 2
Source File: TransitiveHull.java From commons-bcel with Apache License 2.0 | 6 votes |
private void visitRef(final ConstantCP ccp, final boolean method) { final String class_name = ccp.getClass(cp); add(class_name); final ConstantNameAndType cnat = (ConstantNameAndType) cp.getConstant(ccp.getNameAndTypeIndex(), Constants.CONSTANT_NameAndType); final String signature = cnat.getSignature(cp); if (method) { final Type type = Type.getReturnType(signature); checkType(type); for (final Type type1 : Type.getArgumentTypes(signature)) { checkType(type1); } } else { checkType(Type.getType(signature)); } }
Example 3
Source File: UselessSubclassMethod.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
private Method findSuperclassMethod(@DottedClassName String superclassName, Method subclassMethod) throws ClassNotFoundException { String methodName = subclassMethod.getName(); Type[] subArgs = null; JavaClass superClass = Repository.lookupClass(superclassName); Method[] methods = superClass.getMethods(); outer: for (Method m : methods) { if (m.getName().equals(methodName)) { if (subArgs == null) { subArgs = Type.getArgumentTypes(subclassMethod.getSignature()); } Type[] superArgs = Type.getArgumentTypes(m.getSignature()); if (subArgs.length == superArgs.length) { for (int j = 0; j < subArgs.length; j++) { if (!superArgs[j].equals(subArgs[j])) { continue outer; } } return m; } } } if (!"Object".equals(superclassName)) { @DottedClassName String superSuperClassName = superClass.getSuperclassName(); if (superSuperClassName.equals(superclassName)) { throw new ClassNotFoundException("superclass of " + superclassName + " is itself"); } return findSuperclassMethod(superSuperClassName, subclassMethod); } return null; }
Example 4
Source File: ValueRangeAnalysisFactory.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
private static Map<Integer, Value> getParameterTypes(MethodDescriptor descriptor) { Type[] argumentTypes = Type.getArgumentTypes(descriptor.getSignature()); int j = 0; Map<Integer, Value> result = new HashMap<>(); if (!descriptor.isStatic()) { result.put(j++, new Value("this", null, "L" + descriptor.getSlashedClassName() + ";")); } for (int i = 0; i < argumentTypes.length; i++) { result.put(j, new Value("arg" + i, null, argumentTypes[i].getSignature())); j += argumentTypes[i].getSize(); } return result; }
Example 5
Source File: Method.java From ApkToolPlus with Apache License 2.0 | 4 votes |
/** * @return array of method argument types */ public Type[] getArgumentTypes() { return Type.getArgumentTypes(getSignature()); }
Example 6
Source File: UselessSubclassMethod.java From spotbugs with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void sawOpcode(int seen) { switch (state) { case SEEN_NOTHING: if (seen == Const.ALOAD_0) { argTypes = Type.getArgumentTypes(this.getMethodSig()); curParm = 0; curParmOffset = 1; if (argTypes.length > 0) { state = State.SEEN_PARM; } else { state = State.SEEN_LAST_PARM; } } else { state = State.SEEN_INVALID; } break; case SEEN_PARM: if (curParm >= argTypes.length) { state = State.SEEN_INVALID; } else { String signature = argTypes[curParm++].getSignature(); char typeChar0 = signature.charAt(0); if ((typeChar0 == 'L') || (typeChar0 == '[')) { checkParm(seen, Const.ALOAD_0, Const.ALOAD, 1); } else if (typeChar0 == 'D') { checkParm(seen, Const.DLOAD_0, Const.DLOAD, 2); } else if (typeChar0 == 'F') { checkParm(seen, Const.FLOAD_0, Const.FLOAD, 1); } else if (typeChar0 == 'I' || typeChar0 == 'Z' || typeChar0 == 'S' || typeChar0 == 'C') { checkParm(seen, Const.ILOAD_0, Const.ILOAD, 1); } else if (typeChar0 == 'J') { checkParm(seen, Const.LLOAD_0, Const.LLOAD, 2); } else { state = State.SEEN_INVALID; } if ((state != State.SEEN_INVALID) && (curParm >= argTypes.length)) { state = State.SEEN_LAST_PARM; } } break; case SEEN_LAST_PARM: if ((seen == Const.INVOKENONVIRTUAL) && getMethodName().equals(getNameConstantOperand()) && getMethodSig().equals(getSigConstantOperand())) { invokePC = getPC(); state = State.SEEN_INVOKE; } else { state = State.SEEN_INVALID; } break; case SEEN_INVOKE: Type returnType = getMethod().getReturnType(); char retSigChar0 = returnType.getSignature().charAt(0); if ((retSigChar0 == 'V') && (seen == Const.RETURN)) { state = State.SEEN_RETURN; } else if (((retSigChar0 == 'L') || (retSigChar0 == '[')) && (seen == Const.ARETURN)) { state = State.SEEN_RETURN; } else if ((retSigChar0 == 'D') && (seen == Const.DRETURN)) { state = State.SEEN_RETURN; } else if ((retSigChar0 == 'F') && (seen == Const.FRETURN)) { state = State.SEEN_RETURN; } else if ((retSigChar0 == 'I' || retSigChar0 == 'S' || retSigChar0 == 'C' || retSigChar0 == 'B' || retSigChar0 == 'Z') && (seen == Const.IRETURN)) { state = State.SEEN_RETURN; } else if ((retSigChar0 == 'J') && (seen == Const.LRETURN)) { state = State.SEEN_RETURN; } else { state = State.SEEN_INVALID; } break; case SEEN_RETURN: state = State.SEEN_INVALID; break; default: break; } }
Example 7
Source File: InefficientMemberAccess.java From spotbugs with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void sawOpcode(int seen) { if (seen == Const.INVOKESTATIC) { String methodName = getNameConstantOperand(); if (!methodName.startsWith(ACCESS_PREFIX)) { return; } String methodSig = getSigConstantOperand(); Type[] argTypes = Type.getArgumentTypes(methodSig); if ((argTypes.length < 1) || (argTypes.length > 2)) { return; } String parCls = argTypes[0].getSignature(); if (parCls.length() < 3) { return; } parCls = parCls.substring(1, parCls.length() - 1); if (!parCls.equals(getClassConstantOperand())) { return; } if ((argTypes.length == 2) && !argTypes[1].getSignature().equals(new SignatureParser(methodSig).getReturnTypeSignature())) { return; } InnerClassAccess access = null; try { String dottedClassConstantOperand = getDottedClassConstantOperand(); access = AnalysisContext.currentAnalysisContext().getInnerClassAccessMap().getInnerClassAccess(dottedClassConstantOperand, methodName); if (access != null) { // if the enclosing class of the field differs from the enclosing class of the method, we shouln't report // because there is nothing wrong: see bug 1226 if (!access.getField().getClassName().equals(dottedClassConstantOperand)) { return; } // the access method is created to access the synthetic reference to the enclosing class, we shouln't report // user can't do anything here, see bug 1191 if (access.getField().isSynthetic()) { return; } } } catch (ClassNotFoundException e) { } BugInstance bug = new BugInstance(this, "IMA_INEFFICIENT_MEMBER_ACCESS", LOW_PRIORITY).addClassAndMethod(this) .addSourceLine(this); if (access != null) { bug.addField(access.getField()); } bugReporter.reportBug(bug); } }
Example 8
Source File: Method.java From commons-bcel with Apache License 2.0 | 4 votes |
/** * @return array of method argument types */ public Type[] getArgumentTypes() { return Type.getArgumentTypes(getSignature()); }