diff --git a/.idea/runConfigurations/simple_language_plugin.xml b/.idea/runConfigurations/simple_language_plugin.xml deleted file mode 100644 index ef4c9e144..000000000 --- a/.idea/runConfigurations/simple_language_plugin.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations/simple_language_plugin_tests.xml b/.idea/runConfigurations/simple_language_plugin_tests.xml deleted file mode 100644 index 1f38ddc12..000000000 --- a/.idea/runConfigurations/simple_language_plugin_tests.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/code_samples/simple_language_plugin/src/main/gen/com/intellij/sdk/language/SimpleLexer.java b/code_samples/simple_language_plugin/src/main/gen/org/intellij/sdk/language/SimpleLexer.java similarity index 99% rename from code_samples/simple_language_plugin/src/main/gen/com/intellij/sdk/language/SimpleLexer.java rename to code_samples/simple_language_plugin/src/main/gen/org/intellij/sdk/language/SimpleLexer.java index d29665ebe..b20c23625 100644 --- a/code_samples/simple_language_plugin/src/main/gen/com/intellij/sdk/language/SimpleLexer.java +++ b/code_samples/simple_language_plugin/src/main/gen/org/intellij/sdk/language/SimpleLexer.java @@ -1,10 +1,10 @@ /* The following code was generated by JFlex 1.7.0 tweaked for IntelliJ platform */ -package com.intellij.sdk.language; +package org.intellij.sdk.language; import com.intellij.lexer.FlexLexer; import com.intellij.psi.tree.IElementType; -import com.intellij.sdk.language.psi.SimpleTypes; +import org.intellij.sdk.language.psi.SimpleTypes; import com.intellij.psi.TokenType; diff --git a/code_samples/simple_language_plugin/src/main/gen/com/intellij/sdk/language/parser/SimpleParser.java b/code_samples/simple_language_plugin/src/main/gen/org/intellij/sdk/language/parser/SimpleParser.java similarity index 97% rename from code_samples/simple_language_plugin/src/main/gen/com/intellij/sdk/language/parser/SimpleParser.java rename to code_samples/simple_language_plugin/src/main/gen/org/intellij/sdk/language/parser/SimpleParser.java index a70231e85..a4bc36763 100644 --- a/code_samples/simple_language_plugin/src/main/gen/com/intellij/sdk/language/parser/SimpleParser.java +++ b/code_samples/simple_language_plugin/src/main/gen/org/intellij/sdk/language/parser/SimpleParser.java @@ -1,9 +1,9 @@ // This is a generated file. Not intended for manual editing. -package com.intellij.sdk.language.parser; +package org.intellij.sdk.language.parser; import com.intellij.lang.PsiBuilder; import com.intellij.lang.PsiBuilder.Marker; -import static com.intellij.sdk.language.psi.SimpleTypes.*; +import static org.intellij.sdk.language.psi.SimpleTypes.*; import static com.intellij.lang.parser.GeneratedParserUtilBase.*; import com.intellij.psi.tree.IElementType; import com.intellij.lang.ASTNode; diff --git a/code_samples/simple_language_plugin/src/main/gen/com/intellij/sdk/language/psi/SimpleProperty.java b/code_samples/simple_language_plugin/src/main/gen/org/intellij/sdk/language/psi/SimpleProperty.java similarity index 91% rename from code_samples/simple_language_plugin/src/main/gen/com/intellij/sdk/language/psi/SimpleProperty.java rename to code_samples/simple_language_plugin/src/main/gen/org/intellij/sdk/language/psi/SimpleProperty.java index 75a0af3b5..061a0a9a8 100644 --- a/code_samples/simple_language_plugin/src/main/gen/com/intellij/sdk/language/psi/SimpleProperty.java +++ b/code_samples/simple_language_plugin/src/main/gen/org/intellij/sdk/language/psi/SimpleProperty.java @@ -1,5 +1,5 @@ // This is a generated file. Not intended for manual editing. -package com.intellij.sdk.language.psi; +package org.intellij.sdk.language.psi; import java.util.List; import org.jetbrains.annotations.*; diff --git a/code_samples/simple_language_plugin/src/main/gen/com/intellij/sdk/language/psi/SimpleTypes.java b/code_samples/simple_language_plugin/src/main/gen/org/intellij/sdk/language/psi/SimpleTypes.java similarity index 90% rename from code_samples/simple_language_plugin/src/main/gen/com/intellij/sdk/language/psi/SimpleTypes.java rename to code_samples/simple_language_plugin/src/main/gen/org/intellij/sdk/language/psi/SimpleTypes.java index 558678ca9..d02c33f56 100644 --- a/code_samples/simple_language_plugin/src/main/gen/com/intellij/sdk/language/psi/SimpleTypes.java +++ b/code_samples/simple_language_plugin/src/main/gen/org/intellij/sdk/language/psi/SimpleTypes.java @@ -1,10 +1,10 @@ // This is a generated file. Not intended for manual editing. -package com.intellij.sdk.language.psi; +package org.intellij.sdk.language.psi; import com.intellij.psi.tree.IElementType; import com.intellij.psi.PsiElement; import com.intellij.lang.ASTNode; -import com.intellij.sdk.language.psi.impl.*; +import org.intellij.sdk.language.psi.impl.*; public interface SimpleTypes { diff --git a/code_samples/simple_language_plugin/src/main/gen/com/intellij/sdk/language/psi/SimpleVisitor.java b/code_samples/simple_language_plugin/src/main/gen/org/intellij/sdk/language/psi/SimpleVisitor.java similarity index 92% rename from code_samples/simple_language_plugin/src/main/gen/com/intellij/sdk/language/psi/SimpleVisitor.java rename to code_samples/simple_language_plugin/src/main/gen/org/intellij/sdk/language/psi/SimpleVisitor.java index aeacbe65d..51548f62f 100644 --- a/code_samples/simple_language_plugin/src/main/gen/com/intellij/sdk/language/psi/SimpleVisitor.java +++ b/code_samples/simple_language_plugin/src/main/gen/org/intellij/sdk/language/psi/SimpleVisitor.java @@ -1,5 +1,5 @@ // This is a generated file. Not intended for manual editing. -package com.intellij.sdk.language.psi; +package org.intellij.sdk.language.psi; import org.jetbrains.annotations.*; import com.intellij.psi.PsiElementVisitor; diff --git a/code_samples/simple_language_plugin/src/main/gen/com/intellij/sdk/language/psi/impl/SimplePropertyImpl.java b/code_samples/simple_language_plugin/src/main/gen/org/intellij/sdk/language/psi/impl/SimplePropertyImpl.java similarity index 90% rename from code_samples/simple_language_plugin/src/main/gen/com/intellij/sdk/language/psi/impl/SimplePropertyImpl.java rename to code_samples/simple_language_plugin/src/main/gen/org/intellij/sdk/language/psi/impl/SimplePropertyImpl.java index e9fc3a070..3094d83c2 100644 --- a/code_samples/simple_language_plugin/src/main/gen/com/intellij/sdk/language/psi/impl/SimplePropertyImpl.java +++ b/code_samples/simple_language_plugin/src/main/gen/org/intellij/sdk/language/psi/impl/SimplePropertyImpl.java @@ -1,5 +1,5 @@ // This is a generated file. Not intended for manual editing. -package com.intellij.sdk.language.psi.impl; +package org.intellij.sdk.language.psi.impl; import java.util.List; import org.jetbrains.annotations.*; @@ -7,8 +7,8 @@ import com.intellij.lang.ASTNode; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElementVisitor; import com.intellij.psi.util.PsiTreeUtil; -import static com.intellij.sdk.language.psi.SimpleTypes.*; -import com.intellij.sdk.language.psi.*; +import static org.intellij.sdk.language.psi.SimpleTypes.*; +import org.intellij.sdk.language.psi.*; import com.intellij.navigation.ItemPresentation; public class SimplePropertyImpl extends SimpleNamedElementImpl implements SimpleProperty { diff --git a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/Simple.bnf b/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/Simple.bnf deleted file mode 100644 index 3ae45df60..000000000 --- a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/Simple.bnf +++ /dev/null @@ -1,30 +0,0 @@ -{ - parserClass="com.intellij.sdk.language.parser.SimpleParser" - - extends="com.intellij.extapi.psi.ASTWrapperPsiElement" - - psiClassPrefix="Simple" - psiImplClassSuffix="Impl" - psiPackage="com.intellij.sdk.language.psi" - psiImplPackage="com.intellij.sdk.language.psi.impl" - - elementTypeHolderClass="com.intellij.sdk.language.psi.SimpleTypes" - elementTypeClass="com.intellij.sdk.language.psi.SimpleElementType" - tokenTypeClass="com.intellij.sdk.language.psi.SimpleTokenType" - - psiImplUtilClass="com.intellij.sdk.language.psi.impl.SimplePsiImplUtil" -} - -simpleFile ::= item_* - -private item_ ::= (property|COMMENT|CRLF) - -property ::= (KEY? SEPARATOR VALUE?) | KEY { - pin=3 - recoverWhile="recover_property" - mixin="com.intellij.sdk.language.psi.impl.SimpleNamedElementImpl" - implements="com.intellij.sdk.language.psi.SimpleNamedElement" - methods=[getKey getValue getName setName getNameIdentifier getPresentation] -} - -private recover_property ::= !(KEY|SEPARATOR|COMMENT) \ No newline at end of file diff --git a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/psi/SimpleNamedElement.java b/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/psi/SimpleNamedElement.java deleted file mode 100644 index 0cb18830a..000000000 --- a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/psi/SimpleNamedElement.java +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. - -package com.intellij.sdk.language.psi; - -import com.intellij.psi.PsiNameIdentifierOwner; - -public interface SimpleNamedElement extends PsiNameIdentifierOwner { -} \ No newline at end of file diff --git a/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/Simple.bnf b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/Simple.bnf new file mode 100644 index 000000000..d6dc75a4a --- /dev/null +++ b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/Simple.bnf @@ -0,0 +1,30 @@ +{ + parserClass="org.intellij.sdk.language.parser.SimpleParser" + + extends="com.intellij.extapi.psi.ASTWrapperPsiElement" + + psiClassPrefix="Simple" + psiImplClassSuffix="Impl" + psiPackage="org.intellij.sdk.language.psi" + psiImplPackage="org.intellij.sdk.language.psi.impl" + + elementTypeHolderClass="org.intellij.sdk.language.psi.SimpleTypes" + elementTypeClass="org.intellij.sdk.language.psi.SimpleElementType" + tokenTypeClass="org.intellij.sdk.language.psi.SimpleTokenType" + + psiImplUtilClass="org.intellij.sdk.language.psi.impl.SimplePsiImplUtil" +} + +simpleFile ::= item_* + +private item_ ::= (property|COMMENT|CRLF) + +property ::= (KEY? SEPARATOR VALUE?) | KEY { + pin=3 + recoverWhile="recover_property" + mixin="org.intellij.sdk.language.psi.impl.SimpleNamedElementImpl" + implements="org.intellij.sdk.language.psi.SimpleNamedElement" + methods=[getKey getValue getName setName getNameIdentifier getPresentation] +} + +private recover_property ::= !(KEY|SEPARATOR|COMMENT) \ No newline at end of file diff --git a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/Simple.flex b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/Simple.flex similarity index 94% rename from code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/Simple.flex rename to code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/Simple.flex index d71c2a4a9..f306ff342 100644 --- a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/Simple.flex +++ b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/Simple.flex @@ -1,8 +1,8 @@ -package com.intellij.sdk.language; +package org.intellij.sdk.language; import com.intellij.lexer.FlexLexer; import com.intellij.psi.tree.IElementType; -import com.intellij.sdk.language.psi.SimpleTypes; +import org.intellij.sdk.language.psi.SimpleTypes; import com.intellij.psi.TokenType; %% diff --git a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleAnnotator.java b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleAnnotator.java similarity index 97% rename from code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleAnnotator.java rename to code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleAnnotator.java index caef97733..10d024dbf 100644 --- a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleAnnotator.java +++ b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleAnnotator.java @@ -1,10 +1,10 @@ -package com.intellij.sdk.language; +package org.intellij.sdk.language; import com.intellij.lang.annotation.*; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.TextRange; import com.intellij.psi.*; -import com.intellij.sdk.language.psi.SimpleProperty; +import org.intellij.sdk.language.psi.SimpleProperty; import org.jetbrains.annotations.NotNull; import com.intellij.openapi.editor.DefaultLanguageHighlighterColors; diff --git a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleBlock.java b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleBlock.java similarity index 97% rename from code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleBlock.java rename to code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleBlock.java index 1e7b05f7f..77623bbcd 100644 --- a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleBlock.java +++ b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleBlock.java @@ -1,6 +1,6 @@ // Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -package com.intellij.sdk.language; +package org.intellij.sdk.language; import com.intellij.formatting.*; import com.intellij.lang.ASTNode; diff --git a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleChooseByNameContributor.java b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleChooseByNameContributor.java similarity index 81% rename from code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleChooseByNameContributor.java rename to code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleChooseByNameContributor.java index e172c0bdd..eea8b7e4c 100644 --- a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleChooseByNameContributor.java +++ b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleChooseByNameContributor.java @@ -1,10 +1,8 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. - -package com.intellij.sdk.language; +package org.intellij.sdk.language; import com.intellij.navigation.*; import com.intellij.openapi.project.Project; -import com.intellij.sdk.language.psi.SimpleProperty; +import org.intellij.sdk.language.psi.SimpleProperty; import org.jetbrains.annotations.NotNull; import java.util.*; diff --git a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleCodeStyleSettings.java b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleCodeStyleSettings.java similarity index 56% rename from code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleCodeStyleSettings.java rename to code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleCodeStyleSettings.java index 35c41c8a8..1d8a08311 100644 --- a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleCodeStyleSettings.java +++ b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleCodeStyleSettings.java @@ -1,6 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. - -package com.intellij.sdk.language; +package org.intellij.sdk.language; import com.intellij.psi.codeStyle.*; diff --git a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleCodeStyleSettingsProvider.java b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleCodeStyleSettingsProvider.java similarity index 86% rename from code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleCodeStyleSettingsProvider.java rename to code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleCodeStyleSettingsProvider.java index 27823e310..093184c14 100644 --- a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleCodeStyleSettingsProvider.java +++ b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleCodeStyleSettingsProvider.java @@ -1,6 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. - -package com.intellij.sdk.language; +package org.intellij.sdk.language; import com.intellij.application.options.*; import com.intellij.psi.codeStyle.*; diff --git a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleColorSettingsPage.java b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleColorSettingsPage.java similarity index 95% rename from code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleColorSettingsPage.java rename to code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleColorSettingsPage.java index a0ee3f616..d6a265893 100644 --- a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleColorSettingsPage.java +++ b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleColorSettingsPage.java @@ -1,4 +1,4 @@ -package com.intellij.sdk.language; +package org.intellij.sdk.language; import com.intellij.openapi.editor.colors.TextAttributesKey; import com.intellij.openapi.fileTypes.SyntaxHighlighter; @@ -8,8 +8,6 @@ import org.jetbrains.annotations.*; import javax.swing.*; import java.util.Map; -import static com.intellij.sdk.language.SimpleLanguage.*; - public class SimpleColorSettingsPage implements ColorSettingsPage { private static final AttributesDescriptor[] DESCRIPTORS = new AttributesDescriptor[]{ new AttributesDescriptor("Key", SimpleSyntaxHighlighter.KEY), diff --git a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleCommenter.java b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleCommenter.java similarity index 77% rename from code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleCommenter.java rename to code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleCommenter.java index a8c5be9de..9b80882e2 100644 --- a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleCommenter.java +++ b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleCommenter.java @@ -1,6 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. - -package com.intellij.sdk.language; +package org.intellij.sdk.language; import com.intellij.lang.Commenter; import org.jetbrains.annotations.Nullable; diff --git a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleCompletionContributor.java b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleCompletionContributor.java similarity index 80% rename from code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleCompletionContributor.java rename to code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleCompletionContributor.java index 4db1b4182..394c71902 100644 --- a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleCompletionContributor.java +++ b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleCompletionContributor.java @@ -1,12 +1,10 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. - -package com.intellij.sdk.language; +package org.intellij.sdk.language; import com.intellij.codeInsight.completion.*; import com.intellij.codeInsight.lookup.LookupElementBuilder; import com.intellij.patterns.PlatformPatterns; import com.intellij.util.ProcessingContext; -import com.intellij.sdk.language.psi.SimpleTypes; +import org.intellij.sdk.language.psi.SimpleTypes; import org.jetbrains.annotations.NotNull; public class SimpleCompletionContributor extends CompletionContributor { diff --git a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleCreatePropertyQuickFix.java b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleCreatePropertyQuickFix.java similarity index 91% rename from code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleCreatePropertyQuickFix.java rename to code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleCreatePropertyQuickFix.java index bdb3d0f12..cdb1cb7dd 100644 --- a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleCreatePropertyQuickFix.java +++ b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleCreatePropertyQuickFix.java @@ -1,6 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. - -package com.intellij.sdk.language; +package org.intellij.sdk.language; import com.intellij.codeInsight.intention.impl.BaseIntentionAction; import com.intellij.lang.ASTNode; @@ -20,9 +18,9 @@ import com.intellij.psi.PsiManager; import com.intellij.psi.search.FileTypeIndex; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.util.IncorrectOperationException; -import com.intellij.sdk.language.psi.SimpleElementFactory; -import com.intellij.sdk.language.psi.SimpleFile; -import com.intellij.sdk.language.psi.SimpleProperty; +import org.intellij.sdk.language.psi.SimpleElementFactory; +import org.intellij.sdk.language.psi.SimpleFile; +import org.intellij.sdk.language.psi.SimpleProperty; import org.jetbrains.annotations.NotNull; import java.util.Collection; diff --git a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleFileType.java b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleFileType.java similarity index 95% rename from code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleFileType.java rename to code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleFileType.java index f1564fe64..31515ef3f 100644 --- a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleFileType.java +++ b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleFileType.java @@ -1,4 +1,4 @@ -package com.intellij.sdk.language; +package org.intellij.sdk.language; import com.intellij.openapi.fileTypes.LanguageFileType; import org.jetbrains.annotations.NotNull; diff --git a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleFileTypeFactory.java b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleFileTypeFactory.java similarity index 93% rename from code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleFileTypeFactory.java rename to code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleFileTypeFactory.java index 6d823c42c..f09f52ce0 100644 --- a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleFileTypeFactory.java +++ b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleFileTypeFactory.java @@ -1,4 +1,4 @@ -package com.intellij.sdk.language; +package org.intellij.sdk.language; import com.intellij.openapi.fileTypes.FileTypeConsumer; import com.intellij.openapi.fileTypes.FileTypeFactory; diff --git a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleFindUsagesProvider.java b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleFindUsagesProvider.java similarity index 78% rename from code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleFindUsagesProvider.java rename to code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleFindUsagesProvider.java index aa308a388..9e63147a0 100644 --- a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleFindUsagesProvider.java +++ b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleFindUsagesProvider.java @@ -1,14 +1,12 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. - -package com.intellij.sdk.language; +package org.intellij.sdk.language; import com.intellij.lang.cacheBuilder.*; import com.intellij.lang.findUsages.FindUsagesProvider; import com.intellij.psi.*; import com.intellij.psi.tree.TokenSet; -import com.intellij.sdk.language.psi.*; +import org.intellij.sdk.language.psi.SimpleProperty; +import org.intellij.sdk.language.psi.SimpleTypes; import org.jetbrains.annotations.*; -import static com.intellij.sdk.language.SimpleAnnotator.*; public class SimpleFindUsagesProvider implements FindUsagesProvider { @Nullable @@ -55,7 +53,7 @@ public class SimpleFindUsagesProvider implements FindUsagesProvider { @Override public String getNodeText(@NotNull PsiElement element, boolean useFullName) { if (element instanceof SimpleProperty) { - return ((SimpleProperty) element).getKey() + SIMPLE_SEPARATOR_STR + ((SimpleProperty) element).getValue(); + return ((SimpleProperty) element).getKey() + SimpleAnnotator.SIMPLE_SEPARATOR_STR + ((SimpleProperty) element).getValue(); } else { return ""; } diff --git a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleFoldingBuilder.java b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleFoldingBuilder.java similarity index 81% rename from code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleFoldingBuilder.java rename to code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleFoldingBuilder.java index f08168d60..f1009835a 100644 --- a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleFoldingBuilder.java +++ b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleFoldingBuilder.java @@ -1,6 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. - -package com.intellij.sdk.language; +package org.intellij.sdk.language; import com.intellij.lang.ASTNode; import com.intellij.lang.folding.*; @@ -9,11 +7,9 @@ import com.intellij.openapi.project.*; import com.intellij.openapi.util.TextRange; import com.intellij.psi.*; import com.intellij.psi.util.PsiTreeUtil; -import com.intellij.sdk.language.psi.SimpleProperty; +import org.intellij.sdk.language.psi.SimpleProperty; import org.jetbrains.annotations.*; -import static com.intellij.sdk.language.SimpleAnnotator.*; - import java.util.*; public class SimpleFoldingBuilder extends FoldingBuilderEx implements DumbAware { @@ -21,7 +17,7 @@ public class SimpleFoldingBuilder extends FoldingBuilderEx implements DumbAware @Override public FoldingDescriptor[] buildFoldRegions(@NotNull PsiElement root, @NotNull Document document, boolean quick) { // Initialize the group of folding regions that will expand/collapse together. - FoldingGroup group = FoldingGroup.newGroup(SIMPLE_PREFIX_STR); + FoldingGroup group = FoldingGroup.newGroup(SimpleAnnotator.SIMPLE_PREFIX_STR); // Initialize the list of folding regions List< FoldingDescriptor > descriptors = new ArrayList< FoldingDescriptor >(); // Get a collection of the literal expressions in the document below root @@ -30,11 +26,11 @@ public class SimpleFoldingBuilder extends FoldingBuilderEx implements DumbAware // Evaluate the collection for ( final PsiLiteralExpression literalExpression : literalExpressions ) { String value = literalExpression.getValue() instanceof String ? (String) literalExpression.getValue() : null; - if ( value != null && value.startsWith(SIMPLE_PREFIX_STR + SIMPLE_SEPARATOR_STR) ) { + if ( value != null && value.startsWith(SimpleAnnotator.SIMPLE_PREFIX_STR + SimpleAnnotator.SIMPLE_SEPARATOR_STR) ) { Project project = literalExpression.getProject(); - String key = value.substring(SIMPLE_PREFIX_STR.length() + SIMPLE_SEPARATOR_STR.length()); + String key = value.substring(SimpleAnnotator.SIMPLE_PREFIX_STR.length() + SimpleAnnotator.SIMPLE_SEPARATOR_STR.length()); // Get a list of all properties for a given key in the project - final List< SimpleProperty > properties = SimpleUtil.findProperties(project, key); + final List properties = SimpleUtil.findProperties(project, key); if ( properties.size() == 1 ) { // Add a folding descriptor for the literal expression at this node. descriptors.add(new FoldingDescriptor(literalExpression.getNode(), @@ -59,7 +55,7 @@ public class SimpleFoldingBuilder extends FoldingBuilderEx implements DumbAware String retTxt = "..."; if ( node.getPsi() instanceof PsiLiteralExpression ) { PsiLiteralExpression nodeElement = (PsiLiteralExpression) node.getPsi(); - String key = ((String) nodeElement.getValue()).substring(SIMPLE_PREFIX_STR.length() + SIMPLE_SEPARATOR_STR.length()); + String key = ((String) nodeElement.getValue()).substring(SimpleAnnotator.SIMPLE_PREFIX_STR.length() + SimpleAnnotator.SIMPLE_SEPARATOR_STR.length()); final List< SimpleProperty > properties = SimpleUtil.findProperties(nodeElement.getProject(), key); String place = properties.get(0).getValue(); // IMPORTANT: keys can come with no values, so a test for null is needed diff --git a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleFormattingModelBuilder.java b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleFormattingModelBuilder.java similarity index 87% rename from code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleFormattingModelBuilder.java rename to code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleFormattingModelBuilder.java index 31e179678..50970d0a0 100644 --- a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleFormattingModelBuilder.java +++ b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleFormattingModelBuilder.java @@ -1,13 +1,11 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. - -package com.intellij.sdk.language; +package org.intellij.sdk.language; import com.intellij.formatting.*; import com.intellij.lang.ASTNode; import com.intellij.openapi.util.TextRange; import com.intellij.psi.*; import com.intellij.psi.codeStyle.CodeStyleSettings; -import com.intellij.sdk.language.psi.SimpleTypes; +import org.intellij.sdk.language.psi.SimpleTypes; import org.jetbrains.annotations.*; public class SimpleFormattingModelBuilder implements FormattingModelBuilder { diff --git a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleIcons.java b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleIcons.java similarity index 83% rename from code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleIcons.java rename to code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleIcons.java index f891e06af..2286ee0ea 100644 --- a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleIcons.java +++ b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleIcons.java @@ -1,4 +1,4 @@ -package com.intellij.sdk.language; +package org.intellij.sdk.language; import com.intellij.openapi.util.IconLoader; diff --git a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleLanguage.java b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleLanguage.java similarity index 85% rename from code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleLanguage.java rename to code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleLanguage.java index 49e3d2eda..70ccdc383 100644 --- a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleLanguage.java +++ b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleLanguage.java @@ -1,4 +1,4 @@ -package com.intellij.sdk.language; +package org.intellij.sdk.language; import com.intellij.lang.Language; diff --git a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleLanguageCodeStyleSettingsProvider.java b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleLanguageCodeStyleSettingsProvider.java similarity index 90% rename from code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleLanguageCodeStyleSettingsProvider.java rename to code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleLanguageCodeStyleSettingsProvider.java index 974c1e223..7d71eebf5 100644 --- a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleLanguageCodeStyleSettingsProvider.java +++ b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleLanguageCodeStyleSettingsProvider.java @@ -1,6 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. - -package com.intellij.sdk.language; +package org.intellij.sdk.language; import com.intellij.lang.Language; import com.intellij.psi.codeStyle.*; diff --git a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleLexerAdapter.java b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleLexerAdapter.java similarity index 85% rename from code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleLexerAdapter.java rename to code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleLexerAdapter.java index 426ac5226..ed2428eef 100644 --- a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleLexerAdapter.java +++ b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleLexerAdapter.java @@ -1,4 +1,4 @@ -package com.intellij.sdk.language; +package org.intellij.sdk.language; import com.intellij.lexer.FlexAdapter; diff --git a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleLineMarkerProvider.java b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleLineMarkerProvider.java similarity index 77% rename from code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleLineMarkerProvider.java rename to code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleLineMarkerProvider.java index a70ec514e..314e6f4cb 100644 --- a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleLineMarkerProvider.java +++ b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleLineMarkerProvider.java @@ -1,13 +1,12 @@ -package com.intellij.sdk.language; +package org.intellij.sdk.language; import com.intellij.codeInsight.daemon.*; import com.intellij.codeInsight.navigation.NavigationGutterIconBuilder; import com.intellij.openapi.project.Project; import com.intellij.psi.*; import com.intellij.psi.impl.source.tree.java.PsiJavaTokenImpl; -import com.intellij.sdk.language.psi.SimpleProperty; +import org.intellij.sdk.language.psi.SimpleProperty; import org.jetbrains.annotations.NotNull; -import static com.intellij.sdk.language.SimpleAnnotator.*; import java.util.*; @@ -21,12 +20,12 @@ public class SimpleLineMarkerProvider extends RelatedItemLineMarkerProvider { // The literal expression must start with the Simple language literal expression PsiLiteralExpression literalExpression = (PsiLiteralExpression) element.getParent(); String value = literalExpression.getValue() instanceof String ? (String) literalExpression.getValue() : null; - if ( ( value == null ) || !value.startsWith( SIMPLE_PREFIX_STR + SIMPLE_SEPARATOR_STR ) ) return; + if ( ( value == null ) || !value.startsWith( SimpleAnnotator.SIMPLE_PREFIX_STR + SimpleAnnotator.SIMPLE_SEPARATOR_STR ) ) return; // Get the Simple language property usage Project project = element.getProject(); - String possibleProperties = value.substring( SIMPLE_PREFIX_STR.length()+SIMPLE_SEPARATOR_STR.length() ); - final List< SimpleProperty > properties = SimpleUtil.findProperties( project, possibleProperties ); + String possibleProperties = value.substring( SimpleAnnotator.SIMPLE_PREFIX_STR.length()+ SimpleAnnotator.SIMPLE_SEPARATOR_STR.length() ); + final List properties = SimpleUtil.findProperties( project, possibleProperties ); if ( properties.size() > 0 ) { // Add the property to a collection of line marker info NavigationGutterIconBuilder< PsiElement > builder = diff --git a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleParserDefinition.java b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleParserDefinition.java similarity index 92% rename from code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleParserDefinition.java rename to code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleParserDefinition.java index 838c1b9fd..a8c38edda 100644 --- a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleParserDefinition.java +++ b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleParserDefinition.java @@ -1,12 +1,12 @@ -package com.intellij.sdk.language; +package org.intellij.sdk.language; import com.intellij.lang.*; import com.intellij.lexer.Lexer; import com.intellij.openapi.project.Project; import com.intellij.psi.*; import com.intellij.psi.tree.*; -import com.intellij.sdk.language.parser.SimpleParser; -import com.intellij.sdk.language.psi.*; +import org.intellij.sdk.language.parser.SimpleParser; +import org.intellij.sdk.language.psi.*; import org.jetbrains.annotations.NotNull; public class SimpleParserDefinition implements ParserDefinition { diff --git a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleRefactoringSupportProvider.java b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleRefactoringSupportProvider.java similarity index 64% rename from code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleRefactoringSupportProvider.java rename to code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleRefactoringSupportProvider.java index f54b4253b..4842a35bf 100644 --- a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleRefactoringSupportProvider.java +++ b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleRefactoringSupportProvider.java @@ -1,10 +1,8 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. - -package com.intellij.sdk.language; +package org.intellij.sdk.language; import com.intellij.lang.refactoring.RefactoringSupportProvider; import com.intellij.psi.PsiElement; -import com.intellij.sdk.language.psi.SimpleProperty; +import org.intellij.sdk.language.psi.SimpleProperty; import org.jetbrains.annotations.*; public class SimpleRefactoringSupportProvider extends RefactoringSupportProvider { diff --git a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleReference.java b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleReference.java similarity index 88% rename from code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleReference.java rename to code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleReference.java index 859ddbaf0..3cfb0ebbb 100644 --- a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleReference.java +++ b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleReference.java @@ -1,12 +1,10 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. - -package com.intellij.sdk.language; +package org.intellij.sdk.language; import com.intellij.codeInsight.lookup.*; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.TextRange; import com.intellij.psi.*; -import com.intellij.sdk.language.psi.SimpleProperty; +import org.intellij.sdk.language.psi.SimpleProperty; import org.jetbrains.annotations.*; import java.util.*; diff --git a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleReferenceContributor.java b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleReferenceContributor.java similarity index 85% rename from code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleReferenceContributor.java rename to code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleReferenceContributor.java index 66f11f782..cd8681dcd 100644 --- a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleReferenceContributor.java +++ b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleReferenceContributor.java @@ -1,6 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. - -package com.intellij.sdk.language; +package org.intellij.sdk.language; import com.intellij.openapi.util.TextRange; import com.intellij.patterns.PlatformPatterns; @@ -8,7 +6,7 @@ import com.intellij.psi.*; import com.intellij.util.ProcessingContext; import org.jetbrains.annotations.NotNull; -import static com.intellij.sdk.language.SimpleAnnotator.*; +import static org.intellij.sdk.language.SimpleAnnotator.*; public class SimpleReferenceContributor extends PsiReferenceContributor { @Override diff --git a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleStructureViewElement.java b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleStructureViewElement.java similarity index 85% rename from code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleStructureViewElement.java rename to code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleStructureViewElement.java index 2e5efc95f..737f8131e 100644 --- a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleStructureViewElement.java +++ b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleStructureViewElement.java @@ -1,6 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. - -package com.intellij.sdk.language; +package org.intellij.sdk.language; import com.intellij.ide.projectView.PresentationData; import com.intellij.ide.structureView.StructureViewTreeElement; @@ -9,9 +7,9 @@ import com.intellij.ide.util.treeView.smartTree.TreeElement; import com.intellij.navigation.ItemPresentation; import com.intellij.psi.NavigatablePsiElement; import com.intellij.psi.util.PsiTreeUtil; -import com.intellij.sdk.language.psi.SimpleFile; -import com.intellij.sdk.language.psi.SimpleProperty; -import com.intellij.sdk.language.psi.impl.SimplePropertyImpl; +import org.intellij.sdk.language.psi.*; +import org.intellij.sdk.language.psi.SimpleProperty; +import org.intellij.sdk.language.psi.impl.SimplePropertyImpl; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; diff --git a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleStructureViewFactory.java b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleStructureViewFactory.java similarity index 77% rename from code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleStructureViewFactory.java rename to code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleStructureViewFactory.java index 4ef9a11d9..3668a449d 100644 --- a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleStructureViewFactory.java +++ b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleStructureViewFactory.java @@ -1,6 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. - -package com.intellij.sdk.language; +package org.intellij.sdk.language; import com.intellij.ide.structureView.*; import com.intellij.lang.PsiStructureViewFactory; diff --git a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleStructureViewModel.java b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleStructureViewModel.java similarity index 76% rename from code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleStructureViewModel.java rename to code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleStructureViewModel.java index e7352cf82..c06f95a80 100644 --- a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleStructureViewModel.java +++ b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleStructureViewModel.java @@ -1,11 +1,9 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. - -package com.intellij.sdk.language; +package org.intellij.sdk.language; import com.intellij.ide.structureView.*; import com.intellij.ide.util.treeView.smartTree.Sorter; import com.intellij.psi.PsiFile; -import com.intellij.sdk.language.psi.SimpleFile; +import org.intellij.sdk.language.psi.SimpleFile; import org.jetbrains.annotations.NotNull; public class SimpleStructureViewModel extends StructureViewModelBase implements diff --git a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleSyntaxHighlighter.java b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleSyntaxHighlighter.java similarity index 96% rename from code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleSyntaxHighlighter.java rename to code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleSyntaxHighlighter.java index 44ea221ab..41a2c4a13 100644 --- a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleSyntaxHighlighter.java +++ b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleSyntaxHighlighter.java @@ -1,4 +1,4 @@ -package com.intellij.sdk.language; +package org.intellij.sdk.language; import com.intellij.lexer.Lexer; import com.intellij.openapi.editor.*; @@ -6,7 +6,7 @@ import com.intellij.openapi.editor.colors.TextAttributesKey; import com.intellij.openapi.fileTypes.SyntaxHighlighterBase; import com.intellij.psi.TokenType; import com.intellij.psi.tree.IElementType; -import com.intellij.sdk.language.psi.SimpleTypes; +import org.intellij.sdk.language.psi.SimpleTypes; import org.jetbrains.annotations.NotNull; import static com.intellij.openapi.editor.colors.TextAttributesKey.createTextAttributesKey; diff --git a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleSyntaxHighlighterFactory.java b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleSyntaxHighlighterFactory.java similarity index 92% rename from code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleSyntaxHighlighterFactory.java rename to code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleSyntaxHighlighterFactory.java index d8fd3732b..3c176b8d1 100644 --- a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleSyntaxHighlighterFactory.java +++ b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleSyntaxHighlighterFactory.java @@ -1,4 +1,4 @@ -package com.intellij.sdk.language; +package org.intellij.sdk.language; import com.intellij.openapi.fileTypes.*; import com.intellij.openapi.project.Project; diff --git a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleUtil.java b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleUtil.java similarity index 81% rename from code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleUtil.java rename to code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleUtil.java index 4666fa6b3..c4bc5edcc 100644 --- a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleUtil.java +++ b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleUtil.java @@ -1,12 +1,12 @@ -package com.intellij.sdk.language; +package org.intellij.sdk.language; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiManager; import com.intellij.psi.search.*; import com.intellij.psi.util.PsiTreeUtil; -import com.intellij.util.indexing.FileBasedIndex; -import com.intellij.sdk.language.psi.*; +import org.intellij.sdk.language.psi.SimpleFile; +import org.intellij.sdk.language.psi.SimpleProperty; import java.util.*; @@ -14,7 +14,7 @@ public class SimpleUtil { // Searches the entire project for Simple language files with instances of the Simple property with the given key public static List findProperties(Project project, String key) { - List result = null; + List result = new ArrayList<>(); Collection virtualFiles = FileTypeIndex.getFiles(SimpleFileType.INSTANCE, GlobalSearchScope.allScope(project)); for (VirtualFile virtualFile : virtualFiles) { @@ -24,16 +24,13 @@ public class SimpleUtil { if (properties != null) { for (SimpleProperty property : properties) { if (key.equals(property.getKey())) { - if (result == null) { - result = new ArrayList(); - } - result.add(property); + result.add(property); } } } } } - return result != null ? result : Collections.emptyList(); + return result; } public static List findProperties(Project project) { diff --git a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/psi/SimpleElementFactory.java b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/psi/SimpleElementFactory.java similarity index 78% rename from code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/psi/SimpleElementFactory.java rename to code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/psi/SimpleElementFactory.java index 5789a7f1e..eeb7e76c9 100644 --- a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/psi/SimpleElementFactory.java +++ b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/psi/SimpleElementFactory.java @@ -1,29 +1,28 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. - -package com.intellij.sdk.language.psi; +package org.intellij.sdk.language.psi; import com.intellij.openapi.project.Project; import com.intellij.psi.*; -import com.intellij.sdk.language.SimpleFileType; +import org.intellij.sdk.language.SimpleFileType; public class SimpleElementFactory { public static SimpleProperty createProperty(Project project, String name) { final SimpleFile file = createFile(project, name); return (SimpleProperty) file.getFirstChild(); } - - public static SimpleProperty createProperty(Project project, String name, String value) { - final SimpleFile file = createFile(project, name + " = " + value); - return (SimpleProperty) file.getFirstChild(); - } - - public static PsiElement createCRLF(Project project) { - final SimpleFile file = createFile(project, "\n"); - return file.getFirstChild(); - } - + public static SimpleFile createFile(Project project, String text) { String name = "dummy.simple"; return (SimpleFile) PsiFileFactory.getInstance( project).createFileFromText(name, SimpleFileType.INSTANCE, text); } + + public static SimpleProperty createProperty(Project project, String name, String value) { + final SimpleFile file = createFile(project, name + " = " + value); + return (SimpleProperty) file.getFirstChild(); + } + + public static PsiElement createCRLF(Project project) { + final SimpleFile file = createFile(project, "\n"); + return file.getFirstChild(); + } + } \ No newline at end of file diff --git a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/psi/SimpleElementType.java b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/psi/SimpleElementType.java similarity index 77% rename from code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/psi/SimpleElementType.java rename to code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/psi/SimpleElementType.java index cbc6b76d8..8ebb8e5ba 100644 --- a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/psi/SimpleElementType.java +++ b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/psi/SimpleElementType.java @@ -1,7 +1,7 @@ -package com.intellij.sdk.language.psi; +package org.intellij.sdk.language.psi; import com.intellij.psi.tree.IElementType; -import com.intellij.sdk.language.SimpleLanguage; +import org.intellij.sdk.language.SimpleLanguage; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; diff --git a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/psi/SimpleFile.java b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/psi/SimpleFile.java similarity index 84% rename from code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/psi/SimpleFile.java rename to code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/psi/SimpleFile.java index 95cf389c3..73af603df 100644 --- a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/psi/SimpleFile.java +++ b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/psi/SimpleFile.java @@ -1,13 +1,11 @@ -package com.intellij.sdk.language.psi; +package org.intellij.sdk.language.psi; import com.intellij.extapi.psi.PsiFileBase; import com.intellij.openapi.fileTypes.FileType; import com.intellij.psi.FileViewProvider; -import com.intellij.sdk.language.*; +import org.intellij.sdk.language.*; import org.jetbrains.annotations.NotNull; -import javax.swing.*; - public class SimpleFile extends PsiFileBase { public SimpleFile(@NotNull FileViewProvider viewProvider) { super(viewProvider, SimpleLanguage.INSTANCE); diff --git a/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/psi/SimpleNamedElement.java b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/psi/SimpleNamedElement.java new file mode 100644 index 000000000..e358953a0 --- /dev/null +++ b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/psi/SimpleNamedElement.java @@ -0,0 +1,6 @@ +package org.intellij.sdk.language.psi; + +import com.intellij.psi.PsiNameIdentifierOwner; + +public interface SimpleNamedElement extends PsiNameIdentifierOwner { +} \ No newline at end of file diff --git a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/psi/SimpleTokenType.java b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/psi/SimpleTokenType.java similarity index 79% rename from code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/psi/SimpleTokenType.java rename to code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/psi/SimpleTokenType.java index 3300afdc0..863482287 100644 --- a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/psi/SimpleTokenType.java +++ b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/psi/SimpleTokenType.java @@ -1,7 +1,7 @@ -package com.intellij.sdk.language.psi; +package org.intellij.sdk.language.psi; import com.intellij.psi.tree.IElementType; -import com.intellij.sdk.language.SimpleLanguage; +import org.intellij.sdk.language.SimpleLanguage; import org.jetbrains.annotations.*; public class SimpleTokenType extends IElementType { diff --git a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/psi/impl/SimpleNamedElementImpl.java b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/psi/impl/SimpleNamedElementImpl.java similarity index 81% rename from code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/psi/impl/SimpleNamedElementImpl.java rename to code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/psi/impl/SimpleNamedElementImpl.java index 367dd8f99..1ff9751f0 100644 --- a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/psi/impl/SimpleNamedElementImpl.java +++ b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/psi/impl/SimpleNamedElementImpl.java @@ -1,10 +1,10 @@ // Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -package com.intellij.sdk.language.psi.impl; +package org.intellij.sdk.language.psi.impl; import com.intellij.extapi.psi.ASTWrapperPsiElement; import com.intellij.lang.ASTNode; -import com.intellij.sdk.language.psi.SimpleNamedElement; +import org.intellij.sdk.language.psi.SimpleNamedElement; import org.jetbrains.annotations.NotNull; public abstract class SimpleNamedElementImpl extends ASTWrapperPsiElement implements SimpleNamedElement { diff --git a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/psi/impl/SimplePsiImplUtil.java b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/psi/impl/SimplePsiImplUtil.java similarity index 94% rename from code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/psi/impl/SimplePsiImplUtil.java rename to code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/psi/impl/SimplePsiImplUtil.java index 25ccc748c..3316985da 100644 --- a/code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/psi/impl/SimplePsiImplUtil.java +++ b/code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/psi/impl/SimplePsiImplUtil.java @@ -1,11 +1,11 @@ -package com.intellij.sdk.language.psi.impl; +package org.intellij.sdk.language.psi.impl; import com.intellij.lang.ASTNode; import com.intellij.navigation.ItemPresentation; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; -import com.intellij.sdk.language.SimpleIcons; -import com.intellij.sdk.language.psi.*; +import org.intellij.sdk.language.SimpleIcons; +import org.intellij.sdk.language.psi.*; import org.jetbrains.annotations.Nullable; import javax.swing.*; diff --git a/code_samples/simple_language_plugin/src/main/resources/META-INF/plugin.xml b/code_samples/simple_language_plugin/src/main/resources/META-INF/plugin.xml index f09d17ce4..048ca7664 100644 --- a/code_samples/simple_language_plugin/src/main/resources/META-INF/plugin.xml +++ b/code_samples/simple_language_plugin/src/main/resources/META-INF/plugin.xml @@ -3,7 +3,7 @@ - com.intellij.sdk.simple_language + org.intellij.sdk.simple_language SDK: Simple Language Sample Project @@ -40,28 +40,28 @@ IntelliJ Platform SDK - + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/code_samples/simple_language_plugin/src/test/java/com/intellij/sdk/language/SimpleCodeInsightTest.java b/code_samples/simple_language_plugin/src/test/java/org/intellij/sdk/language/SimpleCodeInsightTest.java similarity index 93% rename from code_samples/simple_language_plugin/src/test/java/com/intellij/sdk/language/SimpleCodeInsightTest.java rename to code_samples/simple_language_plugin/src/test/java/org/intellij/sdk/language/SimpleCodeInsightTest.java index bcfd58774..d697864bb 100644 --- a/code_samples/simple_language_plugin/src/test/java/com/intellij/sdk/language/SimpleCodeInsightTest.java +++ b/code_samples/simple_language_plugin/src/test/java/org/intellij/sdk/language/SimpleCodeInsightTest.java @@ -1,4 +1,4 @@ -package com.intellij.sdk.language; +package org.intellij.sdk.language; import com.intellij.application.options.CodeStyle; import com.intellij.codeInsight.completion.CompletionType; @@ -9,7 +9,7 @@ import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase; import com.intellij.usageView.UsageInfo; import com.intellij.util.containers.ContainerUtil; -import com.intellij.sdk.language.psi.SimpleProperty; +import org.intellij.sdk.language.psi.SimpleProperty; import java.util.Arrays; import java.util.Collection; @@ -23,7 +23,7 @@ public class SimpleCodeInsightTest extends LightJavaCodeInsightFixtureTestCase { */ @Override protected String getTestDataPath() { - return "src/test/resources"; + return "src/test/testData"; } public void testCompletion() { @@ -40,7 +40,7 @@ public class SimpleCodeInsightTest extends LightJavaCodeInsightFixtureTestCase { } public void testFormatter() { - myFixture.configureByFiles("FormatterTestData.simple"); + myFixture.configureByFile("FormatterTestData.simple"); CodeStyle.getLanguageSettings(myFixture.getFile()).SPACE_AROUND_ASSIGNMENT_OPERATORS = true; CodeStyle.getLanguageSettings(myFixture.getFile()).KEEP_BLANK_LINES_IN_CODE = 2; WriteCommandAction.writeCommandAction(getProject()).run(() -> { @@ -57,7 +57,7 @@ public class SimpleCodeInsightTest extends LightJavaCodeInsightFixtureTestCase { } public void testFolding() { - myFixture.configureByFiles("DefaultTestData.simple"); + myFixture.configureByFile("DefaultTestData.simple"); myFixture.testFolding(getTestDataPath() + "/FoldingTestData.java"); } diff --git a/code_samples/simple_language_plugin/src/test/java/com/intellij/sdk/language/SimpleParsingTest.java b/code_samples/simple_language_plugin/src/test/java/org/intellij/sdk/language/SimpleParsingTest.java similarity index 89% rename from code_samples/simple_language_plugin/src/test/java/com/intellij/sdk/language/SimpleParsingTest.java rename to code_samples/simple_language_plugin/src/test/java/org/intellij/sdk/language/SimpleParsingTest.java index b0a96d281..342aecc9c 100644 --- a/code_samples/simple_language_plugin/src/test/java/com/intellij/sdk/language/SimpleParsingTest.java +++ b/code_samples/simple_language_plugin/src/test/java/org/intellij/sdk/language/SimpleParsingTest.java @@ -1,4 +1,4 @@ -package com.intellij.sdk.language; +package org.intellij.sdk.language; import com.intellij.testFramework.ParsingTestCase; @@ -17,7 +17,7 @@ public class SimpleParsingTest extends ParsingTestCase { */ @Override protected String getTestDataPath() { - return "src/test/resources"; + return "src/test/testData"; } @Override diff --git a/code_samples/simple_language_plugin/src/test/resources/AnnotatorTestData.java b/code_samples/simple_language_plugin/src/test/testData/AnnotatorTestData.java similarity index 100% rename from code_samples/simple_language_plugin/src/test/resources/AnnotatorTestData.java rename to code_samples/simple_language_plugin/src/test/testData/AnnotatorTestData.java diff --git a/code_samples/simple_language_plugin/src/test/resources/CompleteTestData.java b/code_samples/simple_language_plugin/src/test/testData/CompleteTestData.java similarity index 100% rename from code_samples/simple_language_plugin/src/test/resources/CompleteTestData.java rename to code_samples/simple_language_plugin/src/test/testData/CompleteTestData.java diff --git a/code_samples/simple_language_plugin/src/test/resources/DefaultTestData.simple b/code_samples/simple_language_plugin/src/test/testData/DefaultTestData.simple similarity index 100% rename from code_samples/simple_language_plugin/src/test/resources/DefaultTestData.simple rename to code_samples/simple_language_plugin/src/test/testData/DefaultTestData.simple diff --git a/code_samples/simple_language_plugin/src/test/resources/FindUsagesTestData.java b/code_samples/simple_language_plugin/src/test/testData/FindUsagesTestData.java similarity index 100% rename from code_samples/simple_language_plugin/src/test/resources/FindUsagesTestData.java rename to code_samples/simple_language_plugin/src/test/testData/FindUsagesTestData.java diff --git a/code_samples/simple_language_plugin/src/test/resources/FindUsagesTestData.simple b/code_samples/simple_language_plugin/src/test/testData/FindUsagesTestData.simple similarity index 100% rename from code_samples/simple_language_plugin/src/test/resources/FindUsagesTestData.simple rename to code_samples/simple_language_plugin/src/test/testData/FindUsagesTestData.simple diff --git a/code_samples/simple_language_plugin/src/test/resources/FoldingTestData.java b/code_samples/simple_language_plugin/src/test/testData/FoldingTestData.java similarity index 100% rename from code_samples/simple_language_plugin/src/test/resources/FoldingTestData.java rename to code_samples/simple_language_plugin/src/test/testData/FoldingTestData.java diff --git a/code_samples/simple_language_plugin/src/test/resources/FormatterTestData.simple b/code_samples/simple_language_plugin/src/test/testData/FormatterTestData.simple similarity index 100% rename from code_samples/simple_language_plugin/src/test/resources/FormatterTestData.simple rename to code_samples/simple_language_plugin/src/test/testData/FormatterTestData.simple diff --git a/code_samples/simple_language_plugin/src/test/resources/ParsingTestData.simple b/code_samples/simple_language_plugin/src/test/testData/ParsingTestData.simple similarity index 100% rename from code_samples/simple_language_plugin/src/test/resources/ParsingTestData.simple rename to code_samples/simple_language_plugin/src/test/testData/ParsingTestData.simple diff --git a/code_samples/simple_language_plugin/src/test/resources/ParsingTestData.txt b/code_samples/simple_language_plugin/src/test/testData/ParsingTestData.txt similarity index 100% rename from code_samples/simple_language_plugin/src/test/resources/ParsingTestData.txt rename to code_samples/simple_language_plugin/src/test/testData/ParsingTestData.txt diff --git a/code_samples/simple_language_plugin/src/test/resources/ReferenceTestData.java b/code_samples/simple_language_plugin/src/test/testData/ReferenceTestData.java similarity index 100% rename from code_samples/simple_language_plugin/src/test/resources/ReferenceTestData.java rename to code_samples/simple_language_plugin/src/test/testData/ReferenceTestData.java diff --git a/code_samples/simple_language_plugin/src/test/resources/RenameTestData.java b/code_samples/simple_language_plugin/src/test/testData/RenameTestData.java similarity index 100% rename from code_samples/simple_language_plugin/src/test/resources/RenameTestData.java rename to code_samples/simple_language_plugin/src/test/testData/RenameTestData.java diff --git a/code_samples/simple_language_plugin/src/test/resources/RenameTestData.simple b/code_samples/simple_language_plugin/src/test/testData/RenameTestData.simple similarity index 100% rename from code_samples/simple_language_plugin/src/test/resources/RenameTestData.simple rename to code_samples/simple_language_plugin/src/test/testData/RenameTestData.simple diff --git a/code_samples/simple_language_plugin/src/test/resources/RenameTestDataAfter.simple b/code_samples/simple_language_plugin/src/test/testData/RenameTestDataAfter.simple similarity index 100% rename from code_samples/simple_language_plugin/src/test/resources/RenameTestDataAfter.simple rename to code_samples/simple_language_plugin/src/test/testData/RenameTestDataAfter.simple diff --git a/tutorials/custom_language_support/annotator.md b/tutorials/custom_language_support/annotator.md index c9445b2ee..0ebd36109 100644 --- a/tutorials/custom_language_support/annotator.md +++ b/tutorials/custom_language_support/annotator.md @@ -2,63 +2,31 @@ title: 7. Annotator --- -Annotator helps highlight and annotate any code based on specific rules. +An [Annotator](/reference_guide/custom_language_support/syntax_highlighting_and_error_highlighting.md#annotator) helps highlight and annotate any code based on specific rules. +This section adds annotation functionality to support the Simple Language in the context of Java code. -### 7.1. Define an annotator - -In this tutorial we will annotate usages of our properties within Java code. -Let's consider a literal which starts with *"simple:"* as a usage of our property. +* bullet list +{:toc} +## 7.1. Define an Annotator +The `SimpleAnnotator` subclasses [`Annotator`](upsource:///platform/analysis-api/src/com/intellij/lang/annotation/Annotator.java). +Consider a literal string that starts with "simple:" as a prefix of a Simple Language key. +It isn't part of the Simple Language, but it is a useful convention for detecting Simple Language keys embedded as string literals in other languages, like Java. +Annotate the `simple:key` literal expression, and differentiate between a well-formed vs. an unresolved property: ```java -package com.simpleplugin; - -import com.intellij.lang.annotation.*; -import com.intellij.openapi.editor.DefaultLanguageHighlighterColors; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.TextRange; -import com.intellij.psi.*; -import com.simpleplugin.psi.SimpleProperty; -import org.jetbrains.annotations.NotNull; - -import java.util.List; - -public class SimpleAnnotator implements Annotator { - @Override - public void annotate(@NotNull final PsiElement element, @NotNull AnnotationHolder holder) { - if (element instanceof PsiLiteralExpression) { - PsiLiteralExpression literalExpression = (PsiLiteralExpression) element; - String value = literalExpression.getValue() instanceof String ? (String) literalExpression.getValue() : null; - - if (value != null && value.startsWith("simple" + ":")) { - Project project = element.getProject(); - String key = value.substring(7); - List properties = SimpleUtil.findProperties(project, key); - if (properties.size() == 1) { - TextRange range = new TextRange(element.getTextRange().getStartOffset() + 8, - element.getTextRange().getEndOffset() - 1); - Annotation annotation = holder.createInfoAnnotation(range, null); - annotation.setTextAttributes(DefaultLanguageHighlighterColors.LINE_COMMENT); - } else if (properties.size() == 0) { - TextRange range = new TextRange(element.getTextRange().getStartOffset() + 8, - element.getTextRange().getEndOffset() - 1); - holder.createErrorAnnotation(range, "Unresolved property"); - } - } - } - } -} +{% include /code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleAnnotator.java %} ``` -### 7.2. Register the annotator - +## 7.2. Register the Annotator +Using an extension point, register the Simple Language annotator class with the IntelliJ Platform: ```xml - + + + ``` -### 7.3. Run the project - -Let's define the following Java file and check if the IDE resolves a property. - +## 7.3. Run the Project +As a test, define the following Java file containing a Simple Language `prefix:value` pair: ```java public class Test { public static void main(String[] args) { @@ -67,9 +35,12 @@ public class Test { } ``` -![Annotator](img/annotator.png) +Open this Java file in an IDE Development Instance running the `simple_language_plugin` to check if the IDE resolves a property: -If we type an undefined property name, it will annotate the code with a error. +![Annotator](img/annotator.png){:width="800px"} -![Unresolved property](img/unresolved_property.png) +If the property is an undefined name, the annotator flags the code with an error. +![Unresolved property](img/unresolved_property.png){:width="800px"} + +Try changing the Simple Language [color settings](/tutorials/custom_language_support/syntax_highlighter_and_color_settings_page.md#run-the-project-1) to differentiate the annotation from the default language color settings. \ No newline at end of file diff --git a/tutorials/custom_language_support/code_style_settings.md b/tutorials/custom_language_support/code_style_settings.md index 7592ed0be..c6db15007 100644 --- a/tutorials/custom_language_support/code_style_settings.md +++ b/tutorials/custom_language_support/code_style_settings.md @@ -2,38 +2,50 @@ title: 16. Code Style Setting --- -Code style settings allow defining formatting options. A code style settings provider will create an instance of the settings, and also create an options page in order to edit them. In this example, we'll create a page that uses the default language code style settings, customised by a language code style settings provider. +[Code style settings](/reference_guide/custom_language_support/code_formatting.md#code-style-settings) enable defining formatting options. +A code style settings provider creates an instance of the settings and also creates an options page in settings/preferences. +This example creates a settings/preferences page that uses the default language code style settings, customized by a language code style settings provider. -### 16.1. Define code style settings +* bullet list +{:toc} +## 16.1. Define Code Style Settings +Define a code style settings for Simple Language by subclassing [`CustomCodeStyleSettings`](upsource:///platform/lang-api/src/com/intellij/psi/codeStyle/CustomCodeStyleSettings.java). ```java -{% include /code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleCodeStyleSettings.java %} +{% include /code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleCodeStyleSettings.java %} ``` -### 16.2. Define code style settings provider - +## 16.2. Define Code Style Settings Provider +The code style settings provider gives the IntelliJ Platform a standard way to instantiate `CustomCodeStyleSettings` for the Simple Language. +Define a code style settings provider for Simple Language by subclassing [`CodeStyleSettingsProvider`](upsource:///platform/lang-api/src/com/intellij/psi/codeStyle/CodeStyleSettingsProvider.java). ```java -{% include /code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleCodeStyleSettingsProvider.java %} +{% include /code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleCodeStyleSettingsProvider.java %} ``` -### 16.3. Register the code style settings provider - +## 16.3. Register the Code Style Settings Provider +The `SimpleCodeStyleSettingsProvider` implementation is registered with the IntelliJ Platform in the plugin configuration file using the `codeStyleSettingsProvider` extension point. ```xml - + + + ``` -### 16.4. Define language code style settings provider - +## 16.4. Define the Language Code Style Settings Provider +Define a code style settings provider for Simple Language by subclassing [`LanguageCodeStyleSettingsProvider`](upsource:///platform/lang-api/src/com/intellij/psi/codeStyle/LanguageCodeStyleSettingsProvider.java), which provides common code style settings for a specific language. ```java -{% include /code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleLanguageCodeStyleSettingsProvider.java %} +{% include /code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleLanguageCodeStyleSettingsProvider.java %} ``` -### 16.5. Register the language code style settings provider - +## 16.5. Register the Language Code Style Settings Provider +The `SimpleLanguageCodeStyleSettingsProvider` implementation is registered with the IntelliJ Platform in the plugin configuration file using the `langCodeStyleSettingsProvider` extension point. ```xml - + + + ``` -### 16.6. Run the project +## 16.6. Run the project +In the IDE Development Instance, open the Simple Language code formatting page: **Preferences/Settings \| Editor \| Code Style \| Simple**. ![Code Style Settings](img/code_style_settings.png) diff --git a/tutorials/custom_language_support/commenter.md b/tutorials/custom_language_support/commenter.md index 2843488d9..b1d9ceecb 100644 --- a/tutorials/custom_language_support/commenter.md +++ b/tutorials/custom_language_support/commenter.md @@ -2,20 +2,32 @@ title: 17. Commenter --- -A commenter allows user to comment the code at the cursor or selected code automatically via corresponding actions. +A commenter enables the user to comment-out a line of code at the cursor or selected code automatically. +The [`Commenter`](upsource:///platform/core-api/src/com/intellij/lang/Commenter.java) defines support for "Comment with Line Comment" and "Comment with Block Comment" actions. -### 17.1. Define a commenter +* bullet list +{:toc} +## 17.1. Define a Commenter +The Simple Language commenter subclasses `Commenter`. +This commenter defines the line comment prefix as "#". ```java -{% include /code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleCommenter.java %} +{% include /code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleCommenter.java %} ``` -### 17.2. Register the commenter - +## 17.2. Register the Commenter +The `SimpleCommenter` implementation is registered with the IntelliJ Platform in the plugin configuration file using the `lang.commenter` extension point. ```xml - + + + ``` -### 17.3. Run the project +## 17.3. Run the Project +Open the example Simple Language [properties file ](/tutorials/custom_language_support/lexer_and_parser_definition.md#47-run-the-project) in the IDE Development Instance. +Place the cursor at the `website` line. +Select **Code \| Comment with Line Comment**. +The line is converted to a comment. +Select **Code \| Comment with Line Comment** again, and the comment is converted back to active code. -![Commenter](img/commenter.png) +![Commenter](img/commenter.png){:width="800px"} diff --git a/tutorials/custom_language_support/completion_contributor.md b/tutorials/custom_language_support/completion_contributor.md index 952fd1552..46b58cd4a 100644 --- a/tutorials/custom_language_support/completion_contributor.md +++ b/tutorials/custom_language_support/completion_contributor.md @@ -2,23 +2,32 @@ title: 9. Completion Contributor --- +Custom languages provide code completion using one of [two approaches](/reference_guide/custom_language_support/code_completion.md). +The Simple Language plugin implements the less complex of the two methods, reference completion. -The easiest way to provide completion is to use a completion contributor. - -### 9.1. Define a completion contributor - -Let's provide custom completion for values in property files. +* bullet list +{:toc} +## 9.1. Define a Completion Contributor +For this tutorial, the `simple_language_plugin` provides custom completion for values in Simple Language property files. +Create a completion contributor by subclassing [`CompletionContributor`](upsource:///platform/analysis-api/src/com/intellij/codeInsight/completion/CompletionContributor.java). +This rudimentary completion contributor always adds "Hello" to the results set, regardless of context: ```java -{% include /code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleCompletionContributor.java %} +{% include /code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleCompletionContributor.java %} ``` -### 9.2. Register the completion contributor - +## 9.2. Register the Completion Contributor +The `SimpleCompletionContributor` implementation is registered in the plugin configuration file with the IntelliJ Platform using the `completion.contributor` extension point. ```xml - + + + ``` -### 9.3. Run the project +## 9.3. Run the Project +Run the `simple_language_plugin` in a Development Instance and open the [`test.simple`](/tutorials/custom_language_support/lexer_and_parser_definition.md#run-the-project) file. +Erase the property "English" and invoke [Basic Code Completion](https://www.jetbrains.com/help/idea/auto-completing-code.html#invoke-basic-completion). +The choice "Hello" is shown: -![Completion](img/completion.png) +![Completion](img/completion.png){:width="800px"} diff --git a/tutorials/custom_language_support/find_usages_provider.md b/tutorials/custom_language_support/find_usages_provider.md index 1aa002898..b0a1e60e3 100644 --- a/tutorials/custom_language_support/find_usages_provider.md +++ b/tutorials/custom_language_support/find_usages_provider.md @@ -2,23 +2,31 @@ title: 11. Find Usages Provider --- -A find usage provider uses a word scanner to build an index of words present in every file. -A scanner breaks the text into words, defines the context for each word and passes it to the find usage provider. +A [find usage provider](/reference_guide/custom_language_support/find_usages.md) uses a word scanner to build an index of words in every file. +A scanner breaks the text into words and defines the context for each word. -### 11.1. Define a find usages provider +* bullet list +{:toc} +## 11.1. Define a Find Usages Provider +The `SimpleFindUsagesProvider` implements [`FindUsagesProvider`](upsource:///platform/indexing-api/src/com/intellij/lang/findUsages/FindUsagesProvider.java). +Using the [`DefaultWordsScanner`](upsource:///platform/indexing-api/src/com/intellij/lang/cacheBuilder/DefaultWordsScanner.java) ensures the scanner implementation is thread-safe. +See the comments in `FindUsagesProvider` for more information. ```java -{% include /code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleFindUsagesProvider.java %} +{% include /code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleFindUsagesProvider.java %} ``` -### 11.2. Register the find usages provider - +## 11.2. Register the Find Usages Provider +The `SimpleFindUsagesProvider` implementation is registered with the IntelliJ Platform in the plugin configuration file using the `lang.findUsagesProvider` extension point. ```xml - + + + ``` -### 11.3. Run the project +## 11.3. Run the Project +Rebuild the project, and run `simple_language_plugin` in a Development Instance. +The IDE now supports [Find Usages](https://www.jetbrains.com/help/idea/find-highlight-usages.html) for any property with a reference: -Now we can call *Find Usages* for any property with a reference. - -![Find Usages](img/find_usages.png) +![Find Usages](img/find_usages.png){:width="800px"} diff --git a/tutorials/custom_language_support/folding_builder.md b/tutorials/custom_language_support/folding_builder.md index 4f41047f9..fef294441 100644 --- a/tutorials/custom_language_support/folding_builder.md +++ b/tutorials/custom_language_support/folding_builder.md @@ -2,24 +2,44 @@ title: 12. Folding Builder --- -A folding builder helps you to fold the code regions and replace it with specific text. +A folding builder identifies the folding regions in the code. +In this step of the tutorial, the folding builder is used to identify folding regions and replace the regions with specific text. +Rather than the usual practice of using a folding builder to collapse a class, method, or comments to fewer lines, the folding builder replaces Simple Language keys with their corresponding values. -### 12.1. Define a folding builder +* bullet list +{:toc} -Let's replace usages of properties with its values by default. +## 12.1. Define a Folding Builder +The `SimpleFoldingBuilder` replaces usages of properties with their values by default. +Start by subclassing [`FoldingBuilderEx`](upsource:///community/platform/core-api/src/com/intellij/lang/folding/FoldingBuilderEx.java) + +Note that `SimpleFoldingBuilder` also implements [`DumbAware`](upsource:///platform/core-api/src/com/intellij/openapi/project/DumbAware.java), which means the class is allowed to run in dumb mode, when indices are in background update. + +> **NOTE** A folding builder must implement [`DumbAware`](upsource:///platform/core-api/src/com/intellij/openapi/project/DumbAware.java) to function in this tutorial and pass tests. + +The `buildFoldRegions()` method searches down a PSI tree from `root` to find all literal expressions containing the [simple prefix](/tutorials/custom_language_support/annotator.md#define-an-annotator) `simple:`. +The remainder of such a string is expected to contain a Simple Language key, and so the text range is stored as a [`FoldingDescriptor`](upsource:///platform/core-api/src/com/intellij/lang/folding/FoldingDescriptor.java). + +The `getPlaceholderText()` method retrieves the Simple Language value corresponding to the key associated with the (ASTNode) provided. +The IntelliJ Platform uses the value to substitute for the key when the code gets folded. ```java -{% include /code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleFoldingBuilder.java %} +{% include /code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleFoldingBuilder.java %} ``` -### 12.2. Register the folding builder - +## 12.2. Register the Folding Builder +The `SimpleFoldingBuilder` implementation is registered with the IntelliJ Platform in the plugin configuration file using the `lang.foldingBuilder` extension point. ```xml - + + + ``` -### 12.3. Run the project +## 12.3. Run the Project +Rebuild the project, and run `simple_language_plugin` in a Development Instance. +Now when a Java file is opened in the Editor, it shows the property's value instead of the key. +This is because `SimpleFoldingBuilder.isCollapsedByDefault()` always returns `true`. +Try using **Code \| Folding \| Expand All** to show the key rather than the value. -Now when we open a Java file, it shows the property's value instead of the key. - -![Folding](img/folding.png) +![Folding](img/folding.png){:width="800px"} diff --git a/tutorials/custom_language_support/formatter.md b/tutorials/custom_language_support/formatter.md index 53b5cff81..8d40f3576 100644 --- a/tutorials/custom_language_support/formatter.md +++ b/tutorials/custom_language_support/formatter.md @@ -2,33 +2,41 @@ title: 15. Formatter --- -*A formatter allows to reformat the code automatically based on code style settings.* +The IntelliJ Platform includes a powerful framework for implementing formatting for custom languages. +A [formatter](/reference_guide/custom_language_support/code_formatting.md) enables reformatting code automatically based on code style settings. +The formatter controls spaces, indents, wrap, and alignment. -### 15.1. Define a block - -The formatter uses the blocks to receive formatting rules for each PSI element. -Our goal is to cover each PSI element with such block. Since each block builds own children blocks we can generate extra blocks or skip any PSI elements. +* bullet list +{:toc} +## 15.1. Define a Block +The formatting model represents the formatting structure of a file as a tree of [`Block`](upsource:///platform/lang-api/src/com/intellij/formatting/Block.java) objects, with associated indent, wrap, alignment and spacing settings. +The goal is to cover each PSI element with such a block. +Since each block builds its children's blocks, it can generate extra blocks or skip any PSI elements. +Define `SimpleBlock` based on [`AbstractBlock`](upsource:///platform/lang-impl/src/com/intellij/psi/formatter/common/AbstractBlock.java) ```java -{% include /code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleBlock.java %} +{% include /code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleBlock.java %} ``` -### 15.2. Define a formatting model builder - -Let's define a formatter which removes extra spaces except the single ones around the property separator. - +## 15.2. Define a Formatting Model Builder +Define a formatter that removes extra spaces except for the single spaces around the property separator. +For example, reformat "foo =     bar" to `foo = bar`. +Create `SimpleFormattingModelBuilder` by subclassing [`FormattingModelBuilder`](upsource:///platform/lang-api/src/com/intellij/formatting/FormattingModelBuilder.java). ```java -{% include /code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleFormattingModelBuilder.java %} +{% include /code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleFormattingModelBuilder.java %} ``` -### 15.3. Register the formatter - +## 15.3. Register the Formatter +The `SimpleFormattingModelBuilder` implementation is registered with the IntelliJ Platform in the plugin configuration file using the `lang.formatter` extension point. ```xml - + + + ``` -### 15.4. Run the project +## 15.4. Run the Project +Add some extra spaces around the `=` separator between `language` and `English`. +Reformat the code by selecting **Code \| Show Reformat File Dialog** and choose **Run**. -Now add some extra spaces and reformat the code via **Code \| Reformat Code**. - -![Formatter](img/formatter.png) +![Formatter](img/formatter.png){:width="800px"} diff --git a/tutorials/custom_language_support/go_to_symbol_contributor.md b/tutorials/custom_language_support/go_to_symbol_contributor.md index 291d66ee1..c343f11aa 100644 --- a/tutorials/custom_language_support/go_to_symbol_contributor.md +++ b/tutorials/custom_language_support/go_to_symbol_contributor.md @@ -2,14 +2,15 @@ title: 13. Go To Symbol Contributor --- -*A go to symbol contributor helps user to navigate to any PSI element by its name.* +A _Go to Symbol Contributor_ helps the user to navigate to any PSI element by its name. -### 13.1. Define helper method for generated PSI elements - -To specify how a PSI element looks like in the *Go To Symbol* popup window, *Structure* tool window or another components, it should implement *getPresentation* method. - -This means we need to define this method in our utility *com.simpleplugin.psi.impl.SimplePsiImplUtil* and regenerate the parser and PSI classes. +* bullet list +{:toc} +## 13.1. Define a Helper Method for Generated PSI Elements +To specify how a PSI element looks like in the **Go To Symbol** popup window, **Structure** tool window, or other components, it should implement `getPresentation()`. +This method gets defined in the utility class `SimplePsiImplUtil`, and the parser and PSI classes must be regenerated. +Add the following method to `SimplePsiImplUtil`: ```java public static ItemPresentation getPresentation(final SimpleProperty element) { return new ItemPresentation() { @@ -34,29 +35,35 @@ public static ItemPresentation getPresentation(final SimpleProperty element) { } ``` -### 13.2. Update grammar and regenerate the parser - +## 13.2. Update Grammar and Regenerate the Parser +Now add the `SimplePsiImplUtil.getPresentation()` to the `property` methods definition in the `Simple.bnf` grammar file by replacing the `property` definition with the lines below. +Don't forget to regenerate the parser after updating the file! +Right-click on the `Simple.bnf` file and select **Generate Parser Code**. ```java -property ::= (KEY? SEPARATOR VALUE?) | KEY {mixin="com.simpleplugin.psi.impl.SimpleNamedElementImpl" - implements="com.simpleplugin.psi.SimpleNamedElement" methods=[getKey getValue getName setName getNameIdentifier getPresentation]} +property ::= (KEY? SEPARATOR VALUE?) | KEY { + mixin="org.intellij.sdk.language.psi.impl.SimpleNamedElementImpl" + implements="org.intellij.sdk.language.psi.SimpleNamedElement" + methods=[getKey getValue getName setName getNameIdentifier getPresentation] +} ``` -Regenerate the parser by right clicking on the `Simple.bnf` file and selecting _Generate Parser Code_. - -### 13.3. Define a go to symbol contributor - +## 13.3. Define a Go to Symbol Contributor +To enable the `simple_language_plugin` to contribute items to **Navigate \| Class..., File..., Symbol...** lists, subclass [`ChooseByNameContributor`](upsource:///platform/lang-api/src/com/intellij/navigation/ChooseByNameContributor.java) to create `SimpleChooseByNameContributor`: ```java -{% include /code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleChooseByNameContributor.java %} +{% include /code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleChooseByNameContributor.java %} ``` -### 13.4. Register the go to symbol contributor - +## 13.4. Register the Go To Symbol Contributor +The `SimpleChooseByNameContributor` implementation is registered with the IntelliJ Platform in the plugin configuration file using the `gotoSymbolContributor` extension point. ```xml - + + + ``` -### 13.5. Run the project +## 13.5. Run the Project +Rebuild the project, and run `simple_language_plugin` in a Development Instance. +The IDE now supports navigating to a property definition by name pattern via **Navigate \| Symbol** action. -Now we can navigate to a property definition by name pattern via **Navigate \| Symbol** action. - -![Go To Symbol](img/go_to_symbol.png) +![Go To Symbol](img/go_to_symbol.png){:width="800px"} diff --git a/tutorials/custom_language_support/grammar_and_parser.md b/tutorials/custom_language_support/grammar_and_parser.md index d2b1022ff..ece28ca35 100644 --- a/tutorials/custom_language_support/grammar_and_parser.md +++ b/tutorials/custom_language_support/grammar_and_parser.md @@ -2,40 +2,42 @@ title: 3. Grammar and Parser --- -### 3.1. Define a token type - -Create a file in the `com.simpleplugin.psi` package. +In order for the IntelliJ Platform to parse a Simple Language file, [tokens and elements](/reference_guide/custom_language_support/implementing_parser_and_psi.md) must be defined based on [`IElementType`](upsource:///platform/core-api/src/com/intellij/psi/tree/IElementType.java). +The Simple Language grammar must also be defined to generate a parser. + +* bullet item +{:toc} +## 3.1. Define a Token Type +Create `SimpleTokenType` in the `org.intellij.sdk.language.psi` package (see the `simple_language_plugin` code sample) by subclassing `IElementType`. ```java -{% include /code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/psi/SimpleTokenType.java %} +{% include /code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/psi/SimpleTokenType.java %} ``` -### 3.2. Define an element type - -Create a file in the `com.simpleplugin.psi` package. - +## 3.2. Define an Element Type +Create the `SimpleElementType` in the `org.intellij.sdk.language.psi` package by subclassing `IElementType`. ```java -{% include /code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/psi/SimpleElementType.java %} +{% include /code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/psi/SimpleElementType.java %} ``` -### 3.3. Define grammar - -Define a grammar for the properties language with */com/simpleplugin/Simple.bnf* file. - +## 3.3. Define the Grammar +Define a grammar for the Simple Language in the `com/intellij/sdk/language/Simple.bnf` file. ```java { - parserClass="com.simpleplugin.parser.SimpleParser" + parserClass="org.intellij.sdk.language.parser.SimpleParser" extends="com.intellij.extapi.psi.ASTWrapperPsiElement" psiClassPrefix="Simple" psiImplClassSuffix="Impl" - psiPackage="com.simpleplugin.psi" - psiImplPackage="com.simpleplugin.psi.impl" + psiPackage="org.intellij.sdk.language.psi" + psiImplPackage="org.intellij.sdk.language.psi.impl" - elementTypeHolderClass="com.simpleplugin.psi.SimpleTypes" - elementTypeClass="com.simpleplugin.psi.SimpleElementType" - tokenTypeClass="com.simpleplugin.psi.SimpleTokenType" + elementTypeHolderClass="org.intellij.sdk.language.psi.SimpleTypes" + elementTypeClass="org.intellij.sdk.language.psi.SimpleElementType" + tokenTypeClass="org.intellij.sdk.language.psi.SimpleTokenType" + + psiImplUtilClass="org.intellij.sdk.language.psi.impl.SimplePsiImplUtil" } simpleFile ::= item_* @@ -45,18 +47,17 @@ private item_ ::= (property|COMMENT|CRLF) property ::= (KEY? SEPARATOR VALUE?) | KEY ``` -As you see a properties file can contain properties, comments and line breaks. +As shown, a properties file can contain properties, comments, and line breaks. -The grammar defines how flexible the support for a language can be. -We specified that a property may have or may not have key and value. -This lets the IDE still recognise incorrectly defined properties and provide corresponding code analysis and quick-fixes. +The grammar defines the flexibility of the support for a language. +The above grammar specifies that a property may have or may not have key and value. +This flexibility allows the IntelliJ Platform to recognize incorrectly defined properties and provide corresponding code analysis and quick-fixes. -Note that the `SimpleTypes` class in the `elementTypeHolderClass` field above specifies the name of a class that gets generated from the grammar, it doesn't exist at this point. +Note that the `SimpleTypes` class in the `elementTypeHolderClass` field above specifies the name of a class that gets generated from the grammar; it doesn't exist at this point. -### 3.4. Generate a parser +## 3.4. Generate a Parser +Now that the grammar is defined generate a parser with PSI classes via **Generate Parser Code** from the context menu on the *Simple.bnf* file. +This step generates a parser and PSI elements in the `/src/main/gen` folder of the project. +Mark this folder as *Generated Sources Root* and make sure everything compiles without errors. -Now when the grammar is defined we can generate a parser with PSI classes via *Generate Parser Code* from the context menu on *Simple.bnf* file. -This will generate a parser and PSI elements in *gen* folder. -Mark this folder as *Generated Sources Root* and make sure everything is compiled without errors. - -![Parser](img/generated_parser.png) +![Parser](img/generated_parser.png){:width="800px"} diff --git a/tutorials/custom_language_support/img/annotator.png b/tutorials/custom_language_support/img/annotator.png index 4bc3e0719..ba5cd8a3d 100644 Binary files a/tutorials/custom_language_support/img/annotator.png and b/tutorials/custom_language_support/img/annotator.png differ diff --git a/tutorials/custom_language_support/img/code_style_settings.png b/tutorials/custom_language_support/img/code_style_settings.png index 26ba38e85..9b8114f90 100644 Binary files a/tutorials/custom_language_support/img/code_style_settings.png and b/tutorials/custom_language_support/img/code_style_settings.png differ diff --git a/tutorials/custom_language_support/img/color_settings_page.png b/tutorials/custom_language_support/img/color_settings_page.png index 836b0a6cf..63418c177 100644 Binary files a/tutorials/custom_language_support/img/color_settings_page.png and b/tutorials/custom_language_support/img/color_settings_page.png differ diff --git a/tutorials/custom_language_support/img/commenter.png b/tutorials/custom_language_support/img/commenter.png index 895c51905..f52aca973 100644 Binary files a/tutorials/custom_language_support/img/commenter.png and b/tutorials/custom_language_support/img/commenter.png differ diff --git a/tutorials/custom_language_support/img/completion.png b/tutorials/custom_language_support/img/completion.png index 0d9d9689e..8bbea4af8 100644 Binary files a/tutorials/custom_language_support/img/completion.png and b/tutorials/custom_language_support/img/completion.png differ diff --git a/tutorials/custom_language_support/img/file_type_factory.png b/tutorials/custom_language_support/img/file_type_factory.png index 755e40580..359748c69 100644 Binary files a/tutorials/custom_language_support/img/file_type_factory.png and b/tutorials/custom_language_support/img/file_type_factory.png differ diff --git a/tutorials/custom_language_support/img/find_usages.png b/tutorials/custom_language_support/img/find_usages.png index 0c2155872..17e98392a 100644 Binary files a/tutorials/custom_language_support/img/find_usages.png and b/tutorials/custom_language_support/img/find_usages.png differ diff --git a/tutorials/custom_language_support/img/folding.png b/tutorials/custom_language_support/img/folding.png index 332d56f6e..e220774b6 100644 Binary files a/tutorials/custom_language_support/img/folding.png and b/tutorials/custom_language_support/img/folding.png differ diff --git a/tutorials/custom_language_support/img/formatter.png b/tutorials/custom_language_support/img/formatter.png index 2b3e5bc85..30d566f76 100644 Binary files a/tutorials/custom_language_support/img/formatter.png and b/tutorials/custom_language_support/img/formatter.png differ diff --git a/tutorials/custom_language_support/img/generated_parser.png b/tutorials/custom_language_support/img/generated_parser.png index 3def5db2d..56229801c 100644 Binary files a/tutorials/custom_language_support/img/generated_parser.png and b/tutorials/custom_language_support/img/generated_parser.png differ diff --git a/tutorials/custom_language_support/img/go_to_symbol.png b/tutorials/custom_language_support/img/go_to_symbol.png index d46f69ad7..f6eeae69c 100644 Binary files a/tutorials/custom_language_support/img/go_to_symbol.png and b/tutorials/custom_language_support/img/go_to_symbol.png differ diff --git a/tutorials/custom_language_support/img/in_place_rename.png b/tutorials/custom_language_support/img/in_place_rename.png index 795968e62..d3179f05e 100644 Binary files a/tutorials/custom_language_support/img/in_place_rename.png and b/tutorials/custom_language_support/img/in_place_rename.png differ diff --git a/tutorials/custom_language_support/img/line_marker.png b/tutorials/custom_language_support/img/line_marker.png index 3bb3cb544..a96003e34 100644 Binary files a/tutorials/custom_language_support/img/line_marker.png and b/tutorials/custom_language_support/img/line_marker.png differ diff --git a/tutorials/custom_language_support/img/line_marker_location.png b/tutorials/custom_language_support/img/line_marker_location.png new file mode 100644 index 000000000..ba29bacee Binary files /dev/null and b/tutorials/custom_language_support/img/line_marker_location.png differ diff --git a/tutorials/custom_language_support/img/new_property.png b/tutorials/custom_language_support/img/new_property.png new file mode 100644 index 000000000..0cd68df96 Binary files /dev/null and b/tutorials/custom_language_support/img/new_property.png differ diff --git a/tutorials/custom_language_support/img/psi_elements.png b/tutorials/custom_language_support/img/psi_elements.png index 475162c54..588cbf34a 100644 Binary files a/tutorials/custom_language_support/img/psi_elements.png and b/tutorials/custom_language_support/img/psi_elements.png differ diff --git a/tutorials/custom_language_support/img/quick_fix.png b/tutorials/custom_language_support/img/quick_fix.png index a305d05c4..2637f1eed 100644 Binary files a/tutorials/custom_language_support/img/quick_fix.png and b/tutorials/custom_language_support/img/quick_fix.png differ diff --git a/tutorials/custom_language_support/img/reference_contributor.png b/tutorials/custom_language_support/img/reference_contributor.png index 05c9850bc..87d368920 100644 Binary files a/tutorials/custom_language_support/img/reference_contributor.png and b/tutorials/custom_language_support/img/reference_contributor.png differ diff --git a/tutorials/custom_language_support/img/rename.png b/tutorials/custom_language_support/img/rename.png index 5f0f41230..3904141eb 100644 Binary files a/tutorials/custom_language_support/img/rename.png and b/tutorials/custom_language_support/img/rename.png differ diff --git a/tutorials/custom_language_support/img/simple_named_element.png b/tutorials/custom_language_support/img/simple_named_element.png new file mode 100644 index 000000000..b0c683360 Binary files /dev/null and b/tutorials/custom_language_support/img/simple_named_element.png differ diff --git a/tutorials/custom_language_support/img/structure_view.png b/tutorials/custom_language_support/img/structure_view.png index d9328a82f..783d7cec8 100644 Binary files a/tutorials/custom_language_support/img/structure_view.png and b/tutorials/custom_language_support/img/structure_view.png differ diff --git a/tutorials/custom_language_support/img/syntax_highlighter.png b/tutorials/custom_language_support/img/syntax_highlighter.png index cc092efcd..15811d3a5 100644 Binary files a/tutorials/custom_language_support/img/syntax_highlighter.png and b/tutorials/custom_language_support/img/syntax_highlighter.png differ diff --git a/tutorials/custom_language_support/img/unresolved_property.png b/tutorials/custom_language_support/img/unresolved_property.png index c8d69fc8d..a40da4184 100644 Binary files a/tutorials/custom_language_support/img/unresolved_property.png and b/tutorials/custom_language_support/img/unresolved_property.png differ diff --git a/tutorials/custom_language_support/language_and_filetype.md b/tutorials/custom_language_support/language_and_filetype.md index ae77ac912..183b3f777 100644 --- a/tutorials/custom_language_support/language_and_filetype.md +++ b/tutorials/custom_language_support/language_and_filetype.md @@ -2,63 +2,66 @@ title: 2. Language and File Type --- +The IntelliJ Platform [determines file type](/reference_guide/custom_language_support/registering_file_type.md) by examining the name of a file. +Each language has [Language](upsource:///platform/core-api/src/com/intellij/lang/Language.java) and [LanguageFileType](upsource:///platform/core-api/src/com/intellij/openapi/fileTypes/LanguageFileType.java) objects defining the language. +Register the `LanguageFileType` with the IntelliJ Platform in the plugin configuration file. -### 2.1. Define a language - -Note the case of the name of the language - `Simple`. +* bullet item +{:toc} +## 2.1. Define the Language +The language implemented in this tutorial is named "Simple" - note the case of the name. +The `SimpleLanguage` class is defined in the `org.intellij.sdk.language` package of the `simple_language_plugin` code sample: ```java -{% include /code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleLanguage.java %} +{% include /code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleLanguage.java %} ``` -### 2.2. Define an icon - -Copy the -[icon](https://raw.githubusercontent.com/JetBrains/intellij-sdk-docs/master/code_samples/simple_language_plugin/src/main/resources/icons/jar-gray.png) -to **com.simpleplugin.icons** package. - +## 2.2. Define an Icon +The [icon](https://raw.githubusercontent.com/JetBrains/intellij-sdk-docs/master/code_samples/simple_language_plugin/src/com/simpleplugin/icons/jar-gray.png) for the Simple Language is defined by the `SimpleIcons` class. +There is nothing uniquely Simple Language-specific about [defining the icon](/reference_guide/work_with_icons_and_images.md) itself. +The definition follows a pattern similar to defining, e.g., `SdkIcons`. ```java -{% include /code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleIcons.java %} +{% include /code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleIcons.java %} ``` -### 2.3. Define a file type - +## 2.3. Define a FileType +The Simple Language file type is defined by subclassing [`LanguageFileType`](upsource:///platform/core-api/src/com/intellij/openapi/fileTypes/LanguageFileType.java): ```java -{% include /code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleFileType.java %} +{% include /code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleFileType.java %} ``` -### 2.4. Define a file type factory - -> **NOTE** When targeting 2019.2 or later only, please see [2.5.B](#b-register-file-type-20192-or-later) - -```java -{% include /code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleFileTypeFactory.java %} -``` - -### 2.5. Register the file type factory - -In plugin.xml add: - +## 2.4. Register the FileType Directly +Direct registration is necessary when targeting version 2019.2 (and later) of the IntelliJ Platform. +No `FileTypeFactory` is required. +Instead, the file type is registered of file type is done via the `com.intellij.fileType` extension point in `plugin.xml`: ```xml - - - + + + ``` -### 2.5.B. Register file type (2019.2 or later) +Skip to [section 2.6](#run-the-project). -When matching via file extension, pattern or exact file name, registration of file type should be done via `com.intellij.fileType` extension point instead of implementing dedicated `FileTypeFactory`. +## 2.5. Register the FileType Using a Factory +This pattern is necessary when targeting versions of the IntelliJ Platform prior to 2019.2 +### 2.5.1 Define a FileType Factory +First, define `SimpleFileTypeFactory` as a subclass of [`FileTypeFactory`](upsource:///platform/platform-api/src/com/intellij/openapi/fileTypes/FileTypeFactory.java). +```java +{% include /code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleFileTypeFactory.java %} +``` + +### 2.5.2 Register the FileType Factory +The `SimpleFileTypeFactory` is registered with the IntelliJ Platform using the `com.intellij.openapi.fileTypes.FileTypeFactory` extension point in `plugin.xml`. ```xml - - - + + + ``` -### 2.6. Run the project +## 2.6. Run the Project +Create an empty file with the extension `\*.simple`, and IntelliJ IDEA automatically associates it with our language. +Note the appearance of the Simple Language file icon next to the `test.simple` file in the **Project Tool Window**, and the editor tab for the file. -Create a file with extension *.simple* -and IntelliJ IDEA will automatically associate it with our language. - -![File Type Factory](img/file_type_factory.png) +![File Type Factory](img/file_type_factory.png){:width="800px"} diff --git a/tutorials/custom_language_support/lexer_and_parser_definition.md b/tutorials/custom_language_support/lexer_and_parser_definition.md index 292e2b21a..36b187418 100644 --- a/tutorials/custom_language_support/lexer_and_parser_definition.md +++ b/tutorials/custom_language_support/lexer_and_parser_definition.md @@ -2,57 +2,62 @@ title: 4. Lexer and Parser Definition --- -The lexer defines how the contents of a file is broken into tokens. +The lexical analyzer defines how the [contents of a file are broken into tokens](/reference_guide/custom_language_support/implementing_lexer.md), which is the basis for supporting custom language features. The easiest way to create a lexer is to use [JFlex](https://jflex.de/) -### 4.1. Define a lexer - -Define */com/simpleplugin/Simple.flex* file with rules for our lexer. +* bullet item +{:toc} +## 4.1. Define a Lexer +Define a `Simple.flex` file with rules for the Simple Language lexer, as demonstrated in `org.intellij.sdk.language.Simple.flex`. ```java -{% include /code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/Simple.flex %} +{% include /code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/Simple.flex %} ``` -### 4.2. Generate a lexer class +## 4.2. Generate a Lexer Class +Now generate a lexer class via **JFlex Generator** from the context menu on `Simple.flex` file. -Now we can generate a lexer class via *JFlex Generator* from the context menu on `Simple.flex` file. -The Grammar-Kit plugin uses JFlex lexer generation. -If you run it for the first time, it offers you to choose a folder to download the JFlex library and skeleton to. -Choose the project root directory. +The Grammar-Kit plugin uses the JFlex lexer generation. +When running for the first time, JFlex prompts for a destination folder to download the JFlex library and skeleton. +Choose the project root directory, for example `code_samples/simple_language_plugin`. -After that, the IDE generates the lexer: *com.simpleplugin.SimpleLexer*. +After that, the IDE generates the lexer under the `gen` directory, for example in `simple_language_plugin/src/main/gen/org/intellij/sdk/language/SimpleLexer`. -### 4.3. Define an adapter +See [Implementing Lexer](/reference_guide/custom_language_support/implementing_lexer.md) for more information about using _JFlex_ with the IntelliJ Platform. +## 4.3. Define a Lexer Adapter +The JFlex lexer needs to be adapted to the IntelliJ Platform Lexer API. +This is done by subclassing [`FlexAdapter`](upsource:///platform/core-api/src/com/intellij/lexer/FlexAdapter.java). ```java -{% include /code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleLexerAdapter.java %} +{% include /code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleLexerAdapter.java %} ``` -### 4.4. Define a root file - -Create the class in the `com.simpleplugin.psi` namespace. - +## 4.4. Define a Root File +The `SimpleFile` implementation is the top-level node of the [tree of `PsiElements`](/reference_guide/custom_language_support/implementing_parser_and_psi.md) for a Simple Language file. ```java -{% include /code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/psi/SimpleFile.java %} +{% include /code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/psi/SimpleFile.java %} ``` -### 4.5. Define a parser definition - +## 4.5. Define a Parser +The Simple Language parser is defined by subclassing [`ParserDefinition`](upsource:///platform/core-api/src/com/intellij/lang/ParserDefinition.java). ```java -{% include /code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleParserDefinition.java %} +{% include /code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleParserDefinition.java %} ``` -### 4.6. Register the parser definition - +## 4.6. Register the Parser Definition +Registering the parser definition in the `plugin.xml` file makes it available to the IntelliJ Platform. +Use the `lang.parserDefinition` extension point for registration. +For example, see `simple_language_plugin/src/main/resources/META-INF/plugin.xml`. ```xml - + + + ``` -### 4.7. Run the project - -Create a properties file with the following content: - -``` +## 4.7. Run the Project +With the `simple_language_plugin` loaded in a Development Instance, create a `test.simple` properties file with the following content: +```text # You are reading the ".properties" entry. ! The exclamation mark can also mark text as comments. website = http://en.wikipedia.org/ @@ -69,4 +74,4 @@ tab : \u0009 Now open the *PsiViewer* tool window and check how the lexer breaks the content of the file into tokens, and the parser parsed the tokens into PSI elements. -![PSI Elements](img/psi_elements.png) +![PSI Elements](img/psi_elements.png){:width="900px"} diff --git a/tutorials/custom_language_support/line_marker_provider.md b/tutorials/custom_language_support/line_marker_provider.md index 170e18bc0..6ba2a28c1 100644 --- a/tutorials/custom_language_support/line_marker_provider.md +++ b/tutorials/custom_language_support/line_marker_provider.md @@ -2,31 +2,37 @@ title: 8. Line Marker Provider --- -Line markers help to annotate any code with icons on the gutter. -These icons may provide navigation to related code. +Line markers help annotate code with icons on the gutter. +These markers can provide navigation targets to related code. -### 8.1. Define a line marker provider +* bullet list +{:toc} -Let's annotate usages of our properties within Java code and provide navigation to the definition of these properties. +## 8.1. Define a Line Marker Provider +A line marker provider annotates usages of Simple Language properties within Java code and provides navigation to the definition of these properties. +The visual marker is a Simple Language icon in the gutter of the Editor window. +The Simple Language marker provider subclasses [`RelatedItemLineMarkerProvider`](upsource:///platform/lang-api/src/com/intellij/codeInsight/daemon/RelatedItemLineMarkerProvider.java). +For this example, override the `collectNavigationMarkers()` method to collect usage of a Simple Language [key and separators](/tutorials/custom_language_support/language_and_filetype.md#define-the-language): ```java -{% include /code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleLineMarkerProvider.java %} +{% include /code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleLineMarkerProvider.java %} ``` -## More technical details for implementers - -* Please return line marker info for exact element you were asked for. - For example, do not return class marker info if `getLineMarkerInfo()` was called for a method. - -* Please return relevant line marker info for as small element as possible. - For example, do not return method marker for [`PsiMethod`](upsource:///java/java-psi-api/src/com/intellij/psi/PsiMethod.java). Instead, return it for the [`PsiIdentifier`](upsource:///java/java-psi-api/src/com/intellij/psi/PsiIdentifier.java) which is a name of this method. - -### Even more technical details: - -What happens when `LineMarkerProvider` returns something for too big PsiElement? +## 8.2. Best Practices for Implementing Line Marker Providers +This section addresses important details about implementing a marker provider. +The `collectNavigationMarkers()` method should: +* Only return line marker information consistent with the element passed into the method. + For example, do not return a _class_ marker if `getLineMarkerInfo()` was called with an element that corresponds to a _method_. +* Return line marker information for the appropriate element at the correct scope of the PSI tree. + For example, do not return method marker for [`PsiMethod`](upsource:///java/java-psi-api/src/com/intellij/psi/PsiMethod.java). + Instead, return it for the [`PsiIdentifier`](upsource:///java/java-psi-api/src/com/intellij/psi/PsiIdentifier.java) which contains the name of the method. + +![Line Marker Location](img/line_marker_location.png){:width="900px"} +What happens when a `LineMarkerProvider` returns marker information for a `PsiElement` that is a higher node in the PSI tree? +For example, if `MyWrongLineMarkerProvider()` erroneously returns a `PsiMethod` instead of a `PsiIdentifier` element: ```java -public class MyLineMarkerProvider implements LineMarkerProvider { +public class MyWrongLineMarkerProvider implements LineMarkerProvider { public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement element) { if (element instanceof PsiMethod) return new LineMarkerInfo(element, ...); return null; @@ -34,25 +40,20 @@ public class MyLineMarkerProvider implements LineMarkerProvider { } ``` -Inspection (specifically, [`LineMarkersPass`](upsource:///platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LineMarkersPass.java)) for performance reasons queries all [`LineMarkerProviders`](upsource:///platform/lang-api/src/com/intellij/codeInsight/daemon/LineMarkerProviders.java) in two passes: +The consequences of the `MyWrongLineMarkerProvider()` implementation have to do with how the IntelliJ Platform performs inspections. +For performance reasons, inspection, and specifically the [`LineMarkersPass`](upsource:///platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LineMarkersPass.java) queries all [`LineMarkerProviders`](upsource:///platform/lang-api/src/com/intellij/codeInsight/daemon/LineMarkerProviders.java) in two phases: +* The first pass is for all elements visible in the Editor window, +* The second pass is for the rest of the elements in the file. - * first pass for all elements in visible area - - * second pass for all the rest elements - -If providers return nothing for either area, its line markers are cleared. -So if e.g. a method is half-visible (its name is visible but part of its body isn't) and -some poorly written [`LineMarkerProvider`](upsource:///platform/lang-api/src/com/intellij/codeInsight/daemon/LineMarkerProvider.java) returned info for the `PsiMethod` instead of `PsiIdentifier` then: - - * the first pass removes line marker info because whole `PsiMethod` is not visible. - - * the second pass tries to add line marker info back because `LineMarkerProvider` is called for the `PsiMethod` at last. - -As a result, line marker icon would blink annoyingly. -To fix this, rewrite `LineMarkerProvider` to return info for `PsiIdentifier` instead of `PsiMethod`: +If providers return nothing for either area, the line markers get cleared. +However, if a method like `actionPerformed()` is not completely visible in the Editor window (as shown in the image above,) and `MyWrongLineMarkerProvider()` returns marker info for the `PsiMethod` instead of `PsiIdentifier`, then: +* The first pass removes line marker info because whole `PsiMethod` isn't visible. +* The second pass tries to add a line marker because `MyWrongLineMarkerProvider()` is called for the `PsiMethod`. +As a result, _the line marker icon would blink annoyingly_. +To fix this problem, rewrite `MyWrongLineMarkerProvider` to return info for `PsiIdentifier` instead of `PsiMethod` as shown below: ```java -public class MyLineMarkerProvider implements LineMarkerProvider { +public class MyCorrectLineMarkerProvider implements LineMarkerProvider { public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement element) { if (element instanceof PsiIdentifier && element.getParent() instanceof PsiMethod) return new LineMarkerInfo(element, ...); return null; @@ -60,14 +61,18 @@ public class MyLineMarkerProvider implements LineMarkerProvider { } ``` -### 8.2. Register the line marker provider - +## 8.3. Register the Line Marker Provider +The `SimpleLineMarkerProvider` implementation is registered with the IntelliJ Platform in the plugin configuration file using the `codeInsight.lineMarkerProvider` extension point. ```xml - + + + ``` -### 8.3. Run the project - -Now you see the icon on the gutter and can navigate to the property definition. +## 8.4. Run the Project +Run the `simple_language_plugin` in a Development Instance and open the [Test file](/tutorials/custom_language_support/annotator.md#run-the-project). +Now the icon appears next to line 3 on the gutter. +A user can click on the icon to navigate to the property definition. ![Line Marker](img/line_marker.png) diff --git a/tutorials/custom_language_support/prerequisites.md b/tutorials/custom_language_support/prerequisites.md index 70db94505..28065ad02 100644 --- a/tutorials/custom_language_support/prerequisites.md +++ b/tutorials/custom_language_support/prerequisites.md @@ -2,32 +2,16 @@ title: 1. Prerequisites --- - ### 1.1. Download and Install IntelliJ IDEA - -Download and install either IntelliJ IDEA Ultimate or IntelliJ IDEA Community Edition as described on the -[Creating Your First Plugin](/basics/getting_started.md) page. +Download and install either IntelliJ IDEA Ultimate or IntelliJ IDEA Community Edition as described on the [Creating Your First Plugin](/basics/getting_started.md) page. ### 1.2. Check out Community Edition Source Files - -Download the IntelliJ IDEA Community Edition source files as described in the IntelliJ IDEA Community Edition -[README](upsource:///README.md) file. +Download the IntelliJ IDEA Community Edition source files as described in the IntelliJ IDEA Community Edition [README](upsource:///README.md) file. ### 1.3. Install Required Plugins - Make sure that the bundled *Plugin DevKit* plugin is enabled. -Install and enable -[Grammar-Kit](https://plugins.jetbrains.com/plugin/6606-grammar-kit) -and -[PsiViewer](https://plugins.jetbrains.com/plugin/227-psiviewer) -plugins. +Install and enable [Grammar-Kit](https://plugins.jetbrains.com/plugin/6606-grammar-kit) and [PsiViewer](https://plugins.jetbrains.com/plugin/227-psiviewer) plugins. -### 1.4. Configure the SDK and Source Files - -Configure a common [JDK](upsource:///README.md) -and an [IntelliJ Platform SDK](/basics/getting_started/setting_up_environment.md). - -### 1.5. Create a Project - -Create an [IntelliJ Platform Plugin project](/basics/getting_started/creating_plugin_project.md). +### 1.4. Create a Project +Create an [IntelliJ Platform Plugin project](/tutorials/build_system/prerequisites.md). diff --git a/tutorials/custom_language_support/psi_helper_and_utilities.md b/tutorials/custom_language_support/psi_helper_and_utilities.md index 466ac4c1c..40ecdeb2c 100644 --- a/tutorials/custom_language_support/psi_helper_and_utilities.md +++ b/tutorials/custom_language_support/psi_helper_and_utilities.md @@ -2,24 +2,18 @@ title: 6. PSI Helpers and Utilities --- +Helper classes and utilities can be embedded in the code generated by Grammar-Kit. -### 6.1. Define helper methods for generated PSI elements - -If we want to have custom methods in PSI classes we need to define them separately and ask Grammar-Kit to embed them into generated code. - -Let's define a utility class with these helper methods. +* bullet item +{:toc} +## 6.1. Define Helper Methods for Generated PSI Elements +Custom methods in PSI classes are defined separately, and Grammar-Kit embeds them into generated code. +Define a utility class with these helper methods: ```java -package com.intellij.sdk.language.psi.impl; +package org.intellij.sdk.language.psi.impl; import com.intellij.lang.ASTNode; -import com.intellij.navigation.ItemPresentation; -import com.intellij.psi.*; -import com.simpleplugin.SimpleIcons; -import com.simpleplugin.psi.*; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; public class SimplePsiImplUtil { public static String getKey(SimpleProperty element) { @@ -31,7 +25,7 @@ public class SimplePsiImplUtil { return null; } } - + public static String getValue(SimpleProperty element) { ASTNode valueNode = element.getNode().findChildByType(SimpleTypes.VALUE); if (valueNode != null) { @@ -43,30 +37,29 @@ public class SimplePsiImplUtil { } ``` -Note that the `SimpleProperty` interface referenced in the code above is generated by the parser. Also note that the `element.getKey` method used in `getPresentableText` will not be defined - it's a method generated by the parser, which we'll fix below. +The parser generates the `SimpleProperty` interface referenced in the code above. -### 6.2. Update grammar and regenerate the parser - -Now we tell to use this utility class in the grammar file via `psiImplUtilClass` attribute. - -To tell which methods for which PSI classes must be used we specify methods for particular rule. +## 6.2. Update Grammar and Regenerate the Parser +Now the utility class is added to the grammar file via the `psiImplUtilClass` attribute. +Add methods for a particular rule to specify which one should be used for PSI classes. +Compare the last line of the grammar below to the [previous definition](/tutorials/custom_language_support/grammar_and_parser.md#33-define-the-grammar). ```java { - parserClass="com.intellij.sdk.language.parser.SimpleParser" + parserClass="org.intellij.sdk.language.parser.SimpleParser" extends="com.intellij.extapi.psi.ASTWrapperPsiElement" psiClassPrefix="Simple" psiImplClassSuffix="Impl" - psiPackage="com.intellij.sdk.language.psi" - psiImplPackage="com.intellij.sdk.language.psi.impl" + psiPackage="org.intellij.sdk.language.psi" + psiImplPackage="org.intellij.sdk.language.psi.impl" - elementTypeHolderClass="com.intellij.sdk.language.psi.SimpleTypes" - elementTypeClass="com.intellij.sdk.language.psi.SimpleElementType" - tokenTypeClass="com.intellij.sdk.language.psi.SimpleTokenType" + elementTypeHolderClass="org.intellij.sdk.language.psi.SimpleTypes" + elementTypeClass="org.intellij.sdk.language.psi.SimpleElementType" + tokenTypeClass="org.intellij.sdk.language.psi.SimpleTokenType" - psiImplUtilClass="com.intellij.sdk.language.psi.impl.SimplePsiImplUtil" + psiImplUtilClass="org.intellij.sdk.language.psi.impl.SimplePsiImplUtil" } simpleFile ::= item_* @@ -76,13 +69,12 @@ private item_ ::= (property|COMMENT|CRLF) property ::= (KEY? SEPARATOR VALUE?) | KEY {methods=[getKey getValue]} ``` -After we made our changes to the grammar we can regenerate the parser and PSI classes. - -### 6.3. Define a utility to search properties - -Now we need a utility class to search PSI elements for defined properties over the project. -We will use this utility later when implementing code assistance. +After making changes to the grammar, regenerate the parser and PSI classes. +## 6.3. Define a Utility to Search Properties +Create a utility class to search PSI elements for defined properties over the project. +This utility will be used later when implementing [code completion](https://www.jetbrains.com/help/idea/auto-completing-code.html). ```java -{% include /code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleUtil.java %} +{% include /code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleUtil.java %} ``` + diff --git a/tutorials/custom_language_support/quick_fix.md b/tutorials/custom_language_support/quick_fix.md index 306cebbe4..df01e6b69 100644 --- a/tutorials/custom_language_support/quick_fix.md +++ b/tutorials/custom_language_support/quick_fix.md @@ -2,35 +2,47 @@ title: 18. Quick Fix --- +A quick fix for a custom language supports the IntelliJ Platform-based IDE feature [Intention Actions](https://www.jetbrains.com/help/idea/intention-actions.html#apply-intention-actions). +For the Simple Language, this tutorial adds a quick fix that helps to define an unresolved property from its usage. -A quick fix allows to apply an automatic changes to the code via **Show Intention Actions** (Alt + Enter). - -Let's add a quick fix which helps to define an unresolved property from its usage. - -### 18.1. Update the element factory +* bullet list +{:toc} +## 18.1. Update the Element Factory +The `SimpleElementFactory` is updated to include two new methods to support the user choice of creating a new property for the Simple Language quick fix. +The new `createCRLF()` method supports adding a newline to the end of the [`test.simple`](/tutorials/custom_language_support/lexer_and_parser_definition.md#run-the-project) file before adding a new property. +A new overload of `createProperty()` creates a new `key`-`value` pair for Simple Language. ```java -{% include /code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/psi/SimpleElementFactory.java %} +{% include /code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/psi/SimpleElementFactory.java %} ``` -### 18.2. Define an intention action - -The quick fix will create a property in the file chosen by user, and navigate to this property after creation. - +## 18.2. Define an Intention Action +The `SimpleCreatePropertyQuickFix` creates a property in the file chosen by the user - in this case, a Java file containing a `prefix:key` - and navigate to this property after creation. +Under the hood, `SimpleCreatePropertyQuickFix` is an Intention Action. +For a more in-depth example of an Intention Action, see [`conditional_operator_intention`](https://github.com/JetBrains/intellij-sdk-docs/tree/master/code_samples/conditional_operator_intention). ```java -{% include /code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleCreatePropertyQuickFix.java %} +{% include /code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleCreatePropertyQuickFix.java %} ``` -### 18.3. Update the annotator - -Note the call to `registerFix`. - +## 18.3. Update the Annotator +When a `badProperty` annotation is created, the `badProperty.registerFix()` method is called. +This method call registers the `SimpleCreatePropertyQuickFix` as the Intention Action for the Intellij Platform to use to correct the problem. ```java -{% include /code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleAnnotator.java %} +{% include /code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleAnnotator.java %} ``` -### 18.4. Run the project +## 18.4. Run the project +Open the test [Java file](/tutorials/custom_language_support/annotator.md#run-the-project) in an IDE Development Instance running the `simple_language_plugin`. -Now let's try to use a property which is not defined yet. +To test `SimpleCreatePropertyQuickFix`, change `simple:website` to `simple:website.url`. +The key `website.url` is highlighted by `SimpleAnnotator` as an invalid key, as shown below. +Choose "Create Property". -![Quick Fix](img/quick_fix.png) +![Quick Fix](img/quick_fix.png){:width="800px"} + +The IDE opens the `test.simple` file and adds `website.url` as a new key. +Add the new value `jetbrains.com` for the new `website.url` key. + +![New Property](img/new_property.png){:width="800px"} + +Now switch back to the Java file; the new key is highlighted as valid. \ No newline at end of file diff --git a/tutorials/custom_language_support/reference_contributor.md b/tutorials/custom_language_support/reference_contributor.md index 56d3fdf20..1f6c926e1 100644 --- a/tutorials/custom_language_support/reference_contributor.md +++ b/tutorials/custom_language_support/reference_contributor.md @@ -2,25 +2,24 @@ title: 10. Reference Contributor --- - -References is one of the most important and tricky parts in the implementation of a custom language support. +The [References functionality](/reference_guide/custom_language_support/references_and_resolve.md) is one of the most important parts in the implementation of custom language support. Resolving references means the ability to go from the usage of an element to its declaration, completion, rename refactoring, find usages, etc. -**Every element which can be renamed or referenced needs to implement `com.intellij.psi.PsiNamedElement` interface.** +> **Note** Every PSI element that can be renamed or referenced needs to implement [`PsiNamedElement`](upsource:///platform/core-api/src/com/intellij/psi/PsiNamedElement.java) interface. -### 10.1. Define a base named element class +* bullet list +{:toc} -```java -{% include /code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/psi/SimpleNamedElement.java %} -``` +### 10.1. Define a Named Element Class +The simplified class diagram below shows how the Simple Language fulfills the need to implement `PsiNamedElement`. +The `SimpleNamedElement` interface is subclassed from [`PsiNameIdentifierOwner`](). +The `SimpleNamedElementImpl` class implements the `SimpleNamedElement` interface and extends [`ASTWrapperPsiElement`](upsource:///platform/core-impl/src/com/intellij/extapi/psi/ASTWrapperPsiElement.java). -```java -{% include /code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/psi/impl/SimpleNamedElementImpl.java %} -``` - -### 10.2. Define helper methods for generated PSI elements - -Since we need to implement new methods in PSI class, we should define them in the `SimplePsiImplUtil` class: +![SimpleNamedElementImpl class hierarchy](img/simple_named_element.png){:width="400px"} + +## 10.2. Define Helper Methods for Generated PSI Elements +Modify `SimplePsiImplUtil` to support new methods that get added to the PSI class for Simple Language. +Note that `SimpleElementFactory` isn't defined until the [next step](#103-define-an-element-factory), so for now it shows as an error. ```java public class SimplePsiImplUtil { @@ -55,16 +54,14 @@ public class SimplePsiImplUtil { } ``` -Note that the `SimpleElementFactory` class will show as an error. We'll create it next. - -### 10.3. Define an element factory - +## 10.3. Define an Element Factory +The `SimpleElementFactory` provides methods for creating `SimpleFile`. ```java -package com.simpleplugin.psi; +package org.intellij.sdk.language.psi; import com.intellij.openapi.project.Project; import com.intellij.psi.*; -import com.simpleplugin.SimpleFileType; +import org.intellij.sdk.language.SimpleFileType; public class SimpleElementFactory { public static SimpleProperty createProperty(Project project, String name) { @@ -75,69 +72,76 @@ public class SimpleElementFactory { public static SimpleFile createFile(Project project, String text) { String name = "dummy.simple"; return (SimpleFile) PsiFileFactory.getInstance(project). - createFileFromText(name, SimpleFileType.INSTANCE, text); + createFileFromText(name, SimpleFileType.INSTANCE, text); } } ``` -### 10.4. Update grammar and regenerate the parser - -Now we need to make corresponding changes to the grammar file and regenerate parser and PSI classes. - +## 10.4. Update Grammar and Regenerate the Parser +Now make corresponding changes to the `Simple.bnf` grammar file by replacing the `property` definition with the lines below. +Don't forget to regenerate the parser after updating the file! +Right-click on the `Simple.bnf` file and select **Generate Parser Code**. ```java -property ::= (KEY? SEPARATOR VALUE?) | KEY {mixin="com.simpleplugin.psi.impl.SimpleNamedElementImpl" - implements="com.simpleplugin.psi.SimpleNamedElement" methods=[getKey getValue getName setName getNameIdentifier]} +property ::= (KEY? SEPARATOR VALUE?) | KEY { + mixin="org.intellij.sdk.language.psi.impl.SimpleNamedElementImpl" + implements="org.intellij.sdk.language.psi.SimpleNamedElement" + methods=[getKey getValue getName setName getNameIdentifier] +} ``` -Don't forget to regenerate the parser! Right click on the `Simple.bnf` file and select _Generate Parser Code_. - -### 10.5. Define a reference - -Now we need to define a reference class to resolve a property from its usage. - +## 10.5. Define a Reference +Now define a reference class to resolve a property from its usage. +This requires extending [`PsiReferenceBase`](upsource:///platform/core-api/src/com/intellij/psi/PsiReferenceBase.java) and implementing [`PsiPolyVariantReference`](upsource:///platform/core-api/src/com/intellij/psi/PsiPolyVariantReference.java). +The latter enables the reference to resolve to more than one element or to resolve result(s) for a superset of valid resolve cases. ```java -{% include /code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleReference.java %} +{% include /code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleReference.java %} ``` -### 10.6. Define a reference contributor - -A reference contributor allows you to provide references from elements in other languages such as Java to elements in your language. -Let's contribute a reference to each usage of a property. - +## 10.6. Define a Reference Contributor +A reference contributor allows the `simple_language_plugin` to provide references to Simple Language from elements in other languages such as Java. +Create `SimpleReferenceContributor` by subclassing [`PsiReferenceContributor`](upsource:///platform/core-api/src/com/intellij/psi/PsiReferenceContributor.java). +Contribute a reference to each usage of a property: ```java -{% include /code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleReferenceContributor.java %} +{% include /code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleReferenceContributor.java %} ``` -### 10.7. Register the reference contributor - +## 10.7. Register the Reference Contributor +The `SimpleReferenceContributor` implementation is registered with the IntelliJ Platform using the `psi.referenceContributor` extension point. ```xml - + + + ``` -### 10.8. Run the project +## 10.8. Run the Project +Rebuild the project, and run `simple_language_plugin` in a Development Instance. +The IDE now resolves the property and provides [completion](https://www.jetbrains.com/help/idea/auto-completing-code.html#basic_completion) suggestions: -As you see the IDE now resolves the property and provides completion. +![Reference Contributor](img/reference_contributor.png){:width="800px"} -![Reference Contributor](img/reference_contributor.png) +The [Rename refactoring](https://www.jetbrains.com/help/idea/rename-refactorings.html#invoke-rename-refactoring) functionality is now available from definition and usages. -*Rename* refactoring available from definition and usages. - -![Rename](img/rename.png) - -### 10.9. Define a refactoring support provider - -To allow in-place refactoring we should specify it explicitly in a refactoring support provider. +![Rename](img/rename.png){:width="800px"} +## 10.9. Define a Refactoring Support Provider +Support for in-place refactoring is specified explicitly in a refactoring support provider. +Create `SimpleRefactoringSupportProvider` by subclassing [`RefactoringSupportProvider`](upsource:///platform/lang-api/src/com/intellij/lang/refactoring/RefactoringSupportProvider.java) +As long as an element is a `SimpleProperty` it is allowed to be refactored: ```java -{% include /code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleRefactoringSupportProvider.java %} +{% include /code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleRefactoringSupportProvider.java %} ``` -### 10.10. Register the refactoring support provider - +## 10.10. Register the Refactoring Support Provider +The `SimpleRefactoringSupportProvider` implementation is registered with the IntelliJ Platform in the plugin configuration file using the `lang.refactoringSupport` extension point. ```xml - + + + ``` -### 10.11. Run the project +## 10.11. Run the Project +Rebuild the project, and run `simple_language_plugin` in a Development Instance. +The IDE now supports [refactoring](https://www.jetbrains.com/help/idea/rename-refactorings.html) suggestions: -![In Place Rename](img/in_place_rename.png) +![In Place Rename](img/in_place_rename.png){:width="800px"} diff --git a/tutorials/custom_language_support/structure_view_factory.md b/tutorials/custom_language_support/structure_view_factory.md index 38788d6b4..a9af3a4ea 100644 --- a/tutorials/custom_language_support/structure_view_factory.md +++ b/tutorials/custom_language_support/structure_view_factory.md @@ -2,33 +2,47 @@ title: 14. Structure View Factory --- +The [structure view](/reference_guide/custom_language_support/structure_view.md) in the IntelliJ Platform-based IDE can be customized for a specific file type, including Simple Language. +Creating a structure view factory allows showing the structure of any file in a **Structure** tool window for easy navigation between items. -A structure view factory allows to show the structure of any file in a *Structure* tool window for easy navigation between items. - -### 14.1. Define a structure view factory +* bullet list +{:toc} +## 14.1. Define a Structure View Factory +The structure view factory implements [`PsiStructureViewFactory`](upsource:///platform/editor-ui-api/src/com/intellij/lang/PsiStructureViewFactory.java). +The `getStructureViewBuilder()` implementation reuses the IntelliJ Platform class [`TreeBasedStructureViewBuilder`](upsource:///platform/editor-ui-api/src/com/intellij/ide/structureView/TreeBasedStructureViewBuilder.java). +At this point the project will not compile until `SimpleStructureViewModel` is [implemented below](#define-a-structure-view-model). ```java -{% include /code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleStructureViewFactory.java %} +{% include /code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleStructureViewFactory.java %} ``` -### 14.2. Define a structure view model - +## 14.2. Define a Structure View Model +The `SimpleStructureViewModel` is created by implementing [`StructureViewModel`](upsource:///platform/editor-ui-api/src/com/intellij/ide/structureView/StructureViewModel.java), which defines the model for data displayed in the standard structure view. +It also extends [`StructureViewModelBase`](upsource:///platform/editor-ui-api/src/com/intellij/ide/structureView/StructureViewModelBase.java), an implementation that links the model to a text editor. ```java -{% include /code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleStructureViewModel.java %} +{% include /code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleStructureViewModel.java %} ``` -### 14.3. Define a structure view element - +## 14.3. Define a Structure View Element +The `SimpleStructureViewElement` implements [`StructureViewTreeElement`](upsource:///platform/editor-ui-api/src/com/intellij/ide/structureView/StructureViewTreeElement.java) and [`SortableTreeElement`](upsource:///platform/editor-ui-api/src/com/intellij/ide/util/treeView/smartTree/SortableTreeElement.java). +The `StructureViewTreeElement` represents an element in the Structure View tree model. +The `SortableTreeElement` represents an item in a smart tree that allows using text other than the presentable text as a key for alphabetic sorting. ```java -{% include /code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleStructureViewElement.java %} +{% include /code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleStructureViewElement.java %} ``` -### 14.4. Register the structure view factory - +## 14.4. Register the Structure View Factory +The `SimpleStructureViewFactory` implementation is registered with the IntelliJ Platform in the plugin configuration file using the `lang.psiStructureViewFactory` extension point. ```xml - + + + ``` -### 14.5. Run the project +## 14.5. Run the Project +Rebuild the project, and run `simple_language_plugin` in a Development Instance. +Open the `test.simple` file and choose **View \| Tool Windows \| Structure**. +The IDE now supports a structure view of the Simple Language: -![Structure View](img/structure_view.png) +![Structure View](img/structure_view.png){:width="800px"} diff --git a/tutorials/custom_language_support/syntax_highlighter_and_color_settings_page.md b/tutorials/custom_language_support/syntax_highlighter_and_color_settings_page.md index e71f56f9f..97dfabdbd 100644 --- a/tutorials/custom_language_support/syntax_highlighter_and_color_settings_page.md +++ b/tutorials/custom_language_support/syntax_highlighter_and_color_settings_page.md @@ -2,41 +2,60 @@ title: 5. Syntax Highlighter and Color Settings Page --- +The first level of [syntax highlighting](/reference_guide/custom_language_support/syntax_highlighting_and_error_highlighting.md#lexer) is based on the lexer output, and is provided by `SyntaxHighlighter`. +A plugin can also define [color settings](/reference_guide/custom_language_support/syntax_highlighting_and_error_highlighting.md#color-settings) based on `ColorSettingPage` so the user can configure highlight colors. +The `SimpleSyntaxHighlighter`, `SimpleSyntaxHighlighterFactory`, and `SimpleColorSettingsPage` discussed on this page are demonstrated in the `simple_language_plugin` code sample. -### 5.1. Define a syntax highlighter +* bullet list +{:toc} +## 5.1. Define a Syntax Highlighter +The Simple Language syntax highlighter class extends [`SyntaxHighlighterBase`](upsource:///platform/editor-ui-api/src/com/intellij/openapi/fileTypes/SyntaxHighlighterBase.java). +As recommended in [Color Scheme Management](/reference_guide/color_scheme_management.md#text-attribute-key-dependency), the Simple Language highlighting text attributes are specified as a dependency on one of standard Intellij Platform keys. +For the Simple Language, define only one scheme. ```java -{% include /code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleSyntaxHighlighter.java %} +{% include /code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleSyntaxHighlighter.java %} ``` -### 5.2. Define a syntax highlighter factory - +### 5.2. Define a Syntax Highlighter Factory +The factory provides a standard way for the IntelliJ Platform to instantiate the syntax highlighter for Simple Language files. +Here, `SimpleSyntaxHighlighterFactory` subclasses [`SyntaxHighlighterFactory`](upsource:///platform/editor-ui-api/src/com/intellij/openapi/fileTypes/SyntaxHighlighterFactory.java). ```java -{% include /code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleSyntaxHighlighterFactory.java %} +{% include /code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleSyntaxHighlighterFactory.java %} ``` -### 5.3. Register the syntax highlighter factory - +### 5.3. Register the Syntax Highlighter Factory +Register the factory with the IntelliJ Platform in the plugin configuration file. ```xml - + + + ``` -### 5.4. Run the project +### 5.4. Run the Project +Open the example Simple Language [properties file ](/tutorials/custom_language_support/lexer_and_parser_definition.md#run-the-project) (`test.simple`) in the IDE Development Instance. +The colors for Simple Language Key, Separator, and Value highlighting default to the IDE _Language Defaults_ for Keyword, Braces, Operators, and Strings, respectively. -![Syntax highlighter](img/syntax_highlighter.png) - -### 5.5. Define a color settings page +![Syntax highlighter](img/syntax_highlighter.png){:width="800px"} +## 5.5. Define a Color Settings Page +The color settings page adds the ability for users to customize color settings for the highlighting in Simple Language files. +The `SimpleColorSettingsPage` implements [`ColorSettingsPage`](upsource:///platform/lang-api/src/com/intellij/openapi/options/colors/ColorSettingsPage.java). ```java -{% include /code_samples/simple_language_plugin/src/main/java/com/intellij/sdk/language/SimpleColorSettingsPage.java %} +{% include /code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleColorSettingsPage.java %} ``` -### 5.6. Register the color settings page - +### 5.6. Register the Color Settings Page +The settings page for Simple Language colors gets registered as an extension in the plugin configuration file. ```xml - + + + ``` ### 5.7. Run the project +In the IDE Development Instance, open the Simple Language highlight settings page: **Preferences/Settings \| Editor \| Color Scheme \| Simple**. +Each color initially inherits from a _Language Defaults_ value. -![Color Settings Page](img/color_settings_page.png) +![Color Settings Page](img/color_settings_page.png){:width="800px"} diff --git a/tutorials/custom_language_support_tutorial.md b/tutorials/custom_language_support_tutorial.md index 54b517d0c..cdc83e89e 100644 --- a/tutorials/custom_language_support_tutorial.md +++ b/tutorials/custom_language_support_tutorial.md @@ -2,14 +2,11 @@ title: Custom Language Support Tutorial --- -In this tutorial we will add support for -[.properties](https://en.wikipedia.org/wiki/.properties) -language and its usages within Java code. - -The final code can be found in the [SamplePlugin repo on GitHub](https://github.com/JetBrains/intellij-sdk-docs/tree/master/code_samples/simple_language_plugin). - -This a step-by-step tutorial and it requires performing every step: - +In this tutorial we will add support for a [.properties](https://en.wikipedia.org/wiki/.properties) language and its usages within Java code. +IntelliJ Platform support for custom languages is discussed in more depth in the [Custom Language](/reference_guide/custom_language_support.md) section. + +The example plugin used in this tutorial is the `simple_language_plugin` code sample. +This a step-by-step tutorial, and it requires completing each step, in order: * [1. Prerequisites](custom_language_support/prerequisites.md) * [2. Language and File Type](custom_language_support/language_and_filetype.md) * [3. Grammar and Parser](custom_language_support/grammar_and_parser.md) diff --git a/tutorials/writing_tests_for_plugins.md b/tutorials/writing_tests_for_plugins.md index 101d06043..a170244db 100644 --- a/tutorials/writing_tests_for_plugins.md +++ b/tutorials/writing_tests_for_plugins.md @@ -4,9 +4,9 @@ title: Writing Tests For Plugins > **NOTE** Please see [Testing Plugins](/basics/testing_plugins/testing_plugins.md) for a general introduction. -In this tutorial you will learn how to write and run automated tests for a custom language plugin. +This tutorial demonstrates how to write and run automated tests for a custom language plugin. -As an example we will take the plugin implemented in the [Custom Language Support](/tutorials/custom_language_support_tutorial.md) and cover its code with functional tests. +As an example, the plugin implemented in the [Custom Language Support Tutorial](/tutorials/custom_language_support_tutorial.md) is used to demonstrate functional test development. * [1. Tests Prerequisites](writing_tests_for_plugins/tests_prerequisites.md) * [2. Parsing Test](writing_tests_for_plugins/parsing_test.md) @@ -19,4 +19,4 @@ As an example we will take the plugin implemented in the [Custom Language Suppor * [9. Commenter Test](writing_tests_for_plugins/commenter_test.md) * [10. Reference Test](writing_tests_for_plugins/reference_test.md) -The final code can be found in the [SamplePlugin repo on GitHub](https://github.com/JetBrains/intellij-sdk-docs/tree/master/code_samples/simple_language_plugin). +The plugin and test code can be found in the [simple_language_plugin](https://github.com/JetBrains/intellij-sdk-docs/tree/master/code_samples/simple_language_plugin) code sample. diff --git a/tutorials/writing_tests_for_plugins/annotator_test.md b/tutorials/writing_tests_for_plugins/annotator_test.md index 61acbf7ce..7d1630d62 100644 --- a/tutorials/writing_tests_for_plugins/annotator_test.md +++ b/tutorials/writing_tests_for_plugins/annotator_test.md @@ -2,16 +2,15 @@ title: 4. Annotator Test --- -In this test we will check if the annotator, implemented in the -[Annotator](/tutorials/custom_language_support/annotator.md) section -of the -[Custom Language Support Tutorial](/tutorials/custom_language_support_tutorial.md) -works as expected. +This test checks if the Simple Language annotator functionality, implemented in the [Annotator](/tutorials/custom_language_support/annotator.md) section of the Custom Language Support Tutorial, works as expected. -### 4.1. Define test data - -Create a file *AnnotatorTestData.java*. +## 4.1. Define Input Test Data +The `DefaultTestData.simple` properties file is reused for this test. +Create an input test file `AnnotatorTestData.java` in the `testData` directory. +This file contains two instances of Simple Language embedded in the Java code. +The first instance is a valid use of the `simple:` prefix followed by the Simple Language key `website`. +The second is a valid prefix but an invalid key, as noted by the test `` [highlighting](/basics/testing_plugins/testing_highlighting.md). ```java public class Test { public static void main(String[] args) { @@ -21,8 +20,10 @@ public class Test { } ``` -### 4.2. Define a test method - +## 4.2. Define a Test Method +Add the `testAnnotator()` method to the `SimpleCodeInsightTest` class [previously defined](completion_test.md#define-a-test). +Again, this method configures the test fixture by using the test files. +It then calls the `checkHighlighting()` method to verify weak warnings. ```java public void testAnnotator() { myFixture.configureByFiles("AnnotatorTestData.java", "DefaultTestData.simple"); @@ -30,6 +31,5 @@ public void testAnnotator() { } ``` -### 4.3. Run the test - -Run the test and make sure it's green. +## 4.3. Run the Test +[Run](completion_test.md#run-the-test) the test and make sure it's green. diff --git a/tutorials/writing_tests_for_plugins/commenter_test.md b/tutorials/writing_tests_for_plugins/commenter_test.md index fcfb89c12..388fd5e06 100644 --- a/tutorials/writing_tests_for_plugins/commenter_test.md +++ b/tutorials/writing_tests_for_plugins/commenter_test.md @@ -2,21 +2,24 @@ title: 9. Commenter Test --- -In this test we will check if the commenter, implemented in the [Commenter](/tutorials/custom_language_support/commenter.md) section of the [Custom Language Support Tutorial](/tutorials/custom_language_support_tutorial.md), works as we expect. +This test will check if the commenter, implemented in the [Commenter](/tutorials/custom_language_support/commenter.md) section of the Custom Language Support Tutorial, works as expected. -### 9.1. Define a test method +## 9.1. Define a Test Method +Add the `testCommenter()` method to the `SimpleCodeInsightTest` class [previously defined](completion_test.md#define-a-test). +This test constructs a Simple Language properties file containing one line, with the virtual caret positioned at the beginning of the line. +The test calls the commenter to insert a comment character at the caret, then verifies the results. +It again calls the line comment action to remove the comment character and verifies the results. ```java -public void testCommenter() { + public void testCommenter() { myFixture.configureByText(SimpleFileType.INSTANCE, "website = http://en.wikipedia.org/"); CommentByLineCommentAction commentAction = new CommentByLineCommentAction(); commentAction.actionPerformedImpl(getProject(), myFixture.getEditor()); myFixture.checkResult("#website = http://en.wikipedia.org/"); commentAction.actionPerformedImpl(getProject(), myFixture.getEditor()); myFixture.checkResult("website = http://en.wikipedia.org/"); -} + } ``` -### 9.2. Run the test - -Run the test and make sure it's green. +## 9.2. Run the Test +[Run](completion_test.md#run-the-test) the test and make sure it's green. diff --git a/tutorials/writing_tests_for_plugins/completion_test.md b/tutorials/writing_tests_for_plugins/completion_test.md index 6d2e3ef7c..20126f6eb 100644 --- a/tutorials/writing_tests_for_plugins/completion_test.md +++ b/tutorials/writing_tests_for_plugins/completion_test.md @@ -2,41 +2,60 @@ title: 3. Completion Test --- +This test checks if the Simple Language code completion functionality, implemented in the [Reference Contributor](/tutorials/custom_language_support/reference_contributor.md) section of the Custom Language Support Tutorial, works as expected. -In this test we will check if code completion, implemented in the [Reference Contributor](/tutorials/custom_language_support/reference_contributor.md) section of the [Custom Language Support Tutorial](/tutorials/custom_language_support_tutorial.md) works as we expect. - -### 3.1. Define test data - -Create a file *DefaultTestData.simple*. +## 3.1. Define Test Data +Create the `DefaultTestData.simple` properties file in the `testData` directory. ```bash -# You are reading the ".properties" entry. -! The exclamation mark can also mark text as comments. -website = http://en.wikipedia.org/ - -language = English -# The backslash below tells the application to continue reading -# the value onto the next line. -message = Welcome to \ - Wikipedia! -# Add spaces to the key -key\ with\ spaces = This is the value that could be looked up with the key "key with spaces". -# Unicode -tab : \u0009 +{% include /code_samples/simple_language_plugin/src/test/testData/DefaultTestData.simple %} ``` -Create one more file *CompleteTestData.java*. +Create a test input Java file `CompleteTestData.java` in the `testData` directory. +This file contains a Simple Language snippet within the Java. +```java +{% include /code_samples/simple_language_plugin/src/test/testData/CompleteTestData.java %} +``` + +## 3.2. Define a Test +Subclass `LightJavaCodeInsightFixtureTestCase` to create `SimpleCodeInsightTest`. +Override `getTestDataPath()`, and return the path from the root of this plugin module to the `testData` directory. + +At this point only one test is defined in `SimpleCodeInsightTest`: `testCompletion()`. +This method: +* Configures the test using the two input files. +* Calls the basic completion functionality. + Behind the scenes, this method call creates a list of possible elements to complete the embedded Simple Language reference. +* Checks the list of possible element names to ensure it contains all Simple Language completion possibilities. ```java -{% include /code_samples/simple_language_plugin/src/test/resources/CompleteTestData.java %} +public class SimpleCodeInsightTest extends LightJavaCodeInsightFixtureTestCase { + @Override + protected String getTestDataPath() { + return "src/test/testData"; + } + + public void testCompletion() { + myFixture.configureByFiles("CompleteTestData.java", "DefaultTestData.simple"); + myFixture.complete(CompletionType.BASIC, 1); + List strings = myFixture.getLookupElementStrings(); + assertTrue(strings.containsAll(Arrays.asList("key with spaces", "language", "message", "tab", "website"))); + assertEquals(5, strings.size()); + } +} ``` -### 3.2. Define a test +## 3.3. Run the Test +Run the test by: +* Opening the **Gradle** Tool Window. +* Select the `simple_language_plugin`. + You may need to reimport it as a Gradle project. +* Drill down under `simple_language_plugin` to *Tasks*, *verification*, *test* task. +* Run the *test* task. -```java -{% include /code_samples/simple_language_plugin/src/test/java/com/intellij/sdk/language/SimpleCodeInsightTest.java %} -``` +The results are displayed in the **Run** Tool Window, and also written to the `simple_language_plugin/build/test-results/test/` directory. -### 3.3. Run the test - -Run the test and make sure it's green. +If the **Run** Tool Window displays the error *Test events were not received*, do the following: +* In the **Gradle** Tool Window, drill down under `simple_language_plugin` to *Tasks*, *build*, *clean* task. +* Run the *clean* task, which deletes the `simple_language_plugin/build/` directory. +* Retry the test. \ No newline at end of file diff --git a/tutorials/writing_tests_for_plugins/find_usages_test.md b/tutorials/writing_tests_for_plugins/find_usages_test.md index e1478aa30..e7080b56f 100644 --- a/tutorials/writing_tests_for_plugins/find_usages_test.md +++ b/tutorials/writing_tests_for_plugins/find_usages_test.md @@ -2,51 +2,31 @@ title: 8. Find Usages Test --- -In this test we will check if the find usages provider, implemented in the -[Find Usages Provider](/tutorials/custom_language_support/find_usages_provider.md) -section of the -[Custom Language Support Tutorial](/tutorials/custom_language_support_tutorial.md), -works correctly. +This test ensures the find usages provider, implemented in the [Find Usages Provider](/tutorials/custom_language_support/find_usages_provider.md) section of the Custom Language Support Tutorial, works correctly. -### 8.1. Define test data - -Create a file *FindUsagesTestData.simple*. +## 8.1. Define the Test Data +Create the `FindUsagesTestData.simple` properties file in the `testData` directory. ```bash -# You are reading the ".properties" entry. -! The exclamation mark can also mark text as comments. -website = http://en.wikipedia.org/ - -language = English -# The backslash below tells the application to continue reading -# the value onto the next line. -message = Welcome to \ - Wikipedia! -# Add spaces to the key -key\ with\ spaces = This is the value that could be looked up with the key "key with spaces". -# Unicode -tab : \u0009 +{% include /code_samples/simple_language_plugin/src/test/testData/FindUsagesTestData.simple %} ``` -Create a file *FindUsagesTestData.java*. +Create the test file `FindUsagesTestData.java`, which contains one embedded Simple Language prefix and key. ```java -public class Test { - public static void main(String[] args) { - System.out.println("simple:website"); - } -} +{% include /code_samples/simple_language_plugin/src/test/testData/FindUsagesTestData.java %} ``` -### 8.2. Define a test method +## 8.2. Define a Test Method +Add the `testFindUsages()` method to the `SimpleCodeInsightTest` class [previously defined](completion_test.md#define-a-test). +This test verifies the find usage functionality will identify the "key with spaces". ```java -public void testFindUsages() { + public void testFindUsages() { Collection usageInfos = myFixture.testFindUsages("FindUsagesTestData.simple", "FindUsagesTestData.java"); assertEquals(1, usageInfos.size()); -} + } ``` -### 8.3. Run the test - -Run the test and make sure it's green. +## 8.3. Run the Test +[Run](completion_test.md#run-the-test) the test and make sure it's green. diff --git a/tutorials/writing_tests_for_plugins/folding_test.md b/tutorials/writing_tests_for_plugins/folding_test.md index b7ebdde32..e8261c82f 100644 --- a/tutorials/writing_tests_for_plugins/folding_test.md +++ b/tutorials/writing_tests_for_plugins/folding_test.md @@ -2,33 +2,26 @@ title: 7. Folding Test --- -In this test we will check if the folding builder, implemented in the -[Folding Builder](/tutorials/custom_language_support/folding_builder.md) -section of the -[Custom Language Support Tutorial](/tutorials/custom_language_support_tutorial.md), -works as we expect. +This test verifies the Simple Language folding builder, implemented in the [Folding Builder](/tutorials/custom_language_support/folding_builder.md) section of the Custom Language Support Tutorial, works as expected. -### 7.1. Define test data - -Create a file *FoldingTestData.java*. +> **NOTE** A folding builder must implement [`DumbAware`](upsource:///platform/core-api/src/com/intellij/openapi/project/DumbAware.java) to pass tests. See [Define a Folding Builder](/tutorials/custom_language_support/folding_builder.md#define-a-folding-builder) for more information. +## 7.1. Define Test Data +Create a file `FoldingTestData.java` in the `testData` directory. +This java file contains markup instructions for three different cases of code folding. ```java -public class Test { - public static void main(String[] args) { - System.out.println("simple:website"); - } -} +{% include /code_samples/simple_language_plugin/src/test/testData/FoldingTestData.java %} ``` -### 7.2. Define a test - +## 7.2. Define a Test +Add the `testFolding()` method to the `SimpleCodeInsightTest` class [previously defined](completion_test.md#define-a-test). +This test method reuses the `DefaultTestData.simple` properties file. ```java -public void testFolding() { - myFixture.configureByFiles("DefaultTestData.simple"); + public void testFolding() { + myFixture.configureByFile("DefaultTestData.simple"); myFixture.testFolding(getTestDataPath() + "/FoldingTestData.java"); -} + } ``` -### 7.3. Run the test - -Run the test and make sure it's green. +## 7.3. Run the Test +[Run](completion_test.md#run-the-test) the test and make sure it's green. diff --git a/tutorials/writing_tests_for_plugins/formatter_test.md b/tutorials/writing_tests_for_plugins/formatter_test.md index e37e74659..8e00a2564 100644 --- a/tutorials/writing_tests_for_plugins/formatter_test.md +++ b/tutorials/writing_tests_for_plugins/formatter_test.md @@ -2,51 +2,36 @@ title: 5. Formatter Test --- -In this test we will check if the formatter, implemented in the -[Formatter](/tutorials/custom_language_support/formatter.md) -section of the -[Custom Language Support Tutorial](/tutorials/custom_language_support_tutorial.md) -works as we expect. +This test checks if the Simple Language formatter, implemented in the [Formatter](/tutorials/custom_language_support/formatter.md) section of the Custom Language Support Tutorial, works as expected. -### 5.1. Define test data - -Create a file *FormatterTestData.simple*. +## 5.1. Define Test Data +Create the `FormatterTestData.simple` properties file in the `testData` directory. ```bash -# You are reading the ".properties" entry. -! The exclamation mark can also mark text as comments. -website=http://en.wikipedia.org/ - -language= English -# The backslash below tells the application to continue reading -# the value onto the next line. -message = Welcome to \ - Wikipedia! -# Add spaces to the key -key\ with\ spaces = This is the value that could be looked up with the key "key with spaces". -# Unicode -tab :\u0009 +{% include /code_samples/simple_language_plugin/src/test/testData/FormatterTestData.simple %} ``` -### 5.2. Define a test method +## 5.2. Define a Test Method +Add the `testFormatter()` method to the `SimpleCodeInsightTest` class [previously defined](completion_test.md#define-a-test). +* Again, this method configures the test fixture by using the test file. +* The code style Simple Language settings for spaces and blank lines are set. +* The file is then formatted according to the settings. +* The formatted file is compared to the expected results in the benchmark file `DefaultTestData.simple`. ```java -public void testFormatter() { - myFixture.configureByFiles("FormatterTestData.simple"); - CodeStyleSettingsManager.getSettings(getProject()).SPACE_AROUND_ASSIGNMENT_OPERATORS = true; - new WriteCommandAction.Simple(getProject()) { - @Override - protected void run() throws Throwable { - CodeStyleManager.getInstance(getProject()).reformatText(myFixture.getFile(), - ContainerUtil.newArrayList(myFixture.getFile().getTextRange())); - } - }.execute(); + public void testFormatter() { + myFixture.configureByFile("FormatterTestData.simple"); + CodeStyle.getLanguageSettings(myFixture.getFile()).SPACE_AROUND_ASSIGNMENT_OPERATORS = true; + CodeStyle.getLanguageSettings(myFixture.getFile()).KEEP_BLANK_LINES_IN_CODE = 2; + WriteCommandAction.writeCommandAction(getProject()).run(() -> { + CodeStyleManager.getInstance(getProject()).reformatText(myFixture.getFile(), + ContainerUtil.newArrayList(myFixture.getFile().getTextRange())); + }); myFixture.checkResultByFile("DefaultTestData.simple"); -} + } ``` -### 5.3. Run the test - -Run the test and make sure it's green. +## 5.3. Run the Test +[Run](completion_test.md#run-the-test) the test and make sure it's green. >> **TIP** See also [`FormatterTestCase`](upsource:///platform/testFramework/src/com/intellij/psi/formatter/FormatterTestCase.java) as convenient base class. diff --git a/tutorials/writing_tests_for_plugins/img/plugin_copy_psi.png b/tutorials/writing_tests_for_plugins/img/plugin_copy_psi.png index c59bb73a2..4a89b1061 100644 Binary files a/tutorials/writing_tests_for_plugins/img/plugin_copy_psi.png and b/tutorials/writing_tests_for_plugins/img/plugin_copy_psi.png differ diff --git a/tutorials/writing_tests_for_plugins/parsing_test.md b/tutorials/writing_tests_for_plugins/parsing_test.md index 12501a66c..e645e60c9 100644 --- a/tutorials/writing_tests_for_plugins/parsing_test.md +++ b/tutorials/writing_tests_for_plugins/parsing_test.md @@ -2,103 +2,61 @@ title: 2. Parsing Test --- +The first test checks if the Simple Language parser, implemented in the [Lexer and Parser Definition](/tutorials/custom_language_support/lexer_and_parser_definition.md) section of the Custom Language Support Tutorial, works as expected. -The first test will check if the parser, implemented in the -[Lexer and Parser Definition](/tutorials/custom_language_support/lexer_and_parser_definition.md) -section of the -[Custom Language Support Tutorial](/tutorials/custom_language_support_tutorial.md) -works as we expect it. +## 2.1. Update Grammar and Regenerate the Parser +Before creating the parsing test, ensure the parser definition (`Simple.bnf`) includes the lines shown below. +These additional lines facilitate testing incorrect keys. -### 2.1. Define input test data +If the lines below are not present in `Simple.bnf`, replace the existing `property` definition with the lines below. +Don't forget to regenerate the parser after updating the file! +Right-click on the `Simple.bnf` file and select **Generate Parser Code**. -Create a file *ParsingTestData.simple* in *testData* folder. - -```bash -# You are reading the ".properties" entry. -! The exclamation mark can also mark text as comments. -website = http://en.wikipedia.org/ - -language = English -# The backslash below tells the application to continue reading -# the value onto the next line. -message = Welcome to \ - Wikipedia! -# Add spaces to the key -key\ with\ spaces = This is the value that could be looked up with the key "key with spaces". -# Unicode -tab : \u0009 +```java +property ::= (KEY? SEPARATOR VALUE?) | KEY { + pin=3 + recoverWhile="recover_property" + mixin="org.intellij.sdk.language.psi.impl.SimpleNamedElementImpl" + implements="org.intellij.sdk.language.psi.SimpleNamedElement" + methods=[getKey getValue getName setName getNameIdentifier getPresentation] +} +private recover_property ::= !(KEY|SEPARATOR|COMMENT) ``` -### 2.2. Copy the expected PSI tree +## 2.2. Define Input Test Data +Create the *ParsingTestData.simple* properties file in the *testData* folder. +Note the last few lines define a purposely incorrect key. +```bash +{% include /code_samples/simple_language_plugin/src/test/testData/ParsingTestData.simple %} +``` -The easiest way to get the expected PSI structure for any file is to use PSI Viewer. -Run the project and call `Tools` → `View PSI Structure`. +## 2.3. Copy the Expected PSI Tree +The easiest way to get the expected PSI structure for any file is to use the PSI Viewer. +Run the project and use **Tools \| View PSI Structure**. ![PSI Tree Copy](img/plugin_copy_psi.png) -Use `Copy PSI` button to copy the expected PSI structure to the clipboard. - -### 2.3. Define an output test data +Use the `Copy PSI` button to copy the expected PSI structure to the clipboard. +## 2.3. Define the Output Reference Test Data Create a file *ParsingTestData.txt* with the copied PSI tree. -```java -Simple File(0,433) - PsiComment(SimpleTokenType.COMMENT)('# You are reading the ".properties" entry.')(0,42) - PsiElement(SimpleTokenType.CRLF)('\n')(42,43) - PsiComment(SimpleTokenType.COMMENT)('! The exclamation mark can also mark text as comments.')(43,97) - PsiElement(SimpleTokenType.CRLF)('\n')(97,98) - SimplePropertyImpl(PROPERTY)(98,132) - PsiElement(SimpleTokenType.KEY)('website')(98,105) - PsiWhiteSpace(' ')(105,106) - PsiElement(SimpleTokenType.SEPARATOR)('=')(106,107) - PsiWhiteSpace(' ')(107,108) - PsiElement(SimpleTokenType.VALUE)('http://en.wikipedia.org/')(108,132) - PsiElement(SimpleTokenType.CRLF)('\n')(132,133) - PsiElement(SimpleTokenType.CRLF)('\n')(133,134) - SimplePropertyImpl(PROPERTY)(134,152) - PsiElement(SimpleTokenType.KEY)('language')(134,142) - PsiWhiteSpace(' ')(142,143) - PsiElement(SimpleTokenType.SEPARATOR)('=')(143,144) - PsiWhiteSpace(' ')(144,145) - PsiElement(SimpleTokenType.VALUE)('English')(145,152) - PsiElement(SimpleTokenType.CRLF)('\n')(152,153) - PsiComment(SimpleTokenType.COMMENT)('# The backslash below tells the application to continue reading')(153,216) - PsiElement(SimpleTokenType.CRLF)('\n')(216,217) - PsiComment(SimpleTokenType.COMMENT)('# the value onto the next line.')(217,248) - PsiElement(SimpleTokenType.CRLF)('\n')(248,249) - SimplePropertyImpl(PROPERTY)(249,292) - PsiElement(SimpleTokenType.KEY)('message')(249,256) - PsiWhiteSpace(' ')(256,257) - PsiElement(SimpleTokenType.SEPARATOR)('=')(257,258) - PsiWhiteSpace(' ')(258,259) - PsiElement(SimpleTokenType.VALUE)('Welcome to \\n Wikipedia!')(259,292) - PsiElement(SimpleTokenType.CRLF)('\n')(292,293) - PsiComment(SimpleTokenType.COMMENT)('# Add spaces to the key')(293,316) - PsiElement(SimpleTokenType.CRLF)('\n')(316,317) - SimplePropertyImpl(PROPERTY)(317,410) - PsiElement(SimpleTokenType.KEY)('key\ with\ spaces')(317,334) - PsiWhiteSpace(' ')(334,335) - PsiElement(SimpleTokenType.SEPARATOR)('=')(335,336) - PsiWhiteSpace(' ')(336,337) - PsiElement(SimpleTokenType.VALUE)('This is the value that could be looked up with the key "key with spaces".')(337,410) - PsiElement(SimpleTokenType.CRLF)('\n')(410,411) - PsiComment(SimpleTokenType.COMMENT)('# Unicode')(411,420) - PsiElement(SimpleTokenType.CRLF)('\n')(420,421) - SimplePropertyImpl(PROPERTY)(421,433) - PsiElement(SimpleTokenType.KEY)('tab')(421,424) - PsiWhiteSpace(' ')(424,425) - PsiElement(SimpleTokenType.SEPARATOR)(':')(425,426) - PsiWhiteSpace(' ')(426,427) - PsiElement(SimpleTokenType.VALUE)('\u0009')(427,433) +```text +{% include /code_samples/simple_language_plugin/src/test/testData/ParsingTestData.txt %} ``` -### 2.4. Define a parsing test - +## 2.4. Define a Parsing Test +Subclass [`ParsingTestCase`](upsource:///platform/testFramework/src/com/intellij/testFramework/ParsingTestCase.java) to create `SimpleParsingTest`: ```java -{% include /code_samples/simple_language_plugin/src/test/java/com/intellij/sdk/language/SimpleParsingTest.java %} +{% include /code_samples/simple_language_plugin/src/test/java/org/intellij/sdk/language/SimpleParsingTest.java %} ``` -### 2.5. Run the test +## 2.5. Run the Test +Run the test by: +* Opening the Gradle Tool Window. +* Select the `simple_language_plugin`. + You may need to reimport it as a Gradle project. +* Drill down under `simple_language_plugin` to *Tasks*, *verification*, *test* task. +* Run the *test* task. -Run the test and make sure it's green. +The results are displayed in the **Run** Window, and also written to the `simple_language_plugin/build/test-results/test/` directory. diff --git a/tutorials/writing_tests_for_plugins/reference_test.md b/tutorials/writing_tests_for_plugins/reference_test.md index 20a7aebc2..026252d7a 100644 --- a/tutorials/writing_tests_for_plugins/reference_test.md +++ b/tutorials/writing_tests_for_plugins/reference_test.md @@ -2,35 +2,30 @@ title: 10. Reference Test --- +This test checks if references functionality, implemented in the [Reference Contributor](/tutorials/custom_language_support/reference_contributor.md) section of the Custom Language Support Tutorial, works as expected. -In this test we will check if references, implemented in the -[Reference Contributor](/tutorials/custom_language_support/reference_contributor.md) -section of the -[Custom Language Support Tutorial](/tutorials/custom_language_support_tutorial.md), -works as we expect. +## 10.1. Define Test Data +This test reuses the Simple Language properties file `DefaultTestData.simple`. -### 10.1. Define test data - -Create a file *ReferenceTestData.java*. +Create the test file `ReferenceTestData.java` in the `testData` directory. +This file has one Simple Language prefix and key, with the caret placed after the key. ```java -public class Test { - public static void main(String[] args) { - System.out.println("simple:website"); - } -} +{% include /code_samples/simple_language_plugin/src/test/testData/ReferenceTestData.java %} ``` -### 10.2. Define a test method +## 10.2. Define a Test Method +Add the `testReference()` method to the `SimpleCodeInsightTest` class [previously defined](completion_test.md#define-a-test). +This test is configured by the test files. +The fixture gets the `PsiElement` at the caret, then compares its value with the known value of that key. ```java -public void testReference() { + public void testReference() { myFixture.configureByFiles("ReferenceTestData.java", "DefaultTestData.simple"); PsiElement element = myFixture.getFile().findElementAt(myFixture.getCaretOffset()).getParent(); assertEquals("http://en.wikipedia.org/", ((SimpleProperty) element.getReferences()[0].resolve()).getValue()); -} + } ``` -### 10.3. Run the test - -Run the test and make sure it's green. +## 10.3. Run the Test +[Run](completion_test.md#run-the-test) the test and make sure it's green. diff --git a/tutorials/writing_tests_for_plugins/rename_test.md b/tutorials/writing_tests_for_plugins/rename_test.md index ff6407613..6233c8adb 100644 --- a/tutorials/writing_tests_for_plugins/rename_test.md +++ b/tutorials/writing_tests_for_plugins/rename_test.md @@ -2,72 +2,44 @@ title: 6. Rename Test --- +This test verifies the Simple Language in-place rename functionality, implemented in the [Reference Contributor](/tutorials/custom_language_support/reference_contributor.md) section of the Custom Language Support Tutorial, works as expected. -In this test we will check if in-place rename, implemented in the -[Reference Contributor](/tutorials/custom_language_support/reference_contributor.md) -section of the -[Custom Language Support Tutorial](/tutorials/custom_language_support_tutorial.md), works as we expect. - -### 6.1. Define input test data - -Create a file *RenameTestData.simple*. +## 6.1. Define Input Test Data +Create the `RenameTestData.simple` properties file in the `testData` directory. ```bash -# You are reading the ".properties" entry. -! The exclamation mark can also mark text as comments. -website = http://en.wikipedia.org/ - -language = English -# The backslash below tells the application to continue reading -# the value onto the next line. -message = Welcome to \ - Wikipedia! -# Add spaces to the key -key\ with\ spaces = This is the value that could be looked up with the key "key with spaces". -# Unicode -tab : \u0009 +{% include /code_samples/simple_language_plugin/src/test/testData/RenameTestData.simple %} ``` -Create a file *RenameTestData.java*. +Create the file `RenameTestData.java` in the `testData` directory. +This file contains one Simple Language reference embedded in Java, with the [caret position](/basics/testing_plugins/test_project_and_testdata_directories.md#special-markup) placed just after a Simple Language key. ```java -public class Test { - public static void main(String[] args) { - System.out.println("simple:website"); - } -} +{% include /code_samples/simple_language_plugin/src/test/testData/RenameTestData.java %} ``` -### 6.2. Create output test data - -Create a file *RenameTestDataAfter.simple*. +## 6.2. Create Output Test Data +Create the `RenameTestDataAfter.simple` properties file in the `testData` directory. +This file contains the expected outcome of the test. +Note the `website =` in `RenameTestData.simple` should be renamed to `websiteUrl =` by the test. ```bash -# You are reading the ".properties" entry. -! The exclamation mark can also mark text as comments. -websiteUrl = http://en.wikipedia.org/ - -language = English -# The backslash below tells the application to continue reading -# the value onto the next line. -message = Welcome to \ - Wikipedia! -# Add spaces to the key -key\ with\ spaces = This is the value that could be looked up with the key "key with spaces". -# Unicode -tab : \u0009 +{% include /code_samples/simple_language_plugin/src/test/testData/RenameTestDataAfter.simple %} ``` -### 6.3. Define a test method - +## 6.3. Define a Test Method +Add the `testRename()` method to the `SimpleCodeInsightTest` class [previously defined](completion_test.md#define-a-test). +* Again, this method configures the test fixture by using the test files. +* The fixture then renames the Simple Language element at the caret in `RenameTestData.java`. +* It then compares the input and output property files, ignoring whitespace. + ```java -public void testRename() { + public void testRename() { myFixture.configureByFiles("RenameTestData.java", "RenameTestData.simple"); myFixture.renameElementAtCaret("websiteUrl"); myFixture.checkResultByFile("RenameTestData.simple", "RenameTestDataAfter.simple", false); -} + } ``` -### 6.4. Run the test - -Run the test and make sure it's green. +## 6.4. Run the Test +[Run](completion_test.md#run-the-test) the test and make sure it's green. diff --git a/tutorials/writing_tests_for_plugins/tests_prerequisites.md b/tutorials/writing_tests_for_plugins/tests_prerequisites.md index 47705ae9e..46272ff29 100644 --- a/tutorials/writing_tests_for_plugins/tests_prerequisites.md +++ b/tutorials/writing_tests_for_plugins/tests_prerequisites.md @@ -2,38 +2,32 @@ title: 1. Tests Prerequisites --- +This page discusses the steps to configure a plugin project for creating tests. -### 1.1. Create a folder for tests - -Open the project with the plugin and create a separate folder "tests". -Mark the folder as a test source root via the context menu `Mark Directory As` → `Test Source Root`. - -### 1.2. Create a folder for test data - -In our tests we will use test data, so we need one more folder *"testData"* to store these files. - -### 1.3. Run Configuration Parameters - -Since some of our tests will use Java files as test data, we need to mock up the project SDK. -IntelliJ IDEA does everything automatically when we use the special utility class -[`LightCodeInsightFixtureTestCase`](upsource:///java/testFramework/src/com/intellij/testFramework/fixtures/LightCodeInsightFixtureTestCase.java). - -All we need to do is point the run configuration's working directory to the root of the [IntelliJ IDEA Community Edition sources](upsource:///README.md) (via `idea.home.path`) and enable the following VM options: - +## 1.1. Create a Folder for Tests +Open the plugin project and under the `src` directory create a separate folder `test`. +Under `test`, create the `java` folder for test source code, and the folder `testData` for test resources. +```text +└── src + ├── main + │   ├── java + │   └── resources + └── test + ├── java + └── testData ``` --ea -Xbootclasspath/p:../out/classes/production/boot -XX:+HeapDumpOnOutOfMemoryError -Xmx512m -XX:MaxPermSize=320m --Didea.system.path=../test-system -Didea.home.path=../ -Didea.config.path=../test-config -Didea.test.group=ALL_EXCLUDE_DEFINED -``` +Mark the `java` folder as a test source root via the context menu `Mark Directory As` → `Test Source Root`. +Similarly, mark the `testData` folder as a test resource root via the context menu `Mark Directory As` → `Test Resources Root`. -If you're using Gradle, system properties must be passed to forked JVM via `build.gradle`: +## 1.2. Set the Run Configuration Parameters +Because some of the tests use Java files as test data, the tests need to mock up the project SDK. +IntelliJ IDEA does everything automatically when the utility class [`LightJavaCodeInsightFixtureTestCase`](upsource:///java/testFramework/src/com/intellij/testFramework/fixtures/LightJavaCodeInsightFixtureTestCase.java) is used as the basis for the tests. + +The system properties are defined in the `build.gradle` file using the snippet shown below. +The "/path/to/community/" is set to the absolute path to the root directory of the local intellij-community source on the machine running the tests. +For example, on macOS the "path/to/community/" might be `/Users//Documents//` +```groovy + test { + systemProperty "idea.home.path", "/path/to/community/" + } ``` -test { - systemProperty "idea.home.path", "/path/to/community/" -} -``` - -**Note**: - - > Keep in mind that we have changed the _working directory_, so all the paths in tests extended from - > [`LightCodeInsightFixtureTestCase`](upsource:///java/testFramework/src/com/intellij/testFramework/fixtures/LightCodeInsightFixtureTestCase.java) - > will use relative path to the _source root_ of IntelliJ IDEA Community Edition.