Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using static modifier to normalize methods contract and performance #198

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/org/apache/tools/ant/AntClassLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,7 @@ protected synchronized Class<?> loadClass(final String classname, final boolean
*
* @return the classname in filesystem format (eg java/lang/Integer.class)
*/
private String getClassFilename(final String classname) {
private static String getClassFilename(final String classname) {
return classname.replace('.', '/') + ".class";
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/org/apache/tools/ant/AntTypeDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ public boolean similarDefinition(AntTypeDefinition other, Project project) {
.equals(((AntClassLoader) newLoader).getClasspath()));
}

private String extractClassname(Class<?> c) {
private static String extractClassname(Class<?> c) {
return (c == null) ? "<null>" : c.getName();
}
}
6 changes: 3 additions & 3 deletions src/main/org/apache/tools/ant/ArgumentProcessorRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void registerArgumentProcessor(
registerArgumentProcessor(getProcessor(helperClass));
}

private ArgumentProcessor getProcessor(String helperClassName) {
private static ArgumentProcessor getProcessor(String helperClassName) {
try {
@SuppressWarnings("unchecked")
Class< ? extends ArgumentProcessor> cl = (Class< ? extends ArgumentProcessor>) Class.forName(helperClassName);
Expand All @@ -118,7 +118,7 @@ private ArgumentProcessor getProcessor(String helperClassName) {
}
}

private ArgumentProcessor getProcessor(
private static ArgumentProcessor getProcessor(
Class< ? extends ArgumentProcessor> processorClass) {
ArgumentProcessor processor;
try {
Expand All @@ -143,7 +143,7 @@ public void registerArgumentProcessor(ArgumentProcessor processor) {
}
}

private ArgumentProcessor getProcessorByService(InputStream is)
private static ArgumentProcessor getProcessorByService(InputStream is)
throws IOException {
try (BufferedReader rd = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) {
String processorClassName = rd.readLine();
Expand Down
4 changes: 2 additions & 2 deletions src/main/org/apache/tools/ant/ComponentHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,7 @@ private void printUnknownDefinition(PrintWriter out, String componentName, Strin
/**
* Print class not found.
*/
private void printClassNotFound(PrintWriter out, String classname, boolean optional,
private static void printClassNotFound(PrintWriter out, String classname, boolean optional,
String dirListing) {
out.println("Cause: the class " + classname + " was not found.");
if (optional) {
Expand All @@ -1044,7 +1044,7 @@ private void printClassNotFound(PrintWriter out, String classname, boolean optio
/**
* Print could not load dependent class.
*/
private void printNotLoadDependentClass(PrintWriter out, boolean optional,
private static void printNotLoadDependentClass(PrintWriter out, boolean optional,
NoClassDefFoundError ncdfe, String dirListing) {
out.println("Cause: Could not load a dependent class "
+ ncdfe.getMessage());
Expand Down
2 changes: 1 addition & 1 deletion src/main/org/apache/tools/ant/DirectoryScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -1438,7 +1438,7 @@ && isMorePowerfulThanExcludes(tokenizedName.toString())
* @return whether the pattern is deeper than the name.
* @since Ant 1.6.3
*/
private boolean isDeeper(final TokenizedPattern pattern, final TokenizedPath name) {
private static boolean isDeeper(final TokenizedPattern pattern, final TokenizedPath name) {
return pattern.containsPattern(SelectorUtils.DEEP_TREE_MATCH)
|| pattern.depth() > name.depth();
}
Expand Down
20 changes: 10 additions & 10 deletions src/main/org/apache/tools/ant/IntrospectionHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ private IntrospectionHelper(final Class<?> bean) {
* @param type the type of the set method's parameter
* @return true if the given set method is to be hidden.
*/
private boolean isHiddenSetMethod(final String name, final Class<?> type) {
private static boolean isHiddenSetMethod(final String name, final Class<?> type) {
return "setLocation".equals(name) && Location.class.equals(type)
|| "setTaskType".equals(name) && String.class.equals(type);
}
Expand Down Expand Up @@ -517,7 +517,7 @@ public void addText(final Project project, final Object element, String text)
* @param parent the object which doesn't support a requested element
* @param elementName the name of the Element which is trying to be created.
*/
public void throwNotSupported(final Project project, final Object parent, final String elementName) {
public static void throwNotSupported(final Project project, final Object parent, final String elementName) {
final String msg = project.getElementName(parent)
+ NOT_SUPPORTED_CHILD_PREFIX + elementName
+ NOT_SUPPORTED_CHILD_POSTFIX;
Expand Down Expand Up @@ -581,7 +581,7 @@ Object create(final Project project, final Object parent, final Object ignore) {
*
* @since Ant 1.8.0.
*/
private Object createDynamicElement(final Object parent, final String ns,
private static Object createDynamicElement(final Object parent, final String ns,
final String localName, final String qName) {
Object nestedElement = null;
if (parent instanceof DynamicElementNS) {
Expand Down Expand Up @@ -1035,7 +1035,7 @@ public List<Method> getExtensionPoints() {
* @return an appropriate AttributeSetter instance, or <code>null</code>
* if no appropriate conversion is available.
*/
private AttributeSetter createAttributeSetter(final Method m,
private static AttributeSetter createAttributeSetter(final Method m,
final Class<?> arg,
final String attrName) {
if (Optional.class.equals(arg)) {
Expand Down Expand Up @@ -1274,7 +1274,7 @@ public Object toTargetType(Project project, String value) {
};
}

private AttributeSetter getEnumSetter(
private static AttributeSetter getEnumSetter(
final Class<?> reflectedArg, final Method m, final Class<?> arg) {
if (reflectedArg.isEnum()) {
return new AttributeSetter(m, arg) {
Expand Down Expand Up @@ -1308,7 +1308,7 @@ public Enum<?> toTargetType(Project project, String value) {
*
* @return a description of the element type
*/
private String getElementName(final Project project, final Object element) {
private static String getElementName(final Project project, final Object element) {
return project.getElementName(element);
}

Expand Down Expand Up @@ -1672,7 +1672,7 @@ private void insertAddTypeMethod(final Method method) {
* @param methods the <code>List</code> of methods to search.
* @return a matching <code>Method</code>; null if none found.
*/
private Method findMatchingMethod(final Class<?> paramClass, final List<Method> methods) {
private static Method findMatchingMethod(final Class<?> paramClass, final List<Method> methods) {
if (paramClass == null) {
return null;
}
Expand All @@ -1694,7 +1694,7 @@ private Method findMatchingMethod(final Class<?> paramClass, final List<Method>
return matchedMethod;
}

private String condenseText(final String text) {
private static String condenseText(final String text) {
if (text.length() <= MAX_REPORT_NESTED_TEXT) {
return text;
}
Expand All @@ -1715,7 +1715,7 @@ public MethodAndObject(final Method method, final Object object) {
/**
*
*/
private AntTypeDefinition findRestrictedDefinition(
private static AntTypeDefinition findRestrictedDefinition(
final ComponentHelper helper, final String componentName, final List<Method> methods) {
AntTypeDefinition definition = null;
Class<?> matchedDefinitionClass = null;
Expand Down Expand Up @@ -1747,7 +1747,7 @@ private AntTypeDefinition findRestrictedDefinition(
return definition;
}

private MethodAndObject createRestricted(
private static MethodAndObject createRestricted(
final ComponentHelper helper, final String elementName, final List<Method> addTypeMethods) {

final Project project = helper.getProject();
Expand Down
6 changes: 3 additions & 3 deletions src/main/org/apache/tools/ant/ProjectHelperRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private void registerProjectHelper(Constructor<? extends ProjectHelper> helperCo
helpers.add(helperConstructor);
}

private Constructor<? extends ProjectHelper> getProjectHelperBySystemProperty() {
private static Constructor<? extends ProjectHelper> getProjectHelperBySystemProperty() {
String helperClass = System.getProperty(MagicNames.PROJECT_HELPER_CLASS);
try {
if (helperClass != null) {
Expand All @@ -177,7 +177,7 @@ private Constructor<? extends ProjectHelper> getProjectHelperBySystemProperty()
return null;
}

private Constructor<? extends ProjectHelper> getProjectHelperByService(InputStream is) {
private static Constructor<? extends ProjectHelper> getProjectHelperByService(InputStream is) {
try {
// This code is needed by EBCDIC and other strange systems.
// It's a fix for bugs reported in xerces
Expand Down Expand Up @@ -214,7 +214,7 @@ private Constructor<? extends ProjectHelper> getProjectHelperByService(InputStre
* if the class cannot be found or if a constructor with no
* argument cannot be found.
*/
private Constructor<? extends ProjectHelper> getHelperConstructor(String helperClass) throws BuildException {
private static Constructor<? extends ProjectHelper> getHelperConstructor(String helperClass) throws BuildException {
ClassLoader classLoader = LoaderUtils.getContextClassLoader();
try {
Class<?> clazz = null;
Expand Down
2 changes: 1 addition & 1 deletion src/main/org/apache/tools/ant/PropertyHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public interface PropertyEnumerator extends Delegate {
// --------------------------------------------------------

private static final PropertyEvaluator TO_STRING = new PropertyEvaluator() {
private final String PREFIX = "toString:";
private static final String PREFIX = "toString:";
private final int PREFIX_LEN = PREFIX.length();

public Object evaluate(String property, PropertyHelper propertyHelper) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/org/apache/tools/ant/RuntimeConfigurable.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public boolean isRestricted() {
* @param componentHelper current component helper
* @return AttributeComponentInformation instance
*/
private AttributeComponentInformation isRestrictedAttribute(String name, ComponentHelper componentHelper) {
private static AttributeComponentInformation isRestrictedAttribute(String name, ComponentHelper componentHelper) {
if (!name.contains(":")) {
return new AttributeComponentInformation(null, false);
}
Expand Down Expand Up @@ -211,7 +211,7 @@ public boolean isEnabled(UnknownElement owner) {
return true;
}

private String attrToComponent(String a) {
private static String attrToComponent(String a) {
// need to remove the prefix
int p1 = a.lastIndexOf(':');
int p2 = a.lastIndexOf(':', p1 - 1);
Expand Down
4 changes: 2 additions & 2 deletions src/main/org/apache/tools/ant/XmlLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public void buildFinished(BuildEvent event) {
buildElement = null;
}

private String getProperty(BuildEvent event, String propertyName, String defaultValue) {
private static String getProperty(BuildEvent event, String propertyName, String defaultValue) {
String rv = defaultValue;
if (event != null && event.getProject() != null && event.getProject().getProperty(propertyName) != null) {
rv = event.getProject().getProperty(propertyName);
Expand Down Expand Up @@ -469,7 +469,7 @@ public void setEmacsMode(boolean emacsMode) {
public void setErrorPrintStream(PrintStream err) {
}

private void synchronizedAppend(Node parent, Node child) {
private static void synchronizedAppend(Node parent, Node child) {
synchronized (parent) {
parent.appendChild(child);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/org/apache/tools/ant/helper/ProjectHelper2.java
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,7 @@ public void onStartElement(String uri, String tag, String qname, Attributes attr
}
}

private String getTargetPrefix(AntXMLContext context) {
private static String getTargetPrefix(AntXMLContext context) {
String configuredValue = getCurrentTargetPrefix();
if (configuredValue != null && configuredValue.isEmpty()) {
configuredValue = null;
Expand Down
4 changes: 2 additions & 2 deletions src/main/org/apache/tools/ant/launch/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ private URL[] getSystemURLs(final File antLauncherDir) throws MalformedURLExcept
* @return the URLS from the user's lib dir
* @throws MalformedURLException if the URLs cannot be created.
*/
private URL[] getUserURLs() throws MalformedURLException {
private static URL[] getUserURLs() throws MalformedURLException {
final File userLibDir
= new File(System.getProperty(USER_HOMEDIR), USER_LIBDIR);

Expand All @@ -372,7 +372,7 @@ private URL[] getUserURLs() throws MalformedURLException {
* @return a combined array
* @throws MalformedURLException if there is a problem.
*/
private URL[] getJarArray(final URL[] libJars, final URL[] userJars,
private static URL[] getJarArray(final URL[] libJars, final URL[] userJars,
final URL[] systemJars, final File toolsJar)
throws MalformedURLException {
int numJars = libJars.length + userJars.length + systemJars.length;
Expand Down
6 changes: 3 additions & 3 deletions src/main/org/apache/tools/ant/listener/MailLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ protected void log(String message) {
* Set to null to make required.
* @return The value of the property, or default value.
*/
private String getValue(Map<String, Object> properties, String name,
private static String getValue(Map<String, Object> properties, String name,
String defaultValue) {
String propertyName = "MailLogger." + name;
String value = (String) properties.get(propertyName);
Expand All @@ -345,7 +345,7 @@ private String getValue(Map<String, Object> properties, String name,
* @param message mail body
* @exception IOException thrown if sending message fails
*/
private void sendMail(Values values, String message) throws IOException {
private static void sendMail(Values values, String message) throws IOException {
MailMessage mailMessage = new MailMessage(
values.mailhost(), values.port());
mailMessage.setHeader("Date", DateUtils.getDateForHeader());
Expand Down Expand Up @@ -422,7 +422,7 @@ private void sendMimeMail(Project project, Values values, String message) {
mailer.send();
}

private Vector<EmailAddress> splitEmailAddresses(String listString) {
private static Vector<EmailAddress> splitEmailAddresses(String listString) {
return Stream.of(listString.split(",")).map(EmailAddress::new)
.collect(Collectors.toCollection(Vector::new));
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/org/apache/tools/ant/taskdefs/AbstractCvsTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ public void execute() throws BuildException {
}
}

private String executeToString(Execute execute) {
private static String executeToString(Execute execute) {

String cmdLine = Commandline.describeCommand(execute
.getCommandline());
Expand All @@ -437,7 +437,7 @@ private String executeToString(Execute execute) {
* @param cmdLine the CVS command line
* @return a StringBuffer where the password has been removed (if available)
*/
private StringBuilder removeCvsPassword(String cmdLine) {
private static StringBuilder removeCvsPassword(String cmdLine) {
StringBuilder buf = new StringBuilder(cmdLine);

int start = cmdLine.indexOf("-d:");
Expand Down
4 changes: 2 additions & 2 deletions src/main/org/apache/tools/ant/taskdefs/AntStructure.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public void printHead(final PrintWriter out, final Project p, final Hashtable<St
* <p>Basically this prints the XML declaration, defines some
* entities and the project element.</p>
*/
private void printHead(final PrintWriter out, final Set<String> tasks,
private static void printHead(final PrintWriter out, final Set<String> tasks,
final Set<String> types) {
out.println("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
out.println("<!ENTITY % boolean \"(true|false|on|off|yes|no)\">");
Expand Down Expand Up @@ -229,7 +229,7 @@ public void printTargetDecl(final PrintWriter out) {
/**
* Prints the definition for the target element.
*/
private void printTargetAttrs(final PrintWriter out, final String tag) {
private static void printTargetAttrs(final PrintWriter out, final String tag) {
out.print("<!ATTLIST ");
out.println(tag);
out.println(" id ID #IMPLIED");
Expand Down
2 changes: 1 addition & 1 deletion src/main/org/apache/tools/ant/taskdefs/Antlib.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static Antlib createAntlib(Project project, URL antlibUrl,
Antlib antlib = new Antlib();
antlib.setProject(project);
antlib.setLocation(ue.getLocation());
antlib.setTaskName("antlib");
antlib.setTaskName(TAG);
antlib.init();
ue.configure(antlib);
return antlib;
Expand Down
2 changes: 1 addition & 1 deletion src/main/org/apache/tools/ant/taskdefs/Basename.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void execute() throws BuildException {
removeExtension(file.getName(), suffix));
}

private String removeExtension(String s, String ext) {
private static String removeExtension(String s, String ext) {
if (ext == null || !s.endsWith(ext)) {
return s;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/org/apache/tools/ant/taskdefs/Checksum.java
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ private boolean generateChecksums() throws BuildException {
return checksumMatches;
}

private String createDigestString(byte[] fileDigest) {
private static String createDigestString(byte[] fileDigest) {
StringBuilder checksumSb = new StringBuilder();
for (byte digestByte : fileDigest) {
checksumSb.append(String.format("%02x", BYTE_MASK & digestByte));
Expand Down
2 changes: 1 addition & 1 deletion src/main/org/apache/tools/ant/taskdefs/Copy.java
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@ private FileNameMapper getMapper() {
* @return ex.getMessage() if ex.getMessage() is not null
* otherwise return ex.toString()
*/
private String getMessage(final Exception ex) {
private static String getMessage(final Exception ex) {
return ex.getMessage() == null ? ex.toString() : ex.getMessage();
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/org/apache/tools/ant/taskdefs/Delete.java
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ protected void removeFiles(File d, String[] files, String[] dirs) {
}
}

private boolean isDanglingSymlink(final File f) {
private static boolean isDanglingSymlink(final File f) {
if (!Files.isSymbolicLink(f.toPath())) {
// it's not a symlink, so clearly it's not a dangling one
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/main/org/apache/tools/ant/taskdefs/Deltree.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void execute() throws BuildException {
}
}

private void removeDir(File dir) {
private static void removeDir(File dir) {

// check to make sure that the given dir isn't a symlink
// the comparison of absolute path and canonical path
Expand Down
6 changes: 3 additions & 3 deletions src/main/org/apache/tools/ant/taskdefs/DependSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -263,15 +263,15 @@ private void logFuture(ResourceCollection rc, ResourceSelector rsel) {
}
}

private Resource getXest(ResourceCollection rc, ResourceComparator c) {
private static Resource getXest(ResourceCollection rc, ResourceComparator c) {
return StreamUtils.iteratorAsStream(rc.iterator()).max(c).orElse(null);
}

private Resource getOldest(ResourceCollection rc) {
private static Resource getOldest(ResourceCollection rc) {
return getXest(rc, REVERSE_DATE);
}

private Resource getNewest(ResourceCollection rc) {
private static Resource getNewest(ResourceCollection rc) {
return getXest(rc, DATE);
}

Expand Down
Loading