Java: Adjust comment style.

This commit is contained in:
Anders Schack-Mulligen
2018-10-11 13:48:56 +02:00
parent 24f30999a4
commit ade293407b
14 changed files with 73 additions and 174 deletions

View File

@@ -72,11 +72,8 @@ class CamelTargetClass extends Class {
or
exists(CamelJavaDSLMethodDecl methodDecl | this = methodDecl.getABean())
or
/*
* Any beans referred to in Java DSL bean or beanRef elements are considered as possible
* targets. Whether the route builder is ever constructed or called is not considered.
*/
// Any beans referred to in Java DSL bean or beanRef elements are considered as possible
// targets. Whether the route builder is ever constructed or called is not considered.
exists(CamelJavaDSLBeanDecl beanDecl | this = beanDecl.getABeanClass())
or
exists(CamelJavaDSLBeanRefDecl beanRefDecl | this = beanRefDecl.getABeanClass())

View File

@@ -1,4 +1,5 @@
/* Definitions related to JAXB. */
/** Definitions related to JAXB. */
import semmle.code.java.Type
library class JAXBElement extends Class {
@@ -39,11 +40,8 @@ class JaxbType extends Class {
or
hasJaxbAnnotation(this, "XmlRootElement")
or
/*
* There is at least one Jaxb annotation on a member of this class. The `@XmlType` is implied
* on any class, but we limit our identification to those that have some reference to JAXB.
*/
// There is at least one Jaxb annotation on a member of this class. The `@XmlType` is implied
// on any class, but we limit our identification to those that have some reference to JAXB.
exists(AnnotationType at |
at = this.getAMember().getAnAnnotation().getType() and
at instanceof JaxbMemberAnnotation
@@ -189,17 +187,11 @@ class JaxbBoundGetterSetter extends GetterOrSetterMethod {
or
// Within a JAXB type which has an `XmlAcessType` that binds this method.
exists(JaxbType c | this.getDeclaringType() = c |
/*
* If this is a "property" - both a setter and getter present for the XML element or attribute
* - the `XmlAccessType` of the declaring type may cause this property to be bound.
*/
// If this is a "property" - both a setter and getter present for the XML element or attribute
// - the `XmlAccessType` of the declaring type may cause this property to be bound.
isProperty() and
(
/*
* In the `PUBLIC_MEMBER` case all public properties are considered bound.
*/
// In the `PUBLIC_MEMBER` case all public properties are considered bound.
(c.getXmlAccessType().isPublicMember() and isPublic())
or
// In "property" all properties are considered bound.

View File

@@ -68,11 +68,8 @@ class JaxRsResourceClass extends Class {
or
// A sub-resource
exists(JaxRsResourceClass resourceClass, Method method |
/*
* This is a sub-resource class is if it is referred to from the sub-resource locator of
* another resource class.
*/
// This is a sub-resource class is if it is referred to from the sub-resource locator of
// another resource class.
method = resourceClass.getASubResourceLocator()
|
this = method.getReturnType()
@@ -118,11 +115,8 @@ class JaxRsResourceClass extends Class {
// JaxRs Spec v2.0 - 3.12
// Only root resources are constructed by the JaxRS container.
isRootResource() and
/*
* JaxRS can only construct the class using constructors that are public, and where the
* container can provide all of the parameters. This includes the no-arg constructor.
*/
// JaxRS can only construct the class using constructors that are public, and where the
// container can provide all of the parameters. This includes the no-arg constructor.
result.isPublic() and
forall(Parameter p | p = result.getAParameter() |
p.getAnAnnotation() instanceof JaxRsInjectionAnnotation

View File

@@ -142,11 +142,8 @@ class MockitoMockedField extends MockitoAnnotatedField {
exists(MockitoInjectedField injectedField |
injectedField.getDeclaringType() = getDeclaringType()
|
/*
* A `@Mock` is injected if it is used in one of the invoked callables (constructor or
* setter), or injected directly onto a field.
*/
// A `@Mock` is injected if it is used in one of the invoked callables (constructor or
// setter), or injected directly onto a field.
getType().(RefType).getAnAncestor() = injectedField.getAnInvokedCallable().getAParamType() or
getType().(RefType).getAnAncestor() = injectedField.getASetField().getType()
)
@@ -162,11 +159,8 @@ class MockitoInjectedField extends MockitoAnnotatedField {
override predicate isValid() {
super.isValid() and
(
/*
* If we need to initialize the field, it is only valid if the type is a `Class` that is not
* local, is static if it is a nested class, and is not abstract.
*/
// If we need to initialize the field, it is only valid if the type is a `Class` that is not
// local, is static if it is a nested class, and is not abstract.
exists(getInitializer())
or
exists(Class c | c = getType() |
@@ -176,10 +170,7 @@ class MockitoInjectedField extends MockitoAnnotatedField {
)
) and
(
/*
* If neither of these is true, then mockito will fail to initialize this field.
*/
// If neither of these is true, then mockito will fail to initialize this field.
usingConstructorInjection() or
usingPropertyInjection()
)
@@ -223,11 +214,8 @@ class MockitoInjectedField extends MockitoAnnotatedField {
|
if usingConstructorInjection()
then
/*
* If there is no initializer for this field, and there is a most mockable constructor,
* then we are doing a parameterized injection of mocks into a most mockable constructor.
*/
// If there is no initializer for this field, and there is a most mockable constructor,
// then we are doing a parameterized injection of mocks into a most mockable constructor.
result = mockInjectedClass.getAMostMockableConstructor()
else
if usingPropertyInjection()
@@ -239,21 +227,15 @@ class MockitoInjectedField extends MockitoAnnotatedField {
)
or
(
/*
* Perform property injection into setter fields, but only where there exists a mock
* that can be injected into the method. Otherwise, the setter method is never called.
*/
// Perform property injection into setter fields, but only where there exists a mock
// that can be injected into the method. Otherwise, the setter method is never called.
result = mockInjectedClass.getASetterMethod() and
exists(MockitoMockedField mockedField |
mockedField.getDeclaringType() = this.getDeclaringType() and
mockedField.isValid()
|
/*
* We make a simplifying assumption here - in theory, each mock can only be injected
* once, but we instead assume that there are sufficient mocks to go around.
*/
// We make a simplifying assumption here - in theory, each mock can only be injected
// once, but we instead assume that there are sufficient mocks to go around.
mockedField.getType().(RefType).getAnAncestor() = result.getParameterType(0)
)
)
@@ -276,11 +258,8 @@ class MockitoInjectedField extends MockitoAnnotatedField {
mockedField.getDeclaringType() = this.getDeclaringType() and
mockedField.isValid()
|
/*
* We make a simplifying assumption here - in theory, each mock can only be injected
* once, but we instead assume that there are sufficient mocks to go around.
*/
// We make a simplifying assumption here - in theory, each mock can only be injected
// once, but we instead assume that there are sufficient mocks to go around.
mockedField.getType().(RefType).getAnAncestor() = result.getType()
)
else none()

View File

@@ -317,11 +317,8 @@ class ServletWebXMLListenerType extends RefType {
hasQualifiedName("javax.servlet.http", "HttpSessionAttributeListener") or
hasQualifiedName("javax.servlet.http", "HttpSessionIdListener") or
hasQualifiedName("javax.servlet.http", "HttpSessionListener")
/*
* Listeners that are not configured in `web.xml`:
* - `HttpSessionActivationListener`
* - `HttpSessionBindingListener`
*/
}
// Listeners that are not configured in `web.xml`:
// - `HttpSessionActivationListener`
// - `HttpSessionBindingListener`
}
}

View File

@@ -59,11 +59,8 @@ class CamelJavaDSLBeanDecl extends ProcessorDefinitionElement {
RefType getABeanClass() {
if getArgument(0).getType() instanceof TypeClass
then
/*
* In this case, we've been given a Class<?>, which implies a Spring Bean of this type
* should be loaded. Infer the type of type parameter.
*/
// In this case, we've been given a Class<?>, which implies a Spring Bean of this type
// should be loaded. Infer the type of type parameter.
result = inferClassParameterType(getArgument(0))
else
// In this case, the object itself is used as the target for the Apache Camel messages.

View File

@@ -30,19 +30,13 @@ class GwtEntryPointClass extends Class {
* Holds if this entry point is live - that is, whether it is referred to within an XML element.
*/
predicate isLive() {
/*
* We must have a `*.gwt.xml` in order to determine whether a particular `EntryPoint` is enabled.
* In the absence of such a file, we cannot guarantee that `EntryPoint`s without annotations
* are live.
*/
// We must have a `*.gwt.xml` in order to determine whether a particular `EntryPoint` is enabled.
// In the absence of such a file, we cannot guarantee that `EntryPoint`s without annotations
// are live.
isGwtXmlIncluded()
implies
(
/*
* The entry point is live if it is specified in a `*.gwt.xml` file.
*/
// The entry point is live if it is specified in a `*.gwt.xml` file.
exists(getAGwtXmlFile())
)
}

View File

@@ -204,11 +204,8 @@ class JacksonMixedInCallable extends Callable {
result = getATargetType().getACallable() and
if this instanceof Constructor
then
/*
* The mixed in type will have a different name to the target type, so just compare the
* parameters.
*/
// The mixed in type will have a different name to the target type, so just compare the
// parameters.
result.getSignature().suffix(targetType.getName().length()) = getSignature()
.suffix(getDeclaringType().getName().length())
else

View File

@@ -21,11 +21,8 @@ class PersistentEntity extends RefType {
if exists(getAccessTypeFromAnnotation())
then result = getAccessTypeFromAnnotation()
else
/*
* If the access type is not explicit, then the location of the `Id` annotation determines
* which access type is used.
*/
// If the access type is not explicit, then the location of the `Id` annotation determines
// which access type is used.
if getAMethod().hasAnnotation("javax.persistence", "Id")
then result = "property"
else result = "field"

View File

@@ -23,10 +23,7 @@ predicate hasInjectAnnotation(Annotatable a) {
*/
class SpringComponentConstructor extends Constructor {
SpringComponentConstructor() {
/*
* Must be a live Spring component.
*/
// Must be a live Spring component.
getDeclaringType().(SpringComponent).isLive() and
(
this.getNumberOfParameters() = 0 or
@@ -63,10 +60,7 @@ class SpringBeanPropertySetterMethod extends Method {
*/
class SpringBeanXMLAutowiredSetterMethod extends Method {
SpringBeanXMLAutowiredSetterMethod() {
/*
* The bean as marked with some form of autowiring in the XML file.
*/
// The bean as marked with some form of autowiring in the XML file.
exists(string xmlAutowire |
xmlAutowire = this.getDeclaringType().(SpringBeanRefType).getSpringBean().getAutowire()
|
@@ -95,11 +89,8 @@ class SpringBeanXMLAutowiredSetterMethod extends Method {
xmlAutowire = "byType"
or
(
/*
* When it is set to autodetect, we use "byType" if there is a no-arg constructor. This
* approach has been removed in Spring 4.x.
*/
// When it is set to autodetect, we use "byType" if there is a no-arg constructor. This
// approach has been removed in Spring 4.x.
xmlAutowire = "autodetect" and
exists(Constructor c | c = this.getDeclaringType().getAConstructor() |
c.getNumberOfParameters() = 0

View File

@@ -40,10 +40,7 @@ class SpringCamelXMLRouteContext extends SpringCamelXMLElement {
*/
class SpringCamelXMLRoute extends SpringCamelXMLElement {
SpringCamelXMLRoute() {
/*
* A route must either be in a `<routeContext>` or a `<camelContext>`.
*/
// A route must either be in a `<routeContext>` or a `<camelContext>`.
(
getParent() instanceof SpringCamelXMLRouteContext or
getParent() instanceof SpringCamelXMLContext

View File

@@ -42,10 +42,7 @@ class SpringComponentScan extends Annotation {
result = getAValue("value").(StringLiteral).getRepresentedString()
or
exists(TypeLiteral typeLiteral |
/*
* Base package classes are type literals whose package should be considered a base package.
*/
// Base package classes are type literals whose package should be considered a base package.
typeLiteral = getAValue("basePackageClasses")
|
result = typeLiteral.getTypeName().getType().(RefType).getPackage().getName()
@@ -60,11 +57,8 @@ class SpringComponentScan extends Annotation {
class SpringBasePackage extends string {
SpringBasePackage() {
exists(string basePackages |
/*
* Interpret the contexts of the `web.xml` "contextConfigLocation" parameter as a base package,
* but only if the appropriate context class is chosen.
*/
// Interpret the contexts of the `web.xml` "contextConfigLocation" parameter as a base package,
// but only if the appropriate context class is chosen.
exists(WebXMLFile webXML |
webXML.getContextParamValue("contextClass") = "org.springframework.web.context.support.AnnotationConfigWebApplicationContext"
|
@@ -75,11 +69,8 @@ class SpringBasePackage extends string {
c.hasAnnotation("org.springframework.context.annotation", "Configuration") and
componentScan = c.getAnAnnotation() and
basePackages = componentScan.(SpringComponentScan).getBasePackages() and
/*
* For a `@ComponentScan` annotation to take effect, the configuration class must already be
* picked up by the component scan.
*/
// For a `@ComponentScan` annotation to take effect, the configuration class must already be
// picked up by the component scan.
c.isLive()
)
or
@@ -177,16 +168,13 @@ class SpringComponent extends RefType {
* we need the XML files to accurately determine the component scan.
*/
predicate isLive() {
/*
* Components all have to be registered with Spring. They are usually registered by being
* identified during a component scan, which traverses the class path looking for components in
* particular base packages. Base packages can be defined either using the `@ComponentScan`
* annotation, on an `@Configuration` class, or in an XML configuration file. We can therefore
* only validate whether this class is ever picked up if XML indexing is enabled. If it's
* enabled, then the package of this class must belong in one of the packages defined as a base
* package.
*/
// Components all have to be registered with Spring. They are usually registered by being
// identified during a component scan, which traverses the class path looking for components in
// particular base packages. Base packages can be defined either using the `@ComponentScan`
// annotation, on an `@Configuration` class, or in an XML configuration file. We can therefore
// only validate whether this class is ever picked up if XML indexing is enabled. If it's
// enabled, then the package of this class must belong in one of the packages defined as a base
// package.
not isSpringXMLEnabled()
or
(

View File

@@ -32,12 +32,9 @@ abstract class SpringControllerMethod extends Method {
*/
class SpringModelAttributeMethod extends SpringControllerMethod {
SpringModelAttributeMethod() {
/*
* Any method that declares the @ModelAttribute annotation, or overrides a method that declares
* the annotation. We have to do this explicit check because the @ModelAttribute annotation is
* not declared with @Inherited.
*/
// Any method that declares the @ModelAttribute annotation, or overrides a method that declares
// the annotation. We have to do this explicit check because the @ModelAttribute annotation is
// not declared with @Inherited.
exists(Method superMethod |
this.overrides*(superMethod) and
superMethod.hasAnnotation("org.springframework.web.bind.annotation", "ModelAttribute")
@@ -50,12 +47,9 @@ class SpringModelAttributeMethod extends SpringControllerMethod {
*/
class SpringInitBinderMethod extends SpringControllerMethod {
SpringInitBinderMethod() {
/*
* Any method that declares the @InitBinder annotation, or overrides a method that declares
* the annotation. We have to do this explicit check because the @InitBinder annotation is
* not declared with @Inherited.
*/
// Any method that declares the @InitBinder annotation, or overrides a method that declares
// the annotation. We have to do this explicit check because the @InitBinder annotation is
// not declared with @Inherited.
exists(Method superMethod |
this.overrides*(superMethod) and
superMethod.hasAnnotation("org.springframework.web.bind.annotation", "InitBinder")
@@ -68,12 +62,9 @@ class SpringInitBinderMethod extends SpringControllerMethod {
*/
class SpringRequestMappingMethod extends SpringControllerMethod {
SpringRequestMappingMethod() {
/*
* Any method that declares the @RequestMapping annotation, or overrides a method that declares
* the annotation. We have to do this explicit check because the @RequestMapping annotation is
* not declared with @Inherited.
*/
// Any method that declares the @RequestMapping annotation, or overrides a method that declares
// the annotation. We have to do this explicit check because the @RequestMapping annotation is
// not declared with @Inherited.
exists(Method superMethod |
this.overrides*(superMethod) and
superMethod.hasAnnotation("org.springframework.web.bind.annotation", "RequestMapping")

View File

@@ -15,26 +15,17 @@ private string getStrutsMapperClass(RefType refType) {
class Struts2ActionClass extends Class {
Struts2ActionClass() {
(
/*
* If there are no XML files present, then we assume we any class that extends a struts 2
* action must be reflectively constructed, as we have no better indication.
*/
// If there are no XML files present, then we assume we any class that extends a struts 2
// action must be reflectively constructed, as we have no better indication.
not exists(XMLFile xmlFile) and
this.getAnAncestor().hasQualifiedName("com.opensymphony.xwork2", "Action")
)
or
/*
* If there is a struts.xml file, then any class that is specified as an action is considered
* to be reflectively constructed.
*/
// If there is a struts.xml file, then any class that is specified as an action is considered
// to be reflectively constructed.
exists(StrutsXMLAction strutsAction | this = strutsAction.getActionClass())
or
/*
* We have determined that this is an action class due to the conventions plugin.
*/
// We have determined that this is an action class due to the conventions plugin.
this instanceof Struts2ConventionActionClass
}
@@ -59,11 +50,8 @@ class Struts2ActionClass extends Class {
getStrutsMapperClass(this) = "org.apache.struts2.rest.RestActionMapper" or
getStrutsMapperClass(this) = "rest"
then (
/*
* The "Rest" action mapper is provided with the rest plugin, and maps rest APIs to specific
* methods based on a "ruby-on-rails" style.
*/
// The "Rest" action mapper is provided with the rest plugin, and maps rest APIs to specific
// methods based on a "ruby-on-rails" style.
result.hasName("index") or
result.hasName("show") or
result.hasName("edit") or