Skip to content

[java] Update rule UseDiamondOperator#3253

Merged
adangel merged 48 commits into
pmd:pmd/7.0.xfrom
oowekyala:update-UseDiamondOperator
May 13, 2021
Merged

[java] Update rule UseDiamondOperator#3253
adangel merged 48 commits into
pmd:pmd/7.0.xfrom
oowekyala:update-UseDiamondOperator

Conversation

@oowekyala

@oowekyala oowekyala commented May 5, 2021

Copy link
Copy Markdown
Member

Describe the PR

Update the rule, converting it to a Java rule. The rule now uses the type res framework to improve its accuracy and recall. See the javadoc of the class.

  • Previously the rule had a "java 7 compatibility" property. This is now removed because Java 7-specific inference logic is supported by the type resolution engine now. So the rule doesn't need to care which version of java we use.

  • This should fix many false negatives, including:

    • since Java 9 diamond type arguments are usable in anonymous class instance creation expression.
    • we flag uses of a raw constructor if it may be replaced. Eg List<String> l = new ArrayList() produces an unchecked warning, but you could write new ArrayList<>() and avoid it.
    • many false negatives where the constructor is called in method arguments
  • The rule's description now does not mention the "diamond operator". It's not an operator, it's just shorthand syntax. The JLS says "diamond type arguments", and now we do too. We would ideally rename the rule.

  • Messages are now much better.

  • The diamond

Related issues

Ready?

  • Added unit tests for fixed bug/feature
  • Passing all unit tests
  • Complete build ./mvnw clean verify passes (checked automatically by github actions)
  • Added (in-code) documentation (if needed)
  • This is ready, but ideally [java] Improve resilience to broken classpath #3270 would be merged first

Convert it to a java rule
Remove references to the 'diamond operator'. This is not
an operator, it's just a syntax to avoid mentioning type
arguments. The JLS says 'diamond type arguments', now we
do too.
@oowekyala oowekyala changed the title Update use diamond operator [java] Update rule UseDiamondOperator May 5, 2021
@oowekyala oowekyala added this to the 7.0.0 milestone May 5, 2021
@ghost

ghost commented May 7, 2021

Copy link
Copy Markdown
2 Messages
📖 Compared to pmd/7.0.x:
This changeset changes 0 violations,
introduces 304 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 8 errors and 0 configuration errors.
Full report
📖 Compared to master:
This changeset changes 9507 violations,
introduces 8466 new violations, 1 new errors and 0 new configuration errors,
removes 16079 violations, 10 errors and 2 configuration errors.
Full report
Compared to pmd/7.0.x:
This changeset changes 0 violations,
introduces 304 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 8 errors and 0 configuration errors.
Full report
Compared to master:
This changeset changes 9507 violations,
introduces 8466 new violations, 1 new errors and 0 new configuration errors,
removes 16079 violations, 10 errors and 2 configuration errors.
Full report
Compared to pmd/7.0.x:
This changeset changes 0 violations,
introduces 34450 new violations, 0 new errors and 0 new configuration errors,
removes 15 violations, 976 errors and 0 configuration errors.
Full report
Compared to master:
This changeset changes 9475 violations,
introduces 9912 new violations, 1 new errors and 0 new configuration errors,
removes 15985 violations, 25 errors and 2 configuration errors.
Full report
Compared to pmd/7.0.x:
This changeset changes 0 violations,
introduces 283 new violations, 20 new errors and 0 new configuration errors,
removes 0 violations, 3 errors and 0 configuration errors.
Full report
Compared to master:
This changeset changes 9332 violations,
introduces 9035 new violations, 994 new errors and 0 new configuration errors,
removes 49261 violations, 25 errors and 2 configuration errors.
Full report
Compared to pmd/7.0.x:
This changeset changes 0 violations,
introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 3 errors and 0 configuration errors.
Full report
Compared to master:
This changeset changes 9260 violations,
introduces 8824 new violations, 974 new errors and 0 new configuration errors,
removes 49260 violations, 25 errors and 2 configuration errors.
Full report

Generated by 🚫 Danger

oowekyala added 7 commits May 7, 2021 15:41
Prints eg

net.sourceforge.pmd.internal.util.ContextedAssertionError: Detail message
Exception Context:
	[1:Rule applied on node=[CastExpression:92:53](long ) (2 * (4 / 2 ) )]
also format
@oowekyala oowekyala marked this pull request as ready for review May 9, 2021 15:30
Comment thread pmd-core/src/main/java/net/sourceforge/pmd/internal/util/AssertionUtil.java Outdated
adangel added a commit that referenced this pull request May 13, 2021
@adangel adangel merged commit f2b512f into pmd:pmd/7.0.x May 13, 2021
@oowekyala oowekyala deleted the update-UseDiamondOperator branch May 13, 2021 10:24
@adangel adangel mentioned this pull request Jan 23, 2023
55 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[java] UseDiamondOperator FP when expected type and constructed type have a different parameterization

3 participants