Find relevant type qualifiers needing to be checked for a given method.

@param methodDescriptor
a method
@return Collection of relevant type qualifiers needing to be checked
@throws CheckedAnalysisException
434235
public static Collection<TypeQualifierValue<?>> getRelevantTypeQualifiers(MethodDescriptor methodDescriptor, CFG cfg)
            throws CheckedAnalysisException {

        final HashSet<TypeQualifierValue<?>> result = new HashSet<>();

        XMethod xmethod = XFactory.createXMethod(methodDescriptor);

        if (FIND_EFFECTIVE_RELEVANT_QUALIFIERS) {
            if (DEBUG_FIND_EFFECTIVE_RELEVANT_QUALIFIERS) {
                System.out.println("**** Finding effective type qualifiers for " + xmethod);
            }

            //
            // This will take care of methods using fields annotated with
            // a type qualifier.
            //
            getDirectlyRelevantTypeQualifiers(xmethod, result);

            // For all known type qualifiers, find the effective (direct,
            // inherited,
            // or default) type qualifier annotations
            // on the method and all methods directly called by the method.
            //

            addEffectiveRelevantQualifiers(result, xmethod);

            IAnalysisCache analysisCache = Global.getAnalysisCache();
            ConstantPoolGen cpg = analysisCache.getClassAnalysis(ConstantPoolGen.class, methodDescriptor.getClassDescriptor());
            for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) {
                Location location = i.next();
                Instruction ins = location.getHandle().getInstruction();
                if (ins instanceof InvokeInstruction) {
                    if (ins instanceof INVOKEDYNAMIC) {
                        // TODO handle INVOKEDYNAMIC
                    } else {
                        XMethod called = XFactory.createXMethod((InvokeInstruction) ins, cpg);
                        addEffectiveRelevantQualifiers(result, called);
                    }
                }

                if (DEBUG_FIND_EFFECTIVE_RELEVANT_QUALIFIERS) {
                    System.out.println("===> result: " + result);
                }
            }

            //
            // XXX: this code can go away eventually
            //

            if (!methodDescriptor.isStatic()) {
                // Instance method - must consider type qualifiers inherited
                // from superclasses

                SupertypeTraversalVisitor visitor = new OverriddenMethodsVisitor(xmethod) {
                    /*
                     * (non-Javadoc)
                     *
                     * @see edu.umd.cs.findbugs.ba.ch.OverriddenMethodsVisitor#
                     * visitOverriddenMethod(edu.umd.cs.findbugs.ba.XMethod)
                     */

                    @Override
                    protected boolean visitOverriddenMethod(XMethod xmethod) {
                        getDirectlyRelevantTypeQualifiers(xmethod, result);
                        return true;
                    }
                };

                try {
                    AnalysisContext.currentAnalysisContext().getSubtypes2()
                    .traverseSupertypesDepthFirst(xmethod.getClassDescriptor(), visitor);
                } catch (ClassNotFoundException e) {
                    AnalysisContext.currentAnalysisContext().getLookupFailureCallback().reportMissingClass(e);
                    return Collections.<TypeQualifierValue<?>> emptySet();
                } catch (UncheckedAnalysisException e) {
                    AnalysisContext.currentAnalysisContext().getLookupFailureCallback()
                    .logError("Error getting relevant type qualifiers for " + xmethod.toString(), e);
                    return Collections.<TypeQualifierValue<?>> emptySet();
                }
            }
        }

        return result;

    }
1235383
public static <T extends ByteCodeElement> ElementMatcher.Junction<T> hasDescriptor(String descriptor) {
        return new DescriptorMatcher<T>(new StringMatcher(descriptor, StringMatcher.Mode.EQUALS_FULLY));
    }
1067279
public MethodDescriptor[] getMethodDescriptors() {
        BeanInfo info = getBeanInfo();
        if (info == null) {
            return null;
        }

        MethodDescriptor[] mds = info.getMethodDescriptors();      
        getTeaToolsUtils().sortMethodDescriptors(mds);
        return mds;
    }
442343
public static <T extends MethodDescription> ElementMatcher.Junction<T> isDefaultFinalizer() {
        return isFinalizer().and(isDeclaredBy(TypeDescription.OBJECT));
    }
852853
int getMethodIndex(ExecutableElement method)
    {
        TypeElement declaringClass = (TypeElement) method.getEnclosingElement();
        String fullyQualifiedname = declaringClass.getQualifiedName().toString();
        return getRefIndex(Methodref.class, fullyQualifiedname, method.getSimpleName().toString(), Descriptor.getDesriptor(method));
    }
362904
public MethodDescriptor toMethodDescriptor() {
        return DescriptorFactory.instance().getMethodDescriptor(getSlashedClassName(), method.getName(), method.getSignature(),
                method.isStatic());
    }
180821
public static String getMethodDescriptor(final Method m) {
        Class<?>[] parameters = m.getParameterTypes();
		StringBuilder sb = new StringBuilder();
        sb.append('(');
        for (int i = 0; i < parameters.length; ++i) {
            getDescriptor(sb, parameters[i]);
        }
        sb.append(')');
        getDescriptor(sb, m.getReturnType());
        return sb.toString();
    }
1118450
public static MethodDescriptor buildScriptableMethodDescriptor(
    Class actionClass, String methodName, String[] parameterNames, Class[] parameterTypes )
  {
    MethodDescriptor md = _buildMethodDescriptor( actionClass, methodName, parameterNames, parameterTypes, parameterTypes );
    makeScriptable( md );
    return md;
  }
1283949
@Override
    public TypeDataflow analyze(IAnalysisCache analysisCache, MethodDescriptor descriptor) throws CheckedAnalysisException {
        MethodGen methodGen = getMethodGen(analysisCache, descriptor);
        if (methodGen == null) {
            throw new MethodUnprofitableException(descriptor);
        }
        CFG cfg = getCFG(analysisCache, descriptor);
        DepthFirstSearch dfs = getDepthFirstSearch(analysisCache, descriptor);
        ExceptionSetFactory exceptionSetFactory = getExceptionSetFactory(analysisCache, descriptor);
        Method method = getMethod(analysisCache, descriptor);

        TypeAnalysis typeAnalysis = new TypeAnalysis(method, methodGen, cfg, dfs, AnalysisContext.currentAnalysisContext()
                .getLookupFailureCallback(), exceptionSetFactory);

        if (AnalysisContext.currentAnalysisContext().getBoolProperty(AnalysisFeatures.MODEL_INSTANCEOF)) {
            typeAnalysis.setValueNumberDataflow(getValueNumberDataflow(analysisCache, descriptor));
        }

        // Field store type database.
        // If present, this can give us more accurate type information
        // for values loaded from fields.
        typeAnalysis.setFieldStoreTypeDatabase(AnalysisContext.currentAnalysisContext().getFieldStoreTypeDatabase());

        TypeDataflow typeDataflow = new TypeDataflow(cfg, typeAnalysis);
        try {
            typeDataflow.execute();
        } catch (CheckedAnalysisException e) {
            AnalysisContext.logError("Error performing type dataflow analysis of " + descriptor, e);
            throw e;
        }
        if (TypeAnalysis.DEBUG || ClassContext.DUMP_DATAFLOW_ANALYSIS) {
            ClassContext.dumpTypeDataflow(method, cfg, typeDataflow);
        }

        return typeDataflow;
    }
141658
@Override
    public UnpackedCode analyze(IAnalysisCache analysisCache, MethodDescriptor descriptor) throws CheckedAnalysisException {
        Method method = getMethod(analysisCache, descriptor);
        Code code = method.getCode();
        if (code == null) {
            return null;
        }

        byte[] instructionList = code.getCode();

        // Create callback
        UnpackedBytecodeCallback callback = new UnpackedBytecodeCallback(instructionList.length);

        // Scan the method.
        BytecodeScanner scanner = new BytecodeScanner();
        scanner.scan(instructionList, callback);

        return callback.getUnpackedCode();

    }
746115
public static <T extends ParameterDescription> ElementMatcher.Junction<T> hasGenericType(ElementMatcher<? super TypeDescription.Generic> matcher) {
        return new MethodParameterTypeMatcher<T>(matcher);
    }
1071188
@Override
    public CompactLocationNumbering analyze(IAnalysisCache analysisCache, MethodDescriptor descriptor)
            throws CheckedAnalysisException {
        Method method = analysisCache.getMethodAnalysis(Method.class, descriptor);

        if (method.getCode() == null) {
            return null;
        }

        CFG cfg = getCFG(analysisCache, descriptor);
        return new CompactLocationNumbering(cfg);
    }
717046
public static Type[] getArgumentTypes(final String methodDescriptor) {
    // First step: compute the number of argument types in methodDescriptor.
    int numArgumentTypes = 0;
    // Skip the first character, which is always a '('.
    int currentOffset = 1;
    // Parse the argument types, one at a each loop iteration.
    while (methodDescriptor.charAt(currentOffset) != ')') {
      while (methodDescriptor.charAt(currentOffset) == '[') {
        currentOffset++;
      }
      if (methodDescriptor.charAt(currentOffset++) == 'L') {
        while (methodDescriptor.charAt(currentOffset++) != ';') {
          // Skip the argument descriptor content.
        }
      }
      ++numArgumentTypes;
    }

    // Second step: create a Type instance for each argument type.
    Type[] argumentTypes = new Type[numArgumentTypes];
    // Skip the first character, which is always a '('.
    currentOffset = 1;
    // Parse and create the argument types, one at each loop iteration.
    int currentArgumentTypeIndex = 0;
    while (methodDescriptor.charAt(currentOffset) != ')') {
      final int currentArgumentTypeOffset = currentOffset;
      while (methodDescriptor.charAt(currentOffset) == '[') {
        currentOffset++;
      }
      if (methodDescriptor.charAt(currentOffset++) == 'L') {
        while (methodDescriptor.charAt(currentOffset++) != ';') {
          // Skip the argument descriptor content.
        }
      }
      argumentTypes[currentArgumentTypeIndex++] =
          getType(methodDescriptor, currentArgumentTypeOffset, currentOffset);
    }
    return argumentTypes;
  }
697812
@SuppressWarnings({"unchecked"})
    public @Nonnull <T extends Describable<T>,D extends Descriptor<T>> DescriptorExtensionList<T,D> getDescriptorList(Class<T> type) {
        return descriptorLists.computeIfAbsent(type, key -> DescriptorExtensionList.createDescriptorList(this, key));
    }
1074384
@Override
    public String[] analyze(IAnalysisCache analysisCache, MethodDescriptor descriptor) throws CheckedAnalysisException {
        SignatureParser parser = new SignatureParser(descriptor.getSignature());
        ArrayList<String> resultList = new ArrayList<>();
        for (Iterator<String> i = parser.parameterSignatureIterator(); i.hasNext();) {
            resultList.add(i.next());
        }
        return resultList.toArray(new String[resultList.size()]);
    }
233327
public static List<MethodNode> filterMethodsByVisibility(List<MethodNode> methodNodeList, ClassNode enclosingClassNode) {
        if (!asBoolean(methodNodeList)) {
            return StaticTypeCheckingVisitor.EMPTY_METHODNODE_LIST;
        }

        List<MethodNode> result = new LinkedList<>();

        boolean isEnclosingInnerClass = enclosingClassNode instanceof InnerClassNode;
        List<ClassNode> outerClasses = enclosingClassNode.getOuterClasses();

        outer:
        for (MethodNode methodNode : methodNodeList) {
            if (methodNode instanceof ExtensionMethodNode) {
                result.add(methodNode);
                continue;
            }

            ClassNode declaringClass = methodNode.getDeclaringClass();

            if (isEnclosingInnerClass) {
                for (ClassNode outerClass : outerClasses) {
                    if (outerClass.isDerivedFrom(declaringClass)) {
                        if (outerClass.equals(declaringClass)) {
                            result.add(methodNode);
                            continue outer;
                        } else {
                            if (methodNode.isPublic() || methodNode.isProtected()) {
                                result.add(methodNode);
                                continue outer;
                            }
                        }
                    }
                }
            }

            if (declaringClass instanceof InnerClassNode) {
                if (declaringClass.getOuterClasses().contains(enclosingClassNode)) {
                    result.add(methodNode);
                    continue;
                }
            }

            if (methodNode.isPrivate() && !enclosingClassNode.equals(declaringClass)) {
                continue;
            }
            if (methodNode.isProtected()
                    && !enclosingClassNode.isDerivedFrom(declaringClass)
                    && !samePackageName(enclosingClassNode, declaringClass)) {
                continue;
            }
            if (methodNode.isPackageScope() && !samePackageName(enclosingClassNode, declaringClass)) {
                continue;
            }

            result.add(methodNode);
        }

        return result;
    }
1163431
public void parse(String methodDescriptor) {
		int parenthesisCloseIndex = methodDescriptor.indexOf(')');
		if (parenthesisCloseIndex > -1) {
			parseParameters(methodDescriptor, parenthesisCloseIndex);
			parseReturnValue(methodDescriptor, parenthesisCloseIndex);
		}
	}