redhat-developer / vscode-java

Java Language Support for Visual Studio Code
Eclipse Public License 2.0
2.08k stars 442 forks source link

Package containing dot character not being parsed correctly #1406

Open SnapperGee opened 4 years ago

SnapperGee commented 4 years ago

Issue Type: Bug

In the src folder of a Java Gradle project, there's the package structure:

projectRoot/
└── src/
    ├── main/
    │   ├── java/
    │   │   └── javasnap.domain/
    │   │       └── cli/
    │   │           └── ClStringArgs.java
    └── test/
        ├── java/
        │   └── javasnap.domain/
        │       └── cli/
        │           └── ClStringArgsTest.java

The ClStringArgs.java and ClStringArgsTest.java file contains the package declaration:

package javasnap.domain.cli;

Which is resulting in the package delcaration being highlighted as an error by VScode in both the test and production source file:

The declared package "javasnap.domain.cli" does not match the expected package "" Java(536871240)

It's also highlighting any reference to the class ClStringArgs in both the production and test source code with the following error:

ClStringArgs cannot be resolved to a type Java(16777218)

Splitting the directory name containing the dot character into two separate directories with one nested within the other causes this error to go away.

This package naming is valid for Gradle (and Java) to be able to compile and run source code. Attempting to add a directory to the Java Source Path via VScode results in the following message:

Unsupported operation. Please use build.gradle file to manage the source directories of gradle project.

Source: Language Support for Java(TM) by Red Hat (Extension)

This source directory structure is the default structuring of Gradle builds and this package naming convention is valid and used by multiple Java libraries. Can this bug get fixed or the feature of being able to resolve package names containing the dot character correctly be added to the roadmap?

Extension version: 0.60.0 VS Code version: Code 1.44.2 (ff915844119ce9485abfe8aa9076ec76b5300ddd, 2020-04-16T17:07:18.473Z) OS version: Darwin x64 18.7.0

System Info |Item|Value| |---|---| |CPUs|Intel(R) Core(TM) i7-3740QM CPU @ 2.70GHz (8 x 2700)| |GPU Status|2d_canvas: enabled
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
oop_rasterization: disabled_off
protected_video_decode: unavailable_off
rasterization: enabled
skia_renderer: disabled_off_ok
video_decode: enabled
viz_display_compositor: enabled_on
viz_hit_test_surface_layer: disabled_off_ok
webgl: enabled
webgl2: enabled| |Load (avg)|3, 3, 3| |Memory (System)|16.00GB| |Process Argv|.| |Screen Reader|no| |VM|0%|
fbricon commented 4 years ago

Please attach a sample project reproducing this issue

SnapperGee commented 4 years ago

Since posting this issue I re-cloned the repo where the problem was occurring and that seemed to fix the issue. I even attempted making a new project and then manually re-creating the folder package structure with the dot notation in the name of one of the directories and it still appeared to be working. So whatever the issue was got fixed or was some odd thing in my environment. Either way, I'm going to close this issue for now, but I'm pretty sure i've seen this issue before with other projects so if it occurs again I'll reopen it and include a zip of the project.

fbricon commented 4 years ago

It's actually a known limitation of the Eclipse compiler, but I'm trying to get more info about it

SnapperGee commented 4 years ago

I was just about to say, the issue popped up again so I'm reopening it and including files. Here's what I did to recreate the issue. Essentially just made a default Gradle Java Library project, but since Gradle automatically creates nested directories when you use a dot character in the src package creation when it creates it, I manually go in and change the package structure:

$ mkdir project-root
$ cd project-root/
$ gradle init

Select type of project to generate:
  1: basic
  2: application
  3: library
  4: Gradle plugin
Enter selection (default: basic) [1..4] 3

Select implementation language:
  1: C++
  2: Groovy
  3: Java
  4: Kotlin
  5: Scala
  6: Swift
Enter selection (default: Java) [1..6] 

Select build script DSL:
  1: Groovy
  2: Kotlin
Enter selection (default: Groovy) [1..2] 

Select test framework:
  1: JUnit 4
  2: TestNG
  3: Spock
  4: JUnit Jupiter
Enter selection (default: JUnit 4) [1..4] 4

Project name (default: project-root): example-project
Source package (default: example.project): example.single.dir.project

> Task :init
Get more help with your project: https://docs.gradle.org/6.3/userguide/java_library_plugin.html

BUILD SUCCESSFUL in 52s
2 actionable tasks: 2 executed

# manually change source package directories from example/single/dir/project/Library.java
# to example/single.dir/project/Library.java in file browser
$ open .

$ gradle build

BUILD SUCCESSFUL in 3s
4 actionable tasks: 4 executed

$ code .

And here's a zip of the entire project folder itself and my user settings. project.zip

// Place your settings in this file to overwrite the default settings
{
    "csharp.suppressDotnetInstallWarning": true,

    "debug.inlineValues": true,

    "editor.cursorBlinking": "solid",
    "editor.cursorSmoothCaretAnimation": true,
    "editor.cursorStyle": "block",
    "editor.dragAndDrop": false,
    "editor.fontSize": 13,
    "editor.lineHeight": 20,
    "editor.minimap.showSlider": "always",
    "editor.multiCursorModifier": "ctrlCmd",
    "editor.parameterHints.cycle": true,
    "editor.renderLineHighlight": "gutter",
    "editor.renderWhitespace": "boundary",
    "editor.rulers": [80, 120],
    "editor.smoothScrolling": true,
    "editor.snippetSuggestions": "top",
    "editor.suggestSelection": "first",

    "extensions.ignoreRecommendations": true,
    "extensions.showRecommendationsOnlyOnDemand": true,

    "files.autoGuessEncoding": true,
    "files.exclude": {
        "**/__pycache__": true,
        "**/.apdisk": true,
        "**/.TemporaryItems": true,
        "**.idea": true,
        "**/env": true,
        "**/Thumbs.db": true,
        "**/.classpath": true,
        "**/.project": true,
        "**/.settings": true,
        "**/.factorypath": true
    },
    "files.insertFinalNewline": true,
    "files.trimFinalNewlines": true,
    "files.trimTrailingWhitespace": true,

    "git.branchWhitespaceChar": "_",
    "git.path": "/usr/local/bin/git",
    "git.showPushSuccessNotification": true,

    "java.codeGeneration.useBlocks": true,
    "java.configuration.updateBuildConfiguration": "automatic",
    "java.dependency.showMembers": true,
    "java.home": "/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home",

    "javascript.referencesCodeLens.enabled": true,

    "keyboard.touchbar.enabled": false,

    "npm.enableScriptExplorer": true,

    "php.suggest.basic": false,

    "python.autoComplete.addBrackets": true,
    "python.linting.flake8Enabled": true,
    "python.pythonPath": "/usr/local/bin/python3",

    "search.showLineNumbers": true,
    "search.smartCase": true,
    "search.useGlobalIgnoreFiles": true,

    "terminal.integrated.confirmOnExit": true,
    "terminal.integrated.copyOnSelection": true,
    "terminal.integrated.cursorBlinking": true,

    "typescript.implementationsCodeLens.enabled": true,
    "typescript.referencesCodeLens.enabled": true,

    "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",

    "window.newWindowDimensions": "inherit",
    "window.restoreWindows": "all",
    "window.title": "${activeEditorLong}${separator}${dirty}",

    "workbench.colorTheme": "Monokai",
    "workbench.colorCustomizations": {
        // Inverting active & inactive tab colors
        "tab.activeBackground": "#414343",
        "tab.inactiveBackground": "#272822"

    },
    "workbench.editor.highlightModifiedTabs": true,
    "workbench.enableExperiments": false,
    "workbench.fontAliasing": "antialiased",
    "workbench.iconTheme": "vscode-icons",
    "workbench.settings.editor": "json",
    "workbench.settings.openDefaultKeybindings": true,
    "workbench.settings.openDefaultSettings": true,
    "workbench.settings.useSplitJSON": true,
    "workbench.tree.indent": 4,
    "workbench.tree.renderIndentGuides": "always",
    "workbench.view.alwaysShowHeaderActions": true,
    "cSpell.userWords": [
        "executable's",
        "executables",
        "javasnap",
        "linkplain",
        "printf",
        "subpackage",
        "subpackages"
    ],
    "markdownlint.customRules": [
        "{docsmsft.docs-markdown}/markdownlint-custom-rules/rules.js"
    ],
    "markdownlint.config": {
        "MD025": {
            "front_matter_title": ""
        }
    },
    "files.associations": {
        "*.COBOL*": "cobol",
        "*.COB*": "cobol",
        "*.COBCOPY*": "cobol",
        "*.COPYBOOK*": "cobol",
        "*.COPY*": "cobol",
        "*.PL1*": "pl1",
        "*.PLI*": "pl1",
        "*.INC*": "pl1",
        "*.INCLUDE*": "pl1",
        "*.JCL*": "jcl"
    }
}

Ah, well I guess I'm somewhat relieved it's a known issue and possibly not some messed up environment setting.

I hope this helps and wish you luck in your research. Let me know if you need any more info!

Edit, add image of errors I'm seeing in VScode: error_e

tigerinus commented 4 years ago

I encountered the same issue. I had to mv the ./x.y.z folder to ./x/y/z to work around the problem.

SnapperGee commented 4 years ago

I encountered the same issue. I had to mv the ./x.y.z folder to ./x/y/z to work around the problem.

That's the issue though. It's a valid Java feature and offers greater flexibility when it comes to structuring a package or module with a structure and naming convention such as ./x.y/z. Restructuring the project so it's ./x/y/z can affect how it's implemented and is a work around for a bug that should be fixed.

Thanks for the reply though! I appreciate it! :D

That-Guy977 commented 10 months ago

This is also an issue with directory names including a hyphen (-), a keyword, or leading digits. By convention, these can be legalized with underscores, but the extension's error resolves into an empty package name.

kamzata commented 9 months ago

any news on this?

rgrunber commented 7 months ago

There is work to support the javac compiler as an alternative that would feed its grammar model directly into the existing API we use (so nearly all features should be available as before). I think that work would resolve this issue, since javac will compile such packages without issue.