Fix deprecation warnings Drops support for IntelliJ 2019 Change-Id: Ib8a9550c0bd286db60461e14136e6054ba13ce6a Reviewed-on: https://fuchsia-review.googlesource.com/c/intellij-language-fidl/+/775282 Reviewed-by: Alex Zaslavsky <azaslavsky@google.com>
diff --git a/WORKSPACE b/WORKSPACE index 8d2f20d..830e8bb 100644 --- a/WORKSPACE +++ b/WORKSPACE
@@ -2,19 +2,19 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") -# The plugin api for IntelliJ 2019.3.3. +# The plugin api for IntelliJ 2020.1.4. http_archive( - name = "intellij_ce_2019_3_3", + name = "intellij_ce_2020_1_4", build_file = "//:intellij_platform_sdk/BUILD.idea", - sha256 = "c40536791c754c30dbf378bd6b59e0524b0588f26ddb4d85a9f260cf13454d14", - url = "https://download.jetbrains.com/idea/ideaIC-2019.3.3-no-jbr.tar.gz", + sha256 = "bc36f0b80e9c9f3e6c132d146ecd97937614990dcecfaa723592442d415f4b14", + url = "https://download.jetbrains.com/idea/ideaIC-2020.1.4-no-jbr.tar.gz", ) http_archive( name = "grammar_kit", build_file = "//:grammar_kit/BUILD.grammar_kit", - sha256 = "a33f9732b8bed61e509a8282e9a9ae72130ab5e7e18a449eb60cf00bb142018d", - url = "https://github.com/JetBrains/Grammar-Kit/releases/download/2019.3/grammar-kit-2019.3.zip", + sha256 = "9cfc31d090de5c68ff6e3fd265615168ec1d28a95984c6d96cb0ebabaab08562", + url = "https://github.com/JetBrains/Grammar-Kit/releases/download/2020.1/grammar-kit-2020.1.zip", ) http_archive(
diff --git a/grammar_kit/BUILD.grammar_kit b/grammar_kit/BUILD.grammar_kit index e71fd46..0c79efb 100644 --- a/grammar_kit/BUILD.grammar_kit +++ b/grammar_kit/BUILD.grammar_kit
@@ -2,5 +2,5 @@ java_import( name = "grammar_kit", - jars = ["grammar-kit/lib/grammar-kit-2019.3.jar"], + jars = ["grammar-kit/lib/grammar-kit-2020.1.jar"], )
diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index fe3f05a..68f4749 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml
@@ -22,6 +22,7 @@ <ul> <li>Remove support for deprecated struct defaults.</li> <li>Support for simplified escape sequences</li> + <li>Drop support for IntelliJ 2019.</li> </ul> </li> <li><b>0.18</b> @@ -133,14 +134,13 @@ </change-notes> <!-- please see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/build_number_ranges.html for description --> - <idea-version since-build="183.0"/> + <idea-version since-build="201.0"/> <!-- please see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/plugin_compatibility.html on how to target different products --> <depends>com.intellij.modules.lang</depends> <extensions defaultExtensionNs="com.intellij"> - <fileTypeFactory implementation="fuchsia.developer.plugin.fidl.DeprecatedFidlFileTypeFactory"/> <fileType name="FIDL file" implementationClass="fuchsia.developer.plugin.fidl.FileType" fieldName="INSTANCE" language="FIDL" extensions="fidl"/> <lang.parserDefinition language="FIDL"
diff --git a/src/fuchsia/developer/plugin/fidl/BUILD b/src/fuchsia/developer/plugin/fidl/BUILD index 7ad95f0..8009954 100644 --- a/src/fuchsia/developer/plugin/fidl/BUILD +++ b/src/fuchsia/developer/plugin/fidl/BUILD
@@ -19,7 +19,7 @@ main_class = "org.intellij.grammar.Main", runtime_deps = [ "@grammar_kit", - "@intellij_ce_2019_3_3//:sdk", + "@intellij_ce_2020_1_4//:sdk", ], ) @@ -168,9 +168,9 @@ deps = [ "@google_bazel_common//third_party/java/guava", "@grammar_kit", - "@intellij_ce_2019_3_3//:annotations", - "@intellij_ce_2019_3_3//:platform-api", - "@intellij_ce_2019_3_3//:util", + "@intellij_ce_2020_1_4//:annotations", + "@intellij_ce_2020_1_4//:platform-api", + "@intellij_ce_2020_1_4//:util", ], )
diff --git a/src/fuchsia/developer/plugin/fidl/ContextAwareHighlighter.java b/src/fuchsia/developer/plugin/fidl/ContextAwareHighlighter.java index fe11105..30149c6 100644 --- a/src/fuchsia/developer/plugin/fidl/ContextAwareHighlighter.java +++ b/src/fuchsia/developer/plugin/fidl/ContextAwareHighlighter.java
@@ -1,9 +1,9 @@ package fuchsia.developer.plugin.fidl; import com.intellij.lang.ASTNode; -import com.intellij.lang.annotation.Annotation; import com.intellij.lang.annotation.AnnotationHolder; import com.intellij.lang.annotation.Annotator; +import com.intellij.lang.annotation.HighlightSeverity; import com.intellij.openapi.editor.colors.TextAttributesKey; import com.intellij.openapi.util.TextRange; import com.intellij.psi.PsiElement; @@ -248,8 +248,10 @@ // SyntaxHighlighter might highlight it, then make sure it is colored as an identifier if (parentType == Types.IDENTIFIER_TOKEN && SYNTAX_HIGHLIGHTER.getTokenHighlights(thisType).length != 0) { - Annotation annotation = holder.createInfoAnnotation(element, null); - annotation.setTextAttributes(IDENTIFIER_ATTRIBUTE); + holder + .newSilentAnnotation(HighlightSeverity.INFORMATION) + .textAttributes(IDENTIFIER_ATTRIBUTE) + .create(); } // Context-sensitive keywords, part II: The Syntax Highlighter does not color types. If we @@ -257,8 +259,10 @@ if (parentType == Types.COMPOUND_IDENTIFIER) { if (grandParentType != null && grandParentType == Types.TYPE_CONSTRUCTOR) { if (FidlLexer.ALL_KEYWORDS.contains(element.getText())) { - Annotation annotation = holder.createInfoAnnotation(element, null); - annotation.setTextAttributes(KEYWORD_ATTRIBUTE); + holder + .newAnnotation(HighlightSeverity.INFORMATION, null) + .textAttributes(KEYWORD_ATTRIBUTE) + .create(); } } } @@ -278,15 +282,21 @@ // Only unsigned integers allowed for bits. if (identifierToken != null && identifierToken.findChildByType(UNSIGNED_INTEGRAL_TYPES) == null) { - holder.createErrorAnnotation( - element, "Expected integral type, found " + identifierToken.getText()); + holder + .newAnnotation( + HighlightSeverity.ERROR, + "Expected integral type, found " + identifierToken.getText()) + .create(); } } else { // Only integers allowed for enums. if (identifierToken != null && identifierToken.findChildByType(INTEGRAL_TYPES) == null) { - holder.createErrorAnnotation( - element, "Expected integral type, found " + identifierToken.getText()); + holder + .newAnnotation( + HighlightSeverity.ERROR, + "Expected integral type, found " + identifierToken.getText()) + .create(); } } } @@ -313,14 +323,20 @@ ASTNode numericLiteral = literal.findChildByType(Types.NUMERIC_LITERAL); if (numericLiteral == null) { // Must be a numeric literal in either case: - holder.createErrorAnnotation( - element, "Expected integer value for member, found " + literal.getText()); + holder + .newAnnotation( + HighlightSeverity.ERROR, + "Expected integer value for member, found " + literal.getText()) + .create(); } else { ASTNode integralLiteral = numericLiteral.findChildByType(Types.INTEGRAL_LITERAL); if (integralLiteral == null) { // Must be an integral literal in either case: - holder.createErrorAnnotation( - element, "Expected integer value for member, found " + literal.getText()); + holder + .newAnnotation( + HighlightSeverity.ERROR, + "Expected integer value for member, found " + literal.getText()) + .create(); } else { // INLINE_LAYOUT -> LAYOUT_BODY -> VALUE_LAYOUT -> VALUE_LAYOUT_MEMBER ASTNode subtype = greatGrandParent.getNode().findChildByType(Types.LAYOUT_SUBTYPE); @@ -329,13 +345,13 @@ correctTypeOrError( subtype.findChildByType(Types.TYPE_CONSTRUCTOR), integralLiteral); if (value != null) { - holder.createErrorAnnotation(element, value); + holder.newAnnotation(HighlightSeverity.ERROR, value).create(); } } if (maybeGreatGrandParentLayoutKind == Types.BITS) { String value = unsignedLongPowerOfTwoOrError(integralLiteral); if (value != null) { - holder.createErrorAnnotation(element, value); + holder.newAnnotation(HighlightSeverity.ERROR, value).create(); } } } @@ -350,8 +366,11 @@ if (parent.getNode().getElementType() == Types.ORDINAL_LAYOUT_MEMBER) { ASTNode maybeAttributeList = parent.getNode().findChildByType(Types.ATTRIBUTE_BLOCK); if (maybeAttributeList != null && !maybeAttributeList.getText().equals("")) { - holder.createErrorAnnotation( - maybeAttributeList, "Attributes are not allowed on reserved table members"); + holder + .newAnnotation( + HighlightSeverity.ERROR, "Attributes are not allowed on reserved table members") + .range(maybeAttributeList) + .create(); } } } @@ -375,8 +394,12 @@ if (flexible == null) { flexible = found; } else { - holder.createErrorAnnotation( - found, "The `flexible` modifier cannot be used twice in the same declaration"); + holder + .newAnnotation( + HighlightSeverity.ERROR, + "The `flexible` modifier cannot be used twice in the same declaration") + .range(found) + .create(); } } found = siblingNode.findChildByType(Types.STRICT); @@ -384,8 +407,12 @@ if (strict == null) { strict = found; } else { - holder.createErrorAnnotation( - found, "The `strict` modifier cannot be used twice in the same declaration"); + holder + .newAnnotation( + HighlightSeverity.ERROR, + "The `strict` modifier cannot be used twice in the same declaration") + .range(found) + .create(); } } found = siblingNode.findChildByType(Types.RESOURCE); @@ -393,8 +420,12 @@ if (resource == null) { resource = found; } else { - holder.createErrorAnnotation( - found, "The `resource` modifier cannot be used twice in the same declaration"); + holder + .newAnnotation( + HighlightSeverity.ERROR, + "The `resource` modifier cannot be used twice in the same declaration") + .range(found) + .create(); } } } @@ -405,21 +436,33 @@ && maybeThisLayoutKind != Types.ENUM && maybeThisLayoutKind != Types.UNION) { ASTNode theNode = flexible != null ? flexible : strict; - holder.createErrorAnnotation( - theNode, - "The `flexible` and `strict` modifiers can only be used on bits, enum, and union."); + holder + .newAnnotation( + HighlightSeverity.ERROR, + "The `flexible` and `strict` modifiers can only be used on bits, enum, and" + + " union.") + .range(theNode) + .create(); } if (flexible != null && strict != null) { - holder.createErrorAnnotation( - flexible, "The flexible and strict modifiers cannot be used together"); + holder + .newAnnotation( + HighlightSeverity.ERROR, + "The flexible and strict modifiers cannot be used together") + .range(flexible) + .create(); } } if (resource != null) { if (maybeThisLayoutKind != Types.STRUCT && maybeThisLayoutKind != Types.TABLE && maybeThisLayoutKind != Types.UNION) { - holder.createErrorAnnotation( - resource, "The `resource` modifier can only be used on struct, table, and union."); + holder + .newAnnotation( + HighlightSeverity.ERROR, + "The `resource` modifier can only be used on struct, table, and union.") + .range(resource) + .create(); } } } @@ -444,25 +487,29 @@ literal.getChars(0, literal.length(), chars, 0); for (int i = 1; i < chars.length; i++) { if (chars[i] == '\n' || chars[i] == '\r') { - holder.createErrorAnnotation(element, "CR and LF not allowed in string literal"); + holder.newAnnotation(HighlightSeverity.ERROR, "CR and LF not allowed in string literal"); } if (chars[i] == '\\') { if (i < chars.length - 2) { int jump = isEscape(chars, i + 1); int startOffset = element.getTextOffset() + i; if (jump == -1) { - holder.createErrorAnnotation( - new TextRange(startOffset, startOffset + 2), - "Unknown escape sequence \\" + chars[i + 1]); + holder + .newAnnotation( + HighlightSeverity.ERROR, "Unknown escape sequence \\" + chars[i + 1]) + .range(new TextRange(startOffset, startOffset + 2)) + .create(); } else if (jump == -2) { - holder.createErrorAnnotation( - new TextRange(startOffset, startOffset + 2), - "Malformed \\" + chars[i + 1] + " escape sequence"); + holder + .newAnnotation( + HighlightSeverity.ERROR, "Malformed \\" + chars[i + 1] + " escape sequence") + .range(new TextRange(startOffset, startOffset + 2)) + .create(); } else { i += jump; } } else { - holder.createErrorAnnotation(element, "Illegal string termination"); + holder.newAnnotation(HighlightSeverity.ERROR, "Illegal string termination").create(); } } }
diff --git a/src/fuchsia/developer/plugin/fidl/DeprecatedFidlFileTypeFactory.java b/src/fuchsia/developer/plugin/fidl/DeprecatedFidlFileTypeFactory.java deleted file mode 100644 index 206ff12..0000000 --- a/src/fuchsia/developer/plugin/fidl/DeprecatedFidlFileTypeFactory.java +++ /dev/null
@@ -1,15 +0,0 @@ -// Copyright 2020 The Fuchsia Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package fuchsia.developer.plugin.fidl; - -import com.intellij.openapi.fileTypes.FileTypeConsumer; -import com.intellij.openapi.fileTypes.FileTypeFactory; -import org.jetbrains.annotations.NotNull; - -public class DeprecatedFidlFileTypeFactory extends FileTypeFactory { - public void createFileTypes(@NotNull FileTypeConsumer fileTypeConsumer) { - fileTypeConsumer.consume(FileType.INSTANCE); - } -}
diff --git a/src/fuchsia/developer/plugin/fidl/Icons.java b/src/fuchsia/developer/plugin/fidl/Icons.java index c31cd56..e737b29 100644 --- a/src/fuchsia/developer/plugin/fidl/Icons.java +++ b/src/fuchsia/developer/plugin/fidl/Icons.java
@@ -9,5 +9,5 @@ public class Icons { public static final Icon FILE = - IconLoader.getIcon("/fuchsia/developer/plugin/fidl/icons/fuchsia-logo.svg"); + IconLoader.getIcon("/fuchsia/developer/plugin/fidl/icons/fuchsia-logo.svg", Icons.class); }
diff --git a/src/fuchsia/developer/plugin/fidl/psi/FidlNamedElementImpl.java b/src/fuchsia/developer/plugin/fidl/psi/FidlNamedElementImpl.java index ccd8a01..993e520 100644 --- a/src/fuchsia/developer/plugin/fidl/psi/FidlNamedElementImpl.java +++ b/src/fuchsia/developer/plugin/fidl/psi/FidlNamedElementImpl.java
@@ -31,13 +31,27 @@ String path = "/fuchsia/developer/plugin/fidl/icons/"; icons = ImmutableMap.<Class<? extends FidlNamedElementImpl>, Icon>builder() - .put(FidlConstDeclarationImpl.class, IconLoader.getIcon(path + "C.png")) - .put(FidlProtocolDeclarationImpl.class, IconLoader.getIcon(path + "P.png")) - .put(FidlLayoutDeclarationImpl.class, IconLoader.getIcon(path + "T.png")) - .put(FidlTypeAliasDeclarationImpl.class, IconLoader.getIcon(path + "U.png")) - .put(FidlProtocolMethodImpl.class, IconLoader.getIcon(path + "M.png")) - .put(FidlProtocolEventImpl.class, IconLoader.getIcon(path + "E.png")) - .put(FidlMemberFieldImpl.class, IconLoader.getIcon(path + "F.png")) + .put( + FidlConstDeclarationImpl.class, + IconLoader.getIcon(path + "C.png", FidlNamedElementImpl.class)) + .put( + FidlProtocolDeclarationImpl.class, + IconLoader.getIcon(path + "P.png", FidlNamedElementImpl.class)) + .put( + FidlLayoutDeclarationImpl.class, + IconLoader.getIcon(path + "T.png", FidlNamedElementImpl.class)) + .put( + FidlTypeAliasDeclarationImpl.class, + IconLoader.getIcon(path + "U.png", FidlNamedElementImpl.class)) + .put( + FidlProtocolMethodImpl.class, + IconLoader.getIcon(path + "M.png", FidlNamedElementImpl.class)) + .put( + FidlProtocolEventImpl.class, + IconLoader.getIcon(path + "E.png", FidlNamedElementImpl.class)) + .put( + FidlMemberFieldImpl.class, + IconLoader.getIcon(path + "F.png", FidlNamedElementImpl.class)) .build(); }