Skip to content

Commit

Permalink
style: enable checkstyle modules for name checking (#1411)
Browse files Browse the repository at this point in the history
enable MemberName, ParameterName, TypeName and LocalVariableName checkstyle modules
  • Loading branch information
AlexElin authored and davecramer committed Feb 17, 2019
1 parent 61cc275 commit 6b124a0
Show file tree
Hide file tree
Showing 65 changed files with 1,261 additions and 1,207 deletions.
27 changes: 6 additions & 21 deletions pgjdbc/src/main/checkstyle/checks.xml
Expand Up @@ -115,33 +115,18 @@
value="Package name ''{0}'' must match pattern ''{1}''."/> value="Package name ''{0}'' must match pattern ''{1}''."/>
</module> </module>
<module name="EqualsHashCode"/> <module name="EqualsHashCode"/>
<!--<module name="TypeName"> <module name="MemberName"/>
<message key="name.invalidPattern" <module name="ParameterName"/>
value="Type name ''{0}'' must match pattern ''{1}''."/> <module name="TypeName"/>
</module> <module name="LocalVariableName">
<module name="MemberName"> <property name="allowOneCharVarInForLoop" value="true"/>
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/>
<message key="name.invalidPattern"
value="Member name ''{0}'' must match pattern ''{1}''."/>
</module> </module>
<module name="ParameterName">
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/>
<message key="name.invalidPattern"
value="Parameter name ''{0}'' must match pattern ''{1}''."/>
</module>-->
<!-- Not yet supported by Checkstyle-IDEA <module name="CatchParameterName"> <!-- Not yet supported by Checkstyle-IDEA <module name="CatchParameterName">
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/> <property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/>
<message key="name.invalidPattern" <message key="name.invalidPattern"
value="Catch parameter name ''{0}'' must match pattern ''{1}''."/> value="Catch parameter name ''{0}'' must match pattern ''{1}''."/>
</module> --> </module> -->
<!-- <module name="LocalVariableName"> <!-- <module name="ClassTypeParameterName">
<property name="tokens" value="VARIABLE_DEF"/>
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/>
<property name="allowOneCharVarInForLoop" value="true"/>
<message key="name.invalidPattern"
value="Local variable name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="ClassTypeParameterName">
<property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/> <property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
<message key="name.invalidPattern" <message key="name.invalidPattern"
value="Class type name ''{0}'' must match pattern ''{1}''."/> value="Class type name ''{0}'' must match pattern ''{1}''."/>
Expand Down
36 changes: 18 additions & 18 deletions pgjdbc/src/main/java/org/postgresql/Driver.java
Expand Up @@ -541,31 +541,31 @@ public boolean jdbcCompliant() {
public static Properties parseURL(String url, Properties defaults) { public static Properties parseURL(String url, Properties defaults) {
Properties urlProps = new Properties(defaults); Properties urlProps = new Properties(defaults);


String l_urlServer = url; String urlServer = url;
String l_urlArgs = ""; String urlArgs = "";


int l_qPos = url.indexOf('?'); int qPos = url.indexOf('?');
if (l_qPos != -1) { if (qPos != -1) {
l_urlServer = url.substring(0, l_qPos); urlServer = url.substring(0, qPos);
l_urlArgs = url.substring(l_qPos + 1); urlArgs = url.substring(qPos + 1);
} }


if (!l_urlServer.startsWith("jdbc:postgresql:")) { if (!urlServer.startsWith("jdbc:postgresql:")) {
LOGGER.log(Level.FINE, "JDBC URL must start with \"jdbc:postgresql:\" but was: {0}", url); LOGGER.log(Level.FINE, "JDBC URL must start with \"jdbc:postgresql:\" but was: {0}", url);
return null; return null;
} }
l_urlServer = l_urlServer.substring("jdbc:postgresql:".length()); urlServer = urlServer.substring("jdbc:postgresql:".length());


if (l_urlServer.startsWith("//")) { if (urlServer.startsWith("//")) {
l_urlServer = l_urlServer.substring(2); urlServer = urlServer.substring(2);
int slash = l_urlServer.indexOf('/'); int slash = urlServer.indexOf('/');
if (slash == -1) { if (slash == -1) {
LOGGER.log(Level.WARNING, "JDBC URL must contain a / at the end of the host or port: {0}", url); LOGGER.log(Level.WARNING, "JDBC URL must contain a / at the end of the host or port: {0}", url);
return null; return null;
} }
urlProps.setProperty("PGDBNAME", URLCoder.decode(l_urlServer.substring(slash + 1))); urlProps.setProperty("PGDBNAME", URLCoder.decode(urlServer.substring(slash + 1)));


String[] addresses = l_urlServer.substring(0, slash).split(","); String[] addresses = urlServer.substring(0, slash).split(",");
StringBuilder hosts = new StringBuilder(); StringBuilder hosts = new StringBuilder();
StringBuilder ports = new StringBuilder(); StringBuilder ports = new StringBuilder();
for (String address : addresses) { for (String address : addresses) {
Expand Down Expand Up @@ -607,21 +607,21 @@ public static Properties parseURL(String url, Properties defaults) {
urlProps.setProperty("PGHOST", "localhost"); urlProps.setProperty("PGHOST", "localhost");
} }
if (defaults == null || !defaults.containsKey("PGDBNAME")) { if (defaults == null || !defaults.containsKey("PGDBNAME")) {
urlProps.setProperty("PGDBNAME", URLCoder.decode(l_urlServer)); urlProps.setProperty("PGDBNAME", URLCoder.decode(urlServer));
} }
} }


// parse the args part of the url // parse the args part of the url
String[] args = l_urlArgs.split("&"); String[] args = urlArgs.split("&");
for (String token : args) { for (String token : args) {
if (token.isEmpty()) { if (token.isEmpty()) {
continue; continue;
} }
int l_pos = token.indexOf('='); int pos = token.indexOf('=');
if (l_pos == -1) { if (pos == -1) {
urlProps.setProperty(token, ""); urlProps.setProperty(token, "");
} else { } else {
urlProps.setProperty(token.substring(0, l_pos), URLCoder.decode(token.substring(l_pos + 1))); urlProps.setProperty(token.substring(0, pos), URLCoder.decode(token.substring(pos + 1)));
} }
} }


Expand Down
46 changes: 23 additions & 23 deletions pgjdbc/src/main/java/org/postgresql/PGProperty.java
Expand Up @@ -434,11 +434,11 @@ public enum PGProperty {
+ "from that database. " + "from that database. "
+ "(backend >= 9.4)"); + "(backend >= 9.4)");


private String _name; private final String name;
private String _defaultValue; private final String defaultValue;
private boolean _required; private final boolean required;
private String _description; private final String description;
private String[] _choices; private final String[] choices;


PGProperty(String name, String defaultValue, String description) { PGProperty(String name, String defaultValue, String description) {
this(name, defaultValue, description, false); this(name, defaultValue, description, false);
Expand All @@ -450,11 +450,11 @@ public enum PGProperty {


PGProperty(String name, String defaultValue, String description, boolean required, PGProperty(String name, String defaultValue, String description, boolean required,
String... choices) { String... choices) {
_name = name; this.name = name;
_defaultValue = defaultValue; this.defaultValue = defaultValue;
_required = required; this.required = required;
_description = description; this.description = description;
_choices = choices; this.choices = choices;
} }


/** /**
Expand All @@ -464,7 +464,7 @@ public enum PGProperty {
* @return the name of the connection parameter * @return the name of the connection parameter
*/ */
public String getName() { public String getName() {
return _name; return name;
} }


/** /**
Expand All @@ -473,7 +473,7 @@ public String getName() {
* @return the default value for this connection parameter or null * @return the default value for this connection parameter or null
*/ */
public String getDefaultValue() { public String getDefaultValue() {
return _defaultValue; return defaultValue;
} }


/** /**
Expand All @@ -482,7 +482,7 @@ public String getDefaultValue() {
* @return the available values for this connection parameter or null * @return the available values for this connection parameter or null
*/ */
public String[] getChoices() { public String[] getChoices() {
return _choices; return choices;
} }


/** /**
Expand All @@ -493,7 +493,7 @@ public String[] getChoices() {
* @return evaluated value for this connection parameter * @return evaluated value for this connection parameter
*/ */
public String get(Properties properties) { public String get(Properties properties) {
return properties.getProperty(_name, _defaultValue); return properties.getProperty(name, defaultValue);
} }


/** /**
Expand All @@ -504,9 +504,9 @@ public String get(Properties properties) {
*/ */
public void set(Properties properties, String value) { public void set(Properties properties, String value) {
if (value == null) { if (value == null) {
properties.remove(_name); properties.remove(name);
} else { } else {
properties.setProperty(_name, value); properties.setProperty(name, value);
} }
} }


Expand Down Expand Up @@ -577,7 +577,7 @@ public Integer getInteger(Properties properties) throws PSQLException {
* @param value boolean value for this connection parameter * @param value boolean value for this connection parameter
*/ */
public void set(Properties properties, boolean value) { public void set(Properties properties, boolean value) {
properties.setProperty(_name, Boolean.toString(value)); properties.setProperty(name, Boolean.toString(value));
} }


/** /**
Expand All @@ -587,7 +587,7 @@ public void set(Properties properties, boolean value) {
* @param value int value for this connection parameter * @param value int value for this connection parameter
*/ */
public void set(Properties properties, int value) { public void set(Properties properties, int value) {
properties.setProperty(_name, Integer.toString(value)); properties.setProperty(name, Integer.toString(value));
} }


/** /**
Expand All @@ -608,10 +608,10 @@ public boolean isPresent(Properties properties) {
* @return a DriverPropertyInfo representing this connection parameter * @return a DriverPropertyInfo representing this connection parameter
*/ */
public DriverPropertyInfo toDriverPropertyInfo(Properties properties) { public DriverPropertyInfo toDriverPropertyInfo(Properties properties) {
DriverPropertyInfo propertyInfo = new DriverPropertyInfo(_name, get(properties)); DriverPropertyInfo propertyInfo = new DriverPropertyInfo(name, get(properties));
propertyInfo.required = _required; propertyInfo.required = required;
propertyInfo.description = _description; propertyInfo.description = description;
propertyInfo.choices = _choices; propertyInfo.choices = choices;
return propertyInfo; return propertyInfo;
} }


Expand All @@ -632,7 +632,7 @@ public static PGProperty forName(String name) {
* @return the value of a set property * @return the value of a set property
*/ */
public String getSetString(Properties properties) { public String getSetString(Properties properties) {
Object o = properties.get(_name); Object o = properties.get(name);
if (o instanceof String) { if (o instanceof String) {
return (String) o; return (String) o;
} }
Expand Down
4 changes: 2 additions & 2 deletions pgjdbc/src/main/java/org/postgresql/core/BaseStatement.java
Expand Up @@ -44,13 +44,13 @@ ResultSet createResultSet(Query originalQuery, Field[] fields, List<byte[][]> tu
/** /**
* Execute a query, passing additional query flags. * Execute a query, passing additional query flags.
* *
* @param p_sql the query to execute (JDBC-style query) * @param sql the query to execute (JDBC-style query)
* @param flags additional {@link QueryExecutor} flags for execution; these are bitwise-ORed into * @param flags additional {@link QueryExecutor} flags for execution; these are bitwise-ORed into
* the default flags. * the default flags.
* @return true if there is a result set * @return true if there is a result set
* @throws SQLException if something goes wrong. * @throws SQLException if something goes wrong.
*/ */
boolean executeWithFlags(String p_sql, int flags) throws SQLException; boolean executeWithFlags(String sql, int flags) throws SQLException;


/** /**
* Execute a query, passing additional query flags. * Execute a query, passing additional query flags.
Expand Down
27 changes: 14 additions & 13 deletions pgjdbc/src/main/java/org/postgresql/core/Notification.java
Expand Up @@ -8,37 +8,38 @@
import org.postgresql.PGNotification; import org.postgresql.PGNotification;


public class Notification implements PGNotification { public class Notification implements PGNotification {
public Notification(String p_name, int p_pid) {
this(p_name, p_pid, ""); private final String name;
private final String parameter;
private final int pid;

public Notification(String name, int pid) {
this(name, pid, "");
} }


public Notification(String p_name, int p_pid, String p_parameter) { public Notification(String name, int pid, String parameter) {
m_name = p_name; this.name = name;
m_pid = p_pid; this.pid = pid;
m_parameter = p_parameter; this.parameter = parameter;
} }


/* /*
* Returns name of this notification * Returns name of this notification
*/ */
public String getName() { public String getName() {
return m_name; return name;
} }


/* /*
* Returns the process id of the backend process making this notification * Returns the process id of the backend process making this notification
*/ */
public int getPID() { public int getPID() {
return m_pid; return pid;
} }


public String getParameter() { public String getParameter() {
return m_parameter; return parameter;
} }


private String m_name;
private String m_parameter;
private int m_pid;

} }


6 changes: 3 additions & 3 deletions pgjdbc/src/main/java/org/postgresql/core/PGBindException.java
Expand Up @@ -9,13 +9,13 @@


public class PGBindException extends IOException { public class PGBindException extends IOException {


private IOException _ioe; private final IOException ioe;


public PGBindException(IOException ioe) { public PGBindException(IOException ioe) {
_ioe = ioe; this.ioe = ioe;
} }


public IOException getIOException() { public IOException getIOException() {
return _ioe; return ioe;
} }
} }

0 comments on commit 6b124a0

Please sign in to comment.