repo
stringlengths
7
58
path
stringlengths
12
218
func_name
stringlengths
3
140
original_string
stringlengths
73
34.1k
language
stringclasses
1 value
code
stringlengths
73
34.1k
code_tokens
list
docstring
stringlengths
3
16k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
105
339
partition
stringclasses
1 value
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/SelfCalls.java
SelfCalls.scan
private void scan(CallGraphNode node) throws CFGBuilderException { Method method = node.getMethod(); CFG cfg = classContext.getCFG(method); if (method.isSynchronized()) { hasSynchronization = true; } Iterator<BasicBlock> i = cfg.blockIterator(); while (i.hasNext()) { BasicBlock block = i.next(); Iterator<InstructionHandle> j = block.instructionIterator(); while (j.hasNext()) { InstructionHandle handle = j.next(); Instruction ins = handle.getInstruction(); if (ins instanceof InvokeInstruction) { InvokeInstruction inv = (InvokeInstruction) ins; Method called = isSelfCall(inv); if (called != null) { // Add edge to call graph CallSite callSite = new CallSite(method, block, handle); callGraph.createEdge(node, callGraph.getNodeForMethod(called), callSite); // Add to called method set calledMethodSet.add(called); } } else if (ins instanceof MONITORENTER || ins instanceof MONITOREXIT) { hasSynchronization = true; } } } }
java
private void scan(CallGraphNode node) throws CFGBuilderException { Method method = node.getMethod(); CFG cfg = classContext.getCFG(method); if (method.isSynchronized()) { hasSynchronization = true; } Iterator<BasicBlock> i = cfg.blockIterator(); while (i.hasNext()) { BasicBlock block = i.next(); Iterator<InstructionHandle> j = block.instructionIterator(); while (j.hasNext()) { InstructionHandle handle = j.next(); Instruction ins = handle.getInstruction(); if (ins instanceof InvokeInstruction) { InvokeInstruction inv = (InvokeInstruction) ins; Method called = isSelfCall(inv); if (called != null) { // Add edge to call graph CallSite callSite = new CallSite(method, block, handle); callGraph.createEdge(node, callGraph.getNodeForMethod(called), callSite); // Add to called method set calledMethodSet.add(called); } } else if (ins instanceof MONITORENTER || ins instanceof MONITOREXIT) { hasSynchronization = true; } } } }
[ "private", "void", "scan", "(", "CallGraphNode", "node", ")", "throws", "CFGBuilderException", "{", "Method", "method", "=", "node", ".", "getMethod", "(", ")", ";", "CFG", "cfg", "=", "classContext", ".", "getCFG", "(", "method", ")", ";", "if", "(", "m...
Scan a method for self call sites. @param node the CallGraphNode for the method to be scanned
[ "Scan", "a", "method", "for", "self", "call", "sites", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/SelfCalls.java#L162-L194
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/SelfCalls.java
SelfCalls.isSelfCall
private Method isSelfCall(InvokeInstruction inv) { ConstantPoolGen cpg = classContext.getConstantPoolGen(); JavaClass jclass = classContext.getJavaClass(); String calledClassName = inv.getClassName(cpg); // FIXME: is it possible we would see a superclass name here? // Not a big deal for now, as we are mostly just interested in calls // to private methods, for which we will definitely see the right // called class name. if (!calledClassName.equals(jclass.getClassName())) { return null; } String calledMethodName = inv.getMethodName(cpg); String calledMethodSignature = inv.getSignature(cpg); boolean isStaticCall = (inv instanceof INVOKESTATIC); // Scan methods for one that matches. Method[] methods = jclass.getMethods(); for (Method method : methods) { String methodName = method.getName(); String signature = method.getSignature(); boolean isStatic = method.isStatic(); if (methodName.equals(calledMethodName) && signature.equals(calledMethodSignature) && isStatic == isStaticCall) { // This method looks like a match. return wantCallsFor(method) ? method : null; } } // Hmm...no matching method found. // This is almost certainly because the named method // was inherited from a superclass. LOG.debug("No method found for {}.{} : {}", calledClassName, calledMethodName, calledMethodSignature); return null; }
java
private Method isSelfCall(InvokeInstruction inv) { ConstantPoolGen cpg = classContext.getConstantPoolGen(); JavaClass jclass = classContext.getJavaClass(); String calledClassName = inv.getClassName(cpg); // FIXME: is it possible we would see a superclass name here? // Not a big deal for now, as we are mostly just interested in calls // to private methods, for which we will definitely see the right // called class name. if (!calledClassName.equals(jclass.getClassName())) { return null; } String calledMethodName = inv.getMethodName(cpg); String calledMethodSignature = inv.getSignature(cpg); boolean isStaticCall = (inv instanceof INVOKESTATIC); // Scan methods for one that matches. Method[] methods = jclass.getMethods(); for (Method method : methods) { String methodName = method.getName(); String signature = method.getSignature(); boolean isStatic = method.isStatic(); if (methodName.equals(calledMethodName) && signature.equals(calledMethodSignature) && isStatic == isStaticCall) { // This method looks like a match. return wantCallsFor(method) ? method : null; } } // Hmm...no matching method found. // This is almost certainly because the named method // was inherited from a superclass. LOG.debug("No method found for {}.{} : {}", calledClassName, calledMethodName, calledMethodSignature); return null; }
[ "private", "Method", "isSelfCall", "(", "InvokeInstruction", "inv", ")", "{", "ConstantPoolGen", "cpg", "=", "classContext", ".", "getConstantPoolGen", "(", ")", ";", "JavaClass", "jclass", "=", "classContext", ".", "getJavaClass", "(", ")", ";", "String", "call...
Is the given instruction a self-call?
[ "Is", "the", "given", "instruction", "a", "self", "-", "call?" ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/SelfCalls.java#L199-L235
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/DetectorFactory.java
DetectorFactory.isEnabledForCurrentJRE
public boolean isEnabledForCurrentJRE() { if ("".equals(requireJRE)) { return true; } try { JavaVersion requiredVersion = new JavaVersion(requireJRE); JavaVersion runtimeVersion = JavaVersion.getRuntimeVersion(); if (DEBUG_JAVA_VERSION) { System.out.println("Checking JRE version for " + getShortName() + " (requires " + requiredVersion + ", running on " + runtimeVersion + ")"); } boolean enabledForCurrentJRE = runtimeVersion.isSameOrNewerThan(requiredVersion); if (DEBUG_JAVA_VERSION) { System.out.println("\t==> " + enabledForCurrentJRE); } return enabledForCurrentJRE; } catch (JavaVersionException e) { if (DEBUG_JAVA_VERSION) { System.out.println("Couldn't check Java version: " + e.toString()); e.printStackTrace(System.out); } return false; } }
java
public boolean isEnabledForCurrentJRE() { if ("".equals(requireJRE)) { return true; } try { JavaVersion requiredVersion = new JavaVersion(requireJRE); JavaVersion runtimeVersion = JavaVersion.getRuntimeVersion(); if (DEBUG_JAVA_VERSION) { System.out.println("Checking JRE version for " + getShortName() + " (requires " + requiredVersion + ", running on " + runtimeVersion + ")"); } boolean enabledForCurrentJRE = runtimeVersion.isSameOrNewerThan(requiredVersion); if (DEBUG_JAVA_VERSION) { System.out.println("\t==> " + enabledForCurrentJRE); } return enabledForCurrentJRE; } catch (JavaVersionException e) { if (DEBUG_JAVA_VERSION) { System.out.println("Couldn't check Java version: " + e.toString()); e.printStackTrace(System.out); } return false; } }
[ "public", "boolean", "isEnabledForCurrentJRE", "(", ")", "{", "if", "(", "\"\"", ".", "equals", "(", "requireJRE", ")", ")", "{", "return", "true", ";", "}", "try", "{", "JavaVersion", "requiredVersion", "=", "new", "JavaVersion", "(", "requireJRE", ")", "...
Check to see if we are running on a recent-enough JRE for this detector to be enabled. @return true if the current JRE is recent enough to run the Detector, false if it is too old
[ "Check", "to", "see", "if", "we", "are", "running", "on", "a", "recent", "-", "enough", "JRE", "for", "this", "detector", "to", "be", "enabled", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/DetectorFactory.java#L246-L271
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/DetectorFactory.java
DetectorFactory.getReportedBugPatterns
public Set<BugPattern> getReportedBugPatterns() { Set<BugPattern> result = new TreeSet<>(); StringTokenizer tok = new StringTokenizer(reports, ","); while (tok.hasMoreTokens()) { String type = tok.nextToken(); BugPattern bugPattern = DetectorFactoryCollection.instance().lookupBugPattern(type); if (bugPattern != null) { result.add(bugPattern); } } return result; }
java
public Set<BugPattern> getReportedBugPatterns() { Set<BugPattern> result = new TreeSet<>(); StringTokenizer tok = new StringTokenizer(reports, ","); while (tok.hasMoreTokens()) { String type = tok.nextToken(); BugPattern bugPattern = DetectorFactoryCollection.instance().lookupBugPattern(type); if (bugPattern != null) { result.add(bugPattern); } } return result; }
[ "public", "Set", "<", "BugPattern", ">", "getReportedBugPatterns", "(", ")", "{", "Set", "<", "BugPattern", ">", "result", "=", "new", "TreeSet", "<>", "(", ")", ";", "StringTokenizer", "tok", "=", "new", "StringTokenizer", "(", "reports", ",", "\",\"", ")...
Get set of all BugPatterns this detector reports. An empty set means that we don't know what kind of bug patterns might be reported.
[ "Get", "set", "of", "all", "BugPatterns", "this", "detector", "reports", ".", "An", "empty", "set", "means", "that", "we", "don", "t", "know", "what", "kind", "of", "bug", "patterns", "might", "be", "reported", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/DetectorFactory.java#L345-L356
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/DetectorFactory.java
DetectorFactory.getShortName
public String getShortName() { int endOfPkg = className.lastIndexOf('.'); if (endOfPkg >= 0) { return className.substring(endOfPkg + 1); } return className; }
java
public String getShortName() { int endOfPkg = className.lastIndexOf('.'); if (endOfPkg >= 0) { return className.substring(endOfPkg + 1); } return className; }
[ "public", "String", "getShortName", "(", ")", "{", "int", "endOfPkg", "=", "className", ".", "lastIndexOf", "(", "'", "'", ")", ";", "if", "(", "endOfPkg", ">=", "0", ")", "{", "return", "className", ".", "substring", "(", "endOfPkg", "+", "1", ")", ...
Get the short name of the Detector. This is the name of the detector class without the package qualification.
[ "Get", "the", "short", "name", "of", "the", "Detector", ".", "This", "is", "the", "name", "of", "the", "detector", "class", "without", "the", "package", "qualification", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/DetectorFactory.java#L403-L409
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/ba/vna/LoadedFieldSet.java
LoadedFieldSet.getLoadStoreCount
public LoadStoreCount getLoadStoreCount(XField field) { LoadStoreCount loadStoreCount = loadStoreCountMap.get(field); if (loadStoreCount == null) { loadStoreCount = new LoadStoreCount(); loadStoreCountMap.put(field, loadStoreCount); } return loadStoreCount; }
java
public LoadStoreCount getLoadStoreCount(XField field) { LoadStoreCount loadStoreCount = loadStoreCountMap.get(field); if (loadStoreCount == null) { loadStoreCount = new LoadStoreCount(); loadStoreCountMap.put(field, loadStoreCount); } return loadStoreCount; }
[ "public", "LoadStoreCount", "getLoadStoreCount", "(", "XField", "field", ")", "{", "LoadStoreCount", "loadStoreCount", "=", "loadStoreCountMap", ".", "get", "(", "field", ")", ";", "if", "(", "loadStoreCount", "==", "null", ")", "{", "loadStoreCount", "=", "new"...
Get the number of times given field is loaded and stored within the method. @param field the field @return the load/store count object
[ "Get", "the", "number", "of", "times", "given", "field", "is", "loaded", "and", "stored", "within", "the", "method", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/vna/LoadedFieldSet.java#L87-L94
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/ba/vna/LoadedFieldSet.java
LoadedFieldSet.addLoad
public void addLoad(InstructionHandle handle, XField field) { getLoadStoreCount(field).loadCount++; handleToFieldMap.put(handle, field); loadHandleSet.set(handle.getPosition()); }
java
public void addLoad(InstructionHandle handle, XField field) { getLoadStoreCount(field).loadCount++; handleToFieldMap.put(handle, field); loadHandleSet.set(handle.getPosition()); }
[ "public", "void", "addLoad", "(", "InstructionHandle", "handle", ",", "XField", "field", ")", "{", "getLoadStoreCount", "(", "field", ")", ".", "loadCount", "++", ";", "handleToFieldMap", ".", "put", "(", "handle", ",", "field", ")", ";", "loadHandleSet", "....
Add a load of given field at given instruction. @param handle the instruction @param field the field
[ "Add", "a", "load", "of", "given", "field", "at", "given", "instruction", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/vna/LoadedFieldSet.java#L104-L108
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/ba/vna/LoadedFieldSet.java
LoadedFieldSet.addStore
public void addStore(InstructionHandle handle, XField field) { getLoadStoreCount(field).storeCount++; handleToFieldMap.put(handle, field); }
java
public void addStore(InstructionHandle handle, XField field) { getLoadStoreCount(field).storeCount++; handleToFieldMap.put(handle, field); }
[ "public", "void", "addStore", "(", "InstructionHandle", "handle", ",", "XField", "field", ")", "{", "getLoadStoreCount", "(", "field", ")", ".", "storeCount", "++", ";", "handleToFieldMap", ".", "put", "(", "handle", ",", "field", ")", ";", "}" ]
Add a store of given field at given instruction. @param handle the instruction @param field the field
[ "Add", "a", "store", "of", "given", "field", "at", "given", "instruction", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/vna/LoadedFieldSet.java#L118-L121
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/SourceLineAnnotation.java
SourceLineAnnotation.forFirstLineOfMethod
public static SourceLineAnnotation forFirstLineOfMethod(MethodDescriptor methodDescriptor) { SourceLineAnnotation result = null; try { Method m = Global.getAnalysisCache().getMethodAnalysis(Method.class, methodDescriptor); XClass xclass = Global.getAnalysisCache().getClassAnalysis(XClass.class, methodDescriptor.getClassDescriptor()); LineNumberTable lnt = m.getLineNumberTable(); String sourceFile = xclass.getSource(); if (sourceFile != null && lnt != null) { int firstLine = Integer.MAX_VALUE; int bytecode = 0; LineNumber[] entries = lnt.getLineNumberTable(); for (LineNumber entry : entries) { if (entry.getLineNumber() < firstLine) { firstLine = entry.getLineNumber(); bytecode = entry.getStartPC(); } } if (firstLine < Integer.MAX_VALUE) { result = new SourceLineAnnotation(methodDescriptor.getClassDescriptor().toDottedClassName(), sourceFile, firstLine, firstLine, bytecode, bytecode); } } } catch (CheckedAnalysisException e) { // ignore } if (result == null) { result = createUnknown(methodDescriptor.getClassDescriptor().toDottedClassName()); } return result; }
java
public static SourceLineAnnotation forFirstLineOfMethod(MethodDescriptor methodDescriptor) { SourceLineAnnotation result = null; try { Method m = Global.getAnalysisCache().getMethodAnalysis(Method.class, methodDescriptor); XClass xclass = Global.getAnalysisCache().getClassAnalysis(XClass.class, methodDescriptor.getClassDescriptor()); LineNumberTable lnt = m.getLineNumberTable(); String sourceFile = xclass.getSource(); if (sourceFile != null && lnt != null) { int firstLine = Integer.MAX_VALUE; int bytecode = 0; LineNumber[] entries = lnt.getLineNumberTable(); for (LineNumber entry : entries) { if (entry.getLineNumber() < firstLine) { firstLine = entry.getLineNumber(); bytecode = entry.getStartPC(); } } if (firstLine < Integer.MAX_VALUE) { result = new SourceLineAnnotation(methodDescriptor.getClassDescriptor().toDottedClassName(), sourceFile, firstLine, firstLine, bytecode, bytecode); } } } catch (CheckedAnalysisException e) { // ignore } if (result == null) { result = createUnknown(methodDescriptor.getClassDescriptor().toDottedClassName()); } return result; }
[ "public", "static", "SourceLineAnnotation", "forFirstLineOfMethod", "(", "MethodDescriptor", "methodDescriptor", ")", "{", "SourceLineAnnotation", "result", "=", "null", ";", "try", "{", "Method", "m", "=", "Global", ".", "getAnalysisCache", "(", ")", ".", "getMetho...
Make a best-effort attempt to create a SourceLineAnnotation for the first line of a method. @param methodDescriptor a method @return SourceLineAnnotation describing the first line of the method (insofar as we can actually figure that out from the bytecode)
[ "Make", "a", "best", "-", "effort", "attempt", "to", "create", "a", "SourceLineAnnotation", "for", "the", "first", "line", "of", "a", "method", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/SourceLineAnnotation.java#L322-L354
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/SourceLineAnnotation.java
SourceLineAnnotation.fromVisitedInstruction
public static SourceLineAnnotation fromVisitedInstruction(ClassContext classContext, Method method, Location loc) { return fromVisitedInstruction(classContext, method, loc.getHandle()); }
java
public static SourceLineAnnotation fromVisitedInstruction(ClassContext classContext, Method method, Location loc) { return fromVisitedInstruction(classContext, method, loc.getHandle()); }
[ "public", "static", "SourceLineAnnotation", "fromVisitedInstruction", "(", "ClassContext", "classContext", ",", "Method", "method", ",", "Location", "loc", ")", "{", "return", "fromVisitedInstruction", "(", "classContext", ",", "method", ",", "loc", ".", "getHandle", ...
Create from Method and Location in a visited class. @param classContext ClassContext of visited class @param method Method in visited class @param loc Location in visited class @return SourceLineAnnotation describing visited Location
[ "Create", "from", "Method", "and", "Location", "in", "a", "visited", "class", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/SourceLineAnnotation.java#L399-L401
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/SourceLineAnnotation.java
SourceLineAnnotation.fromVisitedInstruction
public static SourceLineAnnotation fromVisitedInstruction(ClassContext classContext, Method method, InstructionHandle handle) { return fromVisitedInstruction(classContext, method, handle.getPosition()); }
java
public static SourceLineAnnotation fromVisitedInstruction(ClassContext classContext, Method method, InstructionHandle handle) { return fromVisitedInstruction(classContext, method, handle.getPosition()); }
[ "public", "static", "SourceLineAnnotation", "fromVisitedInstruction", "(", "ClassContext", "classContext", ",", "Method", "method", ",", "InstructionHandle", "handle", ")", "{", "return", "fromVisitedInstruction", "(", "classContext", ",", "method", ",", "handle", ".", ...
Create from Method and InstructionHandle in a visited class. @param classContext ClassContext of visited class @param method Method in visited class @param handle InstructionHandle in visited class @return SourceLineAnnotation describing visited instruction
[ "Create", "from", "Method", "and", "InstructionHandle", "in", "a", "visited", "class", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/SourceLineAnnotation.java#L414-L416
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/SourceLineAnnotation.java
SourceLineAnnotation.fromVisitedInstruction
public static SourceLineAnnotation fromVisitedInstruction(MethodDescriptor methodDescriptor, Location location) { return fromVisitedInstruction(methodDescriptor, location.getHandle().getPosition()); }
java
public static SourceLineAnnotation fromVisitedInstruction(MethodDescriptor methodDescriptor, Location location) { return fromVisitedInstruction(methodDescriptor, location.getHandle().getPosition()); }
[ "public", "static", "SourceLineAnnotation", "fromVisitedInstruction", "(", "MethodDescriptor", "methodDescriptor", ",", "Location", "location", ")", "{", "return", "fromVisitedInstruction", "(", "methodDescriptor", ",", "location", ".", "getHandle", "(", ")", ".", "getP...
Create from MethodDescriptor and Location of visited instruction. @param methodDescriptor MethodDescriptor identifying analyzed method @param location Location of instruction within analyed method @return SourceLineAnnotation describing visited instruction
[ "Create", "from", "MethodDescriptor", "and", "Location", "of", "visited", "instruction", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/SourceLineAnnotation.java#L427-L429
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/SourceLineAnnotation.java
SourceLineAnnotation.fromVisitedInstructionRange
public static SourceLineAnnotation fromVisitedInstructionRange(ClassContext classContext, MethodGen methodGen, String sourceFile, InstructionHandle start, InstructionHandle end) { LineNumberTable lineNumberTable = methodGen.getLineNumberTable(methodGen.getConstantPool()); String className = methodGen.getClassName(); if (lineNumberTable == null) { return createUnknown(className, sourceFile, start.getPosition(), end.getPosition()); } int startLine = lineNumberTable.getSourceLine(start.getPosition()); int endLine = lineNumberTable.getSourceLine(end.getPosition()); return new SourceLineAnnotation(className, sourceFile, startLine, endLine, start.getPosition(), end.getPosition()); }
java
public static SourceLineAnnotation fromVisitedInstructionRange(ClassContext classContext, MethodGen methodGen, String sourceFile, InstructionHandle start, InstructionHandle end) { LineNumberTable lineNumberTable = methodGen.getLineNumberTable(methodGen.getConstantPool()); String className = methodGen.getClassName(); if (lineNumberTable == null) { return createUnknown(className, sourceFile, start.getPosition(), end.getPosition()); } int startLine = lineNumberTable.getSourceLine(start.getPosition()); int endLine = lineNumberTable.getSourceLine(end.getPosition()); return new SourceLineAnnotation(className, sourceFile, startLine, endLine, start.getPosition(), end.getPosition()); }
[ "public", "static", "SourceLineAnnotation", "fromVisitedInstructionRange", "(", "ClassContext", "classContext", ",", "MethodGen", "methodGen", ",", "String", "sourceFile", ",", "InstructionHandle", "start", ",", "InstructionHandle", "end", ")", "{", "LineNumberTable", "li...
Factory method for creating a source line annotation describing the source line numbers for a range of instruction in a method. @param classContext theClassContext @param methodGen the method @param start the start instruction @param end the end instruction (inclusive)
[ "Factory", "method", "for", "creating", "a", "source", "line", "annotation", "describing", "the", "source", "line", "numbers", "for", "a", "range", "of", "instruction", "in", "a", "method", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/SourceLineAnnotation.java#L607-L619
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/ba/AssertionMethods.java
AssertionMethods.isAssertionInstruction
public boolean isAssertionInstruction(Instruction ins, ConstantPoolGen cpg) { if (ins instanceof InvokeInstruction) { return isAssertionCall((InvokeInstruction) ins); } if (ins instanceof GETSTATIC) { GETSTATIC getStatic = (GETSTATIC) ins; String className = getStatic.getClassName(cpg); String fieldName = getStatic.getFieldName(cpg); if ("java.util.logging.Level".equals(className) && "SEVERE".equals(fieldName)) { return true; } return "org.apache.log4j.Level".equals(className) && ("ERROR".equals(fieldName) || "FATAL".equals(fieldName)); } return false; }
java
public boolean isAssertionInstruction(Instruction ins, ConstantPoolGen cpg) { if (ins instanceof InvokeInstruction) { return isAssertionCall((InvokeInstruction) ins); } if (ins instanceof GETSTATIC) { GETSTATIC getStatic = (GETSTATIC) ins; String className = getStatic.getClassName(cpg); String fieldName = getStatic.getFieldName(cpg); if ("java.util.logging.Level".equals(className) && "SEVERE".equals(fieldName)) { return true; } return "org.apache.log4j.Level".equals(className) && ("ERROR".equals(fieldName) || "FATAL".equals(fieldName)); } return false; }
[ "public", "boolean", "isAssertionInstruction", "(", "Instruction", "ins", ",", "ConstantPoolGen", "cpg", ")", "{", "if", "(", "ins", "instanceof", "InvokeInstruction", ")", "{", "return", "isAssertionCall", "(", "(", "InvokeInstruction", ")", "ins", ")", ";", "}...
Does the given instruction refer to a likely assertion method? @param ins the instruction @return true if the instruction likely refers to an assertion, false if not
[ "Does", "the", "given", "instruction", "refer", "to", "a", "likely", "assertion", "method?" ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/AssertionMethods.java#L209-L225
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/ba/BytecodeScanner.java
BytecodeScanner.unsignedValueOf
private static short unsignedValueOf(byte value) { short result; if ((value & 0x80) != 0) { result = (short) (value & 0x7F); result |= 0x80; } else { result = value; } return result; }
java
private static short unsignedValueOf(byte value) { short result; if ((value & 0x80) != 0) { result = (short) (value & 0x7F); result |= 0x80; } else { result = value; } return result; }
[ "private", "static", "short", "unsignedValueOf", "(", "byte", "value", ")", "{", "short", "result", ";", "if", "(", "(", "value", "&", "0x80", ")", "!=", "0", ")", "{", "result", "=", "(", "short", ")", "(", "value", "&", "0x7F", ")", ";", "result"...
Convert the unsigned value of a byte into a short. @param value the byte @return the byte's unsigned value as a short
[ "Convert", "the", "unsigned", "value", "of", "a", "byte", "into", "a", "short", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/BytecodeScanner.java#L57-L66
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/ba/BytecodeScanner.java
BytecodeScanner.extractInt
private static int extractInt(byte[] arr, int offset) { return ((arr[offset] & 0xFF) << 24) | ((arr[offset + 1] & 0xFF) << 16) | ((arr[offset + 2] & 0xFF) << 8) | (arr[offset + 3] & 0xFF); }
java
private static int extractInt(byte[] arr, int offset) { return ((arr[offset] & 0xFF) << 24) | ((arr[offset + 1] & 0xFF) << 16) | ((arr[offset + 2] & 0xFF) << 8) | (arr[offset + 3] & 0xFF); }
[ "private", "static", "int", "extractInt", "(", "byte", "[", "]", "arr", ",", "int", "offset", ")", "{", "return", "(", "(", "arr", "[", "offset", "]", "&", "0xFF", ")", "<<", "24", ")", "|", "(", "(", "arr", "[", "offset", "+", "1", "]", "&", ...
Extract an int from bytes at the given offset in the array. @param arr the array @param offset the offset in the array
[ "Extract", "an", "int", "from", "bytes", "at", "the", "given", "offset", "in", "the", "array", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/BytecodeScanner.java#L76-L79
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/ba/deref/UnconditionalValueDerefSet.java
UnconditionalValueDerefSet.makeSameAs
public void makeSameAs(UnconditionalValueDerefSet source) { // Copy value numbers valueNumbersUnconditionallyDereferenced.clear(); valueNumbersUnconditionallyDereferenced.or(source.valueNumbersUnconditionallyDereferenced); lastUpdateTimestamp = source.lastUpdateTimestamp; // Copy dereference locations for each value number derefLocationSetMap.clear(); if (source.derefLocationSetMap.size() > 0) { for (Map.Entry<ValueNumber, Set<Location>> sourceEntry : source.derefLocationSetMap.entrySet()) { Set<Location> derefLocationSet = Util.makeSmallHashSet(sourceEntry.getValue()); derefLocationSetMap.put(sourceEntry.getKey(), derefLocationSet); } } }
java
public void makeSameAs(UnconditionalValueDerefSet source) { // Copy value numbers valueNumbersUnconditionallyDereferenced.clear(); valueNumbersUnconditionallyDereferenced.or(source.valueNumbersUnconditionallyDereferenced); lastUpdateTimestamp = source.lastUpdateTimestamp; // Copy dereference locations for each value number derefLocationSetMap.clear(); if (source.derefLocationSetMap.size() > 0) { for (Map.Entry<ValueNumber, Set<Location>> sourceEntry : source.derefLocationSetMap.entrySet()) { Set<Location> derefLocationSet = Util.makeSmallHashSet(sourceEntry.getValue()); derefLocationSetMap.put(sourceEntry.getKey(), derefLocationSet); } } }
[ "public", "void", "makeSameAs", "(", "UnconditionalValueDerefSet", "source", ")", "{", "// Copy value numbers", "valueNumbersUnconditionallyDereferenced", ".", "clear", "(", ")", ";", "valueNumbersUnconditionallyDereferenced", ".", "or", "(", "source", ".", "valueNumbersUnc...
Make this dataflow fact the same as the given one. @param source another dataflow fact
[ "Make", "this", "dataflow", "fact", "the", "same", "as", "the", "given", "one", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/deref/UnconditionalValueDerefSet.java#L124-L137
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/ba/deref/UnconditionalValueDerefSet.java
UnconditionalValueDerefSet.isSameAs
public boolean isSameAs(UnconditionalValueDerefSet otherFact) { return valueNumbersUnconditionallyDereferenced.equals(otherFact.valueNumbersUnconditionallyDereferenced) && derefLocationSetMap.equals(otherFact.derefLocationSetMap); }
java
public boolean isSameAs(UnconditionalValueDerefSet otherFact) { return valueNumbersUnconditionallyDereferenced.equals(otherFact.valueNumbersUnconditionallyDereferenced) && derefLocationSetMap.equals(otherFact.derefLocationSetMap); }
[ "public", "boolean", "isSameAs", "(", "UnconditionalValueDerefSet", "otherFact", ")", "{", "return", "valueNumbersUnconditionallyDereferenced", ".", "equals", "(", "otherFact", ".", "valueNumbersUnconditionallyDereferenced", ")", "&&", "derefLocationSetMap", ".", "equals", ...
Return whether or not this dataflow fact is identical to the one given. @param otherFact another dataflow fact @return true if the other dataflow fact is identical to this one, false otherwise
[ "Return", "whether", "or", "not", "this", "dataflow", "fact", "is", "identical", "to", "the", "one", "given", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/deref/UnconditionalValueDerefSet.java#L147-L150
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/ba/deref/UnconditionalValueDerefSet.java
UnconditionalValueDerefSet.addDeref
public void addDeref(ValueNumber vn, Location location) { if (UnconditionalValueDerefAnalysis.DEBUG) { System.out.println("Adding dereference of " + vn + " to # " + System.identityHashCode(this) + " @ " + location); } valueNumbersUnconditionallyDereferenced.set(vn.getNumber()); Set<Location> derefLocationSet = getDerefLocationSet(vn); derefLocationSet.add(location); }
java
public void addDeref(ValueNumber vn, Location location) { if (UnconditionalValueDerefAnalysis.DEBUG) { System.out.println("Adding dereference of " + vn + " to # " + System.identityHashCode(this) + " @ " + location); } valueNumbersUnconditionallyDereferenced.set(vn.getNumber()); Set<Location> derefLocationSet = getDerefLocationSet(vn); derefLocationSet.add(location); }
[ "public", "void", "addDeref", "(", "ValueNumber", "vn", ",", "Location", "location", ")", "{", "if", "(", "UnconditionalValueDerefAnalysis", ".", "DEBUG", ")", "{", "System", ".", "out", ".", "println", "(", "\"Adding dereference of \"", "+", "vn", "+", "\" to...
Mark a value as being dereferenced at given Location. @param vn the value @param location the Location
[ "Mark", "a", "value", "as", "being", "dereferenced", "at", "given", "Location", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/deref/UnconditionalValueDerefSet.java#L244-L252
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/ba/deref/UnconditionalValueDerefSet.java
UnconditionalValueDerefSet.setDerefSet
public void setDerefSet(ValueNumber vn, Set<Location> derefSet) { if (UnconditionalValueDerefAnalysis.DEBUG) { System.out.println("Adding dereference of " + vn + " for # " + System.identityHashCode(this) + " to " + derefSet); } valueNumbersUnconditionallyDereferenced.set(vn.getNumber()); Set<Location> derefLocationSet = getDerefLocationSet(vn); derefLocationSet.clear(); derefLocationSet.addAll(derefSet); }
java
public void setDerefSet(ValueNumber vn, Set<Location> derefSet) { if (UnconditionalValueDerefAnalysis.DEBUG) { System.out.println("Adding dereference of " + vn + " for # " + System.identityHashCode(this) + " to " + derefSet); } valueNumbersUnconditionallyDereferenced.set(vn.getNumber()); Set<Location> derefLocationSet = getDerefLocationSet(vn); derefLocationSet.clear(); derefLocationSet.addAll(derefSet); }
[ "public", "void", "setDerefSet", "(", "ValueNumber", "vn", ",", "Set", "<", "Location", ">", "derefSet", ")", "{", "if", "(", "UnconditionalValueDerefAnalysis", ".", "DEBUG", ")", "{", "System", ".", "out", ".", "println", "(", "\"Adding dereference of \"", "+...
Set a value as being unconditionally dereferenced at the given set of locations. @param vn the value @param derefSet the Set of dereference Locations
[ "Set", "a", "value", "as", "being", "unconditionally", "dereferenced", "at", "the", "given", "set", "of", "locations", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/deref/UnconditionalValueDerefSet.java#L263-L272
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/ba/deref/UnconditionalValueDerefSet.java
UnconditionalValueDerefSet.clearDerefSet
public void clearDerefSet(ValueNumber value) { if (UnconditionalValueDerefAnalysis.DEBUG) { System.out.println("Clearing dereference of " + value + " for # " + System.identityHashCode(this)); } valueNumbersUnconditionallyDereferenced.clear(value.getNumber()); derefLocationSetMap.remove(value); }
java
public void clearDerefSet(ValueNumber value) { if (UnconditionalValueDerefAnalysis.DEBUG) { System.out.println("Clearing dereference of " + value + " for # " + System.identityHashCode(this)); } valueNumbersUnconditionallyDereferenced.clear(value.getNumber()); derefLocationSetMap.remove(value); }
[ "public", "void", "clearDerefSet", "(", "ValueNumber", "value", ")", "{", "if", "(", "UnconditionalValueDerefAnalysis", ".", "DEBUG", ")", "{", "System", ".", "out", ".", "println", "(", "\"Clearing dereference of \"", "+", "value", "+", "\" for # \"", "+", "Sys...
Clear the set of dereferences for given ValueNumber @param value the ValueNumber
[ "Clear", "the", "set", "of", "dereferences", "for", "given", "ValueNumber" ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/deref/UnconditionalValueDerefSet.java#L280-L286
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/ba/deref/UnconditionalValueDerefSet.java
UnconditionalValueDerefSet.getDerefLocationSet
public Set<Location> getDerefLocationSet(ValueNumber vn) { Set<Location> derefLocationSet = derefLocationSetMap.get(vn); if (derefLocationSet == null) { derefLocationSet = new HashSet<>(); derefLocationSetMap.put(vn, derefLocationSet); } return derefLocationSet; }
java
public Set<Location> getDerefLocationSet(ValueNumber vn) { Set<Location> derefLocationSet = derefLocationSetMap.get(vn); if (derefLocationSet == null) { derefLocationSet = new HashSet<>(); derefLocationSetMap.put(vn, derefLocationSet); } return derefLocationSet; }
[ "public", "Set", "<", "Location", ">", "getDerefLocationSet", "(", "ValueNumber", "vn", ")", "{", "Set", "<", "Location", ">", "derefLocationSet", "=", "derefLocationSetMap", ".", "get", "(", "vn", ")", ";", "if", "(", "derefLocationSet", "==", "null", ")", ...
Get the set of dereference Locations for given value number. @param vn the value number @return the set of dereference Locations
[ "Get", "the", "set", "of", "dereference", "Locations", "for", "given", "value", "number", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/deref/UnconditionalValueDerefSet.java#L295-L302
train
spotbugs/spotbugs
eclipsePlugin/src/de/tobject/findbugs/actions/LoadXmlAction.java
LoadXmlAction.work
private void work(final IProject project, final String fileName) { FindBugsJob runFindBugs = new FindBugsJob("Loading XML data from " + fileName + "...", project) { @Override protected void runWithProgress(IProgressMonitor monitor) throws CoreException { FindBugsWorker worker = new FindBugsWorker(project, monitor); worker.loadXml(fileName); } }; runFindBugs.setRule(project); runFindBugs.scheduleInteractive(); }
java
private void work(final IProject project, final String fileName) { FindBugsJob runFindBugs = new FindBugsJob("Loading XML data from " + fileName + "...", project) { @Override protected void runWithProgress(IProgressMonitor monitor) throws CoreException { FindBugsWorker worker = new FindBugsWorker(project, monitor); worker.loadXml(fileName); } }; runFindBugs.setRule(project); runFindBugs.scheduleInteractive(); }
[ "private", "void", "work", "(", "final", "IProject", "project", ",", "final", "String", "fileName", ")", "{", "FindBugsJob", "runFindBugs", "=", "new", "FindBugsJob", "(", "\"Loading XML data from \"", "+", "fileName", "+", "\"...\"", ",", "project", ")", "{", ...
Run a FindBugs import on the given project, displaying a progress monitor. @param project The resource to load XMl to.
[ "Run", "a", "FindBugs", "import", "on", "the", "given", "project", "displaying", "a", "progress", "monitor", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/eclipsePlugin/src/de/tobject/findbugs/actions/LoadXmlAction.java#L115-L125
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/detect/BuildObligationPolicyDatabase.java
BuildObligationPolicyDatabase.handleWillCloseWhenClosed
private void handleWillCloseWhenClosed(XMethod xmethod, Obligation deletedObligation) { if (deletedObligation == null) { if (DEBUG_ANNOTATIONS) { System.out.println("Method " + xmethod.toString() + " is marked @WillCloseWhenClosed, " + "but its parameter is not an obligation"); } return; } // See what type of obligation is being created. Obligation createdObligation = null; if ("<init>".equals(xmethod.getName())) { // Constructor - obligation type is the type of object being created // (or some supertype) createdObligation = database.getFactory().getObligationByType(xmethod.getClassDescriptor()); } else { // Factory method - obligation type is the return type Type returnType = Type.getReturnType(xmethod.getSignature()); if (returnType instanceof ObjectType) { try { createdObligation = database.getFactory().getObligationByType((ObjectType) returnType); } catch (ClassNotFoundException e) { reporter.reportMissingClass(e); return; } } } if (createdObligation == null) { if (DEBUG_ANNOTATIONS) { System.out.println("Method " + xmethod.toString() + " is marked @WillCloseWhenClosed, " + "but its return type is not an obligation"); } return; } // Add database entries: // - parameter obligation is deleted // - return value obligation is added database.addEntry(new MatchMethodEntry(xmethod, ObligationPolicyDatabaseActionType.DEL, ObligationPolicyDatabaseEntryType.STRONG, deletedObligation)); database.addEntry(new MatchMethodEntry(xmethod, ObligationPolicyDatabaseActionType.ADD, ObligationPolicyDatabaseEntryType.STRONG, createdObligation)); }
java
private void handleWillCloseWhenClosed(XMethod xmethod, Obligation deletedObligation) { if (deletedObligation == null) { if (DEBUG_ANNOTATIONS) { System.out.println("Method " + xmethod.toString() + " is marked @WillCloseWhenClosed, " + "but its parameter is not an obligation"); } return; } // See what type of obligation is being created. Obligation createdObligation = null; if ("<init>".equals(xmethod.getName())) { // Constructor - obligation type is the type of object being created // (or some supertype) createdObligation = database.getFactory().getObligationByType(xmethod.getClassDescriptor()); } else { // Factory method - obligation type is the return type Type returnType = Type.getReturnType(xmethod.getSignature()); if (returnType instanceof ObjectType) { try { createdObligation = database.getFactory().getObligationByType((ObjectType) returnType); } catch (ClassNotFoundException e) { reporter.reportMissingClass(e); return; } } } if (createdObligation == null) { if (DEBUG_ANNOTATIONS) { System.out.println("Method " + xmethod.toString() + " is marked @WillCloseWhenClosed, " + "but its return type is not an obligation"); } return; } // Add database entries: // - parameter obligation is deleted // - return value obligation is added database.addEntry(new MatchMethodEntry(xmethod, ObligationPolicyDatabaseActionType.DEL, ObligationPolicyDatabaseEntryType.STRONG, deletedObligation)); database.addEntry(new MatchMethodEntry(xmethod, ObligationPolicyDatabaseActionType.ADD, ObligationPolicyDatabaseEntryType.STRONG, createdObligation)); }
[ "private", "void", "handleWillCloseWhenClosed", "(", "XMethod", "xmethod", ",", "Obligation", "deletedObligation", ")", "{", "if", "(", "deletedObligation", "==", "null", ")", "{", "if", "(", "DEBUG_ANNOTATIONS", ")", "{", "System", ".", "out", ".", "println", ...
Handle a method with a WillCloseWhenClosed parameter annotation.
[ "Handle", "a", "method", "with", "a", "WillCloseWhenClosed", "parameter", "annotation", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/BuildObligationPolicyDatabase.java#L381-L424
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/ba/npe/IsNullValue.java
IsNullValue.toExceptionValue
public IsNullValue toExceptionValue() { if (getBaseKind() == NO_KABOOM_NN) { return new IsNullValue(kind | EXCEPTION, locationOfKaBoom); } return instanceByFlagsList[(getFlags() | EXCEPTION) >> FLAG_SHIFT][getBaseKind()]; }
java
public IsNullValue toExceptionValue() { if (getBaseKind() == NO_KABOOM_NN) { return new IsNullValue(kind | EXCEPTION, locationOfKaBoom); } return instanceByFlagsList[(getFlags() | EXCEPTION) >> FLAG_SHIFT][getBaseKind()]; }
[ "public", "IsNullValue", "toExceptionValue", "(", ")", "{", "if", "(", "getBaseKind", "(", ")", "==", "NO_KABOOM_NN", ")", "{", "return", "new", "IsNullValue", "(", "kind", "|", "EXCEPTION", ",", "locationOfKaBoom", ")", ";", "}", "return", "instanceByFlagsLis...
Convert to an exception path value.
[ "Convert", "to", "an", "exception", "path", "value", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/npe/IsNullValue.java#L250-L255
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/ba/npe/IsNullValue.java
IsNullValue.merge
public static IsNullValue merge(IsNullValue a, IsNullValue b) { if (a == b) { return a; } if (a.equals(b)) { return a; } int aKind = a.kind & 0xff; int bKind = b.kind & 0xff; int aFlags = a.getFlags(); int bFlags = b.getFlags(); int combinedFlags = aFlags & bFlags; if (!(a.isNullOnSomePath() || a.isDefinitelyNull()) && b.isException()) { combinedFlags |= EXCEPTION; } else if (!(b.isNullOnSomePath() || b.isDefinitelyNull()) && a.isException()) { combinedFlags |= EXCEPTION; } // Left hand value should be >=, since it is used // as the first dimension of the matrix to index. if (aKind < bKind) { int tmp = aKind; aKind = bKind; bKind = tmp; } assert aKind >= bKind; int result = mergeMatrix[aKind][bKind]; IsNullValue resultValue = (result == NO_KABOOM_NN) ? noKaboomNonNullValue(a.locationOfKaBoom) : instanceByFlagsList[combinedFlags >> FLAG_SHIFT][result]; return resultValue; }
java
public static IsNullValue merge(IsNullValue a, IsNullValue b) { if (a == b) { return a; } if (a.equals(b)) { return a; } int aKind = a.kind & 0xff; int bKind = b.kind & 0xff; int aFlags = a.getFlags(); int bFlags = b.getFlags(); int combinedFlags = aFlags & bFlags; if (!(a.isNullOnSomePath() || a.isDefinitelyNull()) && b.isException()) { combinedFlags |= EXCEPTION; } else if (!(b.isNullOnSomePath() || b.isDefinitelyNull()) && a.isException()) { combinedFlags |= EXCEPTION; } // Left hand value should be >=, since it is used // as the first dimension of the matrix to index. if (aKind < bKind) { int tmp = aKind; aKind = bKind; bKind = tmp; } assert aKind >= bKind; int result = mergeMatrix[aKind][bKind]; IsNullValue resultValue = (result == NO_KABOOM_NN) ? noKaboomNonNullValue(a.locationOfKaBoom) : instanceByFlagsList[combinedFlags >> FLAG_SHIFT][result]; return resultValue; }
[ "public", "static", "IsNullValue", "merge", "(", "IsNullValue", "a", ",", "IsNullValue", "b", ")", "{", "if", "(", "a", "==", "b", ")", "{", "return", "a", ";", "}", "if", "(", "a", ".", "equals", "(", "b", ")", ")", "{", "return", "a", ";", "}...
Merge two values.
[ "Merge", "two", "values", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/npe/IsNullValue.java#L400-L434
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/ba/npe/IsNullValue.java
IsNullValue.isNullOnSomePath
public boolean isNullOnSomePath() { int baseKind = getBaseKind(); if (NCP_EXTRA_BRANCH) { // Note: NCP_EXTRA_BRANCH is an experimental feature // to see how many false warnings we get when we allow // two branches between an explicit null and a // a dereference. return baseKind == NSP || baseKind == NCP2; } else { return baseKind == NSP; } }
java
public boolean isNullOnSomePath() { int baseKind = getBaseKind(); if (NCP_EXTRA_BRANCH) { // Note: NCP_EXTRA_BRANCH is an experimental feature // to see how many false warnings we get when we allow // two branches between an explicit null and a // a dereference. return baseKind == NSP || baseKind == NCP2; } else { return baseKind == NSP; } }
[ "public", "boolean", "isNullOnSomePath", "(", ")", "{", "int", "baseKind", "=", "getBaseKind", "(", ")", ";", "if", "(", "NCP_EXTRA_BRANCH", ")", "{", "// Note: NCP_EXTRA_BRANCH is an experimental feature", "// to see how many false warnings we get when we allow", "// two bra...
Is this value null on some path?
[ "Is", "this", "value", "null", "on", "some", "path?" ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/npe/IsNullValue.java#L447-L458
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/ba/ch/Subtypes2.java
Subtypes2.isContainer
static public boolean isContainer(ReferenceType target) throws ClassNotFoundException { Subtypes2 subtypes2 = AnalysisContext.currentAnalysisContext().getSubtypes2(); return subtypes2.isSubtype(target, COLLECTION_TYPE) || subtypes2.isSubtype(target, MAP_TYPE); }
java
static public boolean isContainer(ReferenceType target) throws ClassNotFoundException { Subtypes2 subtypes2 = AnalysisContext.currentAnalysisContext().getSubtypes2(); return subtypes2.isSubtype(target, COLLECTION_TYPE) || subtypes2.isSubtype(target, MAP_TYPE); }
[ "static", "public", "boolean", "isContainer", "(", "ReferenceType", "target", ")", "throws", "ClassNotFoundException", "{", "Subtypes2", "subtypes2", "=", "AnalysisContext", ".", "currentAnalysisContext", "(", ")", ".", "getSubtypes2", "(", ")", ";", "return", "subt...
A collection, a map, or some other container
[ "A", "collection", "a", "map", "or", "some", "other", "container" ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/ch/Subtypes2.java#L143-L147
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/ba/ch/Subtypes2.java
Subtypes2.addApplicationClass
public void addApplicationClass(XClass appXClass) { for (XMethod m : appXClass.getXMethods()) { if (m.isStub()) { return; } } ClassVertex vertex = addClassAndGetClassVertex(appXClass); vertex.markAsApplicationClass(); }
java
public void addApplicationClass(XClass appXClass) { for (XMethod m : appXClass.getXMethods()) { if (m.isStub()) { return; } } ClassVertex vertex = addClassAndGetClassVertex(appXClass); vertex.markAsApplicationClass(); }
[ "public", "void", "addApplicationClass", "(", "XClass", "appXClass", ")", "{", "for", "(", "XMethod", "m", ":", "appXClass", ".", "getXMethods", "(", ")", ")", "{", "if", "(", "m", ".", "isStub", "(", ")", ")", "{", "return", ";", "}", "}", "ClassVer...
Add an application class, and its transitive supertypes, to the inheritance graph. @param appXClass application XClass to add to the inheritance graph
[ "Add", "an", "application", "class", "and", "its", "transitive", "supertypes", "to", "the", "inheritance", "graph", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/ch/Subtypes2.java#L224-L233
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/ba/ch/Subtypes2.java
Subtypes2.addClassAndGetClassVertex
private ClassVertex addClassAndGetClassVertex(XClass xclass) { if (xclass == null) { throw new IllegalStateException(); } LinkedList<XClass> workList = new LinkedList<>(); workList.add(xclass); while (!workList.isEmpty()) { XClass work = workList.removeFirst(); ClassVertex vertex = classDescriptorToVertexMap.get(work.getClassDescriptor()); if (vertex != null && vertex.isFinished()) { // This class has already been processed. continue; } if (vertex == null) { vertex = ClassVertex.createResolvedClassVertex(work.getClassDescriptor(), work); addVertexToGraph(work.getClassDescriptor(), vertex); } addSupertypeEdges(vertex, workList); vertex.setFinished(true); } return classDescriptorToVertexMap.get(xclass.getClassDescriptor()); }
java
private ClassVertex addClassAndGetClassVertex(XClass xclass) { if (xclass == null) { throw new IllegalStateException(); } LinkedList<XClass> workList = new LinkedList<>(); workList.add(xclass); while (!workList.isEmpty()) { XClass work = workList.removeFirst(); ClassVertex vertex = classDescriptorToVertexMap.get(work.getClassDescriptor()); if (vertex != null && vertex.isFinished()) { // This class has already been processed. continue; } if (vertex == null) { vertex = ClassVertex.createResolvedClassVertex(work.getClassDescriptor(), work); addVertexToGraph(work.getClassDescriptor(), vertex); } addSupertypeEdges(vertex, workList); vertex.setFinished(true); } return classDescriptorToVertexMap.get(xclass.getClassDescriptor()); }
[ "private", "ClassVertex", "addClassAndGetClassVertex", "(", "XClass", "xclass", ")", "{", "if", "(", "xclass", "==", "null", ")", "{", "throw", "new", "IllegalStateException", "(", ")", ";", "}", "LinkedList", "<", "XClass", ">", "workList", "=", "new", "Lin...
Add an XClass and all of its supertypes to the InheritanceGraph. @param xclass an XClass @return the ClassVertex representing the class in the InheritanceGraph
[ "Add", "an", "XClass", "and", "all", "of", "its", "supertypes", "to", "the", "InheritanceGraph", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/ch/Subtypes2.java#L263-L290
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/ba/ch/Subtypes2.java
Subtypes2.isSubtype
public boolean isSubtype(ReferenceType type, ReferenceType possibleSupertype) throws ClassNotFoundException { // Eliminate some easy cases if (type.equals(possibleSupertype)) { return true; } if (possibleSupertype.equals(Type.OBJECT)) { return true; } if (type.equals(Type.OBJECT)) { return false; } boolean typeIsObjectType = (type instanceof ObjectType); boolean possibleSupertypeIsObjectType = (possibleSupertype instanceof ObjectType); if (typeIsObjectType && possibleSupertypeIsObjectType) { // Both types are ordinary object (non-array) types. return isSubtype((ObjectType) type, (ObjectType) possibleSupertype); } boolean typeIsArrayType = (type instanceof ArrayType); boolean possibleSupertypeIsArrayType = (possibleSupertype instanceof ArrayType); if (typeIsArrayType) { // Check superclass/interfaces if (possibleSupertype.equals(SERIALIZABLE) || possibleSupertype.equals(CLONEABLE)) { return true; } // We checked all of the possible class/interface supertypes, // so if possibleSupertype is not an array type, // then we can definitively say no if (!possibleSupertypeIsArrayType) { return false; } // Check array/array subtype relationship ArrayType typeAsArrayType = (ArrayType) type; ArrayType possibleSupertypeAsArrayType = (ArrayType) possibleSupertype; // Must have same number of dimensions if (typeAsArrayType.getDimensions() < possibleSupertypeAsArrayType.getDimensions()) { return false; } Type possibleSupertypeBasicType = possibleSupertypeAsArrayType.getBasicType(); if (!(possibleSupertypeBasicType instanceof ObjectType)) { return false; } Type typeBasicType = typeAsArrayType.getBasicType(); // If dimensions differ, see if element types are compatible. if (typeAsArrayType.getDimensions() > possibleSupertypeAsArrayType.getDimensions()) { return isSubtype( new ArrayType(typeBasicType, typeAsArrayType.getDimensions() - possibleSupertypeAsArrayType.getDimensions()), (ObjectType) possibleSupertypeBasicType); } // type's base type must be a subtype of possibleSupertype's base // type. // Note that neither base type can be a non-ObjectType if we are to // answer yes. if (!(typeBasicType instanceof ObjectType)) { return false; } return isSubtype((ObjectType) typeBasicType, (ObjectType) possibleSupertypeBasicType); } // OK, we've exhausted the possibilities now return false; }
java
public boolean isSubtype(ReferenceType type, ReferenceType possibleSupertype) throws ClassNotFoundException { // Eliminate some easy cases if (type.equals(possibleSupertype)) { return true; } if (possibleSupertype.equals(Type.OBJECT)) { return true; } if (type.equals(Type.OBJECT)) { return false; } boolean typeIsObjectType = (type instanceof ObjectType); boolean possibleSupertypeIsObjectType = (possibleSupertype instanceof ObjectType); if (typeIsObjectType && possibleSupertypeIsObjectType) { // Both types are ordinary object (non-array) types. return isSubtype((ObjectType) type, (ObjectType) possibleSupertype); } boolean typeIsArrayType = (type instanceof ArrayType); boolean possibleSupertypeIsArrayType = (possibleSupertype instanceof ArrayType); if (typeIsArrayType) { // Check superclass/interfaces if (possibleSupertype.equals(SERIALIZABLE) || possibleSupertype.equals(CLONEABLE)) { return true; } // We checked all of the possible class/interface supertypes, // so if possibleSupertype is not an array type, // then we can definitively say no if (!possibleSupertypeIsArrayType) { return false; } // Check array/array subtype relationship ArrayType typeAsArrayType = (ArrayType) type; ArrayType possibleSupertypeAsArrayType = (ArrayType) possibleSupertype; // Must have same number of dimensions if (typeAsArrayType.getDimensions() < possibleSupertypeAsArrayType.getDimensions()) { return false; } Type possibleSupertypeBasicType = possibleSupertypeAsArrayType.getBasicType(); if (!(possibleSupertypeBasicType instanceof ObjectType)) { return false; } Type typeBasicType = typeAsArrayType.getBasicType(); // If dimensions differ, see if element types are compatible. if (typeAsArrayType.getDimensions() > possibleSupertypeAsArrayType.getDimensions()) { return isSubtype( new ArrayType(typeBasicType, typeAsArrayType.getDimensions() - possibleSupertypeAsArrayType.getDimensions()), (ObjectType) possibleSupertypeBasicType); } // type's base type must be a subtype of possibleSupertype's base // type. // Note that neither base type can be a non-ObjectType if we are to // answer yes. if (!(typeBasicType instanceof ObjectType)) { return false; } return isSubtype((ObjectType) typeBasicType, (ObjectType) possibleSupertypeBasicType); } // OK, we've exhausted the possibilities now return false; }
[ "public", "boolean", "isSubtype", "(", "ReferenceType", "type", ",", "ReferenceType", "possibleSupertype", ")", "throws", "ClassNotFoundException", "{", "// Eliminate some easy cases", "if", "(", "type", ".", "equals", "(", "possibleSupertype", ")", ")", "{", "return"...
Determine whether or not a given ReferenceType is a subtype of another. Throws ClassNotFoundException if the question cannot be answered definitively due to a missing class. @param type a ReferenceType @param possibleSupertype another Reference type @return true if <code>type</code> is a subtype of <code>possibleSupertype</code>, false if not @throws ClassNotFoundException if a missing class prevents a definitive answer
[ "Determine", "whether", "or", "not", "a", "given", "ReferenceType", "is", "a", "subtype", "of", "another", ".", "Throws", "ClassNotFoundException", "if", "the", "question", "cannot", "be", "answered", "definitively", "due", "to", "a", "missing", "class", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/ch/Subtypes2.java#L327-L400
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/ba/ch/Subtypes2.java
Subtypes2.isSubtype
public boolean isSubtype(ObjectType type, ObjectType possibleSupertype) throws ClassNotFoundException { if (DEBUG_QUERIES) { System.out.println("isSubtype: check " + type + " subtype of " + possibleSupertype); } if (type.equals(possibleSupertype)) { if (DEBUG_QUERIES) { System.out.println(" ==> yes, types are same"); } return true; } ClassDescriptor typeClassDescriptor = DescriptorFactory.getClassDescriptor(type); ClassDescriptor possibleSuperclassClassDescriptor = DescriptorFactory.getClassDescriptor(possibleSupertype); return isSubtype(typeClassDescriptor, possibleSuperclassClassDescriptor); }
java
public boolean isSubtype(ObjectType type, ObjectType possibleSupertype) throws ClassNotFoundException { if (DEBUG_QUERIES) { System.out.println("isSubtype: check " + type + " subtype of " + possibleSupertype); } if (type.equals(possibleSupertype)) { if (DEBUG_QUERIES) { System.out.println(" ==> yes, types are same"); } return true; } ClassDescriptor typeClassDescriptor = DescriptorFactory.getClassDescriptor(type); ClassDescriptor possibleSuperclassClassDescriptor = DescriptorFactory.getClassDescriptor(possibleSupertype); return isSubtype(typeClassDescriptor, possibleSuperclassClassDescriptor); }
[ "public", "boolean", "isSubtype", "(", "ObjectType", "type", ",", "ObjectType", "possibleSupertype", ")", "throws", "ClassNotFoundException", "{", "if", "(", "DEBUG_QUERIES", ")", "{", "System", ".", "out", ".", "println", "(", "\"isSubtype: check \"", "+", "type"...
Determine whether or not a given ObjectType is a subtype of another. Throws ClassNotFoundException if the question cannot be answered definitively due to a missing class. @param type a ReferenceType @param possibleSupertype another Reference type @return true if <code>type</code> is a subtype of <code>possibleSupertype</code>, false if not @throws ClassNotFoundException if a missing class prevents a definitive answer
[ "Determine", "whether", "or", "not", "a", "given", "ObjectType", "is", "a", "subtype", "of", "another", ".", "Throws", "ClassNotFoundException", "if", "the", "question", "cannot", "be", "answered", "definitively", "due", "to", "a", "missing", "class", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/ch/Subtypes2.java#L508-L523
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/ba/ch/Subtypes2.java
Subtypes2.computeFirstCommonSuperclassOfSameDimensionArrays
private ReferenceType computeFirstCommonSuperclassOfSameDimensionArrays(ArrayType aArrType, ArrayType bArrType) throws ClassNotFoundException { assert aArrType.getDimensions() == bArrType.getDimensions(); Type aBaseType = aArrType.getBasicType(); Type bBaseType = bArrType.getBasicType(); boolean aBaseIsObjectType = (aBaseType instanceof ObjectType); boolean bBaseIsObjectType = (bBaseType instanceof ObjectType); if (!aBaseIsObjectType || !bBaseIsObjectType) { assert (aBaseType instanceof BasicType) || (bBaseType instanceof BasicType); if (aArrType.getDimensions() > 1) { // E.g.: first common supertype of int[][] and WHATEVER[][] is // Object[] return new ArrayType(Type.OBJECT, aArrType.getDimensions() - 1); } else { assert aArrType.getDimensions() == 1; // E.g.: first common supertype type of int[] and WHATEVER[] is // Object return Type.OBJECT; } } else { assert (aBaseType instanceof ObjectType); assert (bBaseType instanceof ObjectType); // Base types are both ObjectTypes, and number of dimensions is // same. // We just need to find the first common supertype of base types // and return a new ArrayType using that base type. ObjectType firstCommonBaseType = getFirstCommonSuperclass((ObjectType) aBaseType, (ObjectType) bBaseType); return new ArrayType(firstCommonBaseType, aArrType.getDimensions()); } }
java
private ReferenceType computeFirstCommonSuperclassOfSameDimensionArrays(ArrayType aArrType, ArrayType bArrType) throws ClassNotFoundException { assert aArrType.getDimensions() == bArrType.getDimensions(); Type aBaseType = aArrType.getBasicType(); Type bBaseType = bArrType.getBasicType(); boolean aBaseIsObjectType = (aBaseType instanceof ObjectType); boolean bBaseIsObjectType = (bBaseType instanceof ObjectType); if (!aBaseIsObjectType || !bBaseIsObjectType) { assert (aBaseType instanceof BasicType) || (bBaseType instanceof BasicType); if (aArrType.getDimensions() > 1) { // E.g.: first common supertype of int[][] and WHATEVER[][] is // Object[] return new ArrayType(Type.OBJECT, aArrType.getDimensions() - 1); } else { assert aArrType.getDimensions() == 1; // E.g.: first common supertype type of int[] and WHATEVER[] is // Object return Type.OBJECT; } } else { assert (aBaseType instanceof ObjectType); assert (bBaseType instanceof ObjectType); // Base types are both ObjectTypes, and number of dimensions is // same. // We just need to find the first common supertype of base types // and return a new ArrayType using that base type. ObjectType firstCommonBaseType = getFirstCommonSuperclass((ObjectType) aBaseType, (ObjectType) bBaseType); return new ArrayType(firstCommonBaseType, aArrType.getDimensions()); } }
[ "private", "ReferenceType", "computeFirstCommonSuperclassOfSameDimensionArrays", "(", "ArrayType", "aArrType", ",", "ArrayType", "bArrType", ")", "throws", "ClassNotFoundException", "{", "assert", "aArrType", ".", "getDimensions", "(", ")", "==", "bArrType", ".", "getDime...
Get first common supertype of arrays with the same number of dimensions. @param aArrType an ArrayType @param bArrType another ArrayType with the same number of dimensions @return first common supertype @throws ClassNotFoundException
[ "Get", "first", "common", "supertype", "of", "arrays", "with", "the", "same", "number", "of", "dimensions", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/ch/Subtypes2.java#L598-L631
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/ba/ch/Subtypes2.java
Subtypes2.computeFirstCommonSuperclassOfDifferentDimensionArrays
private ReferenceType computeFirstCommonSuperclassOfDifferentDimensionArrays(ArrayType aArrType, ArrayType bArrType) { assert aArrType.getDimensions() != bArrType.getDimensions(); boolean aBaseTypeIsPrimitive = (aArrType.getBasicType() instanceof BasicType); boolean bBaseTypeIsPrimitive = (bArrType.getBasicType() instanceof BasicType); if (aBaseTypeIsPrimitive || bBaseTypeIsPrimitive) { int minDimensions, maxDimensions; if (aArrType.getDimensions() < bArrType.getDimensions()) { minDimensions = aArrType.getDimensions(); maxDimensions = bArrType.getDimensions(); } else { minDimensions = bArrType.getDimensions(); maxDimensions = aArrType.getDimensions(); } if (minDimensions == 1) { // One of the types was something like int[]. // The only possible common supertype is Object. return Type.OBJECT; } else { // Weird case: e.g., // - first common supertype of int[][] and char[][][] is // Object[] // because f.c.s. of int[] and char[][] is Object // - first common supertype of int[][][] and char[][][][][] is // Object[][] // because f.c.s. of int[] and char[][][] is Object return new ArrayType(Type.OBJECT, maxDimensions - minDimensions); } } else { // Both a and b have base types which are ObjectTypes. // Since the arrays have different numbers of dimensions, the // f.c.s. will have Object as its base type. // E.g., f.c.s. of Cat[] and Dog[][] is Object[] return new ArrayType(Type.OBJECT, Math.min(aArrType.getDimensions(), bArrType.getDimensions())); } }
java
private ReferenceType computeFirstCommonSuperclassOfDifferentDimensionArrays(ArrayType aArrType, ArrayType bArrType) { assert aArrType.getDimensions() != bArrType.getDimensions(); boolean aBaseTypeIsPrimitive = (aArrType.getBasicType() instanceof BasicType); boolean bBaseTypeIsPrimitive = (bArrType.getBasicType() instanceof BasicType); if (aBaseTypeIsPrimitive || bBaseTypeIsPrimitive) { int minDimensions, maxDimensions; if (aArrType.getDimensions() < bArrType.getDimensions()) { minDimensions = aArrType.getDimensions(); maxDimensions = bArrType.getDimensions(); } else { minDimensions = bArrType.getDimensions(); maxDimensions = aArrType.getDimensions(); } if (minDimensions == 1) { // One of the types was something like int[]. // The only possible common supertype is Object. return Type.OBJECT; } else { // Weird case: e.g., // - first common supertype of int[][] and char[][][] is // Object[] // because f.c.s. of int[] and char[][] is Object // - first common supertype of int[][][] and char[][][][][] is // Object[][] // because f.c.s. of int[] and char[][][] is Object return new ArrayType(Type.OBJECT, maxDimensions - minDimensions); } } else { // Both a and b have base types which are ObjectTypes. // Since the arrays have different numbers of dimensions, the // f.c.s. will have Object as its base type. // E.g., f.c.s. of Cat[] and Dog[][] is Object[] return new ArrayType(Type.OBJECT, Math.min(aArrType.getDimensions(), bArrType.getDimensions())); } }
[ "private", "ReferenceType", "computeFirstCommonSuperclassOfDifferentDimensionArrays", "(", "ArrayType", "aArrType", ",", "ArrayType", "bArrType", ")", "{", "assert", "aArrType", ".", "getDimensions", "(", ")", "!=", "bArrType", ".", "getDimensions", "(", ")", ";", "bo...
Get the first common superclass of arrays with different numbers of dimensions. @param aArrType an ArrayType @param bArrType another ArrayType @return ReferenceType representing first common superclass
[ "Get", "the", "first", "common", "superclass", "of", "arrays", "with", "different", "numbers", "of", "dimensions", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/ch/Subtypes2.java#L643-L680
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/ba/ch/Subtypes2.java
Subtypes2.hasSubtypes
public boolean hasSubtypes(ClassDescriptor classDescriptor) throws ClassNotFoundException { Set<ClassDescriptor> subtypes = getDirectSubtypes(classDescriptor); if (DEBUG) { System.out.println("Direct subtypes of " + classDescriptor + " are " + subtypes); } return !subtypes.isEmpty(); }
java
public boolean hasSubtypes(ClassDescriptor classDescriptor) throws ClassNotFoundException { Set<ClassDescriptor> subtypes = getDirectSubtypes(classDescriptor); if (DEBUG) { System.out.println("Direct subtypes of " + classDescriptor + " are " + subtypes); } return !subtypes.isEmpty(); }
[ "public", "boolean", "hasSubtypes", "(", "ClassDescriptor", "classDescriptor", ")", "throws", "ClassNotFoundException", "{", "Set", "<", "ClassDescriptor", ">", "subtypes", "=", "getDirectSubtypes", "(", "classDescriptor", ")", ";", "if", "(", "DEBUG", ")", "{", "...
Determine whether or not the given class has any known subtypes. @param classDescriptor ClassDescriptor naming a class @return true if the class has subtypes, false if it has no subtypes @throws ClassNotFoundException
[ "Determine", "whether", "or", "not", "the", "given", "class", "has", "any", "known", "subtypes", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/ch/Subtypes2.java#L842-L848
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/ba/ch/Subtypes2.java
Subtypes2.getDirectSubtypes
public Set<ClassDescriptor> getDirectSubtypes(ClassDescriptor classDescriptor) throws ClassNotFoundException { ClassVertex startVertex = resolveClassVertex(classDescriptor); Set<ClassDescriptor> result = new HashSet<>(); Iterator<InheritanceEdge> i = graph.incomingEdgeIterator(startVertex); while (i.hasNext()) { InheritanceEdge edge = i.next(); result.add(edge.getSource().getClassDescriptor()); } return result; }
java
public Set<ClassDescriptor> getDirectSubtypes(ClassDescriptor classDescriptor) throws ClassNotFoundException { ClassVertex startVertex = resolveClassVertex(classDescriptor); Set<ClassDescriptor> result = new HashSet<>(); Iterator<InheritanceEdge> i = graph.incomingEdgeIterator(startVertex); while (i.hasNext()) { InheritanceEdge edge = i.next(); result.add(edge.getSource().getClassDescriptor()); } return result; }
[ "public", "Set", "<", "ClassDescriptor", ">", "getDirectSubtypes", "(", "ClassDescriptor", "classDescriptor", ")", "throws", "ClassNotFoundException", "{", "ClassVertex", "startVertex", "=", "resolveClassVertex", "(", "classDescriptor", ")", ";", "Set", "<", "ClassDescr...
Get known subtypes of given class. @param classDescriptor ClassDescriptor naming a class @return Set of ClassDescriptors which are the known subtypes of the class @throws ClassNotFoundException
[ "Get", "known", "subtypes", "of", "given", "class", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/ch/Subtypes2.java#L858-L870
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/ba/ch/Subtypes2.java
Subtypes2.getTransitiveCommonSubtypes
public Set<ClassDescriptor> getTransitiveCommonSubtypes(ClassDescriptor classDescriptor1, ClassDescriptor classDescriptor2) throws ClassNotFoundException { Set<ClassDescriptor> subtypes1 = getSubtypes(classDescriptor1); Set<ClassDescriptor> result = new HashSet<>(subtypes1); Set<ClassDescriptor> subtypes2 = getSubtypes(classDescriptor2); result.retainAll(subtypes2); return result; }
java
public Set<ClassDescriptor> getTransitiveCommonSubtypes(ClassDescriptor classDescriptor1, ClassDescriptor classDescriptor2) throws ClassNotFoundException { Set<ClassDescriptor> subtypes1 = getSubtypes(classDescriptor1); Set<ClassDescriptor> result = new HashSet<>(subtypes1); Set<ClassDescriptor> subtypes2 = getSubtypes(classDescriptor2); result.retainAll(subtypes2); return result; }
[ "public", "Set", "<", "ClassDescriptor", ">", "getTransitiveCommonSubtypes", "(", "ClassDescriptor", "classDescriptor1", ",", "ClassDescriptor", "classDescriptor2", ")", "throws", "ClassNotFoundException", "{", "Set", "<", "ClassDescriptor", ">", "subtypes1", "=", "getSub...
Get the set of common subtypes of the two given classes. @param classDescriptor1 a ClassDescriptor naming a class @param classDescriptor2 a ClassDescriptor naming another class @return Set containing all common transitive subtypes of the two classes @throws ClassNotFoundException
[ "Get", "the", "set", "of", "common", "subtypes", "of", "the", "two", "given", "classes", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/ch/Subtypes2.java#L882-L889
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/ba/ch/Subtypes2.java
Subtypes2.traverseSupertypes
public void traverseSupertypes(ClassDescriptor start, InheritanceGraphVisitor visitor) throws ClassNotFoundException { LinkedList<SupertypeTraversalPath> workList = new LinkedList<>(); ClassVertex startVertex = resolveClassVertex(start); workList.addLast(new SupertypeTraversalPath(startVertex)); while (!workList.isEmpty()) { SupertypeTraversalPath cur = workList.removeFirst(); ClassVertex vertex = cur.getNext(); assert !cur.hasBeenSeen(vertex.getClassDescriptor()); cur.markSeen(vertex.getClassDescriptor()); if (!visitor.visitClass(vertex.getClassDescriptor(), vertex.getXClass())) { // Visitor doesn't want to continue on this path continue; } if (!vertex.isResolved()) { // Unknown class - so, we don't know its immediate supertypes continue; } // Advance to direct superclass ClassDescriptor superclassDescriptor = vertex.getXClass().getSuperclassDescriptor(); if (superclassDescriptor != null && traverseEdge(vertex, superclassDescriptor, false, visitor)) { addToWorkList(workList, cur, superclassDescriptor); } // Advance to directly-implemented interfaces for (ClassDescriptor ifaceDesc : vertex.getXClass().getInterfaceDescriptorList()) { if (traverseEdge(vertex, ifaceDesc, true, visitor)) { addToWorkList(workList, cur, ifaceDesc); } } } }
java
public void traverseSupertypes(ClassDescriptor start, InheritanceGraphVisitor visitor) throws ClassNotFoundException { LinkedList<SupertypeTraversalPath> workList = new LinkedList<>(); ClassVertex startVertex = resolveClassVertex(start); workList.addLast(new SupertypeTraversalPath(startVertex)); while (!workList.isEmpty()) { SupertypeTraversalPath cur = workList.removeFirst(); ClassVertex vertex = cur.getNext(); assert !cur.hasBeenSeen(vertex.getClassDescriptor()); cur.markSeen(vertex.getClassDescriptor()); if (!visitor.visitClass(vertex.getClassDescriptor(), vertex.getXClass())) { // Visitor doesn't want to continue on this path continue; } if (!vertex.isResolved()) { // Unknown class - so, we don't know its immediate supertypes continue; } // Advance to direct superclass ClassDescriptor superclassDescriptor = vertex.getXClass().getSuperclassDescriptor(); if (superclassDescriptor != null && traverseEdge(vertex, superclassDescriptor, false, visitor)) { addToWorkList(workList, cur, superclassDescriptor); } // Advance to directly-implemented interfaces for (ClassDescriptor ifaceDesc : vertex.getXClass().getInterfaceDescriptorList()) { if (traverseEdge(vertex, ifaceDesc, true, visitor)) { addToWorkList(workList, cur, ifaceDesc); } } } }
[ "public", "void", "traverseSupertypes", "(", "ClassDescriptor", "start", ",", "InheritanceGraphVisitor", "visitor", ")", "throws", "ClassNotFoundException", "{", "LinkedList", "<", "SupertypeTraversalPath", ">", "workList", "=", "new", "LinkedList", "<>", "(", ")", ";...
Starting at the class or interface named by the given ClassDescriptor, traverse the inheritance graph, exploring all paths from the class or interface to java.lang.Object. @param start ClassDescriptor naming the class where the traversal should start @param visitor an InheritanceGraphVisitor @throws ClassNotFoundException if the start vertex cannot be resolved
[ "Starting", "at", "the", "class", "or", "interface", "named", "by", "the", "given", "ClassDescriptor", "traverse", "the", "inheritance", "graph", "exploring", "all", "paths", "from", "the", "class", "or", "interface", "to", "java", ".", "lang", ".", "Object", ...
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/ch/Subtypes2.java#L959-L995
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/ba/ch/Subtypes2.java
Subtypes2.traverseSupertypesDepthFirst
public void traverseSupertypesDepthFirst(ClassDescriptor start, SupertypeTraversalVisitor visitor) throws ClassNotFoundException { this.traverseSupertypesDepthFirstHelper(start, visitor, new HashSet<ClassDescriptor>()); }
java
public void traverseSupertypesDepthFirst(ClassDescriptor start, SupertypeTraversalVisitor visitor) throws ClassNotFoundException { this.traverseSupertypesDepthFirstHelper(start, visitor, new HashSet<ClassDescriptor>()); }
[ "public", "void", "traverseSupertypesDepthFirst", "(", "ClassDescriptor", "start", ",", "SupertypeTraversalVisitor", "visitor", ")", "throws", "ClassNotFoundException", "{", "this", ".", "traverseSupertypesDepthFirstHelper", "(", "start", ",", "visitor", ",", "new", "Hash...
Starting at the class or interface named by the given ClassDescriptor, traverse the inheritance graph depth first, visiting each class only once. This is much faster than traversing all paths in certain circumstances. @param start ClassDescriptor naming the class where the traversal should start @param visitor an InheritanceGraphVisitor @throws ClassNotFoundException if the start vertex cannot be resolved
[ "Starting", "at", "the", "class", "or", "interface", "named", "by", "the", "given", "ClassDescriptor", "traverse", "the", "inheritance", "graph", "depth", "first", "visiting", "each", "class", "only", "once", ".", "This", "is", "much", "faster", "than", "trave...
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/ch/Subtypes2.java#L1010-L1012
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/ba/ch/Subtypes2.java
Subtypes2.computeKnownSubtypes
private Set<ClassDescriptor> computeKnownSubtypes(ClassDescriptor classDescriptor) throws ClassNotFoundException { LinkedList<ClassVertex> workList = new LinkedList<>(); ClassVertex startVertex = resolveClassVertex(classDescriptor); workList.addLast(startVertex); Set<ClassDescriptor> result = new HashSet<>(); while (!workList.isEmpty()) { ClassVertex current = workList.removeFirst(); if (result.contains(current.getClassDescriptor())) { // Already added this class continue; } // Add class to the result result.add(current.getClassDescriptor()); // Add all known subtype vertices to the work list Iterator<InheritanceEdge> i = graph.incomingEdgeIterator(current); while (i.hasNext()) { InheritanceEdge edge = i.next(); workList.addLast(edge.getSource()); } } return new HashSet<>(result); }
java
private Set<ClassDescriptor> computeKnownSubtypes(ClassDescriptor classDescriptor) throws ClassNotFoundException { LinkedList<ClassVertex> workList = new LinkedList<>(); ClassVertex startVertex = resolveClassVertex(classDescriptor); workList.addLast(startVertex); Set<ClassDescriptor> result = new HashSet<>(); while (!workList.isEmpty()) { ClassVertex current = workList.removeFirst(); if (result.contains(current.getClassDescriptor())) { // Already added this class continue; } // Add class to the result result.add(current.getClassDescriptor()); // Add all known subtype vertices to the work list Iterator<InheritanceEdge> i = graph.incomingEdgeIterator(current); while (i.hasNext()) { InheritanceEdge edge = i.next(); workList.addLast(edge.getSource()); } } return new HashSet<>(result); }
[ "private", "Set", "<", "ClassDescriptor", ">", "computeKnownSubtypes", "(", "ClassDescriptor", "classDescriptor", ")", "throws", "ClassNotFoundException", "{", "LinkedList", "<", "ClassVertex", ">", "workList", "=", "new", "LinkedList", "<>", "(", ")", ";", "ClassVe...
Compute set of known subtypes of class named by given ClassDescriptor. @param classDescriptor a ClassDescriptor @throws ClassNotFoundException
[ "Compute", "set", "of", "known", "subtypes", "of", "class", "named", "by", "given", "ClassDescriptor", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/ch/Subtypes2.java#L1090-L1118
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/ba/ch/Subtypes2.java
Subtypes2.getSupertypeQueryResults
public SupertypeQueryResults getSupertypeQueryResults(ClassDescriptor classDescriptor) { SupertypeQueryResults supertypeQueryResults = supertypeSetMap.get(classDescriptor); if (supertypeQueryResults == null) { supertypeQueryResults = computeSupertypes(classDescriptor); supertypeSetMap.put(classDescriptor, supertypeQueryResults); } return supertypeQueryResults; }
java
public SupertypeQueryResults getSupertypeQueryResults(ClassDescriptor classDescriptor) { SupertypeQueryResults supertypeQueryResults = supertypeSetMap.get(classDescriptor); if (supertypeQueryResults == null) { supertypeQueryResults = computeSupertypes(classDescriptor); supertypeSetMap.put(classDescriptor, supertypeQueryResults); } return supertypeQueryResults; }
[ "public", "SupertypeQueryResults", "getSupertypeQueryResults", "(", "ClassDescriptor", "classDescriptor", ")", "{", "SupertypeQueryResults", "supertypeQueryResults", "=", "supertypeSetMap", ".", "get", "(", "classDescriptor", ")", ";", "if", "(", "supertypeQueryResults", "=...
Look up or compute the SupertypeQueryResults for class named by given ClassDescriptor. @param classDescriptor a ClassDescriptor @return SupertypeQueryResults for the class named by the ClassDescriptor
[ "Look", "up", "or", "compute", "the", "SupertypeQueryResults", "for", "class", "named", "by", "given", "ClassDescriptor", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/ch/Subtypes2.java#L1195-L1202
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/ba/ch/Subtypes2.java
Subtypes2.computeSupertypes
private SupertypeQueryResults computeSupertypes(ClassDescriptor classDescriptor) // throws // ClassNotFoundException { if (DEBUG_QUERIES) { System.out.println("Computing supertypes for " + classDescriptor.toDottedClassName()); } // Try to fully resolve the class and its superclasses/superinterfaces. ClassVertex typeVertex = optionallyResolveClassVertex(classDescriptor); // Create new empty SupertypeQueryResults. SupertypeQueryResults supertypeSet = new SupertypeQueryResults(); // Add all known superclasses/superinterfaces. // The ClassVertexes for all of them should be in the // InheritanceGraph by now. LinkedList<ClassVertex> workList = new LinkedList<>(); workList.addLast(typeVertex); while (!workList.isEmpty()) { ClassVertex vertex = workList.removeFirst(); supertypeSet.addSupertype(vertex.getClassDescriptor()); if (vertex.isResolved()) { if (DEBUG_QUERIES) { System.out.println(" Adding supertype " + vertex.getClassDescriptor().toDottedClassName()); } } else { if (DEBUG_QUERIES) { System.out.println(" Encountered unresolved class " + vertex.getClassDescriptor().toDottedClassName() + " in supertype query"); } supertypeSet.setEncounteredMissingClasses(true); } Iterator<InheritanceEdge> i = graph.outgoingEdgeIterator(vertex); while (i.hasNext()) { InheritanceEdge edge = i.next(); workList.addLast(edge.getTarget()); } } return supertypeSet; }
java
private SupertypeQueryResults computeSupertypes(ClassDescriptor classDescriptor) // throws // ClassNotFoundException { if (DEBUG_QUERIES) { System.out.println("Computing supertypes for " + classDescriptor.toDottedClassName()); } // Try to fully resolve the class and its superclasses/superinterfaces. ClassVertex typeVertex = optionallyResolveClassVertex(classDescriptor); // Create new empty SupertypeQueryResults. SupertypeQueryResults supertypeSet = new SupertypeQueryResults(); // Add all known superclasses/superinterfaces. // The ClassVertexes for all of them should be in the // InheritanceGraph by now. LinkedList<ClassVertex> workList = new LinkedList<>(); workList.addLast(typeVertex); while (!workList.isEmpty()) { ClassVertex vertex = workList.removeFirst(); supertypeSet.addSupertype(vertex.getClassDescriptor()); if (vertex.isResolved()) { if (DEBUG_QUERIES) { System.out.println(" Adding supertype " + vertex.getClassDescriptor().toDottedClassName()); } } else { if (DEBUG_QUERIES) { System.out.println(" Encountered unresolved class " + vertex.getClassDescriptor().toDottedClassName() + " in supertype query"); } supertypeSet.setEncounteredMissingClasses(true); } Iterator<InheritanceEdge> i = graph.outgoingEdgeIterator(vertex); while (i.hasNext()) { InheritanceEdge edge = i.next(); workList.addLast(edge.getTarget()); } } return supertypeSet; }
[ "private", "SupertypeQueryResults", "computeSupertypes", "(", "ClassDescriptor", "classDescriptor", ")", "// throws", "// ClassNotFoundException", "{", "if", "(", "DEBUG_QUERIES", ")", "{", "System", ".", "out", ".", "println", "(", "\"Computing supertypes for \"", "+", ...
Compute supertypes for class named by given ClassDescriptor. @param classDescriptor a ClassDescriptor @return SupertypeQueryResults containing known supertypes of the class
[ "Compute", "supertypes", "for", "class", "named", "by", "given", "ClassDescriptor", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/ch/Subtypes2.java#L1211-L1252
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/ba/ch/Subtypes2.java
Subtypes2.resolveClassVertex
private ClassVertex resolveClassVertex(ClassDescriptor classDescriptor) throws ClassNotFoundException { ClassVertex typeVertex = optionallyResolveClassVertex(classDescriptor); if (!typeVertex.isResolved()) { ClassDescriptor.throwClassNotFoundException(classDescriptor); } assert typeVertex.isResolved(); return typeVertex; }
java
private ClassVertex resolveClassVertex(ClassDescriptor classDescriptor) throws ClassNotFoundException { ClassVertex typeVertex = optionallyResolveClassVertex(classDescriptor); if (!typeVertex.isResolved()) { ClassDescriptor.throwClassNotFoundException(classDescriptor); } assert typeVertex.isResolved(); return typeVertex; }
[ "private", "ClassVertex", "resolveClassVertex", "(", "ClassDescriptor", "classDescriptor", ")", "throws", "ClassNotFoundException", "{", "ClassVertex", "typeVertex", "=", "optionallyResolveClassVertex", "(", "classDescriptor", ")", ";", "if", "(", "!", "typeVertex", ".", ...
Resolve a class named by given ClassDescriptor and return its resolved ClassVertex. @param classDescriptor a ClassDescriptor @return resolved ClassVertex representing the class in the InheritanceGraph @throws ClassNotFoundException if the class named by the ClassDescriptor does not exist
[ "Resolve", "a", "class", "named", "by", "given", "ClassDescriptor", "and", "return", "its", "resolved", "ClassVertex", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/ch/Subtypes2.java#L1265-L1274
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/ba/ch/Subtypes2.java
Subtypes2.addSupertypeEdges
private void addSupertypeEdges(ClassVertex vertex, LinkedList<XClass> workList) { XClass xclass = vertex.getXClass(); // Direct superclass ClassDescriptor superclassDescriptor = xclass.getSuperclassDescriptor(); if (superclassDescriptor != null) { addInheritanceEdge(vertex, superclassDescriptor, false, workList); } // Directly implemented interfaces for (ClassDescriptor ifaceDesc : xclass.getInterfaceDescriptorList()) { addInheritanceEdge(vertex, ifaceDesc, true, workList); } }
java
private void addSupertypeEdges(ClassVertex vertex, LinkedList<XClass> workList) { XClass xclass = vertex.getXClass(); // Direct superclass ClassDescriptor superclassDescriptor = xclass.getSuperclassDescriptor(); if (superclassDescriptor != null) { addInheritanceEdge(vertex, superclassDescriptor, false, workList); } // Directly implemented interfaces for (ClassDescriptor ifaceDesc : xclass.getInterfaceDescriptorList()) { addInheritanceEdge(vertex, ifaceDesc, true, workList); } }
[ "private", "void", "addSupertypeEdges", "(", "ClassVertex", "vertex", ",", "LinkedList", "<", "XClass", ">", "workList", ")", "{", "XClass", "xclass", "=", "vertex", ".", "getXClass", "(", ")", ";", "// Direct superclass", "ClassDescriptor", "superclassDescriptor", ...
Add supertype edges to the InheritanceGraph for given ClassVertex. If any direct supertypes have not been processed, add them to the worklist. @param vertex a ClassVertex whose supertype edges need to be added @param workList work list of ClassVertexes that need to have their supertype edges added
[ "Add", "supertype", "edges", "to", "the", "InheritanceGraph", "for", "given", "ClassVertex", ".", "If", "any", "direct", "supertypes", "have", "not", "been", "processed", "add", "them", "to", "the", "worklist", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/ch/Subtypes2.java#L1307-L1320
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/ba/ch/Subtypes2.java
Subtypes2.addClassVertexForMissingClass
private ClassVertex addClassVertexForMissingClass(ClassDescriptor missingClassDescriptor, boolean isInterfaceEdge) { ClassVertex missingClassVertex = ClassVertex.createMissingClassVertex(missingClassDescriptor, isInterfaceEdge); missingClassVertex.setFinished(true); addVertexToGraph(missingClassDescriptor, missingClassVertex); AnalysisContext.currentAnalysisContext(); AnalysisContext.reportMissingClass(missingClassDescriptor); return missingClassVertex; }
java
private ClassVertex addClassVertexForMissingClass(ClassDescriptor missingClassDescriptor, boolean isInterfaceEdge) { ClassVertex missingClassVertex = ClassVertex.createMissingClassVertex(missingClassDescriptor, isInterfaceEdge); missingClassVertex.setFinished(true); addVertexToGraph(missingClassDescriptor, missingClassVertex); AnalysisContext.currentAnalysisContext(); AnalysisContext.reportMissingClass(missingClassDescriptor); return missingClassVertex; }
[ "private", "ClassVertex", "addClassVertexForMissingClass", "(", "ClassDescriptor", "missingClassDescriptor", ",", "boolean", "isInterfaceEdge", ")", "{", "ClassVertex", "missingClassVertex", "=", "ClassVertex", ".", "createMissingClassVertex", "(", "missingClassDescriptor", ","...
Add a ClassVertex representing a missing class. @param missingClassDescriptor ClassDescriptor naming a missing class @param isInterfaceEdge @return the ClassVertex representing the missing class
[ "Add", "a", "ClassVertex", "representing", "a", "missing", "class", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/ch/Subtypes2.java#L1381-L1390
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindUnrelatedTypesInGenericContainer.java
FindUnrelatedTypesInGenericContainer.prescreen
public boolean prescreen(ClassContext classContext, Method method) { BitSet bytecodeSet = classContext.getBytecodeSet(method); return bytecodeSet != null && (bytecodeSet.get(Const.INVOKEINTERFACE) || bytecodeSet.get(Const.INVOKEVIRTUAL) || bytecodeSet.get(Const.INVOKESPECIAL) || bytecodeSet.get(Const.INVOKESTATIC) || bytecodeSet .get(Const.INVOKENONVIRTUAL)); }
java
public boolean prescreen(ClassContext classContext, Method method) { BitSet bytecodeSet = classContext.getBytecodeSet(method); return bytecodeSet != null && (bytecodeSet.get(Const.INVOKEINTERFACE) || bytecodeSet.get(Const.INVOKEVIRTUAL) || bytecodeSet.get(Const.INVOKESPECIAL) || bytecodeSet.get(Const.INVOKESTATIC) || bytecodeSet .get(Const.INVOKENONVIRTUAL)); }
[ "public", "boolean", "prescreen", "(", "ClassContext", "classContext", ",", "Method", "method", ")", "{", "BitSet", "bytecodeSet", "=", "classContext", ".", "getBytecodeSet", "(", "method", ")", ";", "return", "bytecodeSet", "!=", "null", "&&", "(", "bytecodeSet...
Use this to screen out methods that do not contain invocations.
[ "Use", "this", "to", "screen", "out", "methods", "that", "do", "not", "contain", "invocations", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindUnrelatedTypesInGenericContainer.java#L278-L284
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindUnrelatedTypesInGenericContainer.java
FindUnrelatedTypesInGenericContainer.isSynthetic
private boolean isSynthetic(Method m) { if ((m.getAccessFlags() & Const.ACC_SYNTHETIC) != 0) { return true; } Attribute[] attrs = m.getAttributes(); for (Attribute attr : attrs) { if (attr instanceof Synthetic) { return true; } } return false; }
java
private boolean isSynthetic(Method m) { if ((m.getAccessFlags() & Const.ACC_SYNTHETIC) != 0) { return true; } Attribute[] attrs = m.getAttributes(); for (Attribute attr : attrs) { if (attr instanceof Synthetic) { return true; } } return false; }
[ "private", "boolean", "isSynthetic", "(", "Method", "m", ")", "{", "if", "(", "(", "m", ".", "getAccessFlags", "(", ")", "&", "Const", ".", "ACC_SYNTHETIC", ")", "!=", "0", ")", "{", "return", "true", ";", "}", "Attribute", "[", "]", "attrs", "=", ...
Methods marked with the "Synthetic" attribute do not appear in the source code
[ "Methods", "marked", "with", "the", "Synthetic", "attribute", "do", "not", "appear", "in", "the", "source", "code" ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindUnrelatedTypesInGenericContainer.java#L290-L301
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindUnrelatedTypesInGenericContainer.java
FindUnrelatedTypesInGenericContainer.compareTypesOld
private boolean compareTypesOld(Type parmType, Type argType) { // XXX equality not implemented for GenericObjectType // if (parmType.equals(argType)) return true; // Compare type signatures instead if (GenericUtilities.getString(parmType).equals(GenericUtilities.getString(argType))) { return true; } if (parmType instanceof GenericObjectType) { GenericObjectType o = (GenericObjectType) parmType; if (o.getTypeCategory() == GenericUtilities.TypeCategory.WILDCARD_EXTENDS) { return compareTypesOld(o.getExtension(), argType); } } // ignore type variables for now if (parmType instanceof GenericObjectType && !((GenericObjectType) parmType).hasParameters()) { return true; } if (argType instanceof GenericObjectType && !((GenericObjectType) argType).hasParameters()) { return true; } // Case: Both are generic containers if (parmType instanceof GenericObjectType && argType instanceof GenericObjectType) { return true; } else { // Don't consider non reference types (should not be possible) if (!(parmType instanceof ReferenceType && argType instanceof ReferenceType)) { return true; } // Don't consider non object types (for now) if (!(parmType instanceof ObjectType && argType instanceof ObjectType)) { return true; } // Otherwise, compare base types ignoring generic information try { return Repository.instanceOf(((ObjectType) argType).getClassName(), ((ObjectType) parmType).getClassName()); } catch (ClassNotFoundException e) { } } return true; }
java
private boolean compareTypesOld(Type parmType, Type argType) { // XXX equality not implemented for GenericObjectType // if (parmType.equals(argType)) return true; // Compare type signatures instead if (GenericUtilities.getString(parmType).equals(GenericUtilities.getString(argType))) { return true; } if (parmType instanceof GenericObjectType) { GenericObjectType o = (GenericObjectType) parmType; if (o.getTypeCategory() == GenericUtilities.TypeCategory.WILDCARD_EXTENDS) { return compareTypesOld(o.getExtension(), argType); } } // ignore type variables for now if (parmType instanceof GenericObjectType && !((GenericObjectType) parmType).hasParameters()) { return true; } if (argType instanceof GenericObjectType && !((GenericObjectType) argType).hasParameters()) { return true; } // Case: Both are generic containers if (parmType instanceof GenericObjectType && argType instanceof GenericObjectType) { return true; } else { // Don't consider non reference types (should not be possible) if (!(parmType instanceof ReferenceType && argType instanceof ReferenceType)) { return true; } // Don't consider non object types (for now) if (!(parmType instanceof ObjectType && argType instanceof ObjectType)) { return true; } // Otherwise, compare base types ignoring generic information try { return Repository.instanceOf(((ObjectType) argType).getClassName(), ((ObjectType) parmType).getClassName()); } catch (ClassNotFoundException e) { } } return true; }
[ "private", "boolean", "compareTypesOld", "(", "Type", "parmType", ",", "Type", "argType", ")", "{", "// XXX equality not implemented for GenericObjectType", "// if (parmType.equals(argType)) return true;", "// Compare type signatures instead", "if", "(", "GenericUtilities", ".", ...
old version of compare types
[ "old", "version", "of", "compare", "types" ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindUnrelatedTypesInGenericContainer.java#L857-L901
train
spotbugs/spotbugs
spotbugs/src/tools/edu/umd/cs/findbugs/tools/xml/CheckMessages.java
CheckMessages.checkMessages
public void checkMessages(XMLFile messagesDoc) throws DocumentException { // Detector elements must all have a class attribute // and details child element. for (Iterator<Node> i = messagesDoc.xpathIterator("/MessageCollection/Detector"); i.hasNext();) { Node node = i.next(); messagesDoc.checkAttribute(node, "class"); messagesDoc.checkElement(node, "Details"); } // BugPattern elements must all have type attribute // and ShortDescription, LongDescription, and Details // child elements. for (Iterator<Node> i = messagesDoc.xpathIterator("/MessageCollection/BugPattern"); i.hasNext();) { Node node = i.next(); messagesDoc.checkAttribute(node, "type"); messagesDoc.checkElement(node, "ShortDescription"); messagesDoc.checkElement(node, "LongDescription"); messagesDoc.checkElement(node, "Details"); } // BugCode elements must contain abbrev attribute // and have non-empty text for (Iterator<Node> i = messagesDoc.xpathIterator("/MessageCollection/BugCode"); i.hasNext();) { Node node = i.next(); messagesDoc.checkAttribute(node, "abbrev"); messagesDoc.checkNonEmptyText(node); } // Check that all Detectors are described Set<String> describedDetectorsSet = messagesDoc.collectAttributes("/MessageCollection/Detector", "class"); checkDescribed("Bug detectors not described by Detector elements", messagesDoc, declaredDetectorsSet, describedDetectorsSet); // Check that all BugCodes are described Set<String> describedAbbrevsSet = messagesDoc.collectAttributes("/MessageCollection/BugCode", "abbrev"); checkDescribed("Abbreviations not described by BugCode elements", messagesDoc, declaredAbbrevsSet, describedAbbrevsSet); }
java
public void checkMessages(XMLFile messagesDoc) throws DocumentException { // Detector elements must all have a class attribute // and details child element. for (Iterator<Node> i = messagesDoc.xpathIterator("/MessageCollection/Detector"); i.hasNext();) { Node node = i.next(); messagesDoc.checkAttribute(node, "class"); messagesDoc.checkElement(node, "Details"); } // BugPattern elements must all have type attribute // and ShortDescription, LongDescription, and Details // child elements. for (Iterator<Node> i = messagesDoc.xpathIterator("/MessageCollection/BugPattern"); i.hasNext();) { Node node = i.next(); messagesDoc.checkAttribute(node, "type"); messagesDoc.checkElement(node, "ShortDescription"); messagesDoc.checkElement(node, "LongDescription"); messagesDoc.checkElement(node, "Details"); } // BugCode elements must contain abbrev attribute // and have non-empty text for (Iterator<Node> i = messagesDoc.xpathIterator("/MessageCollection/BugCode"); i.hasNext();) { Node node = i.next(); messagesDoc.checkAttribute(node, "abbrev"); messagesDoc.checkNonEmptyText(node); } // Check that all Detectors are described Set<String> describedDetectorsSet = messagesDoc.collectAttributes("/MessageCollection/Detector", "class"); checkDescribed("Bug detectors not described by Detector elements", messagesDoc, declaredDetectorsSet, describedDetectorsSet); // Check that all BugCodes are described Set<String> describedAbbrevsSet = messagesDoc.collectAttributes("/MessageCollection/BugCode", "abbrev"); checkDescribed("Abbreviations not described by BugCode elements", messagesDoc, declaredAbbrevsSet, describedAbbrevsSet); }
[ "public", "void", "checkMessages", "(", "XMLFile", "messagesDoc", ")", "throws", "DocumentException", "{", "// Detector elements must all have a class attribute", "// and details child element.", "for", "(", "Iterator", "<", "Node", ">", "i", "=", "messagesDoc", ".", "xpa...
Check given messages file for validity. @throws DocumentException if the messages file is invalid
[ "Check", "given", "messages", "file", "for", "validity", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/tools/edu/umd/cs/findbugs/tools/xml/CheckMessages.java#L160-L196
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/CheckBcel.java
CheckBcel.check
public static boolean check() { Class<?> objectType; Class<?> type; Class<?> constants; Class<?> emptyVis; Class<?> repository; try { objectType = Class.forName(ORG_APACHE_BCEL_GENERIC_OBJECT_TYPE); type = Class.forName(ORG_APACHE_BCEL_GENERIC_TYPE); constants = Class.forName(ORG_APACHE_BCEL_CONSTANTS); emptyVis = Class.forName(ORG_APACHE_BCEL_CLASSFILE_EMPTY_VISITOR); repository = Class.forName(ORG_APACHE_BCEL_REPOSITORY); } catch (ClassNotFoundException e) { LOG.error("One or more required BCEL classes were missing." + " Ensure that bcel.jar is placed at the same directory with spotbugs.jar"); return false; } if (isFinal(objectType)) { error(ORG_APACHE_BCEL_GENERIC_OBJECT_TYPE); return false; } if (isFinal(type)) { error(ORG_APACHE_BCEL_GENERIC_TYPE); return false; } if (isFinal(constants)) { error(ORG_APACHE_BCEL_CONSTANTS); return false; } if (isFinal(emptyVis)) { error(ORG_APACHE_BCEL_CLASSFILE_EMPTY_VISITOR); return false; } if (isFinal(repository)) { error(ORG_APACHE_BCEL_REPOSITORY); return false; } return true; }
java
public static boolean check() { Class<?> objectType; Class<?> type; Class<?> constants; Class<?> emptyVis; Class<?> repository; try { objectType = Class.forName(ORG_APACHE_BCEL_GENERIC_OBJECT_TYPE); type = Class.forName(ORG_APACHE_BCEL_GENERIC_TYPE); constants = Class.forName(ORG_APACHE_BCEL_CONSTANTS); emptyVis = Class.forName(ORG_APACHE_BCEL_CLASSFILE_EMPTY_VISITOR); repository = Class.forName(ORG_APACHE_BCEL_REPOSITORY); } catch (ClassNotFoundException e) { LOG.error("One or more required BCEL classes were missing." + " Ensure that bcel.jar is placed at the same directory with spotbugs.jar"); return false; } if (isFinal(objectType)) { error(ORG_APACHE_BCEL_GENERIC_OBJECT_TYPE); return false; } if (isFinal(type)) { error(ORG_APACHE_BCEL_GENERIC_TYPE); return false; } if (isFinal(constants)) { error(ORG_APACHE_BCEL_CONSTANTS); return false; } if (isFinal(emptyVis)) { error(ORG_APACHE_BCEL_CLASSFILE_EMPTY_VISITOR); return false; } if (isFinal(repository)) { error(ORG_APACHE_BCEL_REPOSITORY); return false; } return true; }
[ "public", "static", "boolean", "check", "(", ")", "{", "Class", "<", "?", ">", "objectType", ";", "Class", "<", "?", ">", "type", ";", "Class", "<", "?", ">", "constants", ";", "Class", "<", "?", ">", "emptyVis", ";", "Class", "<", "?", ">", "rep...
Check that the BCEL classes present seem to be the right ones. Specifically, we check whether the ones extended in FindBugs code are non-final. @return true iff all checks passed
[ "Check", "that", "the", "BCEL", "classes", "present", "seem", "to", "be", "the", "right", "ones", ".", "Specifically", "we", "check", "whether", "the", "ones", "extended", "in", "FindBugs", "code", "are", "non", "-", "final", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/CheckBcel.java#L99-L138
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/ba/vna/ValueNumberFactory.java
ValueNumberFactory.forNumber
public ValueNumber forNumber(int number) { if (number >= getNumValuesAllocated()) { throw new IllegalArgumentException("Value " + number + " has not been allocated"); } return allocatedValueList.get(number); }
java
public ValueNumber forNumber(int number) { if (number >= getNumValuesAllocated()) { throw new IllegalArgumentException("Value " + number + " has not been allocated"); } return allocatedValueList.get(number); }
[ "public", "ValueNumber", "forNumber", "(", "int", "number", ")", "{", "if", "(", "number", ">=", "getNumValuesAllocated", "(", ")", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Value \"", "+", "number", "+", "\" has not been allocated\"", ")", "...
Return a previously allocated value.
[ "Return", "a", "previously", "allocated", "value", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/vna/ValueNumberFactory.java#L63-L68
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/FindBugsMessageFormat.java
FindBugsMessageFormat.format
public String format(BugAnnotation[] args, ClassAnnotation primaryClass, boolean abridgedMessages) { String pat = pattern; StringBuilder result = new StringBuilder(); while (pat.length() > 0) { int subst = pat.indexOf('{'); if (subst < 0) { result.append(pat); break; } result.append(pat.substring(0, subst)); pat = pat.substring(subst + 1); int end = pat.indexOf('}'); if (end < 0) { throw new IllegalStateException("unmatched { in " + pat); } String substPat = pat.substring(0, end); int dot = substPat.indexOf('.'); String key = ""; if (dot >= 0) { key = substPat.substring(dot + 1); substPat = substPat.substring(0, dot); } else if (abridgedMessages && primaryClass != null) { key = "givenClass"; } int fieldNum; try { fieldNum = Integer.parseInt(substPat); } catch (NumberFormatException e) { throw new IllegalArgumentException("Bad integer value " + substPat + " in " + pattern); } // System.out.println("fn: " + fieldNum); if (fieldNum < 0) { result.append("?<?" + fieldNum + "/" + args.length + "???"); } else if (fieldNum >= args.length) { result.append("?>?" + fieldNum + "/" + args.length + "???"); } else { BugAnnotation field = args[fieldNum]; String formatted = ""; try { formatted = field.format(key, primaryClass); } catch (IllegalArgumentException iae) { if (SystemProperties.ASSERTIONS_ENABLED) { throw new IllegalArgumentException("Problem processing " + pattern + " format " + substPat + " for " + field.getClass().getSimpleName(), iae); } // unknown key -- not unprecedented when reading xml // generated by older versions of findbugs formatted = "\u00BF" + fieldNum + ".(key=" + key + ")?"; // "\u00BF" // is // inverted // question // mark // System.err.println(iae.getMessage()+" in FindBugsMessageFormat"); // // FIXME: log this error better } result.append(formatted); } pat = pat.substring(end + 1); } return result.toString(); }
java
public String format(BugAnnotation[] args, ClassAnnotation primaryClass, boolean abridgedMessages) { String pat = pattern; StringBuilder result = new StringBuilder(); while (pat.length() > 0) { int subst = pat.indexOf('{'); if (subst < 0) { result.append(pat); break; } result.append(pat.substring(0, subst)); pat = pat.substring(subst + 1); int end = pat.indexOf('}'); if (end < 0) { throw new IllegalStateException("unmatched { in " + pat); } String substPat = pat.substring(0, end); int dot = substPat.indexOf('.'); String key = ""; if (dot >= 0) { key = substPat.substring(dot + 1); substPat = substPat.substring(0, dot); } else if (abridgedMessages && primaryClass != null) { key = "givenClass"; } int fieldNum; try { fieldNum = Integer.parseInt(substPat); } catch (NumberFormatException e) { throw new IllegalArgumentException("Bad integer value " + substPat + " in " + pattern); } // System.out.println("fn: " + fieldNum); if (fieldNum < 0) { result.append("?<?" + fieldNum + "/" + args.length + "???"); } else if (fieldNum >= args.length) { result.append("?>?" + fieldNum + "/" + args.length + "???"); } else { BugAnnotation field = args[fieldNum]; String formatted = ""; try { formatted = field.format(key, primaryClass); } catch (IllegalArgumentException iae) { if (SystemProperties.ASSERTIONS_ENABLED) { throw new IllegalArgumentException("Problem processing " + pattern + " format " + substPat + " for " + field.getClass().getSimpleName(), iae); } // unknown key -- not unprecedented when reading xml // generated by older versions of findbugs formatted = "\u00BF" + fieldNum + ".(key=" + key + ")?"; // "\u00BF" // is // inverted // question // mark // System.err.println(iae.getMessage()+" in FindBugsMessageFormat"); // // FIXME: log this error better } result.append(formatted); } pat = pat.substring(end + 1); } return result.toString(); }
[ "public", "String", "format", "(", "BugAnnotation", "[", "]", "args", ",", "ClassAnnotation", "primaryClass", ",", "boolean", "abridgedMessages", ")", "{", "String", "pat", "=", "pattern", ";", "StringBuilder", "result", "=", "new", "StringBuilder", "(", ")", ...
Format the message using the given array of BugAnnotations as arguments to bind to the placeholders in the pattern string. @param args the BugAnnotations used as arguments @param primaryClass TODO @return the formatted message
[ "Format", "the", "message", "using", "the", "given", "array", "of", "BugAnnotations", "as", "arguments", "to", "bind", "to", "the", "placeholders", "in", "the", "pattern", "string", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/FindBugsMessageFormat.java#L70-L140
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/FieldAnnotation.java
FieldAnnotation.fromVisitedField
public static FieldAnnotation fromVisitedField(PreorderVisitor visitor) { return new FieldAnnotation(visitor.getDottedClassName(), visitor.getFieldName(), visitor.getFieldSig(), visitor.getFieldIsStatic()); }
java
public static FieldAnnotation fromVisitedField(PreorderVisitor visitor) { return new FieldAnnotation(visitor.getDottedClassName(), visitor.getFieldName(), visitor.getFieldSig(), visitor.getFieldIsStatic()); }
[ "public", "static", "FieldAnnotation", "fromVisitedField", "(", "PreorderVisitor", "visitor", ")", "{", "return", "new", "FieldAnnotation", "(", "visitor", ".", "getDottedClassName", "(", ")", ",", "visitor", ".", "getFieldName", "(", ")", ",", "visitor", ".", "...
Factory method. Class name, field name, and field signatures are taken from the given visitor, which is visiting the field. @param visitor the visitor which is visiting the field @return the FieldAnnotation object
[ "Factory", "method", ".", "Class", "name", "field", "name", "and", "field", "signatures", "are", "taken", "from", "the", "given", "visitor", "which", "is", "visiting", "the", "field", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/FieldAnnotation.java#L130-L133
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/FieldAnnotation.java
FieldAnnotation.fromFieldDescriptor
public static FieldAnnotation fromFieldDescriptor(FieldDescriptor fieldDescriptor) { return new FieldAnnotation(fieldDescriptor.getClassDescriptor().getDottedClassName(), fieldDescriptor.getName(), fieldDescriptor.getSignature(), fieldDescriptor.isStatic()); }
java
public static FieldAnnotation fromFieldDescriptor(FieldDescriptor fieldDescriptor) { return new FieldAnnotation(fieldDescriptor.getClassDescriptor().getDottedClassName(), fieldDescriptor.getName(), fieldDescriptor.getSignature(), fieldDescriptor.isStatic()); }
[ "public", "static", "FieldAnnotation", "fromFieldDescriptor", "(", "FieldDescriptor", "fieldDescriptor", ")", "{", "return", "new", "FieldAnnotation", "(", "fieldDescriptor", ".", "getClassDescriptor", "(", ")", ".", "getDottedClassName", "(", ")", ",", "fieldDescriptor...
Factory method. Construct from a FieldDescriptor. @param fieldDescriptor the FieldDescriptor @return the FieldAnnotation
[ "Factory", "method", ".", "Construct", "from", "a", "FieldDescriptor", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/FieldAnnotation.java#L183-L186
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/FieldAnnotation.java
FieldAnnotation.isRead
public static FieldAnnotation isRead(Instruction ins, ConstantPoolGen cpg) { if (ins instanceof GETFIELD || ins instanceof GETSTATIC) { FieldInstruction fins = (FieldInstruction) ins; String className = fins.getClassName(cpg); return new FieldAnnotation(className, fins.getName(cpg), fins.getSignature(cpg), fins instanceof GETSTATIC); } else { return null; } }
java
public static FieldAnnotation isRead(Instruction ins, ConstantPoolGen cpg) { if (ins instanceof GETFIELD || ins instanceof GETSTATIC) { FieldInstruction fins = (FieldInstruction) ins; String className = fins.getClassName(cpg); return new FieldAnnotation(className, fins.getName(cpg), fins.getSignature(cpg), fins instanceof GETSTATIC); } else { return null; } }
[ "public", "static", "FieldAnnotation", "isRead", "(", "Instruction", "ins", ",", "ConstantPoolGen", "cpg", ")", "{", "if", "(", "ins", "instanceof", "GETFIELD", "||", "ins", "instanceof", "GETSTATIC", ")", "{", "FieldInstruction", "fins", "=", "(", "FieldInstruc...
Is the given instruction a read of a field? @param ins the Instruction to check @param cpg ConstantPoolGen of the method containing the instruction @return the Field if the instruction is a read of a field, null otherwise
[ "Is", "the", "given", "instruction", "a", "read", "of", "a", "field?" ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/FieldAnnotation.java#L231-L239
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/FieldAnnotation.java
FieldAnnotation.isWrite
public static FieldAnnotation isWrite(Instruction ins, ConstantPoolGen cpg) { if (ins instanceof PUTFIELD || ins instanceof PUTSTATIC) { FieldInstruction fins = (FieldInstruction) ins; String className = fins.getClassName(cpg); return new FieldAnnotation(className, fins.getName(cpg), fins.getSignature(cpg), fins instanceof PUTSTATIC); } else { return null; } }
java
public static FieldAnnotation isWrite(Instruction ins, ConstantPoolGen cpg) { if (ins instanceof PUTFIELD || ins instanceof PUTSTATIC) { FieldInstruction fins = (FieldInstruction) ins; String className = fins.getClassName(cpg); return new FieldAnnotation(className, fins.getName(cpg), fins.getSignature(cpg), fins instanceof PUTSTATIC); } else { return null; } }
[ "public", "static", "FieldAnnotation", "isWrite", "(", "Instruction", "ins", ",", "ConstantPoolGen", "cpg", ")", "{", "if", "(", "ins", "instanceof", "PUTFIELD", "||", "ins", "instanceof", "PUTSTATIC", ")", "{", "FieldInstruction", "fins", "=", "(", "FieldInstru...
Is the instruction a write of a field? @param ins the Instruction to check @param cpg ConstantPoolGen of the method containing the instruction @return the Field if instruction is a write of a field, null otherwise
[ "Is", "the", "instruction", "a", "write", "of", "a", "field?" ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/FieldAnnotation.java#L250-L258
train
spotbugs/spotbugs
eclipsePlugin/src/de/tobject/findbugs/util/Util.java
Util.isClassFile
public static boolean isClassFile(IJavaElement elt) { if (elt == null) { return false; } return elt instanceof IClassFile || elt instanceof ICompilationUnit; }
java
public static boolean isClassFile(IJavaElement elt) { if (elt == null) { return false; } return elt instanceof IClassFile || elt instanceof ICompilationUnit; }
[ "public", "static", "boolean", "isClassFile", "(", "IJavaElement", "elt", ")", "{", "if", "(", "elt", "==", "null", ")", "{", "return", "false", ";", "}", "return", "elt", "instanceof", "IClassFile", "||", "elt", "instanceof", "ICompilationUnit", ";", "}" ]
Checks whether the given java element is a Java class file. @param elt The resource to check. @return <code>true</code> if the given resource is a class file, <code>false</code> otherwise.
[ "Checks", "whether", "the", "given", "java", "element", "is", "a", "Java", "class", "file", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/eclipsePlugin/src/de/tobject/findbugs/util/Util.java#L108-L114
train
spotbugs/spotbugs
eclipsePlugin/src/de/tobject/findbugs/util/Util.java
Util.copyToClipboard
public static void copyToClipboard(String content) { if (content == null) { return; } Clipboard cb = null; try { cb = new Clipboard(Display.getDefault()); cb.setContents(new String[] { content }, new TextTransfer[] { TextTransfer.getInstance() }); } finally { if (cb != null) { cb.dispose(); } } }
java
public static void copyToClipboard(String content) { if (content == null) { return; } Clipboard cb = null; try { cb = new Clipboard(Display.getDefault()); cb.setContents(new String[] { content }, new TextTransfer[] { TextTransfer.getInstance() }); } finally { if (cb != null) { cb.dispose(); } } }
[ "public", "static", "void", "copyToClipboard", "(", "String", "content", ")", "{", "if", "(", "content", "==", "null", ")", "{", "return", ";", "}", "Clipboard", "cb", "=", "null", ";", "try", "{", "cb", "=", "new", "Clipboard", "(", "Display", ".", ...
Copies given string to the system clipboard @param content non null String
[ "Copies", "given", "string", "to", "the", "system", "clipboard" ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/eclipsePlugin/src/de/tobject/findbugs/util/Util.java#L180-L193
train
spotbugs/spotbugs
eclipsePlugin/src/de/tobject/findbugs/util/Util.java
Util.sortIMarkers
public static void sortIMarkers(IMarker[] markers) { Arrays.sort(markers, new Comparator<IMarker>() { @Override public int compare(IMarker arg0, IMarker arg1) { IResource resource0 = arg0.getResource(); IResource resource1 = arg1.getResource(); if (resource0 != null && resource1 != null) { return resource0.getName().compareTo(resource1.getName()); } if (resource0 != null && resource1 == null) { return 1; } if (resource0 == null && resource1 != null) { return -1; } return 0; } }); }
java
public static void sortIMarkers(IMarker[] markers) { Arrays.sort(markers, new Comparator<IMarker>() { @Override public int compare(IMarker arg0, IMarker arg1) { IResource resource0 = arg0.getResource(); IResource resource1 = arg1.getResource(); if (resource0 != null && resource1 != null) { return resource0.getName().compareTo(resource1.getName()); } if (resource0 != null && resource1 == null) { return 1; } if (resource0 == null && resource1 != null) { return -1; } return 0; } }); }
[ "public", "static", "void", "sortIMarkers", "(", "IMarker", "[", "]", "markers", ")", "{", "Arrays", ".", "sort", "(", "markers", ",", "new", "Comparator", "<", "IMarker", ">", "(", ")", "{", "@", "Override", "public", "int", "compare", "(", "IMarker", ...
Sorts an array of IMarkers based on their underlying resource name @param markers
[ "Sorts", "an", "array", "of", "IMarkers", "based", "on", "their", "underlying", "resource", "name" ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/eclipsePlugin/src/de/tobject/findbugs/util/Util.java#L215-L233
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/ba/npe/IsNullConditionDecision.java
IsNullConditionDecision.getDecision
public @CheckForNull IsNullValue getDecision(int edgeType) { switch (edgeType) { case EdgeTypes.IFCMP_EDGE: return ifcmpDecision; case EdgeTypes.FALL_THROUGH_EDGE: return fallThroughDecision; default: throw new IllegalArgumentException("Bad edge type: " + edgeType); } }
java
public @CheckForNull IsNullValue getDecision(int edgeType) { switch (edgeType) { case EdgeTypes.IFCMP_EDGE: return ifcmpDecision; case EdgeTypes.FALL_THROUGH_EDGE: return fallThroughDecision; default: throw new IllegalArgumentException("Bad edge type: " + edgeType); } }
[ "public", "@", "CheckForNull", "IsNullValue", "getDecision", "(", "int", "edgeType", ")", "{", "switch", "(", "edgeType", ")", "{", "case", "EdgeTypes", ".", "IFCMP_EDGE", ":", "return", "ifcmpDecision", ";", "case", "EdgeTypes", ".", "FALL_THROUGH_EDGE", ":", ...
Get the decision reached about the value on outgoing edge of given type. @param edgeType the type of edge; must be IFCMP_EDGE or FALL_THROUGH_EDGE @return the IsNullValue representing the decision, or null if the edge is infeasible
[ "Get", "the", "decision", "reached", "about", "the", "value", "on", "outgoing", "edge", "of", "given", "type", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/npe/IsNullConditionDecision.java#L124-L134
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/detect/NoiseNullDeref.java
NoiseNullDeref.findPreviouslyDeadBlocks
private BitSet findPreviouslyDeadBlocks() throws DataflowAnalysisException, CFGBuilderException { BitSet deadBlocks = new BitSet(); ValueNumberDataflow vnaDataflow = classContext.getValueNumberDataflow(method); for (Iterator<BasicBlock> i = vnaDataflow.getCFG().blockIterator(); i.hasNext();) { BasicBlock block = i.next(); ValueNumberFrame vnaFrame = vnaDataflow.getStartFact(block); if (vnaFrame.isTop()) { deadBlocks.set(block.getLabel()); } } return deadBlocks; }
java
private BitSet findPreviouslyDeadBlocks() throws DataflowAnalysisException, CFGBuilderException { BitSet deadBlocks = new BitSet(); ValueNumberDataflow vnaDataflow = classContext.getValueNumberDataflow(method); for (Iterator<BasicBlock> i = vnaDataflow.getCFG().blockIterator(); i.hasNext();) { BasicBlock block = i.next(); ValueNumberFrame vnaFrame = vnaDataflow.getStartFact(block); if (vnaFrame.isTop()) { deadBlocks.set(block.getLabel()); } } return deadBlocks; }
[ "private", "BitSet", "findPreviouslyDeadBlocks", "(", ")", "throws", "DataflowAnalysisException", ",", "CFGBuilderException", "{", "BitSet", "deadBlocks", "=", "new", "BitSet", "(", ")", ";", "ValueNumberDataflow", "vnaDataflow", "=", "classContext", ".", "getValueNumbe...
Find set of blocks which were known to be dead before doing the null pointer analysis. @return set of previously dead blocks, indexed by block id @throws CFGBuilderException @throws DataflowAnalysisException
[ "Find", "set", "of", "blocks", "which", "were", "known", "to", "be", "dead", "before", "doing", "the", "null", "pointer", "analysis", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/NoiseNullDeref.java#L213-L225
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/detect/StreamResourceTracker.java
StreamResourceTracker.addStreamEscape
public void addStreamEscape(Stream source, Location target) { StreamEscape streamEscape = new StreamEscape(source, target); streamEscapeSet.add(streamEscape); if (FindOpenStream.DEBUG) { System.out.println("Adding potential stream escape " + streamEscape); } }
java
public void addStreamEscape(Stream source, Location target) { StreamEscape streamEscape = new StreamEscape(source, target); streamEscapeSet.add(streamEscape); if (FindOpenStream.DEBUG) { System.out.println("Adding potential stream escape " + streamEscape); } }
[ "public", "void", "addStreamEscape", "(", "Stream", "source", ",", "Location", "target", ")", "{", "StreamEscape", "streamEscape", "=", "new", "StreamEscape", "(", "source", ",", "target", ")", ";", "streamEscapeSet", ".", "add", "(", "streamEscape", ")", ";",...
Indicate that a stream escapes at the given target Location. @param source the Stream that is escaping @param target the target Location (where the stream escapes)
[ "Indicate", "that", "a", "stream", "escapes", "at", "the", "given", "target", "Location", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/StreamResourceTracker.java#L118-L124
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/detect/StreamResourceTracker.java
StreamResourceTracker.addStreamOpenLocation
public void addStreamOpenLocation(Location streamOpenLocation, Stream stream) { if (FindOpenStream.DEBUG) { System.out.println("Stream open location at " + streamOpenLocation); } streamOpenLocationMap.put(streamOpenLocation, stream); if (stream.isUninteresting()) { uninterestingStreamEscapeSet.add(stream); } }
java
public void addStreamOpenLocation(Location streamOpenLocation, Stream stream) { if (FindOpenStream.DEBUG) { System.out.println("Stream open location at " + streamOpenLocation); } streamOpenLocationMap.put(streamOpenLocation, stream); if (stream.isUninteresting()) { uninterestingStreamEscapeSet.add(stream); } }
[ "public", "void", "addStreamOpenLocation", "(", "Location", "streamOpenLocation", ",", "Stream", "stream", ")", "{", "if", "(", "FindOpenStream", ".", "DEBUG", ")", "{", "System", ".", "out", ".", "println", "(", "\"Stream open location at \"", "+", "streamOpenLoc...
Indicate that a stream is constructed at this Location. @param streamOpenLocation the Location @param stream the Stream opened at this Location
[ "Indicate", "that", "a", "stream", "is", "constructed", "at", "this", "Location", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/StreamResourceTracker.java#L208-L216
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindNullDeref.java
FindNullDeref.getMethodNullnessAnnotation
private NullnessAnnotation getMethodNullnessAnnotation() { if (method.getSignature().indexOf(")L") >= 0 || method.getSignature().indexOf(")[") >= 0) { if (DEBUG_NULLRETURN) { System.out.println("Checking return annotation for " + SignatureConverter.convertMethodSignature(classContext.getJavaClass(), method)); } XMethod m = XFactory.createXMethod(classContext.getJavaClass(), method); return AnalysisContext.currentAnalysisContext().getNullnessAnnotationDatabase().getResolvedAnnotation(m, false); } return NullnessAnnotation.UNKNOWN_NULLNESS; }
java
private NullnessAnnotation getMethodNullnessAnnotation() { if (method.getSignature().indexOf(")L") >= 0 || method.getSignature().indexOf(")[") >= 0) { if (DEBUG_NULLRETURN) { System.out.println("Checking return annotation for " + SignatureConverter.convertMethodSignature(classContext.getJavaClass(), method)); } XMethod m = XFactory.createXMethod(classContext.getJavaClass(), method); return AnalysisContext.currentAnalysisContext().getNullnessAnnotationDatabase().getResolvedAnnotation(m, false); } return NullnessAnnotation.UNKNOWN_NULLNESS; }
[ "private", "NullnessAnnotation", "getMethodNullnessAnnotation", "(", ")", "{", "if", "(", "method", ".", "getSignature", "(", ")", ".", "indexOf", "(", "\")L\"", ")", ">=", "0", "||", "method", ".", "getSignature", "(", ")", ".", "indexOf", "(", "\")[\"", ...
See if the currently-visited method declares a @NonNull annotation, or overrides a method which declares a @NonNull annotation.
[ "See", "if", "the", "currently", "-", "visited", "method", "declares", "a" ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindNullDeref.java#L324-L336
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindNullDeref.java
FindNullDeref.checkNonNullParam
private void checkNonNullParam(Location location, ConstantPoolGen cpg, TypeDataflow typeDataflow, InvokeInstruction invokeInstruction, BitSet nullArgSet, BitSet definitelyNullArgSet) { if (inExplicitCatchNullBlock(location)) { return; } boolean caught = inIndirectCatchNullBlock(location); if (caught && skipIfInsideCatchNull()) { return; } if (invokeInstruction instanceof INVOKEDYNAMIC) { return; } XMethod m = XFactory.createXMethod(invokeInstruction, cpg); INullnessAnnotationDatabase db = AnalysisContext.currentAnalysisContext().getNullnessAnnotationDatabase(); SignatureParser sigParser = new SignatureParser(invokeInstruction.getSignature(cpg)); for (int i = nullArgSet.nextSetBit(0); i >= 0; i = nullArgSet.nextSetBit(i + 1)) { if (db.parameterMustBeNonNull(m, i)) { boolean definitelyNull = definitelyNullArgSet.get(i); if (DEBUG_NULLARG) { System.out.println("Checking " + m); System.out.println("QQQ2: " + i + " -- " + i + " is null"); System.out.println("QQQ nullArgSet: " + nullArgSet); System.out.println("QQQ dnullArgSet: " + definitelyNullArgSet); } BugAnnotation variableAnnotation = null; try { ValueNumberFrame vnaFrame = classContext.getValueNumberDataflow(method).getFactAtLocation(location); ValueNumber valueNumber = vnaFrame.getArgument(invokeInstruction, cpg, i, sigParser); variableAnnotation = ValueNumberSourceInfo.findAnnotationFromValueNumber(method, location, valueNumber, vnaFrame, "VALUE_OF"); } catch (DataflowAnalysisException e) { AnalysisContext.logError("error", e); } catch (CFGBuilderException e) { AnalysisContext.logError("error", e); } int priority = definitelyNull ? HIGH_PRIORITY : NORMAL_PRIORITY; if (caught) { priority++; } if (m.isPrivate() && priority == HIGH_PRIORITY) { priority = NORMAL_PRIORITY; } String description = definitelyNull ? "INT_NULL_ARG" : "INT_MAYBE_NULL_ARG"; WarningPropertySet<WarningProperty> propertySet = new WarningPropertySet<>(); Set<Location> derefLocationSet = Collections.singleton(location); addPropertiesForDereferenceLocations(propertySet, derefLocationSet, false); boolean duplicated = isDuplicated(propertySet, location.getHandle().getPosition(), false); if (duplicated) { return; } BugInstance warning = new BugInstance(this, "NP_NONNULL_PARAM_VIOLATION", priority) .addClassAndMethod(classContext.getJavaClass(), method).addMethod(m) .describe(MethodAnnotation.METHOD_CALLED).addParameterAnnotation(i, description) .addOptionalAnnotation(variableAnnotation).addSourceLine(classContext, method, location); propertySet.decorateBugInstance(warning); bugReporter.reportBug(warning); } } }
java
private void checkNonNullParam(Location location, ConstantPoolGen cpg, TypeDataflow typeDataflow, InvokeInstruction invokeInstruction, BitSet nullArgSet, BitSet definitelyNullArgSet) { if (inExplicitCatchNullBlock(location)) { return; } boolean caught = inIndirectCatchNullBlock(location); if (caught && skipIfInsideCatchNull()) { return; } if (invokeInstruction instanceof INVOKEDYNAMIC) { return; } XMethod m = XFactory.createXMethod(invokeInstruction, cpg); INullnessAnnotationDatabase db = AnalysisContext.currentAnalysisContext().getNullnessAnnotationDatabase(); SignatureParser sigParser = new SignatureParser(invokeInstruction.getSignature(cpg)); for (int i = nullArgSet.nextSetBit(0); i >= 0; i = nullArgSet.nextSetBit(i + 1)) { if (db.parameterMustBeNonNull(m, i)) { boolean definitelyNull = definitelyNullArgSet.get(i); if (DEBUG_NULLARG) { System.out.println("Checking " + m); System.out.println("QQQ2: " + i + " -- " + i + " is null"); System.out.println("QQQ nullArgSet: " + nullArgSet); System.out.println("QQQ dnullArgSet: " + definitelyNullArgSet); } BugAnnotation variableAnnotation = null; try { ValueNumberFrame vnaFrame = classContext.getValueNumberDataflow(method).getFactAtLocation(location); ValueNumber valueNumber = vnaFrame.getArgument(invokeInstruction, cpg, i, sigParser); variableAnnotation = ValueNumberSourceInfo.findAnnotationFromValueNumber(method, location, valueNumber, vnaFrame, "VALUE_OF"); } catch (DataflowAnalysisException e) { AnalysisContext.logError("error", e); } catch (CFGBuilderException e) { AnalysisContext.logError("error", e); } int priority = definitelyNull ? HIGH_PRIORITY : NORMAL_PRIORITY; if (caught) { priority++; } if (m.isPrivate() && priority == HIGH_PRIORITY) { priority = NORMAL_PRIORITY; } String description = definitelyNull ? "INT_NULL_ARG" : "INT_MAYBE_NULL_ARG"; WarningPropertySet<WarningProperty> propertySet = new WarningPropertySet<>(); Set<Location> derefLocationSet = Collections.singleton(location); addPropertiesForDereferenceLocations(propertySet, derefLocationSet, false); boolean duplicated = isDuplicated(propertySet, location.getHandle().getPosition(), false); if (duplicated) { return; } BugInstance warning = new BugInstance(this, "NP_NONNULL_PARAM_VIOLATION", priority) .addClassAndMethod(classContext.getJavaClass(), method).addMethod(m) .describe(MethodAnnotation.METHOD_CALLED).addParameterAnnotation(i, description) .addOptionalAnnotation(variableAnnotation).addSourceLine(classContext, method, location); propertySet.decorateBugInstance(warning); bugReporter.reportBug(warning); } } }
[ "private", "void", "checkNonNullParam", "(", "Location", "location", ",", "ConstantPoolGen", "cpg", ",", "TypeDataflow", "typeDataflow", ",", "InvokeInstruction", "invokeInstruction", ",", "BitSet", "nullArgSet", ",", "BitSet", "definitelyNullArgSet", ")", "{", "if", ...
We have a method invocation in which a possibly or definitely null parameter is passed. Check it against the library of nonnull annotations. @param location @param cpg @param typeDataflow @param invokeInstruction @param nullArgSet @param definitelyNullArgSet
[ "We", "have", "a", "method", "invocation", "in", "which", "a", "possibly", "or", "definitely", "null", "parameter", "is", "passed", ".", "Check", "it", "against", "the", "library", "of", "nonnull", "annotations", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindNullDeref.java#L841-L909
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindNullDeref.java
FindNullDeref.isGoto
private boolean isGoto(Instruction instruction) { return instruction.getOpcode() == Const.GOTO || instruction.getOpcode() == Const.GOTO_W; }
java
private boolean isGoto(Instruction instruction) { return instruction.getOpcode() == Const.GOTO || instruction.getOpcode() == Const.GOTO_W; }
[ "private", "boolean", "isGoto", "(", "Instruction", "instruction", ")", "{", "return", "instruction", ".", "getOpcode", "(", ")", "==", "Const", ".", "GOTO", "||", "instruction", ".", "getOpcode", "(", ")", "==", "Const", ".", "GOTO_W", ";", "}" ]
Determine whether or not given instruction is a goto. @param instruction the instruction @return true if the instruction is a goto, false otherwise
[ "Determine", "whether", "or", "not", "given", "instruction", "is", "a", "goto", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindNullDeref.java#L1331-L1333
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/classfile/impl/AnalysisCache.java
AnalysisCache.dispose
public void dispose(){ classAnalysisMap.clear(); classAnalysisEngineMap.clear(); analysisLocals.clear(); databaseFactoryMap.clear(); databaseMap.clear(); methodAnalysisEngineMap.clear(); }
java
public void dispose(){ classAnalysisMap.clear(); classAnalysisEngineMap.clear(); analysisLocals.clear(); databaseFactoryMap.clear(); databaseMap.clear(); methodAnalysisEngineMap.clear(); }
[ "public", "void", "dispose", "(", ")", "{", "classAnalysisMap", ".", "clear", "(", ")", ";", "classAnalysisEngineMap", ".", "clear", "(", ")", ";", "analysisLocals", ".", "clear", "(", ")", ";", "databaseFactoryMap", ".", "clear", "(", ")", ";", "databaseM...
Cleans up all cached data
[ "Cleans", "up", "all", "cached", "data" ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/classfile/impl/AnalysisCache.java#L205-L212
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/classfile/impl/AnalysisCache.java
AnalysisCache.reuseClassAnalysis
public <E> void reuseClassAnalysis(Class<E> analysisClass, Map<ClassDescriptor, Object> map) { Map<ClassDescriptor, Object> myMap = classAnalysisMap.get(analysisClass); if (myMap != null) { myMap.putAll(map); } else { myMap = createMap(classAnalysisEngineMap, analysisClass); myMap.putAll(map); classAnalysisMap.put(analysisClass, myMap); } }
java
public <E> void reuseClassAnalysis(Class<E> analysisClass, Map<ClassDescriptor, Object> map) { Map<ClassDescriptor, Object> myMap = classAnalysisMap.get(analysisClass); if (myMap != null) { myMap.putAll(map); } else { myMap = createMap(classAnalysisEngineMap, analysisClass); myMap.putAll(map); classAnalysisMap.put(analysisClass, myMap); } }
[ "public", "<", "E", ">", "void", "reuseClassAnalysis", "(", "Class", "<", "E", ">", "analysisClass", ",", "Map", "<", "ClassDescriptor", ",", "Object", ">", "map", ")", "{", "Map", "<", "ClassDescriptor", ",", "Object", ">", "myMap", "=", "classAnalysisMap...
Adds the data for given analysis type from given map to the cache @param analysisClass non null analysis type @param map non null, pre-filled map with analysis data for given type
[ "Adds", "the", "data", "for", "given", "analysis", "type", "from", "given", "map", "to", "the", "cache" ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/classfile/impl/AnalysisCache.java#L227-L236
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/classfile/impl/AnalysisCache.java
AnalysisCache.analyzeMethod
@SuppressWarnings("unchecked") private <E> E analyzeMethod(ClassContext classContext, Class<E> analysisClass, MethodDescriptor methodDescriptor) throws CheckedAnalysisException { IMethodAnalysisEngine<E> engine = (IMethodAnalysisEngine<E>) methodAnalysisEngineMap.get(analysisClass); if (engine == null) { throw new IllegalArgumentException("No analysis engine registered to produce " + analysisClass.getName()); } Profiler profiler = getProfiler(); profiler.start(engine.getClass()); try { return engine.analyze(this, methodDescriptor); } finally { profiler.end(engine.getClass()); } }
java
@SuppressWarnings("unchecked") private <E> E analyzeMethod(ClassContext classContext, Class<E> analysisClass, MethodDescriptor methodDescriptor) throws CheckedAnalysisException { IMethodAnalysisEngine<E> engine = (IMethodAnalysisEngine<E>) methodAnalysisEngineMap.get(analysisClass); if (engine == null) { throw new IllegalArgumentException("No analysis engine registered to produce " + analysisClass.getName()); } Profiler profiler = getProfiler(); profiler.start(engine.getClass()); try { return engine.analyze(this, methodDescriptor); } finally { profiler.end(engine.getClass()); } }
[ "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "private", "<", "E", ">", "E", "analyzeMethod", "(", "ClassContext", "classContext", ",", "Class", "<", "E", ">", "analysisClass", ",", "MethodDescriptor", "methodDescriptor", ")", "throws", "CheckedAnalysisExcepti...
Analyze a method. @param classContext ClassContext storing method analysis objects for method's class @param analysisClass class the method analysis object should belong to @param methodDescriptor method descriptor identifying the method to analyze @return the computed analysis object for the method @throws CheckedAnalysisException
[ "Analyze", "a", "method", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/classfile/impl/AnalysisCache.java#L359-L373
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/classfile/impl/AnalysisCache.java
AnalysisCache.findOrCreateDescriptorMap
private static <DescriptorType> Map<DescriptorType, Object> findOrCreateDescriptorMap( final Map<Class<?>, Map<DescriptorType, Object>> analysisClassToDescriptorMapMap, final Map<Class<?>, ? extends IAnalysisEngine<DescriptorType, ?>> engineMap, final Class<?> analysisClass) { Map<DescriptorType, Object> descriptorMap = analysisClassToDescriptorMapMap.get(analysisClass); if (descriptorMap == null) { descriptorMap = createMap(engineMap, analysisClass); analysisClassToDescriptorMapMap.put(analysisClass, descriptorMap); } return descriptorMap; }
java
private static <DescriptorType> Map<DescriptorType, Object> findOrCreateDescriptorMap( final Map<Class<?>, Map<DescriptorType, Object>> analysisClassToDescriptorMapMap, final Map<Class<?>, ? extends IAnalysisEngine<DescriptorType, ?>> engineMap, final Class<?> analysisClass) { Map<DescriptorType, Object> descriptorMap = analysisClassToDescriptorMapMap.get(analysisClass); if (descriptorMap == null) { descriptorMap = createMap(engineMap, analysisClass); analysisClassToDescriptorMapMap.put(analysisClass, descriptorMap); } return descriptorMap; }
[ "private", "static", "<", "DescriptorType", ">", "Map", "<", "DescriptorType", ",", "Object", ">", "findOrCreateDescriptorMap", "(", "final", "Map", "<", "Class", "<", "?", ">", ",", "Map", "<", "DescriptorType", ",", "Object", ">", ">", "analysisClassToDescri...
Find or create a descriptor to analysis object map. @param <DescriptorType> type of descriptor used as the map's key type (ClassDescriptor or MethodDescriptor) @param analysisClassToDescriptorMapMap analysis class to descriptor map map @param engineMap analysis class to analysis engine map @param analysisClass the analysis map @return the descriptor to analysis object map
[ "Find", "or", "create", "a", "descriptor", "to", "analysis", "object", "map", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/classfile/impl/AnalysisCache.java#L416-L426
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/xml/Dom4JXMLOutput.java
Dom4JXMLOutput.writeElementList
public void writeElementList(String tagName, Collection<String> listValues) { for (String listValue : listValues) { openTag(tagName); writeText(listValue); closeTag(tagName); } }
java
public void writeElementList(String tagName, Collection<String> listValues) { for (String listValue : listValues) { openTag(tagName); writeText(listValue); closeTag(tagName); } }
[ "public", "void", "writeElementList", "(", "String", "tagName", ",", "Collection", "<", "String", ">", "listValues", ")", "{", "for", "(", "String", "listValue", ":", "listValues", ")", "{", "openTag", "(", "tagName", ")", ";", "writeText", "(", "listValue",...
Add a list of Strings to document as elements with given tag name to the tree. @param tagName the tag name @param listValues Collection of String values to add
[ "Add", "a", "list", "of", "Strings", "to", "document", "as", "elements", "with", "given", "tag", "name", "to", "the", "tree", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/xml/Dom4JXMLOutput.java#L131-L137
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/ba/obl/ObligationFactory.java
ObligationFactory.isObligationType
public boolean isObligationType(ClassDescriptor classDescriptor) { try { return getObligationByType(BCELUtil.getObjectTypeInstance(classDescriptor.toDottedClassName())) != null; } catch (ClassNotFoundException e) { Global.getAnalysisCache().getErrorLogger().reportMissingClass(e); return false; } }
java
public boolean isObligationType(ClassDescriptor classDescriptor) { try { return getObligationByType(BCELUtil.getObjectTypeInstance(classDescriptor.toDottedClassName())) != null; } catch (ClassNotFoundException e) { Global.getAnalysisCache().getErrorLogger().reportMissingClass(e); return false; } }
[ "public", "boolean", "isObligationType", "(", "ClassDescriptor", "classDescriptor", ")", "{", "try", "{", "return", "getObligationByType", "(", "BCELUtil", ".", "getObjectTypeInstance", "(", "classDescriptor", ".", "toDottedClassName", "(", ")", ")", ")", "!=", "nul...
Determine whether class named by given ClassDescriptor is an Obligation type. @param classDescriptor a class @return true if the class is an Obligation type, false otherwise
[ "Determine", "whether", "class", "named", "by", "given", "ClassDescriptor", "is", "an", "Obligation", "type", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/obl/ObligationFactory.java#L81-L88
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/ba/obl/ObligationFactory.java
ObligationFactory.getParameterObligationTypes
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; }
java
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; }
[ "public", "Obligation", "[", "]", "getParameterObligationTypes", "(", "XMethod", "xmethod", ")", "{", "Type", "[", "]", "paramTypes", "=", "Type", ".", "getArgumentTypes", "(", "xmethod", ".", "getSignature", "(", ")", ")", ";", "Obligation", "[", "]", "resu...
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
[ "Get", "array", "of", "Obligation", "types", "corresponding", "to", "the", "parameters", "of", "the", "given", "method", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/obl/ObligationFactory.java#L151-L165
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/ba/AbstractDataflowAnalysis.java
AbstractDataflowAnalysis.getFactAfterLocation
@Override public Fact getFactAfterLocation(Location location) throws DataflowAnalysisException { BasicBlock basicBlock = location.getBasicBlock(); InstructionHandle handle = location.getHandle(); if (handle == (isForwards() ? basicBlock.getLastInstruction() : basicBlock.getFirstInstruction())) { return getResultFact(basicBlock); } else { return getFactAtLocation(new Location(isForwards() ? handle.getNext() : handle.getPrev(), basicBlock)); } }
java
@Override public Fact getFactAfterLocation(Location location) throws DataflowAnalysisException { BasicBlock basicBlock = location.getBasicBlock(); InstructionHandle handle = location.getHandle(); if (handle == (isForwards() ? basicBlock.getLastInstruction() : basicBlock.getFirstInstruction())) { return getResultFact(basicBlock); } else { return getFactAtLocation(new Location(isForwards() ? handle.getNext() : handle.getPrev(), basicBlock)); } }
[ "@", "Override", "public", "Fact", "getFactAfterLocation", "(", "Location", "location", ")", "throws", "DataflowAnalysisException", "{", "BasicBlock", "basicBlock", "=", "location", ".", "getBasicBlock", "(", ")", ";", "InstructionHandle", "handle", "=", "location", ...
Get the dataflow fact representing the point just after given Location. Note "after" is meant in the logical sense, so for backward analyses, after means before the location in the control flow sense. @param location the location @return the fact at the point just after the location
[ "Get", "the", "dataflow", "fact", "representing", "the", "point", "just", "after", "given", "Location", ".", "Note", "after", "is", "meant", "in", "the", "logical", "sense", "so", "for", "backward", "analyses", "after", "means", "before", "the", "location", ...
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/AbstractDataflowAnalysis.java#L97-L107
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/detect/StaticCalendarDetector.java
StaticCalendarDetector.visit
@Override public void visit(JavaClass someObj) { currentClass = someObj.getClassName(); currentMethod = null; currentCFG = null; currentLockDataFlow = null; sawDateClass = false; }
java
@Override public void visit(JavaClass someObj) { currentClass = someObj.getClassName(); currentMethod = null; currentCFG = null; currentLockDataFlow = null; sawDateClass = false; }
[ "@", "Override", "public", "void", "visit", "(", "JavaClass", "someObj", ")", "{", "currentClass", "=", "someObj", ".", "getClassName", "(", ")", ";", "currentMethod", "=", "null", ";", "currentCFG", "=", "null", ";", "currentLockDataFlow", "=", "null", ";",...
Remembers the class name and resets temporary fields.
[ "Remembers", "the", "class", "name", "and", "resets", "temporary", "fields", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/StaticCalendarDetector.java#L126-L134
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/TextUICommandLine.java
TextUICommandLine.addAuxClassPathEntries
private void addAuxClassPathEntries(String argument) { StringTokenizer tok = new StringTokenizer(argument, File.pathSeparator); while (tok.hasMoreTokens()) { project.addAuxClasspathEntry(tok.nextToken()); } }
java
private void addAuxClassPathEntries(String argument) { StringTokenizer tok = new StringTokenizer(argument, File.pathSeparator); while (tok.hasMoreTokens()) { project.addAuxClasspathEntry(tok.nextToken()); } }
[ "private", "void", "addAuxClassPathEntries", "(", "String", "argument", ")", "{", "StringTokenizer", "tok", "=", "new", "StringTokenizer", "(", "argument", ",", "File", ".", "pathSeparator", ")", ";", "while", "(", "tok", ".", "hasMoreTokens", "(", ")", ")", ...
Parse the argument as auxclasspath entries and add them @param argument
[ "Parse", "the", "argument", "as", "auxclasspath", "entries", "and", "add", "them" ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/TextUICommandLine.java#L569-L574
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/TextUICommandLine.java
TextUICommandLine.choose
private void choose(String argument, String desc, Chooser chooser) { StringTokenizer tok = new StringTokenizer(argument, ","); while (tok.hasMoreTokens()) { String what = tok.nextToken().trim(); if (!what.startsWith("+") && !what.startsWith("-")) { throw new IllegalArgumentException(desc + " must start with " + "\"+\" or \"-\" (saw " + what + ")"); } boolean enabled = what.startsWith("+"); chooser.choose(enabled, what.substring(1)); } }
java
private void choose(String argument, String desc, Chooser chooser) { StringTokenizer tok = new StringTokenizer(argument, ","); while (tok.hasMoreTokens()) { String what = tok.nextToken().trim(); if (!what.startsWith("+") && !what.startsWith("-")) { throw new IllegalArgumentException(desc + " must start with " + "\"+\" or \"-\" (saw " + what + ")"); } boolean enabled = what.startsWith("+"); chooser.choose(enabled, what.substring(1)); } }
[ "private", "void", "choose", "(", "String", "argument", ",", "String", "desc", ",", "Chooser", "chooser", ")", "{", "StringTokenizer", "tok", "=", "new", "StringTokenizer", "(", "argument", ",", "\",\"", ")", ";", "while", "(", "tok", ".", "hasMoreTokens", ...
Common handling code for -chooseVisitors and -choosePlugins options. @param argument the list of visitors or plugins to be chosen @param desc String describing what is being chosen @param chooser callback object to selectively choose list members
[ "Common", "handling", "code", "for", "-", "chooseVisitors", "and", "-", "choosePlugins", "options", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/TextUICommandLine.java#L586-L596
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/TextUICommandLine.java
TextUICommandLine.handleXArgs
public void handleXArgs() throws IOException { if (getXargs()) { try (BufferedReader in = UTF8.bufferedReader(System.in)) { while (true) { String s = in.readLine(); if (s == null) { break; } project.addFile(s); } } } }
java
public void handleXArgs() throws IOException { if (getXargs()) { try (BufferedReader in = UTF8.bufferedReader(System.in)) { while (true) { String s = in.readLine(); if (s == null) { break; } project.addFile(s); } } } }
[ "public", "void", "handleXArgs", "(", ")", "throws", "IOException", "{", "if", "(", "getXargs", "(", ")", ")", "{", "try", "(", "BufferedReader", "in", "=", "UTF8", ".", "bufferedReader", "(", "System", ".", "in", ")", ")", "{", "while", "(", "true", ...
Handle -xargs command line option by reading jar file names from standard input and adding them to the project. @throws IOException
[ "Handle", "-", "xargs", "command", "line", "option", "by", "reading", "jar", "file", "names", "from", "standard", "input", "and", "adding", "them", "to", "the", "project", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/TextUICommandLine.java#L712-L724
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/TextUICommandLine.java
TextUICommandLine.handleAuxClassPathFromFile
private void handleAuxClassPathFromFile(String filePath) throws IOException { try (BufferedReader in = new BufferedReader(UTF8.fileReader(filePath))) { while (true) { String s = in.readLine(); if (s == null) { break; } project.addAuxClasspathEntry(s); } } }
java
private void handleAuxClassPathFromFile(String filePath) throws IOException { try (BufferedReader in = new BufferedReader(UTF8.fileReader(filePath))) { while (true) { String s = in.readLine(); if (s == null) { break; } project.addAuxClasspathEntry(s); } } }
[ "private", "void", "handleAuxClassPathFromFile", "(", "String", "filePath", ")", "throws", "IOException", "{", "try", "(", "BufferedReader", "in", "=", "new", "BufferedReader", "(", "UTF8", ".", "fileReader", "(", "filePath", ")", ")", ")", "{", "while", "(", ...
Handle -readAuxFromFile command line option by reading classpath entries from a file and adding them to the project. @throws IOException
[ "Handle", "-", "readAuxFromFile", "command", "line", "option", "by", "reading", "classpath", "entries", "from", "a", "file", "and", "adding", "them", "to", "the", "project", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/TextUICommandLine.java#L732-L742
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/TextUICommandLine.java
TextUICommandLine.handleAnalyzeFromFile
private void handleAnalyzeFromFile(String filePath) throws IOException { try (BufferedReader in = new BufferedReader(UTF8.fileReader(filePath))) { while (true) { String s = in.readLine(); if (s == null) { break; } project.addFile(s); } } }
java
private void handleAnalyzeFromFile(String filePath) throws IOException { try (BufferedReader in = new BufferedReader(UTF8.fileReader(filePath))) { while (true) { String s = in.readLine(); if (s == null) { break; } project.addFile(s); } } }
[ "private", "void", "handleAnalyzeFromFile", "(", "String", "filePath", ")", "throws", "IOException", "{", "try", "(", "BufferedReader", "in", "=", "new", "BufferedReader", "(", "UTF8", ".", "fileReader", "(", "filePath", ")", ")", ")", "{", "while", "(", "tr...
Handle -analyzeFromFile command line option by reading jar file names from a file and adding them to the project. @throws IOException
[ "Handle", "-", "analyzeFromFile", "command", "line", "option", "by", "reading", "jar", "file", "names", "from", "a", "file", "and", "adding", "them", "to", "the", "project", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/TextUICommandLine.java#L750-L760
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/Project.java
Project.duplicate
public Project duplicate() { Project dup = new Project(); dup.currentWorkingDirectoryList.addAll(this.currentWorkingDirectoryList); dup.projectName = this.projectName; dup.analysisTargets.addAll(this.analysisTargets); dup.srcDirList.addAll(this.srcDirList); dup.auxClasspathEntryList.addAll(this.auxClasspathEntryList); dup.timestampForAnalyzedClasses = timestampForAnalyzedClasses; dup.guiCallback = guiCallback; return dup; }
java
public Project duplicate() { Project dup = new Project(); dup.currentWorkingDirectoryList.addAll(this.currentWorkingDirectoryList); dup.projectName = this.projectName; dup.analysisTargets.addAll(this.analysisTargets); dup.srcDirList.addAll(this.srcDirList); dup.auxClasspathEntryList.addAll(this.auxClasspathEntryList); dup.timestampForAnalyzedClasses = timestampForAnalyzedClasses; dup.guiCallback = guiCallback; return dup; }
[ "public", "Project", "duplicate", "(", ")", "{", "Project", "dup", "=", "new", "Project", "(", ")", ";", "dup", ".", "currentWorkingDirectoryList", ".", "addAll", "(", "this", ".", "currentWorkingDirectoryList", ")", ";", "dup", ".", "projectName", "=", "thi...
Return an exact copy of this Project.
[ "Return", "an", "exact", "copy", "of", "this", "Project", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/Project.java#L172-L182
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/Project.java
Project.add
public void add(Project project2) { analysisTargets = appendWithoutDuplicates(analysisTargets, project2.analysisTargets); srcDirList = appendWithoutDuplicates(srcDirList, project2.srcDirList); auxClasspathEntryList = appendWithoutDuplicates(auxClasspathEntryList, project2.auxClasspathEntryList); }
java
public void add(Project project2) { analysisTargets = appendWithoutDuplicates(analysisTargets, project2.analysisTargets); srcDirList = appendWithoutDuplicates(srcDirList, project2.srcDirList); auxClasspathEntryList = appendWithoutDuplicates(auxClasspathEntryList, project2.auxClasspathEntryList); }
[ "public", "void", "add", "(", "Project", "project2", ")", "{", "analysisTargets", "=", "appendWithoutDuplicates", "(", "analysisTargets", ",", "project2", ".", "analysisTargets", ")", ";", "srcDirList", "=", "appendWithoutDuplicates", "(", "srcDirList", ",", "projec...
add information from project2 to this project
[ "add", "information", "from", "project2", "to", "this", "project" ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/Project.java#L198-L202
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/Project.java
Project.addSourceDirs
public boolean addSourceDirs(Collection<String> sourceDirs) { boolean isNew = false; if (sourceDirs == null || sourceDirs.isEmpty()) { return isNew; } for (String dirName : sourceDirs) { for (String dir : makeAbsoluteCwdCandidates(dirName)) { isNew = addToListInternal(srcDirList, dir) || isNew; } } IO.close(sourceFinder); sourceFinder = new SourceFinder(this); return isNew; }
java
public boolean addSourceDirs(Collection<String> sourceDirs) { boolean isNew = false; if (sourceDirs == null || sourceDirs.isEmpty()) { return isNew; } for (String dirName : sourceDirs) { for (String dir : makeAbsoluteCwdCandidates(dirName)) { isNew = addToListInternal(srcDirList, dir) || isNew; } } IO.close(sourceFinder); sourceFinder = new SourceFinder(this); return isNew; }
[ "public", "boolean", "addSourceDirs", "(", "Collection", "<", "String", ">", "sourceDirs", ")", "{", "boolean", "isNew", "=", "false", ";", "if", "(", "sourceDirs", "==", "null", "||", "sourceDirs", ".", "isEmpty", "(", ")", ")", "{", "return", "isNew", ...
Add source directories to the project. @param sourceDirs The source directories to add. These can be either absolute paths or relative to any of the working directories in this project object. @return true if a source directory was added or false if all source directories were already present
[ "Add", "source", "directories", "to", "the", "project", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/Project.java#L267-L282
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/Project.java
Project.addWorkingDir
public boolean addWorkingDir(String dirName) { if (dirName == null) { throw new NullPointerException(); } return addToListInternal(currentWorkingDirectoryList, new File(dirName)); }
java
public boolean addWorkingDir(String dirName) { if (dirName == null) { throw new NullPointerException(); } return addToListInternal(currentWorkingDirectoryList, new File(dirName)); }
[ "public", "boolean", "addWorkingDir", "(", "String", "dirName", ")", "{", "if", "(", "dirName", "==", "null", ")", "{", "throw", "new", "NullPointerException", "(", ")", ";", "}", "return", "addToListInternal", "(", "currentWorkingDirectoryList", ",", "new", "...
Add a working directory to the project. @param dirName the directory to add @return true if the working directory was added, or false if the working directory was already present
[ "Add", "a", "working", "directory", "to", "the", "project", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/Project.java#L292-L297
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/Project.java
Project.removeSourceDir
public void removeSourceDir(int num) { srcDirList.remove(num); IO.close(sourceFinder); sourceFinder = new SourceFinder(this); isModified = true; }
java
public void removeSourceDir(int num) { srcDirList.remove(num); IO.close(sourceFinder); sourceFinder = new SourceFinder(this); isModified = true; }
[ "public", "void", "removeSourceDir", "(", "int", "num", ")", "{", "srcDirList", ".", "remove", "(", "num", ")", ";", "IO", ".", "close", "(", "sourceFinder", ")", ";", "sourceFinder", "=", "new", "SourceFinder", "(", "this", ")", ";", "isModified", "=", ...
Remove source directory at given index. @param num index of the source directory to remove
[ "Remove", "source", "directory", "at", "given", "index", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/Project.java#L363-L368
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/Project.java
Project.write
@Deprecated public void write(String outputFile, boolean useRelativePaths, String relativeBase) throws IOException { PrintWriter writer = UTF8.printWriter(outputFile); try { writer.println(JAR_FILES_KEY); for (String jarFile : analysisTargets) { if (useRelativePaths) { jarFile = convertToRelative(jarFile, relativeBase); } writer.println(jarFile); } writer.println(SRC_DIRS_KEY); for (String srcDir : srcDirList) { if (useRelativePaths) { srcDir = convertToRelative(srcDir, relativeBase); } writer.println(srcDir); } writer.println(AUX_CLASSPATH_ENTRIES_KEY); for (String auxClasspathEntry : auxClasspathEntryList) { if (useRelativePaths) { auxClasspathEntry = convertToRelative(auxClasspathEntry, relativeBase); } writer.println(auxClasspathEntry); } if (useRelativePaths) { writer.println(OPTIONS_KEY); writer.println(RELATIVE_PATHS + "=true"); } } finally { writer.close(); } // Project successfully saved isModified = false; }
java
@Deprecated public void write(String outputFile, boolean useRelativePaths, String relativeBase) throws IOException { PrintWriter writer = UTF8.printWriter(outputFile); try { writer.println(JAR_FILES_KEY); for (String jarFile : analysisTargets) { if (useRelativePaths) { jarFile = convertToRelative(jarFile, relativeBase); } writer.println(jarFile); } writer.println(SRC_DIRS_KEY); for (String srcDir : srcDirList) { if (useRelativePaths) { srcDir = convertToRelative(srcDir, relativeBase); } writer.println(srcDir); } writer.println(AUX_CLASSPATH_ENTRIES_KEY); for (String auxClasspathEntry : auxClasspathEntryList) { if (useRelativePaths) { auxClasspathEntry = convertToRelative(auxClasspathEntry, relativeBase); } writer.println(auxClasspathEntry); } if (useRelativePaths) { writer.println(OPTIONS_KEY); writer.println(RELATIVE_PATHS + "=true"); } } finally { writer.close(); } // Project successfully saved isModified = false; }
[ "@", "Deprecated", "public", "void", "write", "(", "String", "outputFile", ",", "boolean", "useRelativePaths", ",", "String", "relativeBase", ")", "throws", "IOException", "{", "PrintWriter", "writer", "=", "UTF8", ".", "printWriter", "(", "outputFile", ")", ";"...
Save the project to an output file. @param outputFile name of output file @param useRelativePaths true if the project should be written using only relative paths @param relativeBase if useRelativePaths is true, this file is taken as the base directory in terms of which all files should be made relative @throws IOException if an error occurs while writing
[ "Save", "the", "project", "to", "an", "output", "file", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/Project.java#L637-L675
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/Project.java
Project.readProject
public static Project readProject(String argument) throws IOException { String projectFileName = argument; File projectFile = new File(projectFileName); if (projectFileName.endsWith(".xml") || projectFileName.endsWith(".fbp")) { try { return Project.readXML(projectFile); } catch (SAXException e) { IOException ioe = new IOException("Couldn't read saved FindBugs project"); ioe.initCause(e); throw ioe; } } throw new IllegalArgumentException("Can't read project from " + argument); }
java
public static Project readProject(String argument) throws IOException { String projectFileName = argument; File projectFile = new File(projectFileName); if (projectFileName.endsWith(".xml") || projectFileName.endsWith(".fbp")) { try { return Project.readXML(projectFile); } catch (SAXException e) { IOException ioe = new IOException("Couldn't read saved FindBugs project"); ioe.initCause(e); throw ioe; } } throw new IllegalArgumentException("Can't read project from " + argument); }
[ "public", "static", "Project", "readProject", "(", "String", "argument", ")", "throws", "IOException", "{", "String", "projectFileName", "=", "argument", ";", "File", "projectFile", "=", "new", "File", "(", "projectFileName", ")", ";", "if", "(", "projectFileNam...
Read Project from named file. @param argument command line argument containing project file name @return the Project @throws IOException
[ "Read", "Project", "from", "named", "file", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/Project.java#L730-L745
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/Project.java
Project.convertToRelative
private String convertToRelative(String srcFile, String base) { String slash = SystemProperties.getProperty("file.separator"); if (FILE_IGNORE_CASE) { srcFile = srcFile.toLowerCase(); base = base.toLowerCase(); } if (base.equals(srcFile)) { return "."; } if (!base.endsWith(slash)) { base = base + slash; } if (base.length() <= srcFile.length()) { String root = srcFile.substring(0, base.length()); if (root.equals(base)) { // Strip off the base directory, make relative return "." + SystemProperties.getProperty("file.separator") + srcFile.substring(base.length()); } } // See if we can build a relative path above the base using .. notation int slashPos = srcFile.indexOf(slash); int branchPoint; if (slashPos >= 0) { String subPath = srcFile.substring(0, slashPos); if ((subPath.length() == 0) || base.startsWith(subPath)) { branchPoint = slashPos + 1; slashPos = srcFile.indexOf(slash, branchPoint); while (slashPos >= 0) { subPath = srcFile.substring(0, slashPos); if (base.startsWith(subPath)) { branchPoint = slashPos + 1; } else { break; } slashPos = srcFile.indexOf(slash, branchPoint); } int slashCount = 0; slashPos = base.indexOf(slash, branchPoint); while (slashPos >= 0) { slashCount++; slashPos = base.indexOf(slash, slashPos + 1); } StringBuilder path = new StringBuilder(); String upDir = ".." + slash; for (int i = 0; i < slashCount; i++) { path.append(upDir); } path.append(srcFile.substring(branchPoint)); return path.toString(); } } return srcFile; }
java
private String convertToRelative(String srcFile, String base) { String slash = SystemProperties.getProperty("file.separator"); if (FILE_IGNORE_CASE) { srcFile = srcFile.toLowerCase(); base = base.toLowerCase(); } if (base.equals(srcFile)) { return "."; } if (!base.endsWith(slash)) { base = base + slash; } if (base.length() <= srcFile.length()) { String root = srcFile.substring(0, base.length()); if (root.equals(base)) { // Strip off the base directory, make relative return "." + SystemProperties.getProperty("file.separator") + srcFile.substring(base.length()); } } // See if we can build a relative path above the base using .. notation int slashPos = srcFile.indexOf(slash); int branchPoint; if (slashPos >= 0) { String subPath = srcFile.substring(0, slashPos); if ((subPath.length() == 0) || base.startsWith(subPath)) { branchPoint = slashPos + 1; slashPos = srcFile.indexOf(slash, branchPoint); while (slashPos >= 0) { subPath = srcFile.substring(0, slashPos); if (base.startsWith(subPath)) { branchPoint = slashPos + 1; } else { break; } slashPos = srcFile.indexOf(slash, branchPoint); } int slashCount = 0; slashPos = base.indexOf(slash, branchPoint); while (slashPos >= 0) { slashCount++; slashPos = base.indexOf(slash, slashPos + 1); } StringBuilder path = new StringBuilder(); String upDir = ".." + slash; for (int i = 0; i < slashCount; i++) { path.append(upDir); } path.append(srcFile.substring(branchPoint)); return path.toString(); } } return srcFile; }
[ "private", "String", "convertToRelative", "(", "String", "srcFile", ",", "String", "base", ")", "{", "String", "slash", "=", "SystemProperties", ".", "getProperty", "(", "\"file.separator\"", ")", ";", "if", "(", "FILE_IGNORE_CASE", ")", "{", "srcFile", "=", "...
Converts a full path to a relative path if possible @param srcFile path to convert @return the converted filename
[ "Converts", "a", "full", "path", "to", "a", "relative", "path", "if", "possible" ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/Project.java#L879-L938
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/Project.java
Project.makeAbsoluteCWD
private String makeAbsoluteCWD(String fileName) { List<String> candidates = makeAbsoluteCwdCandidates(fileName); return candidates.get(0); }
java
private String makeAbsoluteCWD(String fileName) { List<String> candidates = makeAbsoluteCwdCandidates(fileName); return candidates.get(0); }
[ "private", "String", "makeAbsoluteCWD", "(", "String", "fileName", ")", "{", "List", "<", "String", ">", "candidates", "=", "makeAbsoluteCwdCandidates", "(", "fileName", ")", ";", "return", "candidates", ".", "get", "(", "0", ")", ";", "}" ]
Make the given filename absolute relative to the current working directory.
[ "Make", "the", "given", "filename", "absolute", "relative", "to", "the", "current", "working", "directory", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/Project.java#L971-L974
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/Project.java
Project.makeAbsoluteCwdCandidates
private List<String> makeAbsoluteCwdCandidates(String fileName) { List<String> candidates = new ArrayList<>(); boolean hasProtocol = (URLClassPath.getURLProtocol(fileName) != null); if (hasProtocol) { candidates.add(fileName); return candidates; } if (new File(fileName).isAbsolute()) { candidates.add(fileName); return candidates; } for (File currentWorkingDirectory : currentWorkingDirectoryList) { File relativeToCurrent = new File(currentWorkingDirectory, fileName); if (relativeToCurrent.exists()) { candidates.add(relativeToCurrent.toString()); } } if (candidates.isEmpty()) { candidates.add(fileName); } return candidates; }
java
private List<String> makeAbsoluteCwdCandidates(String fileName) { List<String> candidates = new ArrayList<>(); boolean hasProtocol = (URLClassPath.getURLProtocol(fileName) != null); if (hasProtocol) { candidates.add(fileName); return candidates; } if (new File(fileName).isAbsolute()) { candidates.add(fileName); return candidates; } for (File currentWorkingDirectory : currentWorkingDirectoryList) { File relativeToCurrent = new File(currentWorkingDirectory, fileName); if (relativeToCurrent.exists()) { candidates.add(relativeToCurrent.toString()); } } if (candidates.isEmpty()) { candidates.add(fileName); } return candidates; }
[ "private", "List", "<", "String", ">", "makeAbsoluteCwdCandidates", "(", "String", "fileName", ")", "{", "List", "<", "String", ">", "candidates", "=", "new", "ArrayList", "<>", "(", ")", ";", "boolean", "hasProtocol", "=", "(", "URLClassPath", ".", "getURLP...
Make the given filename absolute relative to the current working directory candidates. If the given filename exists in more than one of the working directories, a list of these existing absolute paths is returned. The returned list is guaranteed to be non-empty. The returned paths might exist or not exist and might be relative or absolute. @return A list of at least one candidate path for the given filename.
[ "Make", "the", "given", "filename", "absolute", "relative", "to", "the", "current", "working", "directory", "candidates", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/Project.java#L988-L1014
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/Project.java
Project.addToListInternal
private <T> boolean addToListInternal(Collection<T> list, T value) { if (!list.contains(value)) { list.add(value); isModified = true; return true; } else { return false; } }
java
private <T> boolean addToListInternal(Collection<T> list, T value) { if (!list.contains(value)) { list.add(value); isModified = true; return true; } else { return false; } }
[ "private", "<", "T", ">", "boolean", "addToListInternal", "(", "Collection", "<", "T", ">", "list", ",", "T", "value", ")", "{", "if", "(", "!", "list", ".", "contains", "(", "value", ")", ")", "{", "list", ".", "add", "(", "value", ")", ";", "is...
Add a value to given list, making the Project modified if the value is not already present in the list. @param list the list @param value the value to be added @return true if the value was not already present in the list, false otherwise
[ "Add", "a", "value", "to", "given", "list", "making", "the", "Project", "modified", "if", "the", "value", "is", "not", "already", "present", "in", "the", "list", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/Project.java#L1027-L1035
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/ba/vna/ValueNumberFrameModelingVisitor.java
ValueNumberFrameModelingVisitor.doRedundantLoadElimination
private boolean doRedundantLoadElimination() { if (!REDUNDANT_LOAD_ELIMINATION) { return false; } XField xfield = loadedFieldSet.getField(handle); if (xfield == null) { return false; } // TODO: support two-slot fields return !(xfield.getSignature().equals("D") || xfield.getSignature().equals("J")); }
java
private boolean doRedundantLoadElimination() { if (!REDUNDANT_LOAD_ELIMINATION) { return false; } XField xfield = loadedFieldSet.getField(handle); if (xfield == null) { return false; } // TODO: support two-slot fields return !(xfield.getSignature().equals("D") || xfield.getSignature().equals("J")); }
[ "private", "boolean", "doRedundantLoadElimination", "(", ")", "{", "if", "(", "!", "REDUNDANT_LOAD_ELIMINATION", ")", "{", "return", "false", ";", "}", "XField", "xfield", "=", "loadedFieldSet", ".", "getField", "(", "handle", ")", ";", "if", "(", "xfield", ...
Determine whether redundant load elimination should be performed for the heap location referenced by the current instruction. @return true if we should do redundant load elimination for the current instruction, false if not
[ "Determine", "whether", "redundant", "load", "elimination", "should", "be", "performed", "for", "the", "heap", "location", "referenced", "by", "the", "current", "instruction", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/vna/ValueNumberFrameModelingVisitor.java#L156-L168
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/ba/vna/ValueNumberFrameModelingVisitor.java
ValueNumberFrameModelingVisitor.doForwardSubstitution
private boolean doForwardSubstitution() { if (!REDUNDANT_LOAD_ELIMINATION) { return false; } XField xfield = loadedFieldSet.getField(handle); if (xfield == null) { return false; } if(xfield.getSignature().equals("D") || xfield.getSignature().equals("J")) { return false; } // Don't do forward substitution for fields that // are never read. return loadedFieldSet.isLoaded(xfield); }
java
private boolean doForwardSubstitution() { if (!REDUNDANT_LOAD_ELIMINATION) { return false; } XField xfield = loadedFieldSet.getField(handle); if (xfield == null) { return false; } if(xfield.getSignature().equals("D") || xfield.getSignature().equals("J")) { return false; } // Don't do forward substitution for fields that // are never read. return loadedFieldSet.isLoaded(xfield); }
[ "private", "boolean", "doForwardSubstitution", "(", ")", "{", "if", "(", "!", "REDUNDANT_LOAD_ELIMINATION", ")", "{", "return", "false", ";", "}", "XField", "xfield", "=", "loadedFieldSet", ".", "getField", "(", "handle", ")", ";", "if", "(", "xfield", "==",...
Determine whether forward substitution should be performed for the heap location referenced by the current instruction. @return true if we should do forward substitution for the current instruction, false if not
[ "Determine", "whether", "forward", "substitution", "should", "be", "performed", "for", "the", "heap", "location", "referenced", "by", "the", "current", "instruction", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/vna/ValueNumberFrameModelingVisitor.java#L177-L194
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/ba/vna/ValueNumberFrameModelingVisitor.java
ValueNumberFrameModelingVisitor.modelNormalInstruction
@Override public void modelNormalInstruction(Instruction ins, int numWordsConsumed, int numWordsProduced) { int flags = 0; if (ins instanceof InvokeInstruction) { flags = ValueNumber.RETURN_VALUE; } else if (ins instanceof ArrayInstruction) { flags = ValueNumber.ARRAY_VALUE; } else if (ins instanceof ConstantPushInstruction) { flags = ValueNumber.CONSTANT_VALUE; } // Get the input operands to this instruction. ValueNumber[] inputValueList = popInputValues(numWordsConsumed); // See if we have the output operands in the cache. // If not, push default (fresh) values for the output, // and add them to the cache. ValueNumber[] outputValueList = getOutputValues(inputValueList, numWordsProduced, flags); if (VERIFY_INTEGRITY) { checkConsumedAndProducedValues(ins, inputValueList, outputValueList); } // Push output operands on stack. pushOutputValues(outputValueList); }
java
@Override public void modelNormalInstruction(Instruction ins, int numWordsConsumed, int numWordsProduced) { int flags = 0; if (ins instanceof InvokeInstruction) { flags = ValueNumber.RETURN_VALUE; } else if (ins instanceof ArrayInstruction) { flags = ValueNumber.ARRAY_VALUE; } else if (ins instanceof ConstantPushInstruction) { flags = ValueNumber.CONSTANT_VALUE; } // Get the input operands to this instruction. ValueNumber[] inputValueList = popInputValues(numWordsConsumed); // See if we have the output operands in the cache. // If not, push default (fresh) values for the output, // and add them to the cache. ValueNumber[] outputValueList = getOutputValues(inputValueList, numWordsProduced, flags); if (VERIFY_INTEGRITY) { checkConsumedAndProducedValues(ins, inputValueList, outputValueList); } // Push output operands on stack. pushOutputValues(outputValueList); }
[ "@", "Override", "public", "void", "modelNormalInstruction", "(", "Instruction", "ins", ",", "int", "numWordsConsumed", ",", "int", "numWordsProduced", ")", "{", "int", "flags", "=", "0", ";", "if", "(", "ins", "instanceof", "InvokeInstruction", ")", "{", "fla...
This is the default instruction modeling method.
[ "This", "is", "the", "default", "instruction", "modeling", "method", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/vna/ValueNumberFrameModelingVisitor.java#L221-L247
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/ba/vna/ValueNumberFrameModelingVisitor.java
ValueNumberFrameModelingVisitor.popInputValues
private ValueNumber[] popInputValues(int numWordsConsumed) { ValueNumberFrame frame = getFrame(); ValueNumber[] inputValueList = allocateValueNumberArray(numWordsConsumed); // Pop off the input operands. try { frame.getTopStackWords(inputValueList); while (numWordsConsumed-- > 0) { frame.popValue(); } } catch (DataflowAnalysisException e) { throw new InvalidBytecodeException("Error getting input operands", e); } return inputValueList; }
java
private ValueNumber[] popInputValues(int numWordsConsumed) { ValueNumberFrame frame = getFrame(); ValueNumber[] inputValueList = allocateValueNumberArray(numWordsConsumed); // Pop off the input operands. try { frame.getTopStackWords(inputValueList); while (numWordsConsumed-- > 0) { frame.popValue(); } } catch (DataflowAnalysisException e) { throw new InvalidBytecodeException("Error getting input operands", e); } return inputValueList; }
[ "private", "ValueNumber", "[", "]", "popInputValues", "(", "int", "numWordsConsumed", ")", "{", "ValueNumberFrame", "frame", "=", "getFrame", "(", ")", ";", "ValueNumber", "[", "]", "inputValueList", "=", "allocateValueNumberArray", "(", "numWordsConsumed", ")", "...
Pop the input values for the given instruction from the current frame.
[ "Pop", "the", "input", "values", "for", "the", "given", "instruction", "from", "the", "current", "frame", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/vna/ValueNumberFrameModelingVisitor.java#L595-L610
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/ba/vna/ValueNumberFrameModelingVisitor.java
ValueNumberFrameModelingVisitor.pushOutputValues
private void pushOutputValues(ValueNumber[] outputValueList) { ValueNumberFrame frame = getFrame(); for (ValueNumber aOutputValueList : outputValueList) { frame.pushValue(aOutputValueList); } }
java
private void pushOutputValues(ValueNumber[] outputValueList) { ValueNumberFrame frame = getFrame(); for (ValueNumber aOutputValueList : outputValueList) { frame.pushValue(aOutputValueList); } }
[ "private", "void", "pushOutputValues", "(", "ValueNumber", "[", "]", "outputValueList", ")", "{", "ValueNumberFrame", "frame", "=", "getFrame", "(", ")", ";", "for", "(", "ValueNumber", "aOutputValueList", ":", "outputValueList", ")", "{", "frame", ".", "pushVal...
Push given output values onto the current frame.
[ "Push", "given", "output", "values", "onto", "the", "current", "frame", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/vna/ValueNumberFrameModelingVisitor.java#L615-L620
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/ba/vna/ValueNumberFrameModelingVisitor.java
ValueNumberFrameModelingVisitor.loadInstanceField
private void loadInstanceField(XField instanceField, Instruction obj) { if (RLE_DEBUG) { System.out.println("[loadInstanceField for field " + instanceField + " in instruction " + handle); } ValueNumberFrame frame = getFrame(); try { ValueNumber reference = frame.popValue(); AvailableLoad availableLoad = new AvailableLoad(reference, instanceField); if (RLE_DEBUG) { System.out.println("[getfield of " + availableLoad + "]"); } ValueNumber[] loadedValue = frame.getAvailableLoad(availableLoad); if (loadedValue == null) { // Get (or create) the cached result for this instruction ValueNumber[] inputValueList = new ValueNumber[] { reference }; loadedValue = getOutputValues(inputValueList, getNumWordsProduced(obj)); // Make the load available frame.addAvailableLoad(availableLoad, loadedValue); if (RLE_DEBUG) { System.out.println("[Making load available " + availableLoad + " <- " + vlts(loadedValue) + "]"); } } else { // Found an available load! if (RLE_DEBUG) { System.out.println("[Found available load " + availableLoad + " <- " + vlts(loadedValue) + "]"); } } pushOutputValues(loadedValue); if (VERIFY_INTEGRITY) { checkConsumedAndProducedValues(obj, new ValueNumber[] { reference }, loadedValue); } } catch (DataflowAnalysisException e) { throw new InvalidBytecodeException("Error loading from instance field", e); } }
java
private void loadInstanceField(XField instanceField, Instruction obj) { if (RLE_DEBUG) { System.out.println("[loadInstanceField for field " + instanceField + " in instruction " + handle); } ValueNumberFrame frame = getFrame(); try { ValueNumber reference = frame.popValue(); AvailableLoad availableLoad = new AvailableLoad(reference, instanceField); if (RLE_DEBUG) { System.out.println("[getfield of " + availableLoad + "]"); } ValueNumber[] loadedValue = frame.getAvailableLoad(availableLoad); if (loadedValue == null) { // Get (or create) the cached result for this instruction ValueNumber[] inputValueList = new ValueNumber[] { reference }; loadedValue = getOutputValues(inputValueList, getNumWordsProduced(obj)); // Make the load available frame.addAvailableLoad(availableLoad, loadedValue); if (RLE_DEBUG) { System.out.println("[Making load available " + availableLoad + " <- " + vlts(loadedValue) + "]"); } } else { // Found an available load! if (RLE_DEBUG) { System.out.println("[Found available load " + availableLoad + " <- " + vlts(loadedValue) + "]"); } } pushOutputValues(loadedValue); if (VERIFY_INTEGRITY) { checkConsumedAndProducedValues(obj, new ValueNumber[] { reference }, loadedValue); } } catch (DataflowAnalysisException e) { throw new InvalidBytecodeException("Error loading from instance field", e); } }
[ "private", "void", "loadInstanceField", "(", "XField", "instanceField", ",", "Instruction", "obj", ")", "{", "if", "(", "RLE_DEBUG", ")", "{", "System", ".", "out", ".", "println", "(", "\"[loadInstanceField for field \"", "+", "instanceField", "+", "\" in instruc...
Load an instance field. @param instanceField the field @param obj the Instruction loading the field
[ "Load", "an", "instance", "field", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/vna/ValueNumberFrameModelingVisitor.java#L685-L726
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/ba/vna/ValueNumberFrameModelingVisitor.java
ValueNumberFrameModelingVisitor.loadStaticField
private void loadStaticField(XField staticField, Instruction obj) { if (RLE_DEBUG) { System.out.println("[loadStaticField for field " + staticField + " in instruction " + handle); } ValueNumberFrame frame = getFrame(); AvailableLoad availableLoad = new AvailableLoad(staticField); ValueNumber[] loadedValue = frame.getAvailableLoad(availableLoad); if (loadedValue == null) { // Make the load available int numWordsProduced = getNumWordsProduced(obj); loadedValue = getOutputValues(EMPTY_INPUT_VALUE_LIST, numWordsProduced); frame.addAvailableLoad(availableLoad, loadedValue); if (RLE_DEBUG) { System.out.println("[making load of " + staticField + " available]"); } } else { if (RLE_DEBUG) { System.out.println("[found available load of " + staticField + "]"); } } if (VERIFY_INTEGRITY) { checkConsumedAndProducedValues(obj, EMPTY_INPUT_VALUE_LIST, loadedValue); } pushOutputValues(loadedValue); }
java
private void loadStaticField(XField staticField, Instruction obj) { if (RLE_DEBUG) { System.out.println("[loadStaticField for field " + staticField + " in instruction " + handle); } ValueNumberFrame frame = getFrame(); AvailableLoad availableLoad = new AvailableLoad(staticField); ValueNumber[] loadedValue = frame.getAvailableLoad(availableLoad); if (loadedValue == null) { // Make the load available int numWordsProduced = getNumWordsProduced(obj); loadedValue = getOutputValues(EMPTY_INPUT_VALUE_LIST, numWordsProduced); frame.addAvailableLoad(availableLoad, loadedValue); if (RLE_DEBUG) { System.out.println("[making load of " + staticField + " available]"); } } else { if (RLE_DEBUG) { System.out.println("[found available load of " + staticField + "]"); } } if (VERIFY_INTEGRITY) { checkConsumedAndProducedValues(obj, EMPTY_INPUT_VALUE_LIST, loadedValue); } pushOutputValues(loadedValue); }
[ "private", "void", "loadStaticField", "(", "XField", "staticField", ",", "Instruction", "obj", ")", "{", "if", "(", "RLE_DEBUG", ")", "{", "System", ".", "out", ".", "println", "(", "\"[loadStaticField for field \"", "+", "staticField", "+", "\" in instruction \""...
Load a static field. @param staticField the field @param obj the Instruction loading the field
[ "Load", "a", "static", "field", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/vna/ValueNumberFrameModelingVisitor.java#L736-L767
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/ba/vna/ValueNumberFrameModelingVisitor.java
ValueNumberFrameModelingVisitor.storeInstanceField
private void storeInstanceField(XField instanceField, Instruction obj, boolean pushStoredValue) { if (RLE_DEBUG) { System.out.println("[storeInstanceField for field " + instanceField + " in instruction " + handle); } ValueNumberFrame frame = getFrame(); int numWordsConsumed = getNumWordsConsumed(obj); /* * System.out.println("Instruction is " + handle); * System.out.println("numWordsConsumed="+numWordsConsumed); */ ValueNumber[] inputValueList = popInputValues(numWordsConsumed); ValueNumber reference = inputValueList[0]; ValueNumber[] storedValue = allocateValueNumberArray(inputValueList.length - 1); System.arraycopy(inputValueList, 1, storedValue, 0, inputValueList.length - 1); if (pushStoredValue) { pushOutputValues(storedValue); } // Kill all previous loads of the same field, // in case there is aliasing we don't know about frame.killLoadsOfField(instanceField); // Forward substitution frame.addAvailableLoad(new AvailableLoad(reference, instanceField), storedValue); if (RLE_DEBUG) { System.out.println("[making store of " + instanceField + " available]"); } if (VERIFY_INTEGRITY) { /* * System.out.println("pushStoredValue="+pushStoredValue); */ checkConsumedAndProducedValues(obj, inputValueList, pushStoredValue ? storedValue : EMPTY_INPUT_VALUE_LIST); } }
java
private void storeInstanceField(XField instanceField, Instruction obj, boolean pushStoredValue) { if (RLE_DEBUG) { System.out.println("[storeInstanceField for field " + instanceField + " in instruction " + handle); } ValueNumberFrame frame = getFrame(); int numWordsConsumed = getNumWordsConsumed(obj); /* * System.out.println("Instruction is " + handle); * System.out.println("numWordsConsumed="+numWordsConsumed); */ ValueNumber[] inputValueList = popInputValues(numWordsConsumed); ValueNumber reference = inputValueList[0]; ValueNumber[] storedValue = allocateValueNumberArray(inputValueList.length - 1); System.arraycopy(inputValueList, 1, storedValue, 0, inputValueList.length - 1); if (pushStoredValue) { pushOutputValues(storedValue); } // Kill all previous loads of the same field, // in case there is aliasing we don't know about frame.killLoadsOfField(instanceField); // Forward substitution frame.addAvailableLoad(new AvailableLoad(reference, instanceField), storedValue); if (RLE_DEBUG) { System.out.println("[making store of " + instanceField + " available]"); } if (VERIFY_INTEGRITY) { /* * System.out.println("pushStoredValue="+pushStoredValue); */ checkConsumedAndProducedValues(obj, inputValueList, pushStoredValue ? storedValue : EMPTY_INPUT_VALUE_LIST); } }
[ "private", "void", "storeInstanceField", "(", "XField", "instanceField", ",", "Instruction", "obj", ",", "boolean", "pushStoredValue", ")", "{", "if", "(", "RLE_DEBUG", ")", "{", "System", ".", "out", ".", "println", "(", "\"[storeInstanceField for field \"", "+",...
Store an instance field. @param instanceField the field @param obj the instruction which stores the field @param pushStoredValue push the stored value onto the stack (because we are modeling an inner-class field access method)
[ "Store", "an", "instance", "field", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/vna/ValueNumberFrameModelingVisitor.java#L780-L818
train
spotbugs/spotbugs
spotbugs/src/main/java/edu/umd/cs/findbugs/ba/vna/ValueNumberFrameModelingVisitor.java
ValueNumberFrameModelingVisitor.storeStaticField
private void storeStaticField(XField staticField, Instruction obj, boolean pushStoredValue) { if (RLE_DEBUG) { System.out.println("[storeStaticField for field " + staticField + " in instruction " + handle); } ValueNumberFrame frame = getFrame(); AvailableLoad availableLoad = new AvailableLoad(staticField); int numWordsConsumed = getNumWordsConsumed(obj); ValueNumber[] inputValueList = popInputValues(numWordsConsumed); if (pushStoredValue) { pushOutputValues(inputValueList); } // Kill loads of this field frame.killLoadsOfField(staticField); // Make load available frame.addAvailableLoad(availableLoad, inputValueList); if (RLE_DEBUG) { System.out.println("[making store of " + staticField + " available]"); } if (VERIFY_INTEGRITY) { checkConsumedAndProducedValues(obj, inputValueList, pushStoredValue ? inputValueList : EMPTY_INPUT_VALUE_LIST); } }
java
private void storeStaticField(XField staticField, Instruction obj, boolean pushStoredValue) { if (RLE_DEBUG) { System.out.println("[storeStaticField for field " + staticField + " in instruction " + handle); } ValueNumberFrame frame = getFrame(); AvailableLoad availableLoad = new AvailableLoad(staticField); int numWordsConsumed = getNumWordsConsumed(obj); ValueNumber[] inputValueList = popInputValues(numWordsConsumed); if (pushStoredValue) { pushOutputValues(inputValueList); } // Kill loads of this field frame.killLoadsOfField(staticField); // Make load available frame.addAvailableLoad(availableLoad, inputValueList); if (RLE_DEBUG) { System.out.println("[making store of " + staticField + " available]"); } if (VERIFY_INTEGRITY) { checkConsumedAndProducedValues(obj, inputValueList, pushStoredValue ? inputValueList : EMPTY_INPUT_VALUE_LIST); } }
[ "private", "void", "storeStaticField", "(", "XField", "staticField", ",", "Instruction", "obj", ",", "boolean", "pushStoredValue", ")", "{", "if", "(", "RLE_DEBUG", ")", "{", "System", ".", "out", ".", "println", "(", "\"[storeStaticField for field \"", "+", "st...
Store a static field. @param staticField the static field @param obj the instruction which stores the field @param pushStoredValue push the stored value onto the stack (because we are modeling an inner-class field access method)
[ "Store", "a", "static", "field", "." ]
f6365c6eea6515035bded38efa4a7c8b46ccf28c
https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/vna/ValueNumberFrameModelingVisitor.java#L831-L860
train