Java: Rename CallableMethod to Endpoint

This commit is contained in:
Koen Vlaswinkel
2023-09-20 13:57:27 +02:00
parent fee9640077
commit 6e78aac6cc
3 changed files with 36 additions and 34 deletions

View File

@@ -10,20 +10,22 @@
private import java
private import ModelEditor
class ExternalApi extends CallableMethod {
ExternalApi() { not this.fromSource() }
class ExternalEndpoint extends Endpoint {
ExternalEndpoint() { not this.fromSource() }
}
private Call aUsage(ExternalApi api) { result.getCallee().getSourceDeclaration() = api }
private Call aUsage(ExternalEndpoint endpoint) {
result.getCallee().getSourceDeclaration() = endpoint
}
from
ExternalApi externalApi, string apiName, boolean supported, Call usage, string type,
ExternalEndpoint endpoint, string apiName, boolean supported, Call usage, string type,
string classification
where
apiName = externalApi.getApiName() and
supported = isSupported(externalApi) and
usage = aUsage(externalApi) and
type = supportedType(externalApi) and
classification = methodClassification(usage)
select usage, apiName, supported.toString(), "supported", externalApi.jarContainer(),
externalApi.jarVersion(), type, "type", classification, "classification"
apiName = endpoint.getApiName() and
supported = isSupported(endpoint) and
usage = aUsage(endpoint) and
type = supportedType(endpoint) and
classification = usageClassification(usage)
select usage, apiName, supported.toString(), "supported", endpoint.jarContainer(),
endpoint.jarVersion(), type, "type", classification, "classification"

View File

@@ -11,13 +11,13 @@ private import java
private import semmle.code.java.dataflow.internal.ModelExclusions
private import ModelEditor
class PublicMethodFromSource extends CallableMethod, ModelApi { }
class PublicEndpointFromSource extends Endpoint, ModelApi { }
from PublicMethodFromSource publicMethod, string apiName, boolean supported, string type
from PublicEndpointFromSource endpoint, string apiName, boolean supported, string type
where
apiName = publicMethod.getApiName() and
supported = isSupported(publicMethod) and
type = supportedType(publicMethod)
select publicMethod, apiName, supported.toString(), "supported",
publicMethod.getCompilationUnit().getParentContainer().getBaseName(), "library", type, "type",
apiName = endpoint.getApiName() and
supported = isSupported(endpoint) and
type = supportedType(endpoint)
select endpoint, apiName, supported.toString(), "supported",
endpoint.getCompilationUnit().getParentContainer().getBaseName(), "library", type, "type",
"unknown", "classification"

View File

@@ -20,8 +20,8 @@ private predicate isUninteresting(Callable c) {
/**
* A callable method from either the Standard Library, a 3rd party library or from the source.
*/
class CallableMethod extends Callable {
CallableMethod() { not isUninteresting(this) }
class Endpoint extends Callable {
Endpoint() { not isUninteresting(this) }
/**
* Gets information about the external API in the form expected by the MaD modeling framework.
@@ -108,30 +108,30 @@ class CallableMethod extends Callable {
}
}
boolean isSupported(CallableMethod method) {
method.isSupported() and result = true
boolean isSupported(Endpoint endpoint) {
endpoint.isSupported() and result = true
or
not method.isSupported() and result = false
not endpoint.isSupported() and result = false
}
string supportedType(CallableMethod method) {
method.isSink() and result = "sink"
string supportedType(Endpoint endpoint) {
endpoint.isSink() and result = "sink"
or
method.isSource() and result = "source"
endpoint.isSource() and result = "source"
or
method.hasSummary() and result = "summary"
endpoint.hasSummary() and result = "summary"
or
method.isNeutral() and result = "neutral"
endpoint.isNeutral() and result = "neutral"
or
not method.isSupported() and result = ""
not endpoint.isSupported() and result = ""
}
string methodClassification(Call method) {
isInTestFile(method.getLocation().getFile()) and result = "test"
string usageClassification(Call usage) {
isInTestFile(usage.getLocation().getFile()) and result = "test"
or
method.getFile() instanceof GeneratedFile and result = "generated"
usage.getFile() instanceof GeneratedFile and result = "generated"
or
not isInTestFile(method.getLocation().getFile()) and
not method.getFile() instanceof GeneratedFile and
not isInTestFile(usage.getLocation().getFile()) and
not usage.getFile() instanceof GeneratedFile and
result = "source"
}