Skip to content

[WIP] more improvements to constructor completion#1478

Draft
datho7561 wants to merge 1226 commits into
eclipse-jdtls:dom-with-javacfrom
datho7561:dom-with-javac-continue-constructor-first-param
Draft

[WIP] more improvements to constructor completion#1478
datho7561 wants to merge 1226 commits into
eclipse-jdtls:dom-with-javacfrom
datho7561:dom-with-javac-continue-constructor-first-param

Conversation

@datho7561
Copy link
Copy Markdown

No description provided.

@datho7561 datho7561 changed the title Dom with javac continue constructor first param [WIP] more improvements to constructor completion Jun 3, 2025
@datho7561
Copy link
Copy Markdown
Author

I don't think I'll ever be able to resolve these cases; the test results are incoherent to me. For the signature sometimes <> is expected in place of type arguments, sometimes the type arguments are provided, and sometimes the type parameters are provided. This usually is decided by whether the user has provided the type arguments, but sometimes it goes against that.

@datho7561 datho7561 force-pushed the dom-with-javac-continue-constructor-first-param branch from a21bca3 to b47db17 Compare June 4, 2025 12:36
datho7561 and others added 26 commits June 25, 2025 10:28
- Use `$` to separate inner class and outer class in IType key

Signed-off-by: David Thompson <davthomp@redhat.com>
Reconciling or other routines may receive a CompletionFailure in some
-more or less valid- cases. Instead of letting the exception bubble up
to user land, we simply log it and continue anyway.
- consolidate logic for `CatchClause` into one place
- figure out which types are thrown in the body of the try statement,
  prioritize them
- figure out which types are already caught, deprioritize them
  ("uninteresting bindings")
- handle bug related to classes declared with type declaration statements
  - their bindings are still wrong, so that needs work

Signed-off-by: David Thompson <davthomp@redhat.com>
eg.
```java
pub|
```

eg.
```java
package test;
import java.util.List;

abst|
```

- Detect that aren't connected to a type declaration using the text content
  of the CU
- Apply the rules regarding which modifiers prevent others from being
  used
- Prevent statement-like keywords in import or package declarations

Signed-off-by: David Thompson <davthomp@redhat.com>
eg.

```java
switch (i) {
  cas|
}
```

Signed-off-by: David Thompson <davthomp@redhat.com>
Signed-off-by: David Thompson <davthomp@redhat.com>
- Add a bunch more statement-like keywords
- Handle completion for `default` in switch statements and expressions

Should fix around 43 cases

Signed-off-by: David Thompson <davthomp@redhat.com>
- Completion for `new`, `final`, `true`, `false`, and `null` keywords
- Improve logic for checking if only expression-like keywords should be
  suggested
- Prevent default completions in switches without a case label/default
  label

Signed-off-by: David Thompson <davthomp@redhat.com>
Signed-off-by: Rob Stryker <stryker@redhat.com>
Signed-off-by: Rob Stryker <stryker@redhat.com>
Signed-off-by: Rob Stryker <stryker@redhat.com>
Signed-off-by: Rob Stryker <stryker@redhat.com>
- Disable default completion in completion after a try statement without
  a catch or finally
- Complete `catch` and `finally` after try statements
  (do not suggest `finally` if there's already a `finally` statement)
- Suggest `while` after a do-while statement if it's missing
- Prevent default completion after a do-while statement if it's missing
  the `while` keyword

Signed-off-by: David Thompson <davthomp@redhat.com>
- Completion for `instanceof` keyword
  - Since it's sort of like an infix operator,
    I needed to write some more involved logic to get it to work properly.
- Suggest all type-declaration like keywords instead of just `class`
  - eg. `enum`, `interface`, `record`
- Complete the `import` keyword
  - See eclipse-jdt#3799,
    I won't fix that test case
- fix module import completion (only show it when `import module` is used)
- fix replace range on package completion
  - It uses the nested engine currently and the root cause was us not
    modifying the internal state correctly.
    I think using nested engine is bad,
    but I did the lazy hack instead of replacing the nested engine
    with our own `ISearchRequestor` implementation

Signed-off-by: David Thompson <davthomp@redhat.com>
…er bugs

Signed-off-by: Rob Stryker <stryker@redhat.com>
Signed-off-by: Rob Stryker <stryker@redhat.com>
Speeds up completion of types significantly,
since the type hierarchy of `java.lang.Exception` is only created once
every completion invocation.

Signed-off-by: David Thompson <davthomp@redhat.com>
- Handle qualifying types referenced in the method declaration
  - eg. do not qualify imported types
  - eg. do not qualify types from the same package
  - eg. do not qualify inner classes nor inherited inner classes
- Fix parameter names
  - get them from the `IMethod`, which has more accurate
- Handle completion in anonymous classes
- Do not suggest overriding a method that's already overriden

Signed-off-by: David Thompson <davthomp@redhat.com>
Signed-off-by: David Thompson <davthomp@redhat.com>
Should improve a couple tests
+ Added a Timer utility class to help profiling
(for expected types purposes)

Signed-off-by: David Thompson <davthomp@redhat.com>
- Prevent NPE when completing name of the last parameter in a method
  declaration
  - This uses the existing "suggest a name for this variable" logic
- Prevent various NPEs when completing the first parameter of a
  parameterized type
  - eg.
    ```java
    List<| asdf = new ArrayList<>();
    ```
- move private check before deprecated check to avoid NPE trying to
  access the `IMethod` for a private JDK class member.
  (I think the root cause is that the private method doesn't exist in the
  stubbed jar, so we can't access the associated `IMethod`, but it does
  exist in javac's internal bindings, since javac has access to the real
  JDK class)
- when completing throws clause, add null checks when accessing the
  return type and name to compute the scanning index
  - constructors don't have a return type node, and an incomplete method
    declaration might not have a name
- replace a use of "Ljava/lang/Object;" with the constant from KeyUtils

Should fix 5 cases, and switch several test errors over to failures.

Signed-off-by: David Thompson <davthomp@redhat.com>
Signed-off-by: Rob Stryker <stryker@redhat.com>
- handle completing package-qualified method parameter type
- do not suggest overriding existing or declaring new methods in
  annotation type declarations
- when building override method completions, if the `IMethod` of a given
  method binding cannot be found, use the parameter names from
  the bindings instead
- prevent NPE when attempting to suggest completion for a method with
  an incomplete parameter type

Signed-off-by: David Thompson <davthomp@redhat.com>
datho7561 and others added 2 commits June 25, 2025 10:28
Uses a regex to strip some extra information that's present in keys but
not signatures.

Includes a new test case to cover this behaviour, since there is no
existing test for this.

Includes an unrelated fix (relevance number when a raw type is expected) to get the new test case passing.

Fixes eclipse-jdt#1414

Signed-off-by: David Thompson <davthomp@redhat.com>
Signed-off-by: Roland Grunberg <rgrunber@redhat.com>
eg.

```java
public class Outer<A> {
  public class Inner<B> {
  }
}

public class Main {
  public void main(String... args) {
    new Outer<String>().new Inner<Number>();
  }
}
```

Signed-off-by: David Thompson <davthomp@redhat.com>
Signed-off-by: David Thompson <davthomp@redhat.com>
Signed-off-by: David Thompson <davthomp@redhat.com>
@datho7561 datho7561 force-pushed the dom-with-javac-continue-constructor-first-param branch from b47db17 to b0b0160 Compare June 27, 2025 13:11
@robstryker robstryker force-pushed the dom-with-javac branch 3 times, most recently from b1b4e0e to 309f390 Compare September 8, 2025 20:48
@robstryker robstryker force-pushed the dom-with-javac branch 2 times, most recently from 5738537 to 9962d57 Compare December 2, 2025 20:28
@robstryker robstryker force-pushed the dom-with-javac branch 2 times, most recently from dd7aa18 to fbe5e1a Compare March 6, 2026 18:59
@robstryker robstryker force-pushed the dom-with-javac branch 2 times, most recently from 2fcc4f8 to b7970ce Compare April 23, 2026 17:03
@robstryker robstryker force-pushed the dom-with-javac branch 2 times, most recently from 86c88a2 to 4ccbd95 Compare May 7, 2026 17:06
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.

5 participants