From 2a9fdf7fead940f6f2cfc0febe02acd62aa1f0c7 Mon Sep 17 00:00:00 2001 From: Chao Wang Date: Tue, 16 Sep 2025 09:37:44 +0800 Subject: [PATCH] feat: Docker plugin dependency removal. Signed-off-by: Chao Wang --- README.md | 46 + gradle.properties | 2 +- .../image/build/lexer/DockerfileLexer.java | 797 ++++++++++++++++++ .../image/build/parser/DockerfileParser.java | 375 ++++++++ .../build/psi/DockerfileArgDeclaration.java | 16 + .../build/psi/DockerfileArgInstruction.java | 13 + .../image/build/psi/DockerfileArgValue.java | 22 + .../image/build/psi/DockerfileAsClause.java | 13 + .../image/build/psi/DockerfileComplexVar.java | 13 + .../build/psi/DockerfileFromInstruction.java | 19 + .../image/build/psi/DockerfileImageName.java | 13 + .../build/psi/DockerfileImageNameLiteral.java | 16 + .../build/psi/DockerfileImageNamePart.java | 19 + .../build/psi/DockerfileInstruction.java | 19 + .../build/psi/DockerfileInstructionArgs.java | 34 + .../image/build/psi/DockerfileItem.java | 19 + .../build/psi/DockerfileOtherInstruction.java | 13 + .../build/psi/DockerfilePlatformOption.java | 13 + .../build/psi/DockerfilePlatformValue.java | 16 + .../image/build/psi/DockerfileSimpleVar.java | 13 + .../image/build/psi/DockerfileTypes.java | 116 +++ .../build/psi/DockerfileVariableRef.java | 16 + .../image/build/psi/DockerfileVisitor.java | 82 ++ .../impl/DockerfileArgDeclarationImpl.java | 42 + .../impl/DockerfileArgInstructionImpl.java | 36 + .../psi/impl/DockerfileArgValueImpl.java | 54 ++ .../psi/impl/DockerfileAsClauseImpl.java | 36 + .../psi/impl/DockerfileComplexVarImpl.java | 36 + .../impl/DockerfileFromInstructionImpl.java | 48 ++ .../psi/impl/DockerfileImageNameImpl.java | 36 + .../impl/DockerfileImageNameLiteralImpl.java | 42 + .../psi/impl/DockerfileImageNamePartImpl.java | 48 ++ .../impl/DockerfileInstructionArgsImpl.java | 78 ++ .../psi/impl/DockerfileInstructionImpl.java | 48 ++ .../build/psi/impl/DockerfileItemImpl.java | 48 ++ .../impl/DockerfileOtherInstructionImpl.java | 36 + .../impl/DockerfilePlatformOptionImpl.java | 36 + .../psi/impl/DockerfilePlatformValueImpl.java | 42 + .../psi/impl/DockerfileSimpleVarImpl.java | 36 + .../psi/impl/DockerfileVariableRefImpl.java | 42 + .../intellij/image/DockerfileAnnotator.java | 7 + .../intellij/image/ImageReportAction.java | 4 +- .../image/ImageReportIntentionAction.java | 4 +- .../tools/intellij/image/ImageService.java | 201 ++--- .../intellij/image/UBIIntentionAction.java | 4 +- .../tools/intellij/image/build/dockerfile.bnf | 91 ++ .../intellij/image/build/dockerfile.flex | 113 +++ .../build/filetype/DockerfileFileType.java | 51 ++ .../image/build/lang/DockerfileLanguage.java | 22 + .../build/lexer/DockerfileLexerAdapter.java | 20 + .../build/psi/DockerfileElementType.java | 23 + .../image/build/psi/DockerfileFile.java | 36 + .../build/psi/DockerfileParserDefinition.java | 71 ++ .../image/build/psi/DockerfileTokenSets.java | 18 + .../image/build/psi/DockerfileTokenType.java | 28 + src/main/resources/META-INF/plugin.xml | 11 +- 56 files changed, 3017 insertions(+), 136 deletions(-) create mode 100644 src/main/gen/org/jboss/tools/intellij/image/build/lexer/DockerfileLexer.java create mode 100644 src/main/gen/org/jboss/tools/intellij/image/build/parser/DockerfileParser.java create mode 100644 src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileArgDeclaration.java create mode 100644 src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileArgInstruction.java create mode 100644 src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileArgValue.java create mode 100644 src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileAsClause.java create mode 100644 src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileComplexVar.java create mode 100644 src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileFromInstruction.java create mode 100644 src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileImageName.java create mode 100644 src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileImageNameLiteral.java create mode 100644 src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileImageNamePart.java create mode 100644 src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileInstruction.java create mode 100644 src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileInstructionArgs.java create mode 100644 src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileItem.java create mode 100644 src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileOtherInstruction.java create mode 100644 src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfilePlatformOption.java create mode 100644 src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfilePlatformValue.java create mode 100644 src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileSimpleVar.java create mode 100644 src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileTypes.java create mode 100644 src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileVariableRef.java create mode 100644 src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileVisitor.java create mode 100644 src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileArgDeclarationImpl.java create mode 100644 src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileArgInstructionImpl.java create mode 100644 src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileArgValueImpl.java create mode 100644 src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileAsClauseImpl.java create mode 100644 src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileComplexVarImpl.java create mode 100644 src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileFromInstructionImpl.java create mode 100644 src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileImageNameImpl.java create mode 100644 src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileImageNameLiteralImpl.java create mode 100644 src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileImageNamePartImpl.java create mode 100644 src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileInstructionArgsImpl.java create mode 100644 src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileInstructionImpl.java create mode 100644 src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileItemImpl.java create mode 100644 src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileOtherInstructionImpl.java create mode 100644 src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfilePlatformOptionImpl.java create mode 100644 src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfilePlatformValueImpl.java create mode 100644 src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileSimpleVarImpl.java create mode 100644 src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileVariableRefImpl.java create mode 100644 src/main/java/org/jboss/tools/intellij/image/build/dockerfile.bnf create mode 100644 src/main/java/org/jboss/tools/intellij/image/build/dockerfile.flex create mode 100644 src/main/java/org/jboss/tools/intellij/image/build/filetype/DockerfileFileType.java create mode 100644 src/main/java/org/jboss/tools/intellij/image/build/lang/DockerfileLanguage.java create mode 100644 src/main/java/org/jboss/tools/intellij/image/build/lexer/DockerfileLexerAdapter.java create mode 100644 src/main/java/org/jboss/tools/intellij/image/build/psi/DockerfileElementType.java create mode 100644 src/main/java/org/jboss/tools/intellij/image/build/psi/DockerfileFile.java create mode 100644 src/main/java/org/jboss/tools/intellij/image/build/psi/DockerfileParserDefinition.java create mode 100644 src/main/java/org/jboss/tools/intellij/image/build/psi/DockerfileTokenSets.java create mode 100644 src/main/java/org/jboss/tools/intellij/image/build/psi/DockerfileTokenType.java diff --git a/README.md b/README.md index 6882bf5f..f0c19f7c 100644 --- a/README.md +++ b/README.md @@ -191,6 +191,52 @@ according to your preferences. ![ Animated screenshot showing the inline reporting feature of Image Analysis ](src/main/resources/images/image-analysis.gif) +## Development + +### Custom Dockerfile Parser + +This plugin implements a custom Dockerfile parser to provide syntax highlighting and analysis without requiring the Docker plugin dependency. The parser is built using JFlex lexer and Grammar-Kit parser generators. + +#### Parser Architecture + +- **Grammar Definition**: `src/main/java/org/jboss/tools/intellij/image/build/dockerfile.bnf` - Defines Dockerfile syntax rules using Grammar-Kit BNF format +- **Lexer Specification**: `src/main/java/org/jboss/tools/intellij/image/build/dockerfile.flex` - Defines token patterns using JFlex format +- **Generated Classes**: PSI (Program Structure Interface) classes are generated in `src/main/java/org/jboss/tools/intellij/image/build/psi/` + +#### Regenerating Parser Classes + +When modifying the grammar or lexer files, you need to regenerate the parser classes: + +1. **Install JFlex** (if not already installed): + ```bash + # Download JFlex 1.9.2 or later + wget https://github.com/jflex-de/jflex/releases/download/v1.9.2/jflex-1.9.2.jar + ``` + +2. **Generate Lexer**: + ```bash + java -jar jflex-1.9.2.jar src/main/java/org/jboss/tools/intellij/image/build/dockerfile.flex + ``` + +3. **Generate Parser** (using Grammar-Kit plugin in IntelliJ): + - Open the `.bnf` file in IntelliJ IDEA + - Right-click and select "Generate Parser Code" from context menu + - Or use Tools → Grammar Kit → Generate Parser Code + +4. **Important Notes**: + - Always use `IMAGE_NAME_TOKEN` (not `IMAGE_NAME`) in both grammar and lexer to avoid naming conflicts + - The `ANY_CHAR` token serves as a catch-all for any non-whitespace characters in Dockerfile instructions + - Generated PSI classes should be committed to git to ensure reproducible builds + +#### Supported Dockerfile Features + +- All standard Dockerfile instructions (FROM, RUN, COPY, ADD, etc.) +- Multi-stage builds with AS aliases +- Platform specifications (--platform flag) +- Variable substitution (${VAR} and $VAR) +- Comments and complex shell commands +- Comprehensive syntax error handling + - **Excluding dependencies with `exhortignore`**
You can exclude a package from analysis by marking the package for exclusion. If you want to ignore vulnerabilities for a dependency in a `pom.xml` file, you must add `exhortignore` as a comment diff --git a/gradle.properties b/gradle.properties index a813fb97..af929ed0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,7 +10,7 @@ gradleVersion=8.5 # Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html platformBundledPlugins=org.jetbrains.plugins.yaml,com.intellij.java,org.jetbrains.idea.maven -platformPlugins=com.redhat.devtools.intellij.telemetry:1.1.0.52,Docker:251.23774.37 +platformPlugins=com.redhat.devtools.intellij.telemetry:1.1.0.52 # Opt-out flag for bundling Kotlin standard library -> https://jb.gg/intellij-platform-kotlin-stdlib kotlin.stdlib.default.dependency=false diff --git a/src/main/gen/org/jboss/tools/intellij/image/build/lexer/DockerfileLexer.java b/src/main/gen/org/jboss/tools/intellij/image/build/lexer/DockerfileLexer.java new file mode 100644 index 00000000..ba541c83 --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/image/build/lexer/DockerfileLexer.java @@ -0,0 +1,797 @@ +// Generated by JFlex 1.9.2 http://jflex.de/ (tweaked for IntelliJ platform) +// source: dockerfile.flex + +package org.jboss.tools.intellij.image.build.lexer; + +import com.intellij.lexer.FlexLexer; +import com.intellij.psi.tree.IElementType; +import org.jboss.tools.intellij.image.build.psi.DockerfileTypes; +import com.intellij.psi.TokenType; + + +class DockerfileLexer implements FlexLexer { + + /** This character denotes the end of file */ + public static final int YYEOF = -1; + + /** initial size of the lookahead buffer */ + private static final int ZZ_BUFFERSIZE = 16384; + + /** lexical states */ + public static final int YYINITIAL = 0; + + /** + * ZZ_LEXSTATE[l] is the state in the DFA for the lexical state l + * ZZ_LEXSTATE[l+1] is the state in the DFA for the lexical state l + * at the beginning of a line + * l is of the form l = 2*k, k a non negative integer + */ + private static final int ZZ_LEXSTATE[] = { + 0, 0 + }; + + /** + * Top-level table for translating characters to character classes + */ + private static final int [] ZZ_CMAP_TOP = zzUnpackcmap_top(); + + private static final String ZZ_CMAP_TOP_PACKED_0 = + "\1\0\1\u0100\24\u0200\1\u0300\11\u0200\1\u0400\17\u0200\1\u0500"+ + "\247\u0200\10\u0600\u1020\u0200"; + + private static int [] zzUnpackcmap_top() { + int [] result = new int[4352]; + int offset = 0; + offset = zzUnpackcmap_top(ZZ_CMAP_TOP_PACKED_0, offset, result); + return result; + } + + private static int zzUnpackcmap_top(String packed, int offset, int [] result) { + int i = 0; /* index in packed string */ + int j = offset; /* index in unpacked array */ + int l = packed.length(); + while (i < l) { + int count = packed.charAt(i++); + int value = packed.charAt(i++); + do result[j++] = value; while (--count > 0); + } + return j; + } + + + /** + * Second-level tables for translating characters to character classes + */ + private static final int [] ZZ_CMAP_BLOCKS = zzUnpackcmap_blocks(); + + private static final String ZZ_CMAP_BLOCKS_PACKED_0 = + "\11\0\1\1\1\2\1\3\1\4\1\5\22\0\1\1"+ + "\1\0\1\6\1\7\1\10\10\0\1\11\1\12\1\13"+ + "\1\14\2\15\1\16\1\17\1\15\1\20\1\21\1\22"+ + "\1\23\1\24\2\0\1\25\3\0\1\26\1\27\1\30"+ + "\1\31\1\32\1\33\1\34\1\35\1\36\1\35\1\37"+ + "\1\40\1\41\1\42\1\43\1\44\1\35\1\45\1\46"+ + "\1\47\1\50\1\51\1\52\1\53\1\54\1\35\1\0"+ + "\1\55\2\0\1\35\1\0\1\26\1\27\1\30\1\31"+ + "\1\32\1\33\1\34\1\35\1\36\1\35\1\37\1\40"+ + "\1\41\1\42\1\43\1\44\1\35\1\45\1\46\1\47"+ + "\1\50\1\51\1\52\1\53\1\54\1\35\1\56\1\0"+ + "\1\57\7\0\1\3\32\0\1\60\217\0\2\61\115\0"+ + "\1\62\u0200\0\1\60\177\0\13\60\35\0\2\3\5\0"+ + "\1\60\57\0\1\60\240\0\1\60\377\0\u0100\63"; + + private static int [] zzUnpackcmap_blocks() { + int [] result = new int[1792]; + int offset = 0; + offset = zzUnpackcmap_blocks(ZZ_CMAP_BLOCKS_PACKED_0, offset, result); + return result; + } + + private static int zzUnpackcmap_blocks(String packed, int offset, int [] result) { + int i = 0; /* index in packed string */ + int j = offset; /* index in unpacked array */ + int l = packed.length(); + while (i < l) { + int count = packed.charAt(i++); + int value = packed.charAt(i++); + do result[j++] = value; while (--count > 0); + } + return j; + } + + /** + * Translates DFA states to action switch labels. + */ + private static final int [] ZZ_ACTION = zzUnpackAction(); + + private static final String ZZ_ACTION_PACKED_0 = + "\1\0\1\1\1\2\1\3\2\4\1\1\1\5\1\6"+ + "\3\1\1\7\1\10\12\1\1\11\1\12\1\0\1\13"+ + "\1\0\4\14\1\15\3\16\1\17\7\16\1\0\4\16"+ + "\1\14\1\15\1\20\1\21\1\22\2\16\1\23\4\16"+ + "\1\0\1\24\3\16\1\14\1\25\2\16\1\26\2\16"+ + "\1\0\1\27\2\16\1\14\2\16\1\30\1\16\1\0"+ + "\2\16\1\14\1\16\1\31\1\14\1\0\1\32\1\16"+ + "\1\14\1\16\4\14\4\0\1\33\1\14\1\16\5\14"+ + "\5\0\1\14\1\16\1\34\4\14\1\0\1\34\3\0"+ + "\1\35\1\36\4\14\4\0\2\14\2\0\1\14\1\0"; + + private static int [] zzUnpackAction() { + int [] result = new int[144]; + int offset = 0; + offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result); + return result; + } + + private static int zzUnpackAction(String packed, int offset, int [] result) { + int i = 0; /* index in packed string */ + int j = offset; /* index in unpacked array */ + int l = packed.length(); + while (i < l) { + int count = packed.charAt(i++); + int value = packed.charAt(i++); + do result[j++] = value; while (--count > 0); + } + return j; + } + + + /** + * Translates a state to a row index in the transition table + */ + private static final int [] ZZ_ROWMAP = zzUnpackRowMap(); + + private static final String ZZ_ROWMAP_PACKED_0 = + "\0\0\0\64\0\150\0\64\0\64\0\234\0\320\0\u0104"+ + "\0\64\0\u0138\0\u016c\0\u01a0\0\64\0\64\0\u01d4\0\u0208"+ + "\0\u023c\0\u0270\0\u02a4\0\u02d8\0\u030c\0\u0340\0\u0374\0\u03a8"+ + "\0\64\0\64\0\320\0\64\0\u03dc\0\u0410\0\u016c\0\u0444"+ + "\0\u0478\0\u01a0\0\u0208\0\u04ac\0\u04e0\0\u0208\0\u0514\0\u0548"+ + "\0\u057c\0\u05b0\0\u05e4\0\u0618\0\u064c\0\u0680\0\u06b4\0\u06e8"+ + "\0\u071c\0\u0750\0\u0784\0\u0444\0\u0208\0\u0208\0\u0208\0\u07b8"+ + "\0\u07ec\0\u0208\0\u0820\0\u0854\0\u0888\0\u08bc\0\u08f0\0\u0208"+ + "\0\u0924\0\u0958\0\u098c\0\u09c0\0\u0208\0\u09f4\0\u0a28\0\u0208"+ + "\0\u0a5c\0\u0a90\0\u0ac4\0\u0208\0\u0af8\0\u0b2c\0\u0b60\0\u0b94"+ + "\0\u0bc8\0\u0208\0\u0bfc\0\u0c30\0\u0c64\0\u0c98\0\u0ccc\0\u0d00"+ + "\0\u0208\0\u0d34\0\u0d68\0\u0208\0\u0d9c\0\u0dd0\0\u0e04\0\u0e38"+ + "\0\u0e6c\0\u0ea0\0\u0ed4\0\u0f08\0\u0f3c\0\u0f70\0\u0fa4\0\u0208"+ + "\0\u0fd8\0\u100c\0\u1040\0\u1074\0\u10a8\0\u10dc\0\u1110\0\u1144"+ + "\0\u1178\0\u11ac\0\u11e0\0\u1214\0\u1248\0\u127c\0\u016c\0\u12b0"+ + "\0\u12e4\0\u1318\0\u134c\0\u1380\0\64\0\u13b4\0\u13e8\0\u141c"+ + "\0\u016c\0\u0208\0\u1450\0\u1484\0\u14b8\0\u14ec\0\u1520\0\u1554"+ + "\0\u1588\0\u15bc\0\u15f0\0\u1624\0\u1658\0\u168c\0\u16c0\0\u16f4"; + + private static int [] zzUnpackRowMap() { + int [] result = new int[144]; + int offset = 0; + offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result); + return result; + } + + private static int zzUnpackRowMap(String packed, int offset, int [] result) { + int i = 0; /* index in packed string */ + int j = offset; /* index in unpacked array */ + int l = packed.length() - 1; + while (i < l) { + int high = packed.charAt(i++) << 16; + result[j++] = high | packed.charAt(i++); + } + return j; + } + + /** + * The transition table of the DFA + */ + private static final int [] ZZ_TRANS = zzUnpacktrans(); + + private static final String ZZ_TRANS_PACKED_0 = + "\1\2\1\3\1\4\1\5\1\3\1\6\1\7\1\10"+ + "\1\11\1\12\2\13\10\14\1\15\1\16\1\17\1\20"+ + "\1\21\1\20\1\22\1\23\4\20\1\24\4\20\1\25"+ + "\2\20\1\26\1\27\1\30\2\20\1\2\1\31\1\32"+ + "\1\5\3\2\65\0\1\3\2\0\1\3\61\0\1\4"+ + "\61\0\6\33\1\34\46\33\1\35\6\33\2\10\1\0"+ + "\2\10\1\0\56\10\11\0\1\36\12\37\2\0\27\37"+ + "\20\0\13\37\2\0\27\37\20\0\1\40\1\41\1\37"+ + "\10\42\2\0\27\37\20\0\2\43\1\37\10\43\2\0"+ + "\3\43\1\44\13\43\1\45\1\46\6\43\20\0\2\43"+ + "\1\37\10\43\2\0\27\43\20\0\2\43\1\37\10\43"+ + "\2\0\13\43\1\47\1\43\1\50\11\43\20\0\2\43"+ + "\1\37\10\43\2\0\14\43\1\51\10\43\1\52\1\43"+ + "\20\0\2\43\1\37\10\43\2\0\17\43\1\53\7\43"+ + "\20\0\2\43\1\37\10\43\2\0\1\54\7\43\1\55"+ + "\16\43\4\0\1\56\13\0\2\43\1\37\10\43\2\0"+ + "\22\43\1\57\4\43\20\0\2\43\1\37\10\43\2\0"+ + "\20\43\1\60\6\43\20\0\2\43\1\37\10\43\2\0"+ + "\15\43\1\61\11\43\20\0\2\43\1\37\10\43\2\0"+ + "\15\43\1\62\11\43\7\0\2\33\4\0\55\33\12\0"+ + "\13\37\2\0\16\37\1\63\10\37\20\0\2\64\1\37"+ + "\10\64\2\0\27\64\20\0\3\37\10\42\2\0\27\37"+ + "\20\0\2\43\1\37\10\43\2\0\3\43\1\65\23\43"+ + "\20\0\2\43\1\37\10\43\2\0\6\43\1\66\20\43"+ + "\20\0\2\43\1\37\10\43\2\0\3\43\1\67\23\43"+ + "\20\0\2\43\1\37\10\43\2\0\16\43\1\70\10\43"+ + "\20\0\2\43\1\37\10\43\2\0\21\43\1\71\1\43"+ + "\1\72\3\43\20\0\2\43\1\37\10\43\2\0\16\43"+ + "\1\73\10\43\20\0\2\43\1\37\10\43\2\0\15\43"+ + "\1\74\11\43\20\0\2\43\1\37\10\43\2\0\1\43"+ + "\1\75\25\43\20\0\2\43\1\37\10\43\2\0\14\43"+ + "\1\76\12\43\51\0\1\77\32\0\2\43\1\37\10\43"+ + "\2\0\14\43\1\100\12\43\20\0\2\43\1\37\10\43"+ + "\2\0\4\43\1\101\22\43\20\0\2\43\1\37\10\43"+ + "\2\0\12\43\1\102\14\43\20\0\2\43\1\37\10\43"+ + "\2\0\17\43\1\103\7\43\20\0\13\37\2\0\12\37"+ + "\1\104\14\37\20\0\2\43\1\37\10\43\2\0\26\43"+ + "\1\105\20\0\2\43\1\37\10\43\2\0\17\43\1\106"+ + "\7\43\20\0\2\43\1\37\10\43\2\0\15\43\1\107"+ + "\11\43\20\0\2\43\1\37\10\43\2\0\13\43\1\110"+ + "\13\43\20\0\2\43\1\37\10\43\2\0\4\43\1\111"+ + "\22\43\20\0\2\43\1\37\10\43\2\0\22\43\1\112"+ + "\4\43\57\0\1\113\24\0\2\43\1\37\10\43\2\0"+ + "\17\43\1\114\7\43\20\0\2\43\1\37\10\43\2\0"+ + "\22\43\1\115\4\43\20\0\2\43\1\37\10\43\2\0"+ + "\11\43\1\116\15\43\20\0\13\37\2\0\1\117\26\37"+ + "\20\0\2\43\1\37\10\43\2\0\26\43\1\120\20\0"+ + "\2\43\1\37\10\43\2\0\20\43\1\121\6\43\20\0"+ + "\2\43\1\37\10\43\2\0\12\43\1\122\14\43\20\0"+ + "\2\43\1\37\10\43\2\0\25\43\1\123\1\43\62\0"+ + "\1\124\21\0\2\43\1\37\10\43\2\0\13\43\1\125"+ + "\13\43\20\0\2\43\1\37\10\43\2\0\3\43\1\126"+ + "\23\43\20\0\13\37\2\0\21\37\1\127\5\37\20\0"+ + "\2\43\1\37\10\43\2\0\16\43\1\130\10\43\20\0"+ + "\2\43\1\37\10\43\2\0\4\43\1\131\22\43\20\0"+ + "\2\43\1\132\10\43\2\0\27\43\22\0\1\133\61\0"+ + "\2\43\1\37\10\43\2\0\4\43\1\134\22\43\20\0"+ + "\2\43\1\37\10\43\2\0\10\43\1\135\16\43\20\0"+ + "\13\37\2\0\5\37\1\136\21\37\20\0\2\43\1\37"+ + "\10\43\2\0\15\43\1\137\11\43\20\0\5\37\1\140"+ + "\5\37\2\0\1\141\15\37\1\142\1\37\1\143\6\37"+ + "\5\0\1\144\17\0\1\145\7\0\1\146\15\0\1\147"+ + "\1\0\1\144\13\0\1\144\12\0\2\43\1\37\10\43"+ + "\2\0\17\43\1\150\7\43\20\0\13\37\2\0\15\37"+ + "\1\151\11\37\20\0\2\43\1\37\10\43\2\0\10\43"+ + "\1\152\16\43\20\0\11\37\1\153\1\37\2\0\27\37"+ + "\20\0\13\37\2\0\13\37\1\154\3\37\1\155\7\37"+ + "\20\0\13\37\2\0\16\37\1\156\10\37\20\0\5\37"+ + "\1\157\5\37\2\0\27\37\25\0\1\160\67\0\1\161"+ + "\102\0\1\162\3\0\1\163\62\0\1\164\30\0\13\37"+ + "\2\0\17\37\1\165\7\37\20\0\2\43\1\37\10\43"+ + "\2\0\14\43\1\166\12\43\20\0\7\37\1\167\3\37"+ + "\2\0\27\37\20\0\13\37\2\0\3\37\1\170\23\37"+ + "\20\0\13\37\2\0\13\37\1\171\13\37\20\0\13\37"+ + "\2\0\2\37\1\172\24\37\20\0\12\37\1\173\2\0"+ + "\27\37\32\0\1\174\60\0\1\175\74\0\1\176\73\0"+ + "\1\177\52\0\1\200\44\0\13\37\2\0\13\37\1\201"+ + "\13\37\20\0\2\43\1\37\10\43\2\0\21\43\1\202"+ + "\5\43\20\0\7\37\1\203\3\37\2\0\27\37\20\0"+ + "\2\37\1\204\4\37\1\203\3\37\2\0\27\37\20\0"+ + "\7\37\1\205\3\37\2\0\27\37\20\0\3\37\1\206"+ + "\7\37\2\0\27\37\23\0\1\207\67\0\1\210\56\0"+ + "\1\211\4\0\1\210\63\0\1\212\54\0\6\37\1\167"+ + "\4\37\2\0\27\37\20\0\13\37\2\0\23\37\1\213"+ + "\3\37\20\0\6\37\1\214\4\37\2\0\27\37\20\0"+ + "\13\37\2\0\25\37\1\167\1\37\62\0\1\175\27\0"+ + "\1\175\115\0\1\215\31\0\1\216\55\0\7\37\2\167"+ + "\2\37\2\0\27\37\20\0\13\37\2\0\12\37\1\217"+ + "\14\37\27\0\2\175\102\0\1\220\34\0\13\37\2\0"+ + "\4\37\1\167\22\37\41\0\1\175\31\0"; + + private static int [] zzUnpacktrans() { + int [] result = new int[5928]; + int offset = 0; + offset = zzUnpacktrans(ZZ_TRANS_PACKED_0, offset, result); + return result; + } + + private static int zzUnpacktrans(String packed, int offset, int [] result) { + int i = 0; /* index in packed string */ + int j = offset; /* index in unpacked array */ + int l = packed.length(); + while (i < l) { + int count = packed.charAt(i++); + int value = packed.charAt(i++); + value--; + do result[j++] = value; while (--count > 0); + } + return j; + } + + + /* error codes */ + private static final int ZZ_UNKNOWN_ERROR = 0; + private static final int ZZ_NO_MATCH = 1; + private static final int ZZ_PUSHBACK_2BIG = 2; + + /* error messages for the codes above */ + private static final String[] ZZ_ERROR_MSG = { + "Unknown internal scanner error", + "Error: could not match input", + "Error: pushback value was too large" + }; + + /** + * ZZ_ATTRIBUTE[aState] contains the attributes of state {@code aState} + */ + private static final int [] ZZ_ATTRIBUTE = zzUnpackAttribute(); + + private static final String ZZ_ATTRIBUTE_PACKED_0 = + "\1\0\1\11\1\1\2\11\3\1\1\11\3\1\2\11"+ + "\12\1\2\11\1\0\1\11\1\0\20\1\1\0\20\1"+ + "\1\0\13\1\1\0\10\1\1\0\6\1\1\0\10\1"+ + "\4\0\10\1\5\0\7\1\1\0\1\11\3\0\6\1"+ + "\4\0\2\1\2\0\1\1\1\0"; + + private static int [] zzUnpackAttribute() { + int [] result = new int[144]; + int offset = 0; + offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result); + return result; + } + + private static int zzUnpackAttribute(String packed, int offset, int [] result) { + int i = 0; /* index in packed string */ + int j = offset; /* index in unpacked array */ + int l = packed.length(); + while (i < l) { + int count = packed.charAt(i++); + int value = packed.charAt(i++); + do result[j++] = value; while (--count > 0); + } + return j; + } + + /** the input device */ + private java.io.Reader zzReader; + + /** the current state of the DFA */ + private int zzState; + + /** the current lexical state */ + private int zzLexicalState = YYINITIAL; + + /** this buffer contains the current text to be matched and is + the source of the yytext() string */ + private CharSequence zzBuffer = ""; + + /** the textposition at the last accepting state */ + private int zzMarkedPos; + + /** the current text position in the buffer */ + private int zzCurrentPos; + + /** startRead marks the beginning of the yytext() string in the buffer */ + private int zzStartRead; + + /** endRead marks the last character in the buffer, that has been read + from input */ + private int zzEndRead; + + /** zzAtEOF == true <=> the scanner is at the EOF */ + private boolean zzAtEOF; + + /** Number of newlines encountered up to the start of the matched text. */ + @SuppressWarnings("unused") + private int yyline; + + /** Number of characters from the last newline up to the start of the matched text. */ + @SuppressWarnings("unused") + protected int yycolumn; + + /** Number of characters up to the start of the matched text. */ + @SuppressWarnings("unused") + private long yychar; + + /** Whether the scanner is currently at the beginning of a line. */ + @SuppressWarnings("unused") + private boolean zzAtBOL = true; + + /** Whether the user-EOF-code has already been executed. */ + @SuppressWarnings("unused") + private boolean zzEOFDone; + + /* user code: */ + public DockerfileLexer() { + this((java.io.Reader)null); + } + + + /** + * Creates a new scanner + * + * @param in the java.io.Reader to read input from. + */ + DockerfileLexer(java.io.Reader in) { + this.zzReader = in; + } + + + /** Returns the maximum size of the scanner buffer, which limits the size of tokens. */ + private int zzMaxBufferLen() { + return Integer.MAX_VALUE; + } + + /** Whether the scanner buffer can grow to accommodate a larger token. */ + private boolean zzCanGrow() { + return true; + } + + /** + * Translates raw input code points to DFA table row + */ + private static int zzCMap(int input) { + int offset = input & 255; + return offset == input ? ZZ_CMAP_BLOCKS[offset] : ZZ_CMAP_BLOCKS[ZZ_CMAP_TOP[input >> 8] | offset]; + } + + public final int getTokenStart() { + return zzStartRead; + } + + public final int getTokenEnd() { + return getTokenStart() + yylength(); + } + + public void reset(CharSequence buffer, int start, int end, int initialState) { + zzBuffer = buffer; + zzCurrentPos = zzMarkedPos = zzStartRead = start; + zzAtEOF = false; + zzAtBOL = true; + zzEndRead = end; + yybegin(initialState); + } + + /** + * Refills the input buffer. + * + * @return {@code false}, iff there was new input. + * + * @exception java.io.IOException if any I/O-Error occurs + */ + private boolean zzRefill() throws java.io.IOException { + return true; + } + + + /** + * Returns the current lexical state. + */ + public final int yystate() { + return zzLexicalState; + } + + + /** + * Enters a new lexical state + * + * @param newState the new lexical state + */ + public final void yybegin(int newState) { + zzLexicalState = newState; + } + + + /** + * Returns the text matched by the current regular expression. + */ + public final CharSequence yytext() { + return zzBuffer.subSequence(zzStartRead, zzMarkedPos); + } + + + /** + * Returns the character at position {@code pos} from the + * matched text. + * + * It is equivalent to yytext().charAt(pos), but faster + * + * @param pos the position of the character to fetch. + * A value from 0 to yylength()-1. + * + * @return the character at position pos + */ + public final char yycharat(int pos) { + return zzBuffer.charAt(zzStartRead+pos); + } + + + /** + * Returns the length of the matched text region. + */ + public final int yylength() { + return zzMarkedPos-zzStartRead; + } + + + /** + * Reports an error that occurred while scanning. + * + * In a wellformed scanner (no or only correct usage of + * yypushback(int) and a match-all fallback rule) this method + * will only be called with things that "Can't Possibly Happen". + * If this method is called, something is seriously wrong + * (e.g. a JFlex bug producing a faulty scanner etc.). + * + * Usual syntax/scanner level error handling should be done + * in error fallback rules. + * + * @param errorCode the code of the errormessage to display + */ + private void zzScanError(int errorCode) { + String message; + try { + message = ZZ_ERROR_MSG[errorCode]; + } + catch (ArrayIndexOutOfBoundsException e) { + message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR]; + } + + throw new Error(message); + } + + + /** + * Pushes the specified amount of characters back into the input stream. + * + * They will be read again by then next call of the scanning method + * + * @param number the number of characters to be read again. + * This number must not be greater than yylength()! + */ + public void yypushback(int number) { + if ( number > yylength() ) + zzScanError(ZZ_PUSHBACK_2BIG); + + zzMarkedPos -= number; + } + + + /** + * Resumes scanning until the next regular expression is matched, + * the end of input is encountered or an I/O-Error occurs. + * + * @return the next token + * @exception java.io.IOException if any I/O-Error occurs + */ + public IElementType advance() throws java.io.IOException + { + int zzInput; + int zzAction; + + // cached fields: + int zzCurrentPosL; + int zzMarkedPosL; + int zzEndReadL = zzEndRead; + CharSequence zzBufferL = zzBuffer; + + int [] zzTransL = ZZ_TRANS; + int [] zzRowMapL = ZZ_ROWMAP; + int [] zzAttrL = ZZ_ATTRIBUTE; + + while (true) { + zzMarkedPosL = zzMarkedPos; + + zzAction = -1; + + zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL; + + zzState = ZZ_LEXSTATE[zzLexicalState]; + + // set up zzAction for empty match case: + int zzAttributes = zzAttrL[zzState]; + if ( (zzAttributes & 1) == 1 ) { + zzAction = zzState; + } + + + zzForAction: { + while (true) { + + if (zzCurrentPosL < zzEndReadL) { + zzInput = Character.codePointAt(zzBufferL, zzCurrentPosL); + zzCurrentPosL += Character.charCount(zzInput); + } + else if (zzAtEOF) { + zzInput = YYEOF; + break zzForAction; + } + else { + // store back cached positions + zzCurrentPos = zzCurrentPosL; + zzMarkedPos = zzMarkedPosL; + boolean eof = zzRefill(); + // get translated positions and possibly new buffer + zzCurrentPosL = zzCurrentPos; + zzMarkedPosL = zzMarkedPos; + zzBufferL = zzBuffer; + zzEndReadL = zzEndRead; + if (eof) { + zzInput = YYEOF; + break zzForAction; + } + else { + zzInput = Character.codePointAt(zzBufferL, zzCurrentPosL); + zzCurrentPosL += Character.charCount(zzInput); + } + } + int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMap(zzInput) ]; + if (zzNext == -1) break zzForAction; + zzState = zzNext; + + zzAttributes = zzAttrL[zzState]; + if ( (zzAttributes & 1) == 1 ) { + zzAction = zzState; + zzMarkedPosL = zzCurrentPosL; + if ( (zzAttributes & 8) == 8 ) break zzForAction; + } + + } + } + + // store back cached position + zzMarkedPos = zzMarkedPosL; + + if (zzInput == YYEOF && zzStartRead == zzCurrentPos) { + zzAtEOF = true; + return null; + } + else { + switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) { + case 1: + { return DockerfileTypes.ANY_CHAR; + } + // fall through + case 31: break; + case 2: + { return TokenType.WHITE_SPACE; + } + // fall through + case 32: break; + case 3: + { return DockerfileTypes.NEWLINE; + } + // fall through + case 33: break; + case 4: + { return TokenType.BAD_CHARACTER; + } + // fall through + case 34: break; + case 5: + { return DockerfileTypes.COMMENT; + } + // fall through + case 35: break; + case 6: + { return DockerfileTypes.DOLLAR; + } + // fall through + case 36: break; + case 7: + { return DockerfileTypes.COLON; + } + // fall through + case 37: break; + case 8: + { return DockerfileTypes.EQUALS; + } + // fall through + case 38: break; + case 9: + { return DockerfileTypes.LBRACE; + } + // fall through + case 39: break; + case 10: + { return DockerfileTypes.RBRACE; + } + // fall through + case 40: break; + case 11: + { return DockerfileTypes.STRING; + } + // fall through + case 41: break; + case 12: + { return DockerfileTypes.IMAGE_NAME_TOKEN; + } + // fall through + case 42: break; + case 13: + { return DockerfileTypes.VERSION; + } + // fall through + case 43: break; + case 14: + { return DockerfileTypes.IDENTIFIER; + } + // fall through + case 44: break; + case 15: + { return DockerfileTypes.AS; + } + // fall through + case 45: break; + case 16: + { return DockerfileTypes.ADD; + } + // fall through + case 46: break; + case 17: + { return DockerfileTypes.ARG; + } + // fall through + case 47: break; + case 18: + { return DockerfileTypes.CMD; + } + // fall through + case 48: break; + case 19: + { return DockerfileTypes.ENV; + } + // fall through + case 49: break; + case 20: + { return DockerfileTypes.RUN; + } + // fall through + case 50: break; + case 21: + { return DockerfileTypes.COPY; + } + // fall through + case 51: break; + case 22: + { return DockerfileTypes.FROM; + } + // fall through + case 52: break; + case 23: + { return DockerfileTypes.USER; + } + // fall through + case 53: break; + case 24: + { return DockerfileTypes.LABEL; + } + // fall through + case 54: break; + case 25: + { return DockerfileTypes.EXPOSE; + } + // fall through + case 55: break; + case 26: + { return DockerfileTypes.VOLUME; + } + // fall through + case 56: break; + case 27: + { return DockerfileTypes.WORKDIR; + } + // fall through + case 57: break; + case 28: + { return DockerfileTypes.PLATFORM; + } + // fall through + case 58: break; + case 29: + { return DockerfileTypes.PLATFORM_FLAG; + } + // fall through + case 59: break; + case 30: + { return DockerfileTypes.ENTRYPOINT; + } + // fall through + case 60: break; + default: + zzScanError(ZZ_NO_MATCH); + } + } + } + } + + +} diff --git a/src/main/gen/org/jboss/tools/intellij/image/build/parser/DockerfileParser.java b/src/main/gen/org/jboss/tools/intellij/image/build/parser/DockerfileParser.java new file mode 100644 index 00000000..6da5c66f --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/image/build/parser/DockerfileParser.java @@ -0,0 +1,375 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.image.build.parser; + +import com.intellij.lang.PsiBuilder; +import com.intellij.lang.PsiBuilder.Marker; +import static org.jboss.tools.intellij.image.build.psi.DockerfileTypes.*; +import static com.intellij.lang.parser.GeneratedParserUtilBase.*; +import com.intellij.psi.tree.IElementType; +import com.intellij.lang.ASTNode; +import com.intellij.psi.tree.TokenSet; +import com.intellij.lang.PsiParser; +import com.intellij.lang.LightPsiParser; + +@SuppressWarnings({"SimplifiableIfStatement", "UnusedAssignment"}) +public class DockerfileParser implements PsiParser, LightPsiParser { + + public ASTNode parse(IElementType t, PsiBuilder b) { + parseLight(t, b); + return b.getTreeBuilt(); + } + + public void parseLight(IElementType t, PsiBuilder b) { + boolean r; + b = adapt_builder_(t, b, this, null); + Marker m = enter_section_(b, 0, _COLLAPSE_, null); + r = parse_root_(t, b); + exit_section_(b, 0, m, t, r, true, TRUE_CONDITION); + } + + protected boolean parse_root_(IElementType t, PsiBuilder b) { + return parse_root_(t, b, 0); + } + + static boolean parse_root_(IElementType t, PsiBuilder b, int l) { + return dockerFile(b, l + 1); + } + + /* ********************************************************** */ + // IDENTIFIER (EQUALS argValue)? + public static boolean argDeclaration(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "argDeclaration")) return false; + if (!nextTokenIs(b, IDENTIFIER)) return false; + boolean r; + Marker m = enter_section_(b); + r = consumeToken(b, IDENTIFIER); + r = r && argDeclaration_1(b, l + 1); + exit_section_(b, m, ARG_DECLARATION, r); + return r; + } + + // (EQUALS argValue)? + private static boolean argDeclaration_1(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "argDeclaration_1")) return false; + argDeclaration_1_0(b, l + 1); + return true; + } + + // EQUALS argValue + private static boolean argDeclaration_1_0(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "argDeclaration_1_0")) return false; + boolean r; + Marker m = enter_section_(b); + r = consumeToken(b, EQUALS); + r = r && argValue(b, l + 1); + exit_section_(b, m, null, r); + return r; + } + + /* ********************************************************** */ + // ARG argDeclaration + public static boolean argInstruction(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "argInstruction")) return false; + if (!nextTokenIs(b, ARG)) return false; + boolean r; + Marker m = enter_section_(b); + r = consumeToken(b, ARG); + r = r && argDeclaration(b, l + 1); + exit_section_(b, m, ARG_INSTRUCTION, r); + return r; + } + + /* ********************************************************** */ + // STRING | IDENTIFIER | VERSION | variableRef + public static boolean argValue(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "argValue")) return false; + boolean r; + Marker m = enter_section_(b, l, _NONE_, ARG_VALUE, ""); + r = consumeToken(b, STRING); + if (!r) r = consumeToken(b, IDENTIFIER); + if (!r) r = consumeToken(b, VERSION); + if (!r) r = variableRef(b, l + 1); + exit_section_(b, l, m, r, false, null); + return r; + } + + /* ********************************************************** */ + // AS IDENTIFIER + public static boolean asClause(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "asClause")) return false; + if (!nextTokenIs(b, AS)) return false; + boolean r; + Marker m = enter_section_(b); + r = consumeTokens(b, 0, AS, IDENTIFIER); + exit_section_(b, m, AS_CLAUSE, r); + return r; + } + + /* ********************************************************** */ + // LBRACE IDENTIFIER RBRACE + public static boolean complexVar(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "complexVar")) return false; + if (!nextTokenIs(b, LBRACE)) return false; + boolean r; + Marker m = enter_section_(b); + r = consumeTokens(b, 0, LBRACE, IDENTIFIER, RBRACE); + exit_section_(b, m, COMPLEX_VAR, r); + return r; + } + + /* ********************************************************** */ + // item* + static boolean dockerFile(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "dockerFile")) return false; + while (true) { + int c = current_position_(b); + if (!item(b, l + 1)) break; + if (!empty_element_parsed_guard_(b, "dockerFile", c)) break; + } + return true; + } + + /* ********************************************************** */ + // FROM (platformOption)? imageName (asClause)? + public static boolean fromInstruction(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "fromInstruction")) return false; + if (!nextTokenIs(b, FROM)) return false; + boolean r; + Marker m = enter_section_(b); + r = consumeToken(b, FROM); + r = r && fromInstruction_1(b, l + 1); + r = r && imageName(b, l + 1); + r = r && fromInstruction_3(b, l + 1); + exit_section_(b, m, FROM_INSTRUCTION, r); + return r; + } + + // (platformOption)? + private static boolean fromInstruction_1(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "fromInstruction_1")) return false; + fromInstruction_1_0(b, l + 1); + return true; + } + + // (platformOption) + private static boolean fromInstruction_1_0(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "fromInstruction_1_0")) return false; + boolean r; + Marker m = enter_section_(b); + r = platformOption(b, l + 1); + exit_section_(b, m, null, r); + return r; + } + + // (asClause)? + private static boolean fromInstruction_3(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "fromInstruction_3")) return false; + fromInstruction_3_0(b, l + 1); + return true; + } + + // (asClause) + private static boolean fromInstruction_3_0(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "fromInstruction_3_0")) return false; + boolean r; + Marker m = enter_section_(b); + r = asClause(b, l + 1); + exit_section_(b, m, null, r); + return r; + } + + /* ********************************************************** */ + // imageNamePart+ + public static boolean imageName(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "imageName")) return false; + boolean r; + Marker m = enter_section_(b, l, _NONE_, IMAGE_NAME, ""); + r = imageNamePart(b, l + 1); + while (r) { + int c = current_position_(b); + if (!imageNamePart(b, l + 1)) break; + if (!empty_element_parsed_guard_(b, "imageName", c)) break; + } + exit_section_(b, l, m, r, false, null); + return r; + } + + /* ********************************************************** */ + // IMAGE_NAME_TOKEN | IDENTIFIER + public static boolean imageNameLiteral(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "imageNameLiteral")) return false; + if (!nextTokenIs(b, "", IDENTIFIER, IMAGE_NAME_TOKEN)) return false; + boolean r; + Marker m = enter_section_(b, l, _NONE_, IMAGE_NAME_LITERAL, ""); + r = consumeToken(b, IMAGE_NAME_TOKEN); + if (!r) r = consumeToken(b, IDENTIFIER); + exit_section_(b, l, m, r, false, null); + return r; + } + + /* ********************************************************** */ + // imageNameLiteral | variableRef | COLON | VERSION + public static boolean imageNamePart(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "imageNamePart")) return false; + boolean r; + Marker m = enter_section_(b, l, _NONE_, IMAGE_NAME_PART, ""); + r = imageNameLiteral(b, l + 1); + if (!r) r = variableRef(b, l + 1); + if (!r) r = consumeToken(b, COLON); + if (!r) r = consumeToken(b, VERSION); + exit_section_(b, l, m, r, false, null); + return r; + } + + /* ********************************************************** */ + // fromInstruction | argInstruction | otherInstruction + public static boolean instruction(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "instruction")) return false; + boolean r; + Marker m = enter_section_(b, l, _NONE_, INSTRUCTION, ""); + r = fromInstruction(b, l + 1); + if (!r) r = argInstruction(b, l + 1); + if (!r) r = otherInstruction(b, l + 1); + exit_section_(b, l, m, r, false, null); + return r; + } + + /* ********************************************************** */ + // STRING | IDENTIFIER | VERSION | IMAGE_NAME_TOKEN | OTHER_TOKEN | COLON | EQUALS | DOLLAR | LBRACE | RBRACE | PLATFORM_FLAG | PLATFORM | ANY_CHAR | variableRef + public static boolean instructionArgs(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "instructionArgs")) return false; + boolean r; + Marker m = enter_section_(b, l, _NONE_, INSTRUCTION_ARGS, ""); + r = consumeToken(b, STRING); + if (!r) r = consumeToken(b, IDENTIFIER); + if (!r) r = consumeToken(b, VERSION); + if (!r) r = consumeToken(b, IMAGE_NAME_TOKEN); + if (!r) r = consumeToken(b, OTHER_TOKEN); + if (!r) r = consumeToken(b, COLON); + if (!r) r = consumeToken(b, EQUALS); + if (!r) r = consumeToken(b, DOLLAR); + if (!r) r = consumeToken(b, LBRACE); + if (!r) r = consumeToken(b, RBRACE); + if (!r) r = consumeToken(b, PLATFORM_FLAG); + if (!r) r = consumeToken(b, PLATFORM); + if (!r) r = consumeToken(b, ANY_CHAR); + if (!r) r = variableRef(b, l + 1); + exit_section_(b, l, m, r, false, null); + return r; + } + + /* ********************************************************** */ + // instruction | COMMENT | NEWLINE + public static boolean item(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "item")) return false; + boolean r; + Marker m = enter_section_(b, l, _NONE_, ITEM, ""); + r = instruction(b, l + 1); + if (!r) r = consumeToken(b, COMMENT); + if (!r) r = consumeToken(b, NEWLINE); + exit_section_(b, l, m, r, false, null); + return r; + } + + /* ********************************************************** */ + // (RUN | COPY | ADD | WORKDIR | CMD | ENTRYPOINT | ENV | EXPOSE | VOLUME | USER | LABEL) instructionArgs* + public static boolean otherInstruction(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "otherInstruction")) return false; + boolean r; + Marker m = enter_section_(b, l, _NONE_, OTHER_INSTRUCTION, ""); + r = otherInstruction_0(b, l + 1); + r = r && otherInstruction_1(b, l + 1); + exit_section_(b, l, m, r, false, null); + return r; + } + + // RUN | COPY | ADD | WORKDIR | CMD | ENTRYPOINT | ENV | EXPOSE | VOLUME | USER | LABEL + private static boolean otherInstruction_0(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "otherInstruction_0")) return false; + boolean r; + r = consumeToken(b, RUN); + if (!r) r = consumeToken(b, COPY); + if (!r) r = consumeToken(b, ADD); + if (!r) r = consumeToken(b, WORKDIR); + if (!r) r = consumeToken(b, CMD); + if (!r) r = consumeToken(b, ENTRYPOINT); + if (!r) r = consumeToken(b, ENV); + if (!r) r = consumeToken(b, EXPOSE); + if (!r) r = consumeToken(b, VOLUME); + if (!r) r = consumeToken(b, USER); + if (!r) r = consumeToken(b, LABEL); + return r; + } + + // instructionArgs* + private static boolean otherInstruction_1(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "otherInstruction_1")) return false; + while (true) { + int c = current_position_(b); + if (!instructionArgs(b, l + 1)) break; + if (!empty_element_parsed_guard_(b, "otherInstruction_1", c)) break; + } + return true; + } + + /* ********************************************************** */ + // PLATFORM_FLAG EQUALS platformValue + public static boolean platformOption(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "platformOption")) return false; + if (!nextTokenIs(b, PLATFORM_FLAG)) return false; + boolean r; + Marker m = enter_section_(b); + r = consumeTokens(b, 0, PLATFORM_FLAG, EQUALS); + r = r && platformValue(b, l + 1); + exit_section_(b, m, PLATFORM_OPTION, r); + return r; + } + + /* ********************************************************** */ + // PLATFORM | variableRef + public static boolean platformValue(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "platformValue")) return false; + if (!nextTokenIs(b, "", DOLLAR, PLATFORM)) return false; + boolean r; + Marker m = enter_section_(b, l, _NONE_, PLATFORM_VALUE, ""); + r = consumeToken(b, PLATFORM); + if (!r) r = variableRef(b, l + 1); + exit_section_(b, l, m, r, false, null); + return r; + } + + /* ********************************************************** */ + // IDENTIFIER + public static boolean simpleVar(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "simpleVar")) return false; + if (!nextTokenIs(b, IDENTIFIER)) return false; + boolean r; + Marker m = enter_section_(b); + r = consumeToken(b, IDENTIFIER); + exit_section_(b, m, SIMPLE_VAR, r); + return r; + } + + /* ********************************************************** */ + // DOLLAR (simpleVar | complexVar) + public static boolean variableRef(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "variableRef")) return false; + if (!nextTokenIs(b, DOLLAR)) return false; + boolean r; + Marker m = enter_section_(b); + r = consumeToken(b, DOLLAR); + r = r && variableRef_1(b, l + 1); + exit_section_(b, m, VARIABLE_REF, r); + return r; + } + + // simpleVar | complexVar + private static boolean variableRef_1(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "variableRef_1")) return false; + boolean r; + r = simpleVar(b, l + 1); + if (!r) r = complexVar(b, l + 1); + return r; + } + +} diff --git a/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileArgDeclaration.java b/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileArgDeclaration.java new file mode 100644 index 00000000..a75262f3 --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileArgDeclaration.java @@ -0,0 +1,16 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.image.build.psi; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.psi.PsiElement; + +public interface DockerfileArgDeclaration extends PsiElement { + + @Nullable + DockerfileArgValue getArgValue(); + + @NotNull + PsiElement getIdentifier(); + +} diff --git a/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileArgInstruction.java b/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileArgInstruction.java new file mode 100644 index 00000000..f6288148 --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileArgInstruction.java @@ -0,0 +1,13 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.image.build.psi; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.psi.PsiElement; + +public interface DockerfileArgInstruction extends PsiElement { + + @NotNull + DockerfileArgDeclaration getArgDeclaration(); + +} diff --git a/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileArgValue.java b/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileArgValue.java new file mode 100644 index 00000000..1ed36dd9 --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileArgValue.java @@ -0,0 +1,22 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.image.build.psi; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.psi.PsiElement; + +public interface DockerfileArgValue extends PsiElement { + + @Nullable + DockerfileVariableRef getVariableRef(); + + @Nullable + PsiElement getIdentifier(); + + @Nullable + PsiElement getString(); + + @Nullable + PsiElement getVersion(); + +} diff --git a/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileAsClause.java b/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileAsClause.java new file mode 100644 index 00000000..71482dd8 --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileAsClause.java @@ -0,0 +1,13 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.image.build.psi; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.psi.PsiElement; + +public interface DockerfileAsClause extends PsiElement { + + @NotNull + PsiElement getIdentifier(); + +} diff --git a/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileComplexVar.java b/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileComplexVar.java new file mode 100644 index 00000000..a34e668c --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileComplexVar.java @@ -0,0 +1,13 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.image.build.psi; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.psi.PsiElement; + +public interface DockerfileComplexVar extends PsiElement { + + @NotNull + PsiElement getIdentifier(); + +} diff --git a/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileFromInstruction.java b/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileFromInstruction.java new file mode 100644 index 00000000..e1195883 --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileFromInstruction.java @@ -0,0 +1,19 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.image.build.psi; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.psi.PsiElement; + +public interface DockerfileFromInstruction extends PsiElement { + + @Nullable + DockerfileAsClause getAsClause(); + + @NotNull + DockerfileImageName getImageName(); + + @Nullable + DockerfilePlatformOption getPlatformOption(); + +} diff --git a/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileImageName.java b/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileImageName.java new file mode 100644 index 00000000..843ea4fd --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileImageName.java @@ -0,0 +1,13 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.image.build.psi; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.psi.PsiElement; + +public interface DockerfileImageName extends PsiElement { + + @NotNull + List getImageNamePartList(); + +} diff --git a/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileImageNameLiteral.java b/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileImageNameLiteral.java new file mode 100644 index 00000000..dc8aba55 --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileImageNameLiteral.java @@ -0,0 +1,16 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.image.build.psi; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.psi.PsiElement; + +public interface DockerfileImageNameLiteral extends PsiElement { + + @Nullable + PsiElement getIdentifier(); + + @Nullable + PsiElement getImageNameToken(); + +} diff --git a/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileImageNamePart.java b/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileImageNamePart.java new file mode 100644 index 00000000..acce192f --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileImageNamePart.java @@ -0,0 +1,19 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.image.build.psi; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.psi.PsiElement; + +public interface DockerfileImageNamePart extends PsiElement { + + @Nullable + DockerfileImageNameLiteral getImageNameLiteral(); + + @Nullable + DockerfileVariableRef getVariableRef(); + + @Nullable + PsiElement getVersion(); + +} diff --git a/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileInstruction.java b/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileInstruction.java new file mode 100644 index 00000000..0a40dc3e --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileInstruction.java @@ -0,0 +1,19 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.image.build.psi; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.psi.PsiElement; + +public interface DockerfileInstruction extends PsiElement { + + @Nullable + DockerfileArgInstruction getArgInstruction(); + + @Nullable + DockerfileFromInstruction getFromInstruction(); + + @Nullable + DockerfileOtherInstruction getOtherInstruction(); + +} diff --git a/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileInstructionArgs.java b/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileInstructionArgs.java new file mode 100644 index 00000000..e8593878 --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileInstructionArgs.java @@ -0,0 +1,34 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.image.build.psi; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.psi.PsiElement; + +public interface DockerfileInstructionArgs extends PsiElement { + + @Nullable + DockerfileVariableRef getVariableRef(); + + @Nullable + PsiElement getAnyChar(); + + @Nullable + PsiElement getIdentifier(); + + @Nullable + PsiElement getImageNameToken(); + + @Nullable + PsiElement getOtherToken(); + + @Nullable + PsiElement getPlatform(); + + @Nullable + PsiElement getString(); + + @Nullable + PsiElement getVersion(); + +} diff --git a/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileItem.java b/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileItem.java new file mode 100644 index 00000000..fe435a9f --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileItem.java @@ -0,0 +1,19 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.image.build.psi; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.psi.PsiElement; + +public interface DockerfileItem extends PsiElement { + + @Nullable + DockerfileInstruction getInstruction(); + + @Nullable + PsiElement getComment(); + + @Nullable + PsiElement getNewline(); + +} diff --git a/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileOtherInstruction.java b/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileOtherInstruction.java new file mode 100644 index 00000000..ab83293d --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileOtherInstruction.java @@ -0,0 +1,13 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.image.build.psi; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.psi.PsiElement; + +public interface DockerfileOtherInstruction extends PsiElement { + + @NotNull + List getInstructionArgsList(); + +} diff --git a/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfilePlatformOption.java b/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfilePlatformOption.java new file mode 100644 index 00000000..6da4f241 --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfilePlatformOption.java @@ -0,0 +1,13 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.image.build.psi; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.psi.PsiElement; + +public interface DockerfilePlatformOption extends PsiElement { + + @NotNull + DockerfilePlatformValue getPlatformValue(); + +} diff --git a/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfilePlatformValue.java b/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfilePlatformValue.java new file mode 100644 index 00000000..87422e5a --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfilePlatformValue.java @@ -0,0 +1,16 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.image.build.psi; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.psi.PsiElement; + +public interface DockerfilePlatformValue extends PsiElement { + + @Nullable + DockerfileVariableRef getVariableRef(); + + @Nullable + PsiElement getPlatform(); + +} diff --git a/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileSimpleVar.java b/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileSimpleVar.java new file mode 100644 index 00000000..257a3283 --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileSimpleVar.java @@ -0,0 +1,13 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.image.build.psi; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.psi.PsiElement; + +public interface DockerfileSimpleVar extends PsiElement { + + @NotNull + PsiElement getIdentifier(); + +} diff --git a/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileTypes.java b/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileTypes.java new file mode 100644 index 00000000..18296ac6 --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileTypes.java @@ -0,0 +1,116 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.image.build.psi; + +import com.intellij.psi.tree.IElementType; +import com.intellij.psi.PsiElement; +import com.intellij.lang.ASTNode; +import org.jboss.tools.intellij.image.build.psi.impl.*; + +public interface DockerfileTypes { + + IElementType ARG_DECLARATION = new DockerfileElementType("ARG_DECLARATION"); + IElementType ARG_INSTRUCTION = new DockerfileElementType("ARG_INSTRUCTION"); + IElementType ARG_VALUE = new DockerfileElementType("ARG_VALUE"); + IElementType AS_CLAUSE = new DockerfileElementType("AS_CLAUSE"); + IElementType COMPLEX_VAR = new DockerfileElementType("COMPLEX_VAR"); + IElementType FROM_INSTRUCTION = new DockerfileElementType("FROM_INSTRUCTION"); + IElementType IMAGE_NAME = new DockerfileElementType("IMAGE_NAME"); + IElementType IMAGE_NAME_LITERAL = new DockerfileElementType("IMAGE_NAME_LITERAL"); + IElementType IMAGE_NAME_PART = new DockerfileElementType("IMAGE_NAME_PART"); + IElementType INSTRUCTION = new DockerfileElementType("INSTRUCTION"); + IElementType INSTRUCTION_ARGS = new DockerfileElementType("INSTRUCTION_ARGS"); + IElementType ITEM = new DockerfileElementType("ITEM"); + IElementType OTHER_INSTRUCTION = new DockerfileElementType("OTHER_INSTRUCTION"); + IElementType PLATFORM_OPTION = new DockerfileElementType("PLATFORM_OPTION"); + IElementType PLATFORM_VALUE = new DockerfileElementType("PLATFORM_VALUE"); + IElementType SIMPLE_VAR = new DockerfileElementType("SIMPLE_VAR"); + IElementType VARIABLE_REF = new DockerfileElementType("VARIABLE_REF"); + + IElementType ADD = new DockerfileTokenType("add"); + IElementType ANY_CHAR = new DockerfileTokenType("ANY_CHAR"); + IElementType ARG = new DockerfileTokenType("arg"); + IElementType AS = new DockerfileTokenType("as"); + IElementType CMD = new DockerfileTokenType("cmd"); + IElementType COLON = new DockerfileTokenType(":"); + IElementType COMMENT = new DockerfileTokenType("COMMENT"); + IElementType COPY = new DockerfileTokenType("copy"); + IElementType DOLLAR = new DockerfileTokenType("$"); + IElementType ENTRYPOINT = new DockerfileTokenType("entrypoint"); + IElementType ENV = new DockerfileTokenType("env"); + IElementType EQUALS = new DockerfileTokenType("="); + IElementType EXPOSE = new DockerfileTokenType("expose"); + IElementType FROM = new DockerfileTokenType("from"); + IElementType IDENTIFIER = new DockerfileTokenType("IDENTIFIER"); + IElementType IMAGE_NAME_TOKEN = new DockerfileTokenType("IMAGE_NAME_TOKEN"); + IElementType LABEL = new DockerfileTokenType("label"); + IElementType LBRACE = new DockerfileTokenType("{"); + IElementType NEWLINE = new DockerfileTokenType("NEWLINE"); + IElementType OTHER_TOKEN = new DockerfileTokenType("OTHER_TOKEN"); + IElementType PLATFORM = new DockerfileTokenType("PLATFORM"); + IElementType PLATFORM_FLAG = new DockerfileTokenType("--platform"); + IElementType RBRACE = new DockerfileTokenType("}"); + IElementType RUN = new DockerfileTokenType("run"); + IElementType STRING = new DockerfileTokenType("STRING"); + IElementType USER = new DockerfileTokenType("user"); + IElementType VERSION = new DockerfileTokenType("VERSION"); + IElementType VOLUME = new DockerfileTokenType("volume"); + IElementType WORKDIR = new DockerfileTokenType("workdir"); + + class Factory { + public static PsiElement createElement(ASTNode node) { + IElementType type = node.getElementType(); + if (type == ARG_DECLARATION) { + return new DockerfileArgDeclarationImpl(node); + } + else if (type == ARG_INSTRUCTION) { + return new DockerfileArgInstructionImpl(node); + } + else if (type == ARG_VALUE) { + return new DockerfileArgValueImpl(node); + } + else if (type == AS_CLAUSE) { + return new DockerfileAsClauseImpl(node); + } + else if (type == COMPLEX_VAR) { + return new DockerfileComplexVarImpl(node); + } + else if (type == FROM_INSTRUCTION) { + return new DockerfileFromInstructionImpl(node); + } + else if (type == IMAGE_NAME) { + return new DockerfileImageNameImpl(node); + } + else if (type == IMAGE_NAME_LITERAL) { + return new DockerfileImageNameLiteralImpl(node); + } + else if (type == IMAGE_NAME_PART) { + return new DockerfileImageNamePartImpl(node); + } + else if (type == INSTRUCTION) { + return new DockerfileInstructionImpl(node); + } + else if (type == INSTRUCTION_ARGS) { + return new DockerfileInstructionArgsImpl(node); + } + else if (type == ITEM) { + return new DockerfileItemImpl(node); + } + else if (type == OTHER_INSTRUCTION) { + return new DockerfileOtherInstructionImpl(node); + } + else if (type == PLATFORM_OPTION) { + return new DockerfilePlatformOptionImpl(node); + } + else if (type == PLATFORM_VALUE) { + return new DockerfilePlatformValueImpl(node); + } + else if (type == SIMPLE_VAR) { + return new DockerfileSimpleVarImpl(node); + } + else if (type == VARIABLE_REF) { + return new DockerfileVariableRefImpl(node); + } + throw new AssertionError("Unknown element type: " + type); + } + } +} diff --git a/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileVariableRef.java b/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileVariableRef.java new file mode 100644 index 00000000..138303de --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileVariableRef.java @@ -0,0 +1,16 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.image.build.psi; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.psi.PsiElement; + +public interface DockerfileVariableRef extends PsiElement { + + @Nullable + DockerfileComplexVar getComplexVar(); + + @Nullable + DockerfileSimpleVar getSimpleVar(); + +} diff --git a/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileVisitor.java b/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileVisitor.java new file mode 100644 index 00000000..cd23a9d5 --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/image/build/psi/DockerfileVisitor.java @@ -0,0 +1,82 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.image.build.psi; + +import org.jetbrains.annotations.*; +import com.intellij.psi.PsiElementVisitor; +import com.intellij.psi.PsiElement; + +public class DockerfileVisitor extends PsiElementVisitor { + + public void visitArgDeclaration(@NotNull DockerfileArgDeclaration o) { + visitPsiElement(o); + } + + public void visitArgInstruction(@NotNull DockerfileArgInstruction o) { + visitPsiElement(o); + } + + public void visitArgValue(@NotNull DockerfileArgValue o) { + visitPsiElement(o); + } + + public void visitAsClause(@NotNull DockerfileAsClause o) { + visitPsiElement(o); + } + + public void visitComplexVar(@NotNull DockerfileComplexVar o) { + visitPsiElement(o); + } + + public void visitFromInstruction(@NotNull DockerfileFromInstruction o) { + visitPsiElement(o); + } + + public void visitImageName(@NotNull DockerfileImageName o) { + visitPsiElement(o); + } + + public void visitImageNameLiteral(@NotNull DockerfileImageNameLiteral o) { + visitPsiElement(o); + } + + public void visitImageNamePart(@NotNull DockerfileImageNamePart o) { + visitPsiElement(o); + } + + public void visitInstruction(@NotNull DockerfileInstruction o) { + visitPsiElement(o); + } + + public void visitInstructionArgs(@NotNull DockerfileInstructionArgs o) { + visitPsiElement(o); + } + + public void visitItem(@NotNull DockerfileItem o) { + visitPsiElement(o); + } + + public void visitOtherInstruction(@NotNull DockerfileOtherInstruction o) { + visitPsiElement(o); + } + + public void visitPlatformOption(@NotNull DockerfilePlatformOption o) { + visitPsiElement(o); + } + + public void visitPlatformValue(@NotNull DockerfilePlatformValue o) { + visitPsiElement(o); + } + + public void visitSimpleVar(@NotNull DockerfileSimpleVar o) { + visitPsiElement(o); + } + + public void visitVariableRef(@NotNull DockerfileVariableRef o) { + visitPsiElement(o); + } + + public void visitPsiElement(@NotNull PsiElement o) { + visitElement(o); + } + +} diff --git a/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileArgDeclarationImpl.java b/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileArgDeclarationImpl.java new file mode 100644 index 00000000..660c764a --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileArgDeclarationImpl.java @@ -0,0 +1,42 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.image.build.psi.impl; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiElementVisitor; +import com.intellij.psi.util.PsiTreeUtil; +import static org.jboss.tools.intellij.image.build.psi.DockerfileTypes.*; +import com.intellij.extapi.psi.ASTWrapperPsiElement; +import org.jboss.tools.intellij.image.build.psi.*; + +public class DockerfileArgDeclarationImpl extends ASTWrapperPsiElement implements DockerfileArgDeclaration { + + public DockerfileArgDeclarationImpl(@NotNull ASTNode node) { + super(node); + } + + public void accept(@NotNull DockerfileVisitor visitor) { + visitor.visitArgDeclaration(this); + } + + @Override + public void accept(@NotNull PsiElementVisitor visitor) { + if (visitor instanceof DockerfileVisitor) accept((DockerfileVisitor)visitor); + else super.accept(visitor); + } + + @Override + @Nullable + public DockerfileArgValue getArgValue() { + return findChildByClass(DockerfileArgValue.class); + } + + @Override + @NotNull + public PsiElement getIdentifier() { + return findNotNullChildByType(IDENTIFIER); + } + +} diff --git a/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileArgInstructionImpl.java b/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileArgInstructionImpl.java new file mode 100644 index 00000000..2b1de7b9 --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileArgInstructionImpl.java @@ -0,0 +1,36 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.image.build.psi.impl; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiElementVisitor; +import com.intellij.psi.util.PsiTreeUtil; +import static org.jboss.tools.intellij.image.build.psi.DockerfileTypes.*; +import com.intellij.extapi.psi.ASTWrapperPsiElement; +import org.jboss.tools.intellij.image.build.psi.*; + +public class DockerfileArgInstructionImpl extends ASTWrapperPsiElement implements DockerfileArgInstruction { + + public DockerfileArgInstructionImpl(@NotNull ASTNode node) { + super(node); + } + + public void accept(@NotNull DockerfileVisitor visitor) { + visitor.visitArgInstruction(this); + } + + @Override + public void accept(@NotNull PsiElementVisitor visitor) { + if (visitor instanceof DockerfileVisitor) accept((DockerfileVisitor)visitor); + else super.accept(visitor); + } + + @Override + @NotNull + public DockerfileArgDeclaration getArgDeclaration() { + return findNotNullChildByClass(DockerfileArgDeclaration.class); + } + +} diff --git a/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileArgValueImpl.java b/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileArgValueImpl.java new file mode 100644 index 00000000..c2a3a3ec --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileArgValueImpl.java @@ -0,0 +1,54 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.image.build.psi.impl; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiElementVisitor; +import com.intellij.psi.util.PsiTreeUtil; +import static org.jboss.tools.intellij.image.build.psi.DockerfileTypes.*; +import com.intellij.extapi.psi.ASTWrapperPsiElement; +import org.jboss.tools.intellij.image.build.psi.*; + +public class DockerfileArgValueImpl extends ASTWrapperPsiElement implements DockerfileArgValue { + + public DockerfileArgValueImpl(@NotNull ASTNode node) { + super(node); + } + + public void accept(@NotNull DockerfileVisitor visitor) { + visitor.visitArgValue(this); + } + + @Override + public void accept(@NotNull PsiElementVisitor visitor) { + if (visitor instanceof DockerfileVisitor) accept((DockerfileVisitor)visitor); + else super.accept(visitor); + } + + @Override + @Nullable + public DockerfileVariableRef getVariableRef() { + return findChildByClass(DockerfileVariableRef.class); + } + + @Override + @Nullable + public PsiElement getIdentifier() { + return findChildByType(IDENTIFIER); + } + + @Override + @Nullable + public PsiElement getString() { + return findChildByType(STRING); + } + + @Override + @Nullable + public PsiElement getVersion() { + return findChildByType(VERSION); + } + +} diff --git a/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileAsClauseImpl.java b/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileAsClauseImpl.java new file mode 100644 index 00000000..53527ffc --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileAsClauseImpl.java @@ -0,0 +1,36 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.image.build.psi.impl; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiElementVisitor; +import com.intellij.psi.util.PsiTreeUtil; +import static org.jboss.tools.intellij.image.build.psi.DockerfileTypes.*; +import com.intellij.extapi.psi.ASTWrapperPsiElement; +import org.jboss.tools.intellij.image.build.psi.*; + +public class DockerfileAsClauseImpl extends ASTWrapperPsiElement implements DockerfileAsClause { + + public DockerfileAsClauseImpl(@NotNull ASTNode node) { + super(node); + } + + public void accept(@NotNull DockerfileVisitor visitor) { + visitor.visitAsClause(this); + } + + @Override + public void accept(@NotNull PsiElementVisitor visitor) { + if (visitor instanceof DockerfileVisitor) accept((DockerfileVisitor)visitor); + else super.accept(visitor); + } + + @Override + @NotNull + public PsiElement getIdentifier() { + return findNotNullChildByType(IDENTIFIER); + } + +} diff --git a/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileComplexVarImpl.java b/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileComplexVarImpl.java new file mode 100644 index 00000000..fbb5db95 --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileComplexVarImpl.java @@ -0,0 +1,36 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.image.build.psi.impl; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiElementVisitor; +import com.intellij.psi.util.PsiTreeUtil; +import static org.jboss.tools.intellij.image.build.psi.DockerfileTypes.*; +import com.intellij.extapi.psi.ASTWrapperPsiElement; +import org.jboss.tools.intellij.image.build.psi.*; + +public class DockerfileComplexVarImpl extends ASTWrapperPsiElement implements DockerfileComplexVar { + + public DockerfileComplexVarImpl(@NotNull ASTNode node) { + super(node); + } + + public void accept(@NotNull DockerfileVisitor visitor) { + visitor.visitComplexVar(this); + } + + @Override + public void accept(@NotNull PsiElementVisitor visitor) { + if (visitor instanceof DockerfileVisitor) accept((DockerfileVisitor)visitor); + else super.accept(visitor); + } + + @Override + @NotNull + public PsiElement getIdentifier() { + return findNotNullChildByType(IDENTIFIER); + } + +} diff --git a/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileFromInstructionImpl.java b/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileFromInstructionImpl.java new file mode 100644 index 00000000..b85db05c --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileFromInstructionImpl.java @@ -0,0 +1,48 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.image.build.psi.impl; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiElementVisitor; +import com.intellij.psi.util.PsiTreeUtil; +import static org.jboss.tools.intellij.image.build.psi.DockerfileTypes.*; +import com.intellij.extapi.psi.ASTWrapperPsiElement; +import org.jboss.tools.intellij.image.build.psi.*; + +public class DockerfileFromInstructionImpl extends ASTWrapperPsiElement implements DockerfileFromInstruction { + + public DockerfileFromInstructionImpl(@NotNull ASTNode node) { + super(node); + } + + public void accept(@NotNull DockerfileVisitor visitor) { + visitor.visitFromInstruction(this); + } + + @Override + public void accept(@NotNull PsiElementVisitor visitor) { + if (visitor instanceof DockerfileVisitor) accept((DockerfileVisitor)visitor); + else super.accept(visitor); + } + + @Override + @Nullable + public DockerfileAsClause getAsClause() { + return findChildByClass(DockerfileAsClause.class); + } + + @Override + @NotNull + public DockerfileImageName getImageName() { + return findNotNullChildByClass(DockerfileImageName.class); + } + + @Override + @Nullable + public DockerfilePlatformOption getPlatformOption() { + return findChildByClass(DockerfilePlatformOption.class); + } + +} diff --git a/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileImageNameImpl.java b/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileImageNameImpl.java new file mode 100644 index 00000000..938fad5d --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileImageNameImpl.java @@ -0,0 +1,36 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.image.build.psi.impl; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiElementVisitor; +import com.intellij.psi.util.PsiTreeUtil; +import static org.jboss.tools.intellij.image.build.psi.DockerfileTypes.*; +import com.intellij.extapi.psi.ASTWrapperPsiElement; +import org.jboss.tools.intellij.image.build.psi.*; + +public class DockerfileImageNameImpl extends ASTWrapperPsiElement implements DockerfileImageName { + + public DockerfileImageNameImpl(@NotNull ASTNode node) { + super(node); + } + + public void accept(@NotNull DockerfileVisitor visitor) { + visitor.visitImageName(this); + } + + @Override + public void accept(@NotNull PsiElementVisitor visitor) { + if (visitor instanceof DockerfileVisitor) accept((DockerfileVisitor)visitor); + else super.accept(visitor); + } + + @Override + @NotNull + public List getImageNamePartList() { + return PsiTreeUtil.getChildrenOfTypeAsList(this, DockerfileImageNamePart.class); + } + +} diff --git a/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileImageNameLiteralImpl.java b/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileImageNameLiteralImpl.java new file mode 100644 index 00000000..6adabf27 --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileImageNameLiteralImpl.java @@ -0,0 +1,42 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.image.build.psi.impl; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiElementVisitor; +import com.intellij.psi.util.PsiTreeUtil; +import static org.jboss.tools.intellij.image.build.psi.DockerfileTypes.*; +import com.intellij.extapi.psi.ASTWrapperPsiElement; +import org.jboss.tools.intellij.image.build.psi.*; + +public class DockerfileImageNameLiteralImpl extends ASTWrapperPsiElement implements DockerfileImageNameLiteral { + + public DockerfileImageNameLiteralImpl(@NotNull ASTNode node) { + super(node); + } + + public void accept(@NotNull DockerfileVisitor visitor) { + visitor.visitImageNameLiteral(this); + } + + @Override + public void accept(@NotNull PsiElementVisitor visitor) { + if (visitor instanceof DockerfileVisitor) accept((DockerfileVisitor)visitor); + else super.accept(visitor); + } + + @Override + @Nullable + public PsiElement getIdentifier() { + return findChildByType(IDENTIFIER); + } + + @Override + @Nullable + public PsiElement getImageNameToken() { + return findChildByType(IMAGE_NAME_TOKEN); + } + +} diff --git a/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileImageNamePartImpl.java b/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileImageNamePartImpl.java new file mode 100644 index 00000000..7fd99894 --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileImageNamePartImpl.java @@ -0,0 +1,48 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.image.build.psi.impl; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiElementVisitor; +import com.intellij.psi.util.PsiTreeUtil; +import static org.jboss.tools.intellij.image.build.psi.DockerfileTypes.*; +import com.intellij.extapi.psi.ASTWrapperPsiElement; +import org.jboss.tools.intellij.image.build.psi.*; + +public class DockerfileImageNamePartImpl extends ASTWrapperPsiElement implements DockerfileImageNamePart { + + public DockerfileImageNamePartImpl(@NotNull ASTNode node) { + super(node); + } + + public void accept(@NotNull DockerfileVisitor visitor) { + visitor.visitImageNamePart(this); + } + + @Override + public void accept(@NotNull PsiElementVisitor visitor) { + if (visitor instanceof DockerfileVisitor) accept((DockerfileVisitor)visitor); + else super.accept(visitor); + } + + @Override + @Nullable + public DockerfileImageNameLiteral getImageNameLiteral() { + return findChildByClass(DockerfileImageNameLiteral.class); + } + + @Override + @Nullable + public DockerfileVariableRef getVariableRef() { + return findChildByClass(DockerfileVariableRef.class); + } + + @Override + @Nullable + public PsiElement getVersion() { + return findChildByType(VERSION); + } + +} diff --git a/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileInstructionArgsImpl.java b/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileInstructionArgsImpl.java new file mode 100644 index 00000000..cb60e099 --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileInstructionArgsImpl.java @@ -0,0 +1,78 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.image.build.psi.impl; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiElementVisitor; +import com.intellij.psi.util.PsiTreeUtil; +import static org.jboss.tools.intellij.image.build.psi.DockerfileTypes.*; +import com.intellij.extapi.psi.ASTWrapperPsiElement; +import org.jboss.tools.intellij.image.build.psi.*; + +public class DockerfileInstructionArgsImpl extends ASTWrapperPsiElement implements DockerfileInstructionArgs { + + public DockerfileInstructionArgsImpl(@NotNull ASTNode node) { + super(node); + } + + public void accept(@NotNull DockerfileVisitor visitor) { + visitor.visitInstructionArgs(this); + } + + @Override + public void accept(@NotNull PsiElementVisitor visitor) { + if (visitor instanceof DockerfileVisitor) accept((DockerfileVisitor)visitor); + else super.accept(visitor); + } + + @Override + @Nullable + public DockerfileVariableRef getVariableRef() { + return findChildByClass(DockerfileVariableRef.class); + } + + @Override + @Nullable + public PsiElement getAnyChar() { + return findChildByType(ANY_CHAR); + } + + @Override + @Nullable + public PsiElement getIdentifier() { + return findChildByType(IDENTIFIER); + } + + @Override + @Nullable + public PsiElement getImageNameToken() { + return findChildByType(IMAGE_NAME_TOKEN); + } + + @Override + @Nullable + public PsiElement getOtherToken() { + return findChildByType(OTHER_TOKEN); + } + + @Override + @Nullable + public PsiElement getPlatform() { + return findChildByType(PLATFORM); + } + + @Override + @Nullable + public PsiElement getString() { + return findChildByType(STRING); + } + + @Override + @Nullable + public PsiElement getVersion() { + return findChildByType(VERSION); + } + +} diff --git a/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileInstructionImpl.java b/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileInstructionImpl.java new file mode 100644 index 00000000..cb14fc04 --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileInstructionImpl.java @@ -0,0 +1,48 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.image.build.psi.impl; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiElementVisitor; +import com.intellij.psi.util.PsiTreeUtil; +import static org.jboss.tools.intellij.image.build.psi.DockerfileTypes.*; +import com.intellij.extapi.psi.ASTWrapperPsiElement; +import org.jboss.tools.intellij.image.build.psi.*; + +public class DockerfileInstructionImpl extends ASTWrapperPsiElement implements DockerfileInstruction { + + public DockerfileInstructionImpl(@NotNull ASTNode node) { + super(node); + } + + public void accept(@NotNull DockerfileVisitor visitor) { + visitor.visitInstruction(this); + } + + @Override + public void accept(@NotNull PsiElementVisitor visitor) { + if (visitor instanceof DockerfileVisitor) accept((DockerfileVisitor)visitor); + else super.accept(visitor); + } + + @Override + @Nullable + public DockerfileArgInstruction getArgInstruction() { + return findChildByClass(DockerfileArgInstruction.class); + } + + @Override + @Nullable + public DockerfileFromInstruction getFromInstruction() { + return findChildByClass(DockerfileFromInstruction.class); + } + + @Override + @Nullable + public DockerfileOtherInstruction getOtherInstruction() { + return findChildByClass(DockerfileOtherInstruction.class); + } + +} diff --git a/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileItemImpl.java b/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileItemImpl.java new file mode 100644 index 00000000..af4439c5 --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileItemImpl.java @@ -0,0 +1,48 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.image.build.psi.impl; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiElementVisitor; +import com.intellij.psi.util.PsiTreeUtil; +import static org.jboss.tools.intellij.image.build.psi.DockerfileTypes.*; +import com.intellij.extapi.psi.ASTWrapperPsiElement; +import org.jboss.tools.intellij.image.build.psi.*; + +public class DockerfileItemImpl extends ASTWrapperPsiElement implements DockerfileItem { + + public DockerfileItemImpl(@NotNull ASTNode node) { + super(node); + } + + public void accept(@NotNull DockerfileVisitor visitor) { + visitor.visitItem(this); + } + + @Override + public void accept(@NotNull PsiElementVisitor visitor) { + if (visitor instanceof DockerfileVisitor) accept((DockerfileVisitor)visitor); + else super.accept(visitor); + } + + @Override + @Nullable + public DockerfileInstruction getInstruction() { + return findChildByClass(DockerfileInstruction.class); + } + + @Override + @Nullable + public PsiElement getComment() { + return findChildByType(COMMENT); + } + + @Override + @Nullable + public PsiElement getNewline() { + return findChildByType(NEWLINE); + } + +} diff --git a/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileOtherInstructionImpl.java b/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileOtherInstructionImpl.java new file mode 100644 index 00000000..f06a6f36 --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileOtherInstructionImpl.java @@ -0,0 +1,36 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.image.build.psi.impl; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiElementVisitor; +import com.intellij.psi.util.PsiTreeUtil; +import static org.jboss.tools.intellij.image.build.psi.DockerfileTypes.*; +import com.intellij.extapi.psi.ASTWrapperPsiElement; +import org.jboss.tools.intellij.image.build.psi.*; + +public class DockerfileOtherInstructionImpl extends ASTWrapperPsiElement implements DockerfileOtherInstruction { + + public DockerfileOtherInstructionImpl(@NotNull ASTNode node) { + super(node); + } + + public void accept(@NotNull DockerfileVisitor visitor) { + visitor.visitOtherInstruction(this); + } + + @Override + public void accept(@NotNull PsiElementVisitor visitor) { + if (visitor instanceof DockerfileVisitor) accept((DockerfileVisitor)visitor); + else super.accept(visitor); + } + + @Override + @NotNull + public List getInstructionArgsList() { + return PsiTreeUtil.getChildrenOfTypeAsList(this, DockerfileInstructionArgs.class); + } + +} diff --git a/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfilePlatformOptionImpl.java b/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfilePlatformOptionImpl.java new file mode 100644 index 00000000..2a09629c --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfilePlatformOptionImpl.java @@ -0,0 +1,36 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.image.build.psi.impl; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiElementVisitor; +import com.intellij.psi.util.PsiTreeUtil; +import static org.jboss.tools.intellij.image.build.psi.DockerfileTypes.*; +import com.intellij.extapi.psi.ASTWrapperPsiElement; +import org.jboss.tools.intellij.image.build.psi.*; + +public class DockerfilePlatformOptionImpl extends ASTWrapperPsiElement implements DockerfilePlatformOption { + + public DockerfilePlatformOptionImpl(@NotNull ASTNode node) { + super(node); + } + + public void accept(@NotNull DockerfileVisitor visitor) { + visitor.visitPlatformOption(this); + } + + @Override + public void accept(@NotNull PsiElementVisitor visitor) { + if (visitor instanceof DockerfileVisitor) accept((DockerfileVisitor)visitor); + else super.accept(visitor); + } + + @Override + @NotNull + public DockerfilePlatformValue getPlatformValue() { + return findNotNullChildByClass(DockerfilePlatformValue.class); + } + +} diff --git a/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfilePlatformValueImpl.java b/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfilePlatformValueImpl.java new file mode 100644 index 00000000..b8ed2057 --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfilePlatformValueImpl.java @@ -0,0 +1,42 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.image.build.psi.impl; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiElementVisitor; +import com.intellij.psi.util.PsiTreeUtil; +import static org.jboss.tools.intellij.image.build.psi.DockerfileTypes.*; +import com.intellij.extapi.psi.ASTWrapperPsiElement; +import org.jboss.tools.intellij.image.build.psi.*; + +public class DockerfilePlatformValueImpl extends ASTWrapperPsiElement implements DockerfilePlatformValue { + + public DockerfilePlatformValueImpl(@NotNull ASTNode node) { + super(node); + } + + public void accept(@NotNull DockerfileVisitor visitor) { + visitor.visitPlatformValue(this); + } + + @Override + public void accept(@NotNull PsiElementVisitor visitor) { + if (visitor instanceof DockerfileVisitor) accept((DockerfileVisitor)visitor); + else super.accept(visitor); + } + + @Override + @Nullable + public DockerfileVariableRef getVariableRef() { + return findChildByClass(DockerfileVariableRef.class); + } + + @Override + @Nullable + public PsiElement getPlatform() { + return findChildByType(PLATFORM); + } + +} diff --git a/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileSimpleVarImpl.java b/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileSimpleVarImpl.java new file mode 100644 index 00000000..389289ab --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileSimpleVarImpl.java @@ -0,0 +1,36 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.image.build.psi.impl; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiElementVisitor; +import com.intellij.psi.util.PsiTreeUtil; +import static org.jboss.tools.intellij.image.build.psi.DockerfileTypes.*; +import com.intellij.extapi.psi.ASTWrapperPsiElement; +import org.jboss.tools.intellij.image.build.psi.*; + +public class DockerfileSimpleVarImpl extends ASTWrapperPsiElement implements DockerfileSimpleVar { + + public DockerfileSimpleVarImpl(@NotNull ASTNode node) { + super(node); + } + + public void accept(@NotNull DockerfileVisitor visitor) { + visitor.visitSimpleVar(this); + } + + @Override + public void accept(@NotNull PsiElementVisitor visitor) { + if (visitor instanceof DockerfileVisitor) accept((DockerfileVisitor)visitor); + else super.accept(visitor); + } + + @Override + @NotNull + public PsiElement getIdentifier() { + return findNotNullChildByType(IDENTIFIER); + } + +} diff --git a/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileVariableRefImpl.java b/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileVariableRefImpl.java new file mode 100644 index 00000000..1c3b54ab --- /dev/null +++ b/src/main/gen/org/jboss/tools/intellij/image/build/psi/impl/DockerfileVariableRefImpl.java @@ -0,0 +1,42 @@ +// This is a generated file. Not intended for manual editing. +package org.jboss.tools.intellij.image.build.psi.impl; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiElementVisitor; +import com.intellij.psi.util.PsiTreeUtil; +import static org.jboss.tools.intellij.image.build.psi.DockerfileTypes.*; +import com.intellij.extapi.psi.ASTWrapperPsiElement; +import org.jboss.tools.intellij.image.build.psi.*; + +public class DockerfileVariableRefImpl extends ASTWrapperPsiElement implements DockerfileVariableRef { + + public DockerfileVariableRefImpl(@NotNull ASTNode node) { + super(node); + } + + public void accept(@NotNull DockerfileVisitor visitor) { + visitor.visitVariableRef(this); + } + + @Override + public void accept(@NotNull PsiElementVisitor visitor) { + if (visitor instanceof DockerfileVisitor) accept((DockerfileVisitor)visitor); + else super.accept(visitor); + } + + @Override + @Nullable + public DockerfileComplexVar getComplexVar() { + return findChildByClass(DockerfileComplexVar.class); + } + + @Override + @Nullable + public DockerfileSimpleVar getSimpleVar() { + return findChildByClass(DockerfileSimpleVar.class); + } + +} diff --git a/src/main/java/org/jboss/tools/intellij/image/DockerfileAnnotator.java b/src/main/java/org/jboss/tools/intellij/image/DockerfileAnnotator.java index 240385d2..19c90bb5 100644 --- a/src/main/java/org/jboss/tools/intellij/image/DockerfileAnnotator.java +++ b/src/main/java/org/jboss/tools/intellij/image/DockerfileAnnotator.java @@ -30,6 +30,8 @@ import com.redhat.exhort.api.v4.Severity; import com.redhat.exhort.api.v4.Source; import com.redhat.exhort.image.ImageRef; +import org.jboss.tools.intellij.image.build.filetype.DockerfileFileType; +import org.jboss.tools.intellij.image.build.psi.*; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -235,6 +237,11 @@ static String getRecommendation(AnalysisReport report, ImageRef imageRef) { @Override public @Nullable Info collectInformation(@NotNull PsiFile file) { + // Only process our custom Dockerfile type + if (!DockerfileFileType.INSTANCE.equals(file.getFileType())) { + return null; + } + var inspection = getInspection(file); if (inspection == null) { return null; diff --git a/src/main/java/org/jboss/tools/intellij/image/ImageReportAction.java b/src/main/java/org/jboss/tools/intellij/image/ImageReportAction.java index 26a86649..1d7f6e6a 100644 --- a/src/main/java/org/jboss/tools/intellij/image/ImageReportAction.java +++ b/src/main/java/org/jboss/tools/intellij/image/ImageReportAction.java @@ -11,7 +11,7 @@ package org.jboss.tools.intellij.image; -import com.intellij.docker.dockerFile.DockerFileType; +import org.jboss.tools.intellij.image.build.filetype.DockerfileFileType; import com.intellij.openapi.actionSystem.ActionUpdateThread; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; @@ -37,7 +37,7 @@ public void actionPerformed(@NotNull AnActionEvent event) { @Override public void update(@NotNull AnActionEvent event) { var psiFile = event.getData(CommonDataKeys.PSI_FILE); - if (psiFile != null && DockerFileType.DOCKER_FILE_TYPE.equals(psiFile.getFileType())) { + if (psiFile != null && DockerfileFileType.INSTANCE.equals(psiFile.getFileType())) { event.getPresentation().setEnabledAndVisible(true); } else { event.getPresentation().setEnabledAndVisible(false); diff --git a/src/main/java/org/jboss/tools/intellij/image/ImageReportIntentionAction.java b/src/main/java/org/jboss/tools/intellij/image/ImageReportIntentionAction.java index f59fc9cc..c47115b7 100644 --- a/src/main/java/org/jboss/tools/intellij/image/ImageReportIntentionAction.java +++ b/src/main/java/org/jboss/tools/intellij/image/ImageReportIntentionAction.java @@ -14,7 +14,7 @@ import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.codeInspection.util.IntentionFamilyName; import com.intellij.codeInspection.util.IntentionName; -import com.intellij.docker.dockerFile.DockerFileType; +import org.jboss.tools.intellij.image.build.filetype.DockerfileFileType; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiFile; @@ -34,7 +34,7 @@ public class ImageReportIntentionAction implements IntentionAction { @Override public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile psiFile) { - return DockerFileType.DOCKER_FILE_TYPE.equals(psiFile.getFileType()); + return DockerfileFileType.INSTANCE.equals(psiFile.getFileType()); } @Override diff --git a/src/main/java/org/jboss/tools/intellij/image/ImageService.java b/src/main/java/org/jboss/tools/intellij/image/ImageService.java index eabe22fd..20db6942 100644 --- a/src/main/java/org/jboss/tools/intellij/image/ImageService.java +++ b/src/main/java/org/jboss/tools/intellij/image/ImageService.java @@ -12,13 +12,6 @@ package org.jboss.tools.intellij.image; import com.google.gson.JsonObject; -import com.intellij.docker.dockerFile.DockerFileType; -import com.intellij.docker.dockerFile.parser.psi.DockerFileArgCommand; -import com.intellij.docker.dockerFile.parser.psi.DockerFileFromCommand; -import com.intellij.docker.dockerFile.parser.psi.DockerFileRegularOption; -import com.intellij.docker.dockerFile.parser.psi.DockerFileStringLiteral; -import com.intellij.docker.dockerFile.parser.psi.DockerFileVariableRefFull; -import com.intellij.docker.dockerFile.parser.psi.DockerFileVariableRefSimple; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.components.Service; import com.intellij.openapi.diagnostic.Logger; @@ -28,17 +21,13 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; +import com.intellij.psi.util.PsiTreeUtil; +import org.jboss.tools.intellij.image.build.filetype.DockerfileFileType; +import org.jboss.tools.intellij.image.build.psi.*; import org.jboss.tools.intellij.report.AnalyticsReportUtils; import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -51,129 +40,87 @@ static ImageService getInstance() { return ApplicationManager.getApplication().getService(ImageService.class); } - static void handleArgCommand(DockerFileArgCommand command, Map variables) { - var declaration = command.getArgDeclaration(); + static void handleArgInstruction(DockerfileArgInstruction argInstruction, Map variables) { + DockerfileArgDeclaration declaration = argInstruction.getArgDeclaration(); if (declaration == null) { return; } - var name = declaration.getDeclaredName(); - var value = declaration.getAnyValue(); - if (value == null) { - return; + String varName = declaration.getText().split("=")[0].trim(); + String varValue = ""; + if (declaration.getText().contains("=")) { + varValue = declaration.getText().substring(declaration.getText().indexOf("=") + 1).trim(); + varValue = expandVariables(varValue, variables); } - String varValue = value.getText(); - varValue = handleStringLiteral(varValue, value.getStringLiteralList(), variables); - varValue = handleVariableRefFull(varValue, value.getVariableRefFullList(), variables); - varValue = handleVariableRefSimple(varValue, value.getVariableRefSimpleList(), variables); - - if (varValue != null) { - variables.put(name.getText(), varValue); - } + variables.put(varName, varValue); } - static String handleStringLiteral(String value, List literals, Map variables) { - var v = value; - for (var literal : literals) { - var text = literal.getText(); - text = handleVariableRefFull(text, literal.getVariableRefFullList(), variables); - text = handleVariableRefSimple(text, literal.getVariableRefSimpleList(), variables); - text = text.trim(); - if (text.startsWith("\"")) { - text = text.substring(1); - } - if (text.endsWith("\"")) { - text = text.substring(0, text.length() - 1); - } - v = v.replaceFirst(Pattern.quote(literal.getText()), text); - } - return v; - } + static String expandVariables(String value, Map variables) { + String result = value; - static String handleVariableRefFull(String value, List refs, Map variables) { - var v = value; - for (var ref : refs) { - if (ref.getVariableRefPostProcessing() != null) { - var refPost = ref.getVariableRefPostProcessing(); - - var text = ref.getText(); - text = handleStringLiteral(text, refPost.getStringLiteralList(), variables); - text = handleVariableRefFull(text, refPost.getVariableRefFullList(), variables); - text = handleVariableRefSimple(text, refPost.getVariableRefSimpleList(), variables); - v = v.replaceFirst(Pattern.quote(ref.getText()), text); - } else { - var varName = ref.getReferencedName(); - if (varName != null && variables.containsKey(varName.getText())) { - v = v.replaceFirst(Pattern.quote(ref.getText()), variables.get(varName.getText())); - } + // Handle ${VAR} format + Pattern fullVarPattern = Pattern.compile("\\$\\{([^}]+)\\}"); + java.util.regex.Matcher fullMatcher = fullVarPattern.matcher(result); + while (fullMatcher.find()) { + String varName = fullMatcher.group(1); + if (variables.containsKey(varName)) { + result = result.replace(fullMatcher.group(0), variables.get(varName)); } } - return v; - } - static String handleVariableRefSimple(String value, List refs, Map variables) { - var v = value; - for (var ref : refs) { - var varName = ref.getReferencedName(); - if (varName != null && variables.containsKey(varName.getText())) { - var refValue = variables.get(varName.getText()); - v = v.replaceFirst(Pattern.quote(ref.getText()), refValue); + // Handle $VAR format + Pattern simpleVarPattern = Pattern.compile("\\$([a-zA-Z_][a-zA-Z0-9_]*)"); + java.util.regex.Matcher simpleMatcher = simpleVarPattern.matcher(result); + while (simpleMatcher.find()) { + String varName = simpleMatcher.group(1); + if (variables.containsKey(varName)) { + result = result.replace(simpleMatcher.group(0), variables.get(varName)); } } - return v; + + return result; } - static BaseImage handleFromCommand(DockerFileFromCommand command, Map variables, Set aliases) { - var text = command.getText(); - text = text.substring(text.indexOf("FROM") + 4); - for (var option : command.getRegularOptionList()) { - text = text.replaceFirst(Pattern.quote(option.getText()), ""); - } - if (command.getFromStageDeclaration() != null) { - text = text.substring(0, text.lastIndexOf(command.getFromStageDeclaration().getText())); + static BaseImage handleFromInstruction(DockerfileFromInstruction fromInstruction, Map variables, Set aliases) { + DockerfileImageName imageName = fromInstruction.getImageName(); + if (imageName == null) { + return null; } - var names = command.getNameChainList(); - var first = names.get(0).getText(); - text = text.substring(text.indexOf(first)); - if (names.size() > 1) { - var last = names.get(names.size() - 1).getText(); - text = text.substring(0, text.lastIndexOf(last) + last.length()); + + String imageText = imageName.getText(); + imageText = expandVariables(imageText, variables); + + if (aliases.contains(imageText)) { + return null; } - var image = text; - for (var name : names) { - var t = name.getText(); - t = handleVariableRefFull(t, name.getVariableRefFullList(), variables); - t = handleVariableRefSimple(t, name.getVariableRefSimpleList(), variables); - image = image.replaceFirst(Pattern.quote(name.getText()), t); + String platform = extractPlatform(fromInstruction.getPlatformOption(), variables); + + DockerfileAsClause asClause = fromInstruction.getAsClause(); + if (asClause != null) { + String asText = asClause.getText().trim(); + if (asText.startsWith("AS ")) { + String alias = asText.substring(3).trim(); // Remove "AS " prefix + aliases.add(alias); + } } - image = image.trim(); - if (aliases.contains(image)) { + + return new BaseImage(imageText, platform); + } + + static String extractPlatform(DockerfilePlatformOption platformOption, Map variables) { + if (platformOption == null) { return null; } - var options = command.getRegularOptionList(); - var platform = options.stream() - .filter(option -> "platform".equalsIgnoreCase(option.getOptionName().getText())) - .map(DockerFileRegularOption::getRegularValue) - .map(value -> { - var v = value.getText(); - v = handleStringLiteral(v, value.getStringLiteralList(), variables); - v = handleVariableRefFull(v, value.getVariableRefFullList(), variables); - v = handleVariableRefSimple(v, value.getVariableRefSimpleList(), variables); - return v; - }) - .findAny() - .orElse(null); - - var stage = command.getFromStageDeclaration(); - if (stage != null) { - var alias = stage.getDeclaredName().getText(); - aliases.add(alias); + DockerfilePlatformValue platformValue = platformOption.getPlatformValue(); + if (platformValue == null) { + return null; } - return new BaseImage(image, platform); + String platform = platformValue.getText(); + return expandVariables(platform, variables); } Map> getBaseImages(PsiFile file) { @@ -184,17 +131,19 @@ Map> getBaseImages(PsiFile file) { Set aliases = new HashSet<>(); aliases.add("scratch"); - Arrays.stream(file.getChildren()) - .forEachOrdered(element -> { - if (element instanceof DockerFileFromCommand) { - var baseImage = handleFromCommand((DockerFileFromCommand) element, variables, aliases); - if (baseImage != null) { - infoMap.computeIfAbsent(baseImage, k -> new LinkedList<>()).add(element); - } - } else if (element instanceof DockerFileArgCommand) { - handleArgCommand((DockerFileArgCommand) element, variables); - } - }); + Collection fromInstructions = PsiTreeUtil.findChildrenOfType(file, DockerfileFromInstruction.class); + Collection argInstructions = PsiTreeUtil.findChildrenOfType(file, DockerfileArgInstruction.class); + + for (DockerfileArgInstruction argInstruction : argInstructions) { + handleArgInstruction(argInstruction, variables); + } + + for (DockerfileFromInstruction fromInstruction : fromInstructions) { + BaseImage baseImage = handleFromInstruction(fromInstruction, variables, aliases); + if (baseImage != null) { + infoMap.computeIfAbsent(baseImage, k -> new LinkedList<>()).add(fromInstruction); + } + } return infoMap; } @@ -238,7 +187,7 @@ Path generateAnalysisHtmlReport(final Set baseImages) { } JsonObject performImageAnalysis(List images, VirtualFile dockerfile) { - if (DockerFileType.DOCKER_FILE_TYPE.equals(dockerfile.getFileType())) { + if (DockerfileFileType.INSTANCE.equals(dockerfile.getFileType())) { var reportLink = generateAnalysisHtmlReport(new HashSet<>(images)).toUri().toString(); var manifestDetails = new JsonObject(); @@ -295,4 +244,4 @@ void openAnalysisHtmlReport(Project project, PsiFile dockerfile) { } } } -} +} \ No newline at end of file diff --git a/src/main/java/org/jboss/tools/intellij/image/UBIIntentionAction.java b/src/main/java/org/jboss/tools/intellij/image/UBIIntentionAction.java index 10d132a9..9c7374bb 100644 --- a/src/main/java/org/jboss/tools/intellij/image/UBIIntentionAction.java +++ b/src/main/java/org/jboss/tools/intellij/image/UBIIntentionAction.java @@ -14,7 +14,7 @@ import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.codeInspection.util.IntentionFamilyName; import com.intellij.codeInspection.util.IntentionName; -import com.intellij.docker.dockerFile.DockerFileType; +import org.jboss.tools.intellij.image.build.filetype.DockerfileFileType; import com.intellij.ide.BrowserUtil; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; @@ -40,7 +40,7 @@ public class UBIIntentionAction implements IntentionAction { @Override public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile psiFile) { - return DockerFileType.DOCKER_FILE_TYPE.equals(psiFile.getFileType()); + return DockerfileFileType.INSTANCE.equals(psiFile.getFileType()); } @Override diff --git a/src/main/java/org/jboss/tools/intellij/image/build/dockerfile.bnf b/src/main/java/org/jboss/tools/intellij/image/build/dockerfile.bnf new file mode 100644 index 00000000..51d62456 --- /dev/null +++ b/src/main/java/org/jboss/tools/intellij/image/build/dockerfile.bnf @@ -0,0 +1,91 @@ +{ + parserClass="org.jboss.tools.intellij.image.build.parser.DockerfileParser" + + extends="com.intellij.extapi.psi.ASTWrapperPsiElement" + + psiClassPrefix="Dockerfile" + psiImplClassSuffix="Impl" + psiPackage="org.jboss.tools.intellij.image.build.psi" + psiImplPackage="org.jboss.tools.intellij.image.build.psi.impl" + + elementTypeHolderClass="org.jboss.tools.intellij.image.build.psi.DockerfileTypes" + elementTypeClass="org.jboss.tools.intellij.image.build.psi.DockerfileElementType" + tokenTypeClass="org.jboss.tools.intellij.image.build.psi.DockerfileTokenType" + + tokens=[ + COMMENT='regexp:#.*' + + FROM='from' + ARG='arg' + AS='as' + PLATFORM_FLAG='--platform' + + RUN='run' + COPY='copy' + ADD='add' + WORKDIR='workdir' + CMD='cmd' + ENTRYPOINT='entrypoint' + ENV='env' + EXPOSE='expose' + VOLUME='volume' + USER='user' + LABEL='label' + + EQUALS='=' + COLON=':' + DOLLAR='$' + LBRACE='{' + RBRACE='}' + + ANY_CHAR='regexp:[^\s\r\n]' + + IDENTIFIER='regexp:[a-zA-Z_][a-zA-Z0-9_.\-/]*' + IMAGE_NAME_TOKEN='regexp:[a-zA-Z0-9._\-/]+' + VERSION='regexp:[a-zA-Z0-9._\-]+' + PLATFORM='regexp:linux/(amd64|arm64|386|arm/v7|arm/v6|ppc64le|s390x)' + + STRING='regexp:"([^"\\]|\\.)*"' + + OTHER_TOKEN='regexp:[^\s\r\n]+' + + WHITESPACE='regexp:\s+' + NEWLINE='regexp:\r?\n' + ] +} + +dockerFile ::= item* + +item ::= instruction | COMMENT | NEWLINE + +instruction ::= fromInstruction | argInstruction | otherInstruction + +fromInstruction ::= FROM (platformOption)? imageName (asClause)? + +platformOption ::= PLATFORM_FLAG EQUALS platformValue + +platformValue ::= PLATFORM | variableRef + +imageName ::= imageNamePart+ + +imageNamePart ::= imageNameLiteral | variableRef | COLON | VERSION + +imageNameLiteral ::= IMAGE_NAME_TOKEN | IDENTIFIER + +asClause ::= AS IDENTIFIER + +argInstruction ::= ARG argDeclaration + +argDeclaration ::= IDENTIFIER (EQUALS argValue)? + +argValue ::= STRING | IDENTIFIER | VERSION | variableRef + +otherInstruction ::= (RUN | COPY | ADD | WORKDIR | CMD | ENTRYPOINT | ENV | EXPOSE | VOLUME | USER | LABEL) instructionArgs* + +instructionArgs ::= STRING | IDENTIFIER | VERSION | IMAGE_NAME_TOKEN | OTHER_TOKEN | COLON | EQUALS | DOLLAR | LBRACE | RBRACE | PLATFORM_FLAG | PLATFORM | ANY_CHAR | variableRef + +variableRef ::= DOLLAR (simpleVar | complexVar) + +simpleVar ::= IDENTIFIER + +complexVar ::= LBRACE IDENTIFIER RBRACE \ No newline at end of file diff --git a/src/main/java/org/jboss/tools/intellij/image/build/dockerfile.flex b/src/main/java/org/jboss/tools/intellij/image/build/dockerfile.flex new file mode 100644 index 00000000..d11cb6e9 --- /dev/null +++ b/src/main/java/org/jboss/tools/intellij/image/build/dockerfile.flex @@ -0,0 +1,113 @@ +package org.jboss.tools.intellij.image.build.lexer; + +import com.intellij.lexer.FlexLexer; +import com.intellij.psi.tree.IElementType; +import org.jboss.tools.intellij.image.build.psi.DockerfileTypes; +import com.intellij.psi.TokenType; + +%% + +%class DockerfileLexer +%implements FlexLexer +%function advance +%type IElementType +%unicode +%ignorecase + +%{ + public DockerfileLexer() { + this((java.io.Reader)null); + } +%} + +// Whitespace and line endings +WHITESPACE = [ \t\f]+ +NEWLINE = \r?\n + +// Comments +COMMENT = "#"[^\r\n]* + +// Keywords (case insensitive) +FROM = [Ff][Rr][Oo][Mm] +ARG = [Aa][Rr][Gg] +AS = [Aa][Ss] +RUN = [Rr][Uu][Nn] +COPY = [Cc][Oo][Pp][Yy] +ADD = [Aa][Dd][Dd] +WORKDIR = [Ww][Oo][Rr][Kk][Dd][Ii][Rr] +CMD = [Cc][Mm][Dd] +ENTRYPOINT = [Ee][Nn][Tt][Rr][Yy][Pp][Oo][Ii][Nn][Tt] +ENV = [Ee][Nn][Vv] +EXPOSE = [Ee][Xx][Pp][Oo][Ss][Ee] +VOLUME = [Vv][Oo][Ll][Uu][Mm][Ee] +USER = [Uu][Ss][Ee][Rr] +LABEL = [Ll][Aa][Bb][Ee][Ll] + +// Platform option +PLATFORM_FLAG = "--platform" + +// Operators and delimiters +EQUALS = "=" +COLON = ":" +DOLLAR = "$" +LBRACE = "{" +RBRACE = "}" + +// Any non-whitespace, non-newline character (catch-all for any instruction content) +ANY_CHAR = [^\s\r\n] + +// Platform values (specific patterns first) +PLATFORM = "linux/"("amd64"|"arm64"|"386"|"arm/v7"|"arm/v6"|"ppc64le"|"s390x") + +// Strings +STRING = "\""([^\"\\]|\\.)*"\"" + +// Version numbers (numbers starting patterns) +VERSION = [0-9]+(\.[0-9]+)*(\-[a-zA-Z0-9\-_.]+)? + +// Identifiers (letter starting patterns) +IDENTIFIER = [a-zA-Z_][a-zA-Z0-9_.\-]* + +// Image names (most general pattern, should be last) +IMAGE_NAME_TOKEN = [a-zA-Z0-9._\-/]+ + +%% + + { + {WHITESPACE} { return TokenType.WHITE_SPACE; } + {NEWLINE} { return DockerfileTypes.NEWLINE; } + {COMMENT} { return DockerfileTypes.COMMENT; } + + {FROM} { return DockerfileTypes.FROM; } + {ARG} { return DockerfileTypes.ARG; } + {AS} { return DockerfileTypes.AS; } + {RUN} { return DockerfileTypes.RUN; } + {COPY} { return DockerfileTypes.COPY; } + {ADD} { return DockerfileTypes.ADD; } + {WORKDIR} { return DockerfileTypes.WORKDIR; } + {CMD} { return DockerfileTypes.CMD; } + {ENTRYPOINT} { return DockerfileTypes.ENTRYPOINT; } + {ENV} { return DockerfileTypes.ENV; } + {EXPOSE} { return DockerfileTypes.EXPOSE; } + {VOLUME} { return DockerfileTypes.VOLUME; } + {USER} { return DockerfileTypes.USER; } + {LABEL} { return DockerfileTypes.LABEL; } + + {PLATFORM_FLAG} { return DockerfileTypes.PLATFORM_FLAG; } + + {EQUALS} { return DockerfileTypes.EQUALS; } + {COLON} { return DockerfileTypes.COLON; } + {DOLLAR} { return DockerfileTypes.DOLLAR; } + {LBRACE} { return DockerfileTypes.LBRACE; } + {RBRACE} { return DockerfileTypes.RBRACE; } + + {ANY_CHAR} { return DockerfileTypes.ANY_CHAR; } + + {STRING} { return DockerfileTypes.STRING; } + {PLATFORM} { return DockerfileTypes.PLATFORM; } + {VERSION} { return DockerfileTypes.VERSION; } + {IDENTIFIER} { return DockerfileTypes.IDENTIFIER; } + {IMAGE_NAME_TOKEN} { return DockerfileTypes.IMAGE_NAME_TOKEN; } + + [^] { return TokenType.BAD_CHARACTER; } +} \ No newline at end of file diff --git a/src/main/java/org/jboss/tools/intellij/image/build/filetype/DockerfileFileType.java b/src/main/java/org/jboss/tools/intellij/image/build/filetype/DockerfileFileType.java new file mode 100644 index 00000000..65163e59 --- /dev/null +++ b/src/main/java/org/jboss/tools/intellij/image/build/filetype/DockerfileFileType.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2024 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v2.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v20.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ + +package org.jboss.tools.intellij.image.build.filetype; + +import com.intellij.openapi.fileTypes.LanguageFileType; +import org.jboss.tools.intellij.image.build.lang.DockerfileLanguage; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; + +public class DockerfileFileType extends LanguageFileType { + public static final DockerfileFileType INSTANCE = new DockerfileFileType(); + + private DockerfileFileType() { + super(DockerfileLanguage.INSTANCE); + } + + @NotNull + @Override + public String getName() { + return "rhda-dockerfile"; + } + + @NotNull + @Override + public String getDescription() { + return "RHDA Dockerfile"; + } + + @NotNull + @Override + public String getDefaultExtension() { + return ""; + } + + @Nullable + @Override + public Icon getIcon() { + return null; + } +} \ No newline at end of file diff --git a/src/main/java/org/jboss/tools/intellij/image/build/lang/DockerfileLanguage.java b/src/main/java/org/jboss/tools/intellij/image/build/lang/DockerfileLanguage.java new file mode 100644 index 00000000..e3117c72 --- /dev/null +++ b/src/main/java/org/jboss/tools/intellij/image/build/lang/DockerfileLanguage.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2024 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v2.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v20.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ + +package org.jboss.tools.intellij.image.build.lang; + +import com.intellij.lang.Language; + +public class DockerfileLanguage extends Language { + public static final DockerfileLanguage INSTANCE = new DockerfileLanguage(); + + private DockerfileLanguage() { + super("rhda-dockerfile"); + } +} \ No newline at end of file diff --git a/src/main/java/org/jboss/tools/intellij/image/build/lexer/DockerfileLexerAdapter.java b/src/main/java/org/jboss/tools/intellij/image/build/lexer/DockerfileLexerAdapter.java new file mode 100644 index 00000000..9403ef90 --- /dev/null +++ b/src/main/java/org/jboss/tools/intellij/image/build/lexer/DockerfileLexerAdapter.java @@ -0,0 +1,20 @@ +/******************************************************************************* + * Copyright (c) 2024 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v2.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v20.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ + +package org.jboss.tools.intellij.image.build.lexer; + +import com.intellij.lexer.FlexAdapter; + +public class DockerfileLexerAdapter extends FlexAdapter { + public DockerfileLexerAdapter() { + super(new DockerfileLexer(null)); + } +} \ No newline at end of file diff --git a/src/main/java/org/jboss/tools/intellij/image/build/psi/DockerfileElementType.java b/src/main/java/org/jboss/tools/intellij/image/build/psi/DockerfileElementType.java new file mode 100644 index 00000000..574433b2 --- /dev/null +++ b/src/main/java/org/jboss/tools/intellij/image/build/psi/DockerfileElementType.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2024 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v2.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v20.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ + +package org.jboss.tools.intellij.image.build.psi; + +import com.intellij.psi.tree.IElementType; +import org.jboss.tools.intellij.image.build.lang.DockerfileLanguage; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; + +public class DockerfileElementType extends IElementType { + public DockerfileElementType(@NotNull @NonNls String debugName) { + super(debugName, DockerfileLanguage.INSTANCE); + } +} \ No newline at end of file diff --git a/src/main/java/org/jboss/tools/intellij/image/build/psi/DockerfileFile.java b/src/main/java/org/jboss/tools/intellij/image/build/psi/DockerfileFile.java new file mode 100644 index 00000000..02a67ee1 --- /dev/null +++ b/src/main/java/org/jboss/tools/intellij/image/build/psi/DockerfileFile.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2024 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v2.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v20.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ + +package org.jboss.tools.intellij.image.build.psi; + +import com.intellij.extapi.psi.PsiFileBase; +import com.intellij.openapi.fileTypes.FileType; +import com.intellij.psi.FileViewProvider; +import org.jboss.tools.intellij.image.build.filetype.DockerfileFileType; +import org.jboss.tools.intellij.image.build.lang.DockerfileLanguage; +import org.jetbrains.annotations.NotNull; + +public class DockerfileFile extends PsiFileBase { + public DockerfileFile(@NotNull FileViewProvider viewProvider) { + super(viewProvider, DockerfileLanguage.INSTANCE); + } + + @NotNull + @Override + public FileType getFileType() { + return DockerfileFileType.INSTANCE; + } + + @Override + public String toString() { + return "Dockerfile File"; + } +} \ No newline at end of file diff --git a/src/main/java/org/jboss/tools/intellij/image/build/psi/DockerfileParserDefinition.java b/src/main/java/org/jboss/tools/intellij/image/build/psi/DockerfileParserDefinition.java new file mode 100644 index 00000000..fc843b4d --- /dev/null +++ b/src/main/java/org/jboss/tools/intellij/image/build/psi/DockerfileParserDefinition.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2024 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v2.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v20.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ + +package org.jboss.tools.intellij.image.build.psi; + +import com.intellij.lang.ASTNode; +import com.intellij.lang.ParserDefinition; +import com.intellij.lang.PsiParser; +import com.intellij.lexer.Lexer; +import com.intellij.openapi.project.Project; +import com.intellij.psi.FileViewProvider; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiFile; +import com.intellij.psi.tree.IFileElementType; +import com.intellij.psi.tree.TokenSet; +import org.jboss.tools.intellij.image.build.lang.DockerfileLanguage; +import org.jboss.tools.intellij.image.build.lexer.DockerfileLexerAdapter; +import org.jboss.tools.intellij.image.build.parser.DockerfileParser; +import org.jetbrains.annotations.NotNull; + +public class DockerfileParserDefinition implements ParserDefinition { + public static final IFileElementType FILE = new IFileElementType(DockerfileLanguage.INSTANCE); + + @NotNull + @Override + public Lexer createLexer(Project project) { + return new DockerfileLexerAdapter(); + } + + @Override + public @NotNull PsiParser createParser(Project project) { + return new DockerfileParser(); + } + + @NotNull + @Override + public IFileElementType getFileNodeType() { + return FILE; + } + + @NotNull + @Override + public TokenSet getCommentTokens() { + return DockerfileTokenSets.COMMENTS; + } + + @NotNull + @Override + public TokenSet getStringLiteralElements() { + return TokenSet.EMPTY; + } + + @NotNull + @Override + public PsiElement createElement(ASTNode node) { + return DockerfileTypes.Factory.createElement(node); + } + + @Override + public @NotNull PsiFile createFile(@NotNull FileViewProvider viewProvider) { + return new DockerfileFile(viewProvider); + } +} \ No newline at end of file diff --git a/src/main/java/org/jboss/tools/intellij/image/build/psi/DockerfileTokenSets.java b/src/main/java/org/jboss/tools/intellij/image/build/psi/DockerfileTokenSets.java new file mode 100644 index 00000000..5b8a9871 --- /dev/null +++ b/src/main/java/org/jboss/tools/intellij/image/build/psi/DockerfileTokenSets.java @@ -0,0 +1,18 @@ +/******************************************************************************* + * Copyright (c) 2024 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v2.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v20.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ + +package org.jboss.tools.intellij.image.build.psi; + +import com.intellij.psi.tree.TokenSet; + +public class DockerfileTokenSets { + public static final TokenSet COMMENTS = TokenSet.create(DockerfileTypes.COMMENT); +} \ No newline at end of file diff --git a/src/main/java/org/jboss/tools/intellij/image/build/psi/DockerfileTokenType.java b/src/main/java/org/jboss/tools/intellij/image/build/psi/DockerfileTokenType.java new file mode 100644 index 00000000..e5bd44a2 --- /dev/null +++ b/src/main/java/org/jboss/tools/intellij/image/build/psi/DockerfileTokenType.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2024 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v2.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v20.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ + +package org.jboss.tools.intellij.image.build.psi; + +import com.intellij.psi.tree.IElementType; +import org.jboss.tools.intellij.image.build.lang.DockerfileLanguage; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; + +public class DockerfileTokenType extends IElementType { + public DockerfileTokenType(@NotNull @NonNls String debugName) { + super(debugName, DockerfileLanguage.INSTANCE); + } + + @Override + public String toString() { + return "DockerfileTokenType." + super.toString(); + } +} \ No newline at end of file diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 8396f138..ecab1105 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -478,7 +478,6 @@ com.intellij.java org.jetbrains.idea.maven com.redhat.devtools.intellij.telemetry - Docker @@ -544,12 +543,18 @@ implementationClass="org.jboss.tools.intellij.componentanalysis.golang.GoCAInspection"/> + + - -