From ade293407bdb66d8cee709e27776d50d70d561e8 Mon Sep 17 00:00:00 2001 From: Anders Schack-Mulligen Date: Thu, 11 Oct 2018 13:48:56 +0200 Subject: [PATCH] Java: Adjust comment style. --- .../src/semmle/code/java/frameworks/Camel.qll | 7 +-- .../src/semmle/code/java/frameworks/JAXB.qll | 22 +++------ .../src/semmle/code/java/frameworks/JaxWS.qll | 14 ++---- .../semmle/code/java/frameworks/Mockito.qll | 47 +++++-------------- .../semmle/code/java/frameworks/Servlets.qll | 11 ++--- .../java/frameworks/camel/CamelJavaDSL.qll | 7 +-- .../semmle/code/java/frameworks/gwt/GWT.qll | 14 ++---- .../jackson/JacksonSerializability.qll | 7 +-- .../java/frameworks/javaee/Persistence.qll | 7 +-- .../java/frameworks/spring/SpringAutowire.qll | 17 ++----- .../java/frameworks/spring/SpringCamel.qll | 5 +- .../frameworks/spring/SpringComponentScan.qll | 36 +++++--------- .../frameworks/spring/SpringController.qll | 27 ++++------- .../java/frameworks/struts/StrutsActions.qll | 26 +++------- 14 files changed, 73 insertions(+), 174 deletions(-) diff --git a/java/ql/src/semmle/code/java/frameworks/Camel.qll b/java/ql/src/semmle/code/java/frameworks/Camel.qll index 894083252ea..6e93a2d82ba 100644 --- a/java/ql/src/semmle/code/java/frameworks/Camel.qll +++ b/java/ql/src/semmle/code/java/frameworks/Camel.qll @@ -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()) diff --git a/java/ql/src/semmle/code/java/frameworks/JAXB.qll b/java/ql/src/semmle/code/java/frameworks/JAXB.qll index 6d68b54ac9d..1a4170f33bc 100644 --- a/java/ql/src/semmle/code/java/frameworks/JAXB.qll +++ b/java/ql/src/semmle/code/java/frameworks/JAXB.qll @@ -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. diff --git a/java/ql/src/semmle/code/java/frameworks/JaxWS.qll b/java/ql/src/semmle/code/java/frameworks/JaxWS.qll index 5699ebcc03e..b13e18cf16b 100644 --- a/java/ql/src/semmle/code/java/frameworks/JaxWS.qll +++ b/java/ql/src/semmle/code/java/frameworks/JaxWS.qll @@ -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 diff --git a/java/ql/src/semmle/code/java/frameworks/Mockito.qll b/java/ql/src/semmle/code/java/frameworks/Mockito.qll index 4973b6fcd05..b6585089dca 100644 --- a/java/ql/src/semmle/code/java/frameworks/Mockito.qll +++ b/java/ql/src/semmle/code/java/frameworks/Mockito.qll @@ -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() diff --git a/java/ql/src/semmle/code/java/frameworks/Servlets.qll b/java/ql/src/semmle/code/java/frameworks/Servlets.qll index 27fa9cba4e0..aa725596c84 100644 --- a/java/ql/src/semmle/code/java/frameworks/Servlets.qll +++ b/java/ql/src/semmle/code/java/frameworks/Servlets.qll @@ -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` + } } diff --git a/java/ql/src/semmle/code/java/frameworks/camel/CamelJavaDSL.qll b/java/ql/src/semmle/code/java/frameworks/camel/CamelJavaDSL.qll index a9cba4468df..1d1f852e937 100644 --- a/java/ql/src/semmle/code/java/frameworks/camel/CamelJavaDSL.qll +++ b/java/ql/src/semmle/code/java/frameworks/camel/CamelJavaDSL.qll @@ -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. diff --git a/java/ql/src/semmle/code/java/frameworks/gwt/GWT.qll b/java/ql/src/semmle/code/java/frameworks/gwt/GWT.qll index 9363875ec6f..4ce38e44001 100644 --- a/java/ql/src/semmle/code/java/frameworks/gwt/GWT.qll +++ b/java/ql/src/semmle/code/java/frameworks/gwt/GWT.qll @@ -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()) ) } diff --git a/java/ql/src/semmle/code/java/frameworks/jackson/JacksonSerializability.qll b/java/ql/src/semmle/code/java/frameworks/jackson/JacksonSerializability.qll index 2b750cba3ba..da4fdc817b3 100644 --- a/java/ql/src/semmle/code/java/frameworks/jackson/JacksonSerializability.qll +++ b/java/ql/src/semmle/code/java/frameworks/jackson/JacksonSerializability.qll @@ -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 diff --git a/java/ql/src/semmle/code/java/frameworks/javaee/Persistence.qll b/java/ql/src/semmle/code/java/frameworks/javaee/Persistence.qll index 4075fa049bf..9347be7f345 100644 --- a/java/ql/src/semmle/code/java/frameworks/javaee/Persistence.qll +++ b/java/ql/src/semmle/code/java/frameworks/javaee/Persistence.qll @@ -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" diff --git a/java/ql/src/semmle/code/java/frameworks/spring/SpringAutowire.qll b/java/ql/src/semmle/code/java/frameworks/spring/SpringAutowire.qll index 197393402ad..344a238fb9c 100644 --- a/java/ql/src/semmle/code/java/frameworks/spring/SpringAutowire.qll +++ b/java/ql/src/semmle/code/java/frameworks/spring/SpringAutowire.qll @@ -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 diff --git a/java/ql/src/semmle/code/java/frameworks/spring/SpringCamel.qll b/java/ql/src/semmle/code/java/frameworks/spring/SpringCamel.qll index ee71b0e4a4d..3cbbf6acf11 100644 --- a/java/ql/src/semmle/code/java/frameworks/spring/SpringCamel.qll +++ b/java/ql/src/semmle/code/java/frameworks/spring/SpringCamel.qll @@ -40,10 +40,7 @@ class SpringCamelXMLRouteContext extends SpringCamelXMLElement { */ class SpringCamelXMLRoute extends SpringCamelXMLElement { SpringCamelXMLRoute() { - /* - * A route must either be in a `` or a ``. - */ - + // A route must either be in a `` or a ``. ( getParent() instanceof SpringCamelXMLRouteContext or getParent() instanceof SpringCamelXMLContext diff --git a/java/ql/src/semmle/code/java/frameworks/spring/SpringComponentScan.qll b/java/ql/src/semmle/code/java/frameworks/spring/SpringComponentScan.qll index e8c811a373d..bf413499035 100644 --- a/java/ql/src/semmle/code/java/frameworks/spring/SpringComponentScan.qll +++ b/java/ql/src/semmle/code/java/frameworks/spring/SpringComponentScan.qll @@ -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 ( diff --git a/java/ql/src/semmle/code/java/frameworks/spring/SpringController.qll b/java/ql/src/semmle/code/java/frameworks/spring/SpringController.qll index e7a3b063ae8..f98119e396d 100644 --- a/java/ql/src/semmle/code/java/frameworks/spring/SpringController.qll +++ b/java/ql/src/semmle/code/java/frameworks/spring/SpringController.qll @@ -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") diff --git a/java/ql/src/semmle/code/java/frameworks/struts/StrutsActions.qll b/java/ql/src/semmle/code/java/frameworks/struts/StrutsActions.qll index 711f44ac62c..d329920ab7e 100644 --- a/java/ql/src/semmle/code/java/frameworks/struts/StrutsActions.qll +++ b/java/ql/src/semmle/code/java/frameworks/struts/StrutsActions.qll @@ -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