public static void main(String[] args) { if (args.length != 1) { System.err.println("Usage: " + SignatureParser.class.getName() + " '<method signature>'"); System.exit(1); } SignatureParser parser = new SignatureParser(args[0]); for (Iterator<String> i = parser.parameterSignatureIterator(); i.hasNext();) { System.out.println(i.next()); } System.out.println(parser.getNumParameters() + " parameter(s)"); } }
/** * Get the number of parameters passed to method invocation. * * @param inv * @param cpg * @return int number of parameters */ public static int getNumParametersForInvocation(InvokeInstruction inv, ConstantPoolGen cpg) { SignatureParser sigParser = new SignatureParser(inv.getSignature(cpg)); return sigParser.getNumParameters(); }
@Override public int getNumParams() { // FIXME: cache this? return new SignatureParser(getSignature()).getNumParameters(); }
@Override public int getNumParams() { return new SignatureParser(getSignature()).getNumParameters(); }
public int getNumParams() { return new SignatureParser(getSignature()).getNumParameters(); }
/** * Get the number of arguments passed to given method invocation. * * @param ins * the method invocation instruction * @param cpg * the ConstantPoolGen for the class containing the method * @return number of arguments; note that this excludes the object instance * for instance methods */ public int getNumArguments(InvokeInstruction ins, ConstantPoolGen cpg) { SignatureParser parser = new SignatureParser(ins.getSignature(cpg)); return parser.getNumParameters(); }
/** * Get the <i>i</i>th argument passed to given method invocation. * * @param ins * the method invocation instruction * @param cpg * the ConstantPoolGen for the class containing the method * @param i * index of the argument; 0 for the first argument, etc. * @return the <i>i</i>th argument * @throws DataflowAnalysisException */ public ValueType getArgument(InvokeInstruction ins, ConstantPoolGen cpg, int i, SignatureParser sigParser) throws DataflowAnalysisException { if (i >= sigParser.getNumParameters()) { throw new IllegalArgumentException("requesting parameter # " + i + " of " + sigParser); } return getStackValue(sigParser.getSlotsFromTopOfStackForParameter(i)); }
@Override public org.objectweb.asm.AnnotationVisitor visitParameterAnnotation(int parameter, String desc, boolean visible) { AnnotationValue value = new AnnotationValue(desc); int shift = 0; if (parameterCount >= 0) { // if we have synthetic parameter, shift `parameter` value shift = new SignatureParser(methodDesc).getNumParameters() - parameterCount; } mBuilder.addParameterAnnotation(parameter + shift, desc, value); return value.getAnnotationVisitor(); }
/** * Get set of arguments passed to a method invocation which match given * predicate. * * @param invokeInstruction * the InvokeInstruction * @param cpg * the ConstantPoolGen * @param chooser * predicate to choose which argument values should be in the * returned set * @return BitSet specifying which arguments match the predicate, indexed by * argument number (starting from 0) * @throws DataflowAnalysisException */ public BitSet getArgumentSet(InvokeInstruction invokeInstruction, ConstantPoolGen cpg, DataflowValueChooser<ValueType> chooser) throws DataflowAnalysisException { BitSet chosenArgSet = new BitSet(); SignatureParser sigParser = new SignatureParser(invokeInstruction.getSignature(cpg)); for (int i = 0; i < sigParser.getNumParameters(); ++i) { ValueType value = getArgument(invokeInstruction, cpg, i, sigParser); if (chooser.choose(value)) { chosenArgSet.set(i); } } return chosenArgSet; }
static boolean compatibleParameters(String signature, String superSignature) { SignatureParser sig = new SignatureParser(signature); SignatureParser superSig = new SignatureParser(superSignature); if (sig.getNumParameters() == superSig.getNumParameters()) { Iterator<String> params = sig.parameterSignatureIterator(); Iterator<String> superParams = superSig.parameterSignatureIterator(); while (params.hasNext()) { String param = params.next(); String superParam = superParams.next(); if (areRelated(param, superParam)) { continue; } return false; } String retSig = sig.getReturnTypeSignature(); String superRetSig = superSig.getReturnTypeSignature(); if (areRelated(retSig, superRetSig)) { // it is compatible return true; } } return false; }
/** * @param result * @param m */ public static void addKnownTypeQualifiersForParameters(HashSet<? super TypeQualifierValue<?>> result, XMethod m) { int numParameters = new SignatureParser(m.getSignature()).getNumParameters(); for (int p = 0; p < numParameters; p++) { addKnownTypeQualifiers(result, TypeQualifierApplications.getApplicableApplications(m, p)); } }
/** * Build map of value numbers to param indices. The first parameter has * index 0, the second has index 1, etc. * * @param methodSignature * signature of the method analyzed by the ValueNumberAnalysis * @param isStatic * true if the method is static, false if not * @return the value number to parameter index map */ public Map<ValueNumber, Integer> getValueNumberToParamMap(String methodSignature, boolean isStatic) { HashMap<ValueNumber, Integer> valueNumberToParamMap = new HashMap<>(); ValueNumberFrame frameAtEntry = getStartFact(getCFG().getEntry()); int numParams = new SignatureParser(methodSignature).getNumParameters(); int shift = isStatic ? 0 : 1; for (int i = 0; i < numParams; ++i) { valueNumberToParamMap.put(frameAtEntry.getValue(i + shift), i); } return valueNumberToParamMap; }
protected void addMethodParameterAnnotation(String cName, String mName, String mSig, boolean isStatic, int param, AnnotationEnum annotation) { // if (!Subtypes.DO_NOT_USE) { // subtypes.addNamedClass(cName); // } if (addClassOnly) { return; } SignatureParser parser = new SignatureParser(mSig); if (param < 0 || param >= parser.getNumParameters()) { throw new IllegalArgumentException("can't annotation parameter #" + param + " of " + cName + "." + mName + mSig); } String signature = parser.getParameter(param); char firstChar = signature.charAt(0); boolean isReference = firstChar == 'L' || firstChar == '['; if (onlyAppliesToReferenceParameters(annotation) && !isReference) { AnalysisContext.logError("Can't apply " + annotation + " to parameter " + param + " with signature " + signature + " of " + cName + "." + mName + " : " + mSig); return; } XMethod m = XFactory.createXMethod(cName, mName, mSig, isStatic); addDirectAnnotation(new XMethodParameter(m, param), annotation); } }
@Override public void addMethodParameterAnnotation(@DottedClassName String cName, String mName, String sig, boolean isStatic, int param, NullnessAnnotation annotation) { if (DEBUG) { System.out.println("addMethodParameterAnnotation: annotate " + cName + "." + mName + " param " + param + " with " + annotation); } XMethod xmethod = getXMethod(cName, mName, sig, isStatic); if (xmethod == null) { return; } // Get JSR-305 nullness annotation type ClassDescriptor nullnessAnnotationType = getNullnessAnnotationClassDescriptor(annotation); // Create an AnnotationValue AnnotationValue annotationValue = new AnnotationValue(nullnessAnnotationType); if (!xmethod.getClassName().equals(cName)) { if (SystemProperties.ASSERTIONS_ENABLED) { AnalysisContext.logError("Could not fully resolve method " + cName + "." + mName + sig + " to apply annotation " + annotation); } return; } if (SystemProperties.ASSERTIONS_ENABLED) { SignatureParser parser = new SignatureParser(sig); int numParams = parser.getNumParameters(); assert param < numParams; } // Destructively add the annotation to the MethodInfo object xmethod.addParameterAnnotation(param, annotationValue); }
int numParams = sigParser.getNumParameters(); if (numParams == 0 || !sigParser.hasReferenceParameters()) { return Collections.emptySet();
int numParams = sigParser.getNumParameters();
} else if(accessForField && fieldInstructionCount == 1) { boolean isSetter = methodDesc.endsWith(")V"); int numArg = new SignatureParser(methodDesc).getNumParameters(); int expected = 0; if (!accessIsStatic) {
if (parser.getNumParameters() == 1 && ( booleanComparisonMethod(invoking) && sig.endsWith(";)Z") || comparatorMethod(invoking) && sig.endsWith(";)I"))) { checkForSelfOperation(classContext, location, valueNumberDataflow, "COMPARISON", method, methodGen,
for (int i = 0; i < parser.getNumParameters(); i++) { String p = ClassName.fromFieldSignature(parser.getParameter(i)); if (getClassName().equals(p)) {
if (sigParser.getNumParameters() == 0) { return;