You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "eric-milles (via GitHub)" <gi...@apache.org> on 2023/07/25 16:03:55 UTC
[GitHub] [groovy] eric-milles opened a new pull request, #1922: introduce interface `MetaMember`
eric-milles opened a new pull request, #1922:
URL: https://github.com/apache/groovy/pull/1922
I'd like to be able to refer to elements of the meta-method index's `FastArray` uniformly. What I want to do is check access modifiers. However `CachedConstructor` and `MetaMethod` only share the non-abstract class `ParameterTypes`. That does not seem the appropriate place to add member name, modifiers and anything else that is common to a class member.
I looked at `java.lang.reflect.Member` and it specifies `getName()`, `getModifiers()`, `isSynthetic()` and `getDeclaringClass()`. `CachedConstructor` could implement `Member` but `MetaMethod` (the other subclass of `ParameterTypes`) cannot due to a conflict with the `getDeclaringClass()` return type. So I'd like to introduce the interface `groovy.lang.MetaMember` that is inspired by `Member` but does not declare `getDeclaringClass()`. With this, the name and modifiers (and common modifier conveniences) are available without a bunch of `instanceof` checks.
Here is a sample from `MetaClassImpl` where `ParameterTypes` and `MetaMethod` can be used in tandem:
```java
private Object chooseMethodInternal(String methodName, Object methodOrList, Class[] arguments) throws MethodSelectionException {
...
List<MetaMember> matchingMethods = new ArrayList<>(methodCount);
Object[] methodArray = methods.getArray();
for (int i = 0; i < methodCount; i += 1) {
var method = (ParameterTypes & MetaMember) methodArray[i];
if (method.isValidMethod(arguments)) {
matchingMethods.add(method);
}
}
methodCount = matchingMethods.size();
if (methodCount == 0) {
return null;
} else if (methodCount == 1) {
return matchingMethods.get(0);
}
return doChooseMostSpecificParams(theClass.getName(), methodName, matchingMethods, arguments, false);
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [groovy] eric-milles merged pull request #1922: introduce interface `MetaMember`
Posted by "eric-milles (via GitHub)" <gi...@apache.org>.
eric-milles merged PR #1922:
URL: https://github.com/apache/groovy/pull/1922
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [groovy] sonatype-lift[bot] commented on pull request #1922: introduce interface `MetaMember`
Posted by "sonatype-lift[bot] (via GitHub)" <gi...@apache.org>.
sonatype-lift[bot] commented on PR #1922:
URL: https://github.com/apache/groovy/pull/1922#issuecomment-1650307368
## 🛠 Lift Auto-fix
Some of the Lift findings in this PR can be automatically fixed. You can download and apply these changes in your local project directory of your branch to review the suggestions before committing.[^1]
```bash
# Download the patch
curl https://lift.sonatype.com/api/patch/github.com/apache/groovy/1922.diff -o lift-autofixes.diff
# Apply the patch with git
git apply lift-autofixes.diff
# Review the changes
git diff
```
Want it all in a single command? Open a terminal in your project's directory and copy and paste the following command:
```bash
curl https://lift.sonatype.com/api/patch/github.com/apache/groovy/1922.diff | git apply
```
Once you're satisfied, commit and push your changes in your project.
[^1]: You can preview the patch by opening the [patch URL](https://lift.sonatype.com/api/patch/github.com/apache/groovy/1922.diff) in the browser.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [groovy] sonatype-lift[bot] commented on a diff in pull request #1922: introduce interface `MetaMember`
Posted by "sonatype-lift[bot] (via GitHub)" <gi...@apache.org>.
sonatype-lift[bot] commented on code in PR #1922:
URL: https://github.com/apache/groovy/pull/1922#discussion_r1273912446
##########
src/main/java/org/codehaus/groovy/reflection/CachedConstructor.java:
##########
@@ -46,6 +46,28 @@ protected Class[] getPT() {
return cachedConstructor.getParameterTypes();
}
+ @Override
+ public String getName() {
+ return cachedConstructor.getName();
+ }
+
+ @Override
+ public int getModifiers() {
+ return cachedConstructor.getModifiers();
+ }
+
+ @Override
+ public boolean isSynthetic() {
+ return cachedConstructor.isSynthetic();
+ }
+
+ @Override
+ public String toString() {
+ return cachedConstructor.toString();
+ }
+
+ //--------------------------------------------------------------------------
+
public static CachedConstructor find(Constructor constructor) {
CachedConstructor[] constructors = ReflectionCache.getCachedClass(constructor.getDeclaringClass()).getConstructors();
Review Comment:
<picture><img alt="12% of developers fix this issue" src="https://lift.sonatype.com/api/commentimage/fixrate/12/display.svg"></picture>
<b>*NULL_DEREFERENCE:</b>* object returned by `getCachedClass(constructor.getDeclaringClass())` could be null and is dereferenced at line 72.
---
<details><summary>ℹ️ Expand to see all <b>@sonatype-lift</b> commands</summary>
You can reply with the following commands. For example, reply with ***@sonatype-lift ignoreall*** to leave out all findings.
| **Command** | **Usage** |
| ------------- | ------------- |
| `@sonatype-lift ignore` | Leave out the above finding from this PR |
| `@sonatype-lift ignoreall` | Leave out all the existing findings from this PR |
| `@sonatype-lift exclude <file\|issue\|path\|tool>` | Exclude specified `file\|issue\|path\|tool` from Lift findings by updating your config.toml file |
**Note:** When talking to LiftBot, you need to **refresh** the page to see its response.
<sub>[Click here](https://github.com/apps/sonatype-lift/installations/new) to add LiftBot to another repo.</sub></details>
##########
src/main/java/groovy/lang/MetaMember.java:
##########
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package groovy.lang;
+
+import java.lang.reflect.Modifier;
+
+/**
+ * @since 5.0.0
Review Comment:
<picture><img alt="31% of developers fix this issue" src="https://lift.sonatype.com/api/commentimage/fixrate/31/display.svg"></picture>
<b>*[MissingSummary](https://google.github.io/styleguide/javaguide.html#s7.2-summary-fragment):</b>* A summary line is required on public/protected Javadocs.
---
<details><summary>ℹ️ Expand to see all <b>@sonatype-lift</b> commands</summary>
You can reply with the following commands. For example, reply with ***@sonatype-lift ignoreall*** to leave out all findings.
| **Command** | **Usage** |
| ------------- | ------------- |
| `@sonatype-lift ignore` | Leave out the above finding from this PR |
| `@sonatype-lift ignoreall` | Leave out all the existing findings from this PR |
| `@sonatype-lift exclude <file\|issue\|path\|tool>` | Exclude specified `file\|issue\|path\|tool` from Lift findings by updating your config.toml file |
**Note:** When talking to LiftBot, you need to **refresh** the page to see its response.
<sub>[Click here](https://github.com/apps/sonatype-lift/installations/new) to add LiftBot to another repo.</sub></details>
##########
src/main/java/groovy/lang/MetaMethod.java:
##########
@@ -185,30 +178,6 @@ public boolean isDefault() {
return (getModifiers() & (Modifier.ABSTRACT | Modifier.PUBLIC | Modifier.STATIC)) == Modifier.PUBLIC && getDeclaringClass().isInterface;
}
- /**
- * Returns whether this method is private.
- * @return true if this method is private
- */
- public final boolean isPrivate() {
- return (getModifiers() & Modifier.PRIVATE) != 0;
- }
-
- /**
- * Returns whether this method is protected.
- * @return true if this method is protected
- */
- public final boolean isProtected() {
- return (getModifiers() & Modifier.PROTECTED) != 0;
- }
-
- /**
- * Returns whether this method is public.
- * @return true if this method is public
- */
- public final boolean isPublic() {
- return (getModifiers() & Modifier.PUBLIC) != 0;
- }
-
/**
* @param method the method to compare against
Review Comment:
<picture><img alt="31% of developers fix this issue" src="https://lift.sonatype.com/api/commentimage/fixrate/31/display.svg"></picture>
<b>*[MissingSummary](https://google.github.io/styleguide/javaguide.html#s7.2-summary-fragment):</b>* A summary fragment is required; consider using the value of the @return block as a summary fragment instead.
---
```suggestion
*Returns true if the given method has the same name, parameters, return type
```
---
<details><summary>ℹ️ Expand to see all <b>@sonatype-lift</b> commands</summary>
You can reply with the following commands. For example, reply with ***@sonatype-lift ignoreall*** to leave out all findings.
| **Command** | **Usage** |
| ------------- | ------------- |
| `@sonatype-lift ignore` | Leave out the above finding from this PR |
| `@sonatype-lift ignoreall` | Leave out all the existing findings from this PR |
| `@sonatype-lift exclude <file\|issue\|path\|tool>` | Exclude specified `file\|issue\|path\|tool` from Lift findings by updating your config.toml file |
**Note:** When talking to LiftBot, you need to **refresh** the page to see its response.
<sub>[Click here](https://github.com/apps/sonatype-lift/installations/new) to add LiftBot to another repo.</sub></details>
##########
src/main/java/groovy/lang/MetaClassImpl.java:
##########
@@ -1714,11 +1704,11 @@ public boolean isBeanConstructor() {
}
/**
- * This is a helper method added in Groovy 2.1.0, which is used only by indy.
- * This method is for internal use only.
+ * This is a helper method which is used only by indy. It is for internal use.
*
- * @since Groovy 2.1.0
+ * @since 2.1.0
*/
+ @groovy.transform.Internal
Review Comment:
<picture><img alt="4% of developers fix this issue" src="https://lift.sonatype.com/api/commentimage/fixrate/4/display.svg"></picture>
<b>*[UnnecessarilyFullyQualified](https://errorprone.info/bugpattern/UnnecessarilyFullyQualified):</b>* This fully qualified name is unambiguous to the compiler if imported.
---
```suggestion
@Internal
```
---
<details><summary>ℹ️ Expand to see all <b>@sonatype-lift</b> commands</summary>
You can reply with the following commands. For example, reply with ***@sonatype-lift ignoreall*** to leave out all findings.
| **Command** | **Usage** |
| ------------- | ------------- |
| `@sonatype-lift ignore` | Leave out the above finding from this PR |
| `@sonatype-lift ignoreall` | Leave out all the existing findings from this PR |
| `@sonatype-lift exclude <file\|issue\|path\|tool>` | Exclude specified `file\|issue\|path\|tool` from Lift findings by updating your config.toml file |
**Note:** When talking to LiftBot, you need to **refresh** the page to see its response.
<sub>[Click here](https://github.com/apps/sonatype-lift/installations/new) to add LiftBot to another repo.</sub></details>
##########
src/main/java/groovy/lang/MetaClassImpl.java:
##########
@@ -1663,11 +1653,11 @@ protected void checkInitalised() {
}
/**
- * This is a helper class introduced in Groovy 2.1.0, which is used only by
- * indy. This class is for internal use only.
+ * This is a helper class which is used only by indy. It is for internal use.
*
- * @since Groovy 2.1.0
+ * @since 2.1.0
*/
+ @groovy.transform.Internal
Review Comment:
<picture><img alt="4% of developers fix this issue" src="https://lift.sonatype.com/api/commentimage/fixrate/4/display.svg"></picture>
<b>*[UnnecessarilyFullyQualified](https://errorprone.info/bugpattern/UnnecessarilyFullyQualified):</b>* This fully qualified name is unambiguous to the compiler if imported.
---
```suggestion
@Internal
```
---
<details><summary>ℹ️ Expand to see all <b>@sonatype-lift</b> commands</summary>
You can reply with the following commands. For example, reply with ***@sonatype-lift ignoreall*** to leave out all findings.
| **Command** | **Usage** |
| ------------- | ------------- |
| `@sonatype-lift ignore` | Leave out the above finding from this PR |
| `@sonatype-lift ignoreall` | Leave out all the existing findings from this PR |
| `@sonatype-lift exclude <file\|issue\|path\|tool>` | Exclude specified `file\|issue\|path\|tool` from Lift findings by updating your config.toml file |
**Note:** When talking to LiftBot, you need to **refresh** the page to see its response.
<sub>[Click here](https://github.com/apps/sonatype-lift/installations/new) to add LiftBot to another repo.</sub></details>
##########
src/main/java/groovy/lang/MetaClassImpl.java:
##########
@@ -1580,18 +1576,15 @@ private int selectConstructorAndTransformArguments0(final int numberOfConstructo
Review Comment:
<picture><img alt="9% of developers fix this issue" src="https://lift.sonatype.com/api/commentimage/fixrate/9/display.svg"></picture>
<b>*[AvoidObjectArrays](https://errorprone.info/bugpattern/AvoidObjectArrays):</b>* Avoid accepting a Object[]; consider an Iterable<Object> instead
❗❗ <b>2 similar findings have been found in this PR</b>
<details><summary>🔎 Expand here to view all instances of this finding</summary><br/>
<div align=\"center\">
| **File Path** | **Line Number** |
| ------------- | ------------- |
| src/main/java/org/codehaus/groovy/reflection/CachedMethod.java | [237](https://github.com/apache/groovy/blob/bf748bfeeca45d3fb4e86932d1c3c73c1bbd4652/src/main/java/org/codehaus/groovy/reflection/CachedMethod.java#L237) |
| src/main/java/groovy/lang/MetaClassImpl.java | [1712](https://github.com/apache/groovy/blob/bf748bfeeca45d3fb4e86932d1c3c73c1bbd4652/src/main/java/groovy/lang/MetaClassImpl.java#L1712) |
<p><a href="https://lift.sonatype.com/results/github.com/apache/groovy/01H6702AP87Q3YSJHAGQ133BHN?t=ErrorProne|AvoidObjectArrays" target="_blank">Visit the Lift Web Console</a> to find more details in your report.</p></div></details>
---
<details><summary>ℹ️ Expand to see all <b>@sonatype-lift</b> commands</summary>
You can reply with the following commands. For example, reply with ***@sonatype-lift ignoreall*** to leave out all findings.
| **Command** | **Usage** |
| ------------- | ------------- |
| `@sonatype-lift ignore` | Leave out the above finding from this PR |
| `@sonatype-lift ignoreall` | Leave out all the existing findings from this PR |
| `@sonatype-lift exclude <file\|issue\|path\|tool>` | Exclude specified `file\|issue\|path\|tool` from Lift findings by updating your config.toml file |
**Note:** When talking to LiftBot, you need to **refresh** the page to see its response.
<sub>[Click here](https://github.com/apps/sonatype-lift/installations/new) to add LiftBot to another repo.</sub></details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [groovy] sonatype-lift[bot] commented on pull request #1922: introduce interface `MetaMember`
Posted by "sonatype-lift[bot] (via GitHub)" <gi...@apache.org>.
sonatype-lift[bot] commented on PR #1922:
URL: https://github.com/apache/groovy/pull/1922#issuecomment-1650121077
## Sonatype Lift is retiring
Sonatype Lift will be retiring on <b>Sep 12, 2023</b>, with its analysis stopping on Aug 12, 2023. We understand that this news may come as a disappointment, and Sonatype is committed to helping you transition off it seamlessly. If you’d like to retain your data, please export your issues from the web console.
We are extremely grateful and thank you for your support over the years.
<b>[📖 Read about the impacts and timeline](https://www.sonatype.com/lift-retirement)</b>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [groovy] daniellansun commented on pull request #1922: introduce interface `MetaMember`
Posted by "daniellansun (via GitHub)" <gi...@apache.org>.
daniellansun commented on PR #1922:
URL: https://github.com/apache/groovy/pull/1922#issuecomment-1656888257
LGTM
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org