Skip to content

Use $PROJECT_DIR$ instead of absolute path in misc.xml ANTLR configuration #420

Open
@blueglyph

Description

@blueglyph

Summary

The output directory is configured as an absolute path, which leads to problems when the project is moved.

Version

plugin: 1.14
Windows 7 x64
IntelliJ IDEA Community 2020.2

Description

When the user creates a parser file, right-clicks on it and selects 'Configure ANTLR', he is presented with a configuration fill form with, among other settings, 'Output directory where all output is generated'.

The setting is stored in $PROJECT_DIR$/.idea/misc.xml, for ex:

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="ANTLRGenerationPreferences">
    <option name="perGrammarGenerationSettings">
      <list>
        <PerGrammarGenerationSettings>
          <option name="outputDir" value="D:\projects\test\gen\myParser" />
[...]

Note that 'outputDir' is an absolute path, with the OS convention for directory separators.
When the project is used on another machine, or in another directory, this has the side-effect that the output directory is mislocated, at best. On a different OS it may be misinterpreted completely.

Instead, it should look like this:

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="ANTLRGenerationPreferences">
    <option name="perGrammarGenerationSettings">
      <list>
        <PerGrammarGenerationSettings>
          <option name="outputDir" value="$PROJECT_DIR$/gen/myParser" />
[...]

The solution is to:

  • detect whether the output directory is under the project path, and if so, replace the project path with $PROJECT_DIR$
  • use the slash character as directory separator

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions