Checkpoint IJSDK-479B

This commit is contained in:
JohnHake 2020-02-11 19:35:37 -08:00
parent fe88cf3f03
commit c83e24d8bd
86 changed files with 472 additions and 545 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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.*;

View File

@ -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 {

View File

@ -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;

View File

@ -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 {

View File

@ -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)

View File

@ -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 {
}

View File

@ -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)

View File

@ -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;
%%

View File

@ -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;

View File

@ -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;

View File

@ -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.*;

View File

@ -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.*;

View File

@ -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.*;

View File

@ -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),

View File

@ -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;

View File

@ -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 {

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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 "";
}

View File

@ -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<SimpleProperty> 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

View File

@ -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 {

View File

@ -1,4 +1,4 @@
package com.intellij.sdk.language;
package org.intellij.sdk.language;
import com.intellij.openapi.util.IconLoader;

View File

@ -1,4 +1,4 @@
package com.intellij.sdk.language;
package org.intellij.sdk.language;
import com.intellij.lang.Language;

View File

@ -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.*;

View File

@ -1,4 +1,4 @@
package com.intellij.sdk.language;
package org.intellij.sdk.language;
import com.intellij.lexer.FlexAdapter;

View File

@ -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<SimpleProperty> properties = SimpleUtil.findProperties( project, possibleProperties );
if ( properties.size() > 0 ) {
// Add the property to a collection of line marker info
NavigationGutterIconBuilder< PsiElement > builder =

View File

@ -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 {

View File

@ -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 {

View File

@ -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.*;

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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.*;

View File

@ -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();
}
}

View File

@ -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;

View File

@ -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);

View File

@ -0,0 +1,6 @@
package org.intellij.sdk.language.psi;
import com.intellij.psi.PsiNameIdentifierOwner;
public interface SimpleNamedElement extends PsiNameIdentifierOwner {
}

View File

@ -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 {

View File

@ -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 {

View File

@ -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.*;

View File

@ -3,7 +3,7 @@
<idea-plugin>
<!-- Unique id for this plugin. Must stay constant for the life of the plugin. -->
<id>com.intellij.sdk.simple_language</id>
<id>org.intellij.sdk.simple_language</id>
<!-- Text to display as name on Preferences/Settings | Plugin page -->
<name>SDK: Simple Language Sample Project</name>
@ -40,28 +40,28 @@
<vendor url="https://plugins.jetbrains.com">IntelliJ Platform SDK</vendor>
<extensions defaultExtensionNs="com.intellij">
<fileType name="Simple file" implementationClass="com.intellij.sdk.language.SimpleFileType" fieldName="INSTANCE"
language="Simple" extensions="simple"/>
<fileType name="Simple file" implementationClass="org.intellij.sdk.language.SimpleFileType" fieldName="INSTANCE"
language="Simple" extensions="simple"/>
<!-- Only required for versions of the IntelliJ Platform prior to v2019.2.
Use fileTypeFactory extension point INSTEAD of fileType.
<fileTypeFactory implementation="com.intellij.sdk.language.SimpleFileTypeFactory"/>
<fileTypeFactory implementation="org.intellij.sdk.language.SimpleFileTypeFactory"/>
-->
<lang.parserDefinition language="Simple" implementationClass="com.intellij.sdk.language.SimpleParserDefinition"/>
<lang.syntaxHighlighterFactory language="Simple" implementationClass="com.intellij.sdk.language.SimpleSyntaxHighlighterFactory"/>
<colorSettingsPage implementation="com.intellij.sdk.language.SimpleColorSettingsPage"/>
<annotator language="JAVA" implementationClass="com.intellij.sdk.language.SimpleAnnotator"/>
<codeInsight.lineMarkerProvider language="JAVA" implementationClass="com.intellij.sdk.language.SimpleLineMarkerProvider"/>
<completion.contributor language="Simple" implementationClass="com.intellij.sdk.language.SimpleCompletionContributor"/>
<psi.referenceContributor implementation="com.intellij.sdk.language.SimpleReferenceContributor"/>
<lang.refactoringSupport language="Simple" implementationClass="com.intellij.sdk.language.SimpleRefactoringSupportProvider"/>
<lang.findUsagesProvider language="Simple" implementationClass="com.intellij.sdk.language.SimpleFindUsagesProvider"/>
<lang.foldingBuilder language="JAVA" implementationClass="com.intellij.sdk.language.SimpleFoldingBuilder"/>
<gotoSymbolContributor implementation="com.intellij.sdk.language.SimpleChooseByNameContributor"/>
<lang.psiStructureViewFactory language="Simple" implementationClass="com.intellij.sdk.language.SimpleStructureViewFactory"/>
<lang.formatter language="Simple" implementationClass="com.intellij.sdk.language.SimpleFormattingModelBuilder"/>
<codeStyleSettingsProvider implementation="com.intellij.sdk.language.SimpleCodeStyleSettingsProvider"/>
<langCodeStyleSettingsProvider implementation="com.intellij.sdk.language.SimpleLanguageCodeStyleSettingsProvider"/>
<lang.commenter language="Simple" implementationClass="com.intellij.sdk.language.SimpleCommenter"/>
<lang.parserDefinition language="Simple" implementationClass="org.intellij.sdk.language.SimpleParserDefinition"/>
<lang.syntaxHighlighterFactory language="Simple" implementationClass="org.intellij.sdk.language.SimpleSyntaxHighlighterFactory"/>
<colorSettingsPage implementation="org.intellij.sdk.language.SimpleColorSettingsPage"/>
<annotator language="JAVA" implementationClass="org.intellij.sdk.language.SimpleAnnotator"/>
<codeInsight.lineMarkerProvider language="JAVA" implementationClass="org.intellij.sdk.language.SimpleLineMarkerProvider"/>
<completion.contributor language="Simple" implementationClass="org.intellij.sdk.language.SimpleCompletionContributor"/>
<psi.referenceContributor implementation="org.intellij.sdk.language.SimpleReferenceContributor"/>
<lang.refactoringSupport language="Simple" implementationClass="org.intellij.sdk.language.SimpleRefactoringSupportProvider"/>
<lang.findUsagesProvider language="Simple" implementationClass="org.intellij.sdk.language.SimpleFindUsagesProvider"/>
<lang.foldingBuilder language="JAVA" implementationClass="org.intellij.sdk.language.SimpleFoldingBuilder"/>
<gotoSymbolContributor implementation="org.intellij.sdk.language.SimpleChooseByNameContributor"/>
<lang.psiStructureViewFactory language="Simple" implementationClass="org.intellij.sdk.language.SimpleStructureViewFactory"/>
<lang.formatter language="Simple" implementationClass="org.intellij.sdk.language.SimpleFormattingModelBuilder"/>
<codeStyleSettingsProvider implementation="org.intellij.sdk.language.SimpleCodeStyleSettingsProvider"/>
<langCodeStyleSettingsProvider implementation="org.intellij.sdk.language.SimpleLanguageCodeStyleSettingsProvider"/>
<lang.commenter language="Simple" implementationClass="org.intellij.sdk.language.SimpleCommenter"/>
</extensions>
</idea-plugin>

View File

@ -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() {

View File

@ -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

View File

@ -5,7 +5,7 @@ title: 7. Annotator
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.
* bullet item
* bullet list
{:toc}
## 7.1. Define an Annotator
@ -14,14 +14,14 @@ Consider a literal string that starts with "simple:" as a prefix of a Simple lan
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
{% include /code_samples/simple_language/src/main/java/com/intellij/sdk/language/SimpleAnnotator.java %}
{% include /code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleAnnotator.java %}
```
## 7.2. Register the Annotator
Using an extension point, register the Simple language annotator class with the IntelliJ Platform:
```xml
<extensions defaultExtensionNs="com.intellij">
<annotator language="JAVA" implementationClass="com.intellij.sdk.language.SimpleAnnotator"/>
<annotator language="JAVA" implementationClass="org.intellij.sdk.language.SimpleAnnotator"/>
</extensions>
```
@ -35,11 +35,11 @@ public class Test {
}
```
Open this Java file in an IDE Development Instance running the `simple_language` plugin to check if the IDE resolves a property:
Open this Java file in an IDE Development Instance running the `simple_language_plugin` to check if the IDE resolves a property:
![Annotator](img/annotator.png){:width="800px"}
If the property is an undefined name, the annotator will annotate the code with an error.
If the property is an undefined name, the annotator flags the code with an error.
![Unresolved property](img/unresolved_property.png){:width="800px"}

View File

@ -3,8 +3,8 @@ title: 16. Code Style Setting
---
[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, customised by a language code style settings provider.
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.
* bullet list
{:toc}
@ -12,35 +12,36 @@ This example creates a settings/preferences page that uses the default language
## 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/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
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/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
The `SimpleCodeStyleSettingsProvider` implementation is registered with the IntelliJ Platform in `plugin.xml` using the `codeStyleSettingsProvider` extension point.
The `SimpleCodeStyleSettingsProvider` implementation is registered with the IntelliJ Platform in the plugin configuration file using the `codeStyleSettingsProvider` extension point.
```xml
<extensions defaultExtensionNs="com.intellij">
<codeStyleSettingsProvider implementation="com.intellij.sdk.language.SimpleCodeStyleSettingsProvider"/>
<codeStyleSettingsProvider implementation="org.intellij.sdk.language.SimpleCodeStyleSettingsProvider"/>
</extensions>
```
## 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/com/simpleplugin/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
The `SimpleLanguageCodeStyleSettingsProvider` implementation is registered with the IntelliJ Platform in `plugin.xml` using the `langCodeStyleSettingsProvider` extension point.
The `SimpleLanguageCodeStyleSettingsProvider` implementation is registered with the IntelliJ Platform in the plugin configuration file using the `langCodeStyleSettingsProvider` extension point.
```xml
<extensions defaultExtensionNs="com.intellij">
<langCodeStyleSettingsProvider implementation="com.intellij.sdk.language.SimpleLanguageCodeStyleSettingsProvider"/>
<langCodeStyleSettingsProvider
implementation="org.intellij.sdk.language.SimpleLanguageCodeStyleSettingsProvider"/>
</extensions>
```

View File

@ -2,7 +2,7 @@
title: 17. Commenter
---
A commenter enables the user to comment out line of code at the cursor or selected code automatically.
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.
* bullet list
@ -12,14 +12,14 @@ The [`Commenter`](upsource:///platform/core-api/src/com/intellij/lang/Commenter.
The Simple language commenter subclasses `Commenter`.
This commenter defines the line comment prefix as "#".
```java
{% include /code_samples/simple_language/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
The `SimpleCommenter` implementation is registered with the IntelliJ Platform in `plugin.xml` using the `lang.commenter` extension point.
The `SimpleCommenter` implementation is registered with the IntelliJ Platform in the plugin configuration file using the `lang.commenter` extension point.
```xml
<extensions defaultExtensionNs="com.intellij">
<lang.commenter language="Simple" implementationClass="com.intellij.sdk.language.SimpleCommenter"/>
<lang.commenter language="Simple" implementationClass="org.intellij.sdk.language.SimpleCommenter"/>
</extensions>
```
@ -30,4 +30,4 @@ 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) {:width="800px"}
![Commenter](img/commenter.png){:width="800px"}

View File

@ -9,23 +9,24 @@ The Simple language plugin implements the less complex of the two methods, refer
{:toc}
## 9.1. Define a Completion Contributor
For the purposes of this tutorial, the `simple_language` plugin provides custom completion for values in Simple language property files.
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/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
The `SimpleCompletionContributor` implementation is registered with the IntelliJ Platform using the `completion.contributor` extension point.
The `SimpleCompletionContributor` implementation is registered in the plugin configuration file with the IntelliJ Platform using the `completion.contributor` extension point.
```xml
<extensions defaultExtensionNs="com.intellij">
<completion.contributor language="Simple" implementationClass="com.intellij.sdk.language.SimpleCompletionContributor"/>
<completion.contributor language="Simple"
implementationClass="org.intellij.sdk.language.SimpleCompletionContributor"/>
</extensions>
```
## 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.
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:

View File

@ -3,29 +3,30 @@ title: 11. Find Usages 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, defines the context for each word, and passes it to the find usage provider.
A scanner breaks the text into words and defines the context for each word.
* bullet list
{:toc}
## 11.1. Define a Find Usages Provider
The `SimpleFindUsagesProvider` is implements [`FindUsagesProvider`](upsource:///platform/indexing-api/src/com/intellij/lang/findUsages/FindUsagesProvider.java).
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/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
The `SimpleFindUsagesProvider` implementation is registered with the IntelliJ Platform using the `lang.findUsagesProvider` extension point.
The `SimpleFindUsagesProvider` implementation is registered with the IntelliJ Platform in the plugin configuration file using the `lang.findUsagesProvider` extension point.
```xml
<extensions defaultExtensionNs="com.intellij">
<lang.findUsagesProvider language="Simple" implementationClass="com.intellij.sdk.language.SimpleFindUsagesProvider"/>
<lang.findUsagesProvider language="Simple"
implementationClass="org.intellij.sdk.language.SimpleFindUsagesProvider"/>
</extensions>
```
## 11.3. Run the Project
Rebuild the project, and run `simple_language` in a Development Instance.
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:
![Find Usages](img/find_usages.png){:width="800px"}

View File

@ -3,38 +3,41 @@ title: 12. Folding Builder
---
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 will replace Simple language keys with their corresponding values.
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.
* bullet list
{:toc}
## 12.1. Define a Folding Builder
The `SimpleFoldingBuilder` will replace usages of properties with their values by default.
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`, which means the class is allowed to run in dumb mode, when indices are in background update.
Implementing `DumbAware` is required for successful operation and testing.
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 considered 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 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 is folded.
The IntelliJ Platform uses the value to substitute for the key when the code gets folded.
```java
{% include /code_samples/simple_language/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
The `SimpleFoldingBuilder` implementation is registered with the IntelliJ Platform using the `lang.foldingBuilder` extension point.
The `SimpleFoldingBuilder` implementation is registered with the IntelliJ Platform in the plugin configuration file using the `lang.foldingBuilder` extension point.
```xml
<extensions defaultExtensionNs="com.intellij">
<lang.foldingBuilder language="JAVA" implementationClass="com.intellij.sdk.language.SimpleFoldingBuilder"/>
<lang.foldingBuilder language="JAVA"
implementationClass="org.intellij.sdk.language.SimpleFoldingBuilder"/>
</extensions>
```
## 12.3. Run the Project
Rebuild the project, and run `simple_language` in a Development Instance.
Now when a Java file is opened in the Editor it shows the property's value instead of the key.
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.

View File

@ -10,25 +10,28 @@ The formatter controls spaces, indents, wrap, and alignment.
{:toc}
## 15.1. Define a Block
The formatting model builds 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 setting
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/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
Define a formatter which removes extra spaces except the single spaces around the property separator.
For example, reformat `foo = bar` to `foo = bar`.
Define a formatter that removes extra spaces except for the single spaces around the property separator.
For example, reformat "foo = &nbsp;&nbsp;&nbsp;&nbsp;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/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
The `SimpleFormattingModelBuilder` implementation is registered with the IntelliJ Platform in `plugin.xml` using the `lang.formatter` extension point.
The `SimpleFormattingModelBuilder` implementation is registered with the IntelliJ Platform in the plugin configuration file using the `lang.formatter` extension point.
```xml
<extensions defaultExtensionNs="com.intellij">
<lang.formatter language="Simple" implementationClass="com.intellij.sdk.language.SimpleFormattingModelBuilder"/>
<lang.formatter language="Simple"
implementationClass="org.intellij.sdk.language.SimpleFormattingModelBuilder"/>
</extensions>
```

View File

@ -2,14 +2,14 @@
title: 13. Go To Symbol Contributor
---
A go to symbol contributor helps the 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.
* 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 another components, it should implement `getPresentation()`.
This means defining this method in the utility `com.intellij.sdk.language.psi.impl.SimplePsiImplUtil` and regenerate the parser and PSI classes.
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) {
@ -36,30 +36,34 @@ public static ItemPresentation getPresentation(final SimpleProperty element) {
```
## 13.2. Update Grammar and Regenerate the Parser
Now add the `SimplePsiImplUtil.getPresentation()` to the `property` definition in the `Simple.bnf` grammar file by replacing the `property` definition with the lines below.
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**.
Right-click on the `Simple.bnf` file and select **Generate Parser Code**.
```java
property ::= (KEY? SEPARATOR VALUE?) | KEY {mixin="com.intellij.sdk.language.psi.impl.SimpleNamedElementImpl"
implements="com.intellij.sdk.language.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]
}
```
## 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 `SimpleChooseNameContributor`:
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/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
The `SimpleChooseByNameContributor` implementation is registered with the IntelliJ Platform using the `gotoSymbolContributor` extension point.
## 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
<extensions defaultExtensionNs="com.intellij">
<gotoSymbolContributor implementation="com.intellij.sdk.language.SimpleChooseByNameContributor"/>
<gotoSymbolContributor
implementation="org.intellij.sdk.language.SimpleChooseByNameContributor"/>
</extensions>
```
## 13.5. Run the project
Rebuild the project, and run `simple_language` in a Development Instance.
## 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.
![Go To Symbol](img/go_to_symbol.png){:width="800px"}

View File

@ -2,42 +2,42 @@
title: 3. Grammar and Parser
---
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 in order to generate a parser.
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 `com.intellij.sdk.language.psi` package (see the `simple_language` code sample) by subclassing `IElementType`.
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/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 the `SimpleElementType` in the `com.intellij.sdk.language.psi` package by subclassing `IElementType`.
Create the `SimpleElementType` in the `org.intellij.sdk.language.psi` package by subclassing `IElementType`.
```java
{% include /code_samples/simple_language/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 the Grammar
Define a grammar for the Simple language in the `com/intellij/sdk/language/Simple.bnf` file.
```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_*
@ -51,13 +51,13 @@ As shown, a properties file can contain properties, comments, and line breaks.
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 allows the IntelliJ Platform to still recognise incorrectly defined properties and provide corresponding code analysis and quick-fixes.
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.
## 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 will generate 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 is compiled without errors.
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.
![Parser](img/generated_parser.png){:width="800px"}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 42 KiB

After

Width:  |  Height:  |  Size: 47 KiB

View File

@ -4,16 +4,16 @@ 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.
The `LanguageFileType` is registered with the IntelliJ Platform in the plugin configuration file.
Register the `LanguageFileType` with the IntelliJ Platform in the plugin configuration file.
* 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 `com.intellij.sdk.language` package of the `simple_language` code sample:
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/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
@ -21,13 +21,13 @@ The [icon](https://raw.githubusercontent.com/JetBrains/intellij-sdk-docs/master/
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/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 FileType
The Simple language file type is defined by subclassing `LanguageFileType`:
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/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. Register the FileType Directly
@ -35,33 +35,33 @@ Direct registration is necessary when targeting version 2019.2 (and later) of th
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
<extensions defaultExtensionNs="com.intellij">
<fileType name="Simple file" implementationClass="com.intellij.sdk.language.SimpleFileType" fieldName="INSTANCE"
language="Simple" extensions="simple"/>
</extensions>
<extensions defaultExtensionNs="com.intellij">
<fileType name="Simple file" implementationClass="org.intellij.sdk.language.SimpleFileType"
fieldName="INSTANCE" language="Simple" extensions="simple"/>
</extensions>
```
Skip to [section 2.6](#26-run-the-project).
Skip to [section 2.6](#run-the-project).
## 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`.
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/src/main/java/com/intellij/sdk/language/SimpleFileTypeFactory.java %}
{% include /code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleFileTypeFactory.java %}
```
### 2.5.2 Register the FileType Factory
The `FileTypeFactory` is registered with the IntelliJ Platform using the `com.intellij.openapi.fileTypes.FileTypeFactory` extension point in `plugin.xml`.
The `SimpleFileTypeFactory` is registered with the IntelliJ Platform using the `com.intellij.openapi.fileTypes.FileTypeFactory` extension point in `plugin.xml`.
```xml
<extensions defaultExtensionNs="com.intellij">
<fileTypeFactory implementation="com.intellij.sdk.language.SimpleFileTypeFactory"/>
</extensions>
<extensions defaultExtensionNs="com.intellij">
<fileTypeFactory implementation="org.intellij.sdk.language.SimpleFileTypeFactory"/>
</extensions>
```
## 2.6. Run the Project
Create an empty file with the extension `\*.simple` and IntelliJ IDEA will automatically associate 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 in the editor tab for the file.
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.
![File Type Factory](img/file_type_factory.png){:width="800px"}

View File

@ -9,19 +9,19 @@ The easiest way to create a lexer is to use [JFlex](https://jflex.de/)
{:toc}
## 4.1. Define a Lexer
Define a `Simple.flex` file with rules for the Simple language lexer, as demonstrated in `com.intellij.sdk.language.Simple.flex`.
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/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
Now generate a lexer class via **JFlex Generator** from the context menu on `Simple.flex` file.
The Grammar-Kit plugin uses JFlex lexer generation.
When run for the first time, it prompts for a destination folder to download the JFlex library and skeleton.
Choose the project root directory, for example `code_samples/simple_language`.
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 under the `gen` directory, for example in `simple_language/src/main/gen/com/intellij/sdk/language/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`.
See [Implementing Lexer](/reference_guide/custom_language_support/implementing_lexer.md) for more information about using _JFlex_ with the IntelliJ Platform.
@ -29,33 +29,34 @@ See [Implementing Lexer](/reference_guide/custom_language_support/implementing_l
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/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
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/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
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/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
Registering the parser definition in the `plugin.xml` file makes it available to the IntelliJ Platform.
The `lang.parserDefinition` extension point is used for registration.
For example, see `simple_language/src/main/resources/META-INF/plugin.xml`.
Use the `lang.parserDefinition` extension point for registration.
For example, see `simple_language_plugin/src/main/resources/META-INF/plugin.xml`.
```xml
<extensions defaultExtensionNs="com.intellij">
<lang.parserDefinition language="Simple" implementationClass="com.intellij.sdk.language.SimpleParserDefinition"/>
<lang.parserDefinition language="Simple"
implementationClass="org.intellij.sdk.language.SimpleParserDefinition"/>
</extensions>
```
## 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:
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.

View File

@ -10,12 +10,12 @@ These markers can provide navigation targets to related code.
## 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 will be a Simple language icon in the gutter of the Editor window.
The visual marker is a Simple language icon in the gutter of the Editor window.
The Simple language marker provider is subclassed from [`RelatedItemLineMarkerProvider`](upsource:///platform/lang-api/src/com/intellij/codeInsight/daemon/RelatedItemLineMarkerProvider.java).
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/src/main/java/com/intellij/sdk/language/SimpleLineMarkerProvider.java %}
{% include /code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleLineMarkerProvider.java %}
```
## 8.2. Best Practices for Implementing Line Marker Providers
@ -45,7 +45,7 @@ For performance reasons, inspection, and specifically the [`LineMarkersPass`](up
* 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.
If providers return nothing for either area, the line markers are cleared.
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`.
@ -62,15 +62,16 @@ public class MyCorrectLineMarkerProvider implements LineMarkerProvider {
```
## 8.3. Register the Line Marker Provider
The `SimpleLineMarkerProvider` implementation is registered with the IntelliJ Platform using the `codeInsight.lineMarkerProvider` extension point.
The `SimpleLineMarkerProvider` implementation is registered with the IntelliJ Platform in the plugin configuration file using the `codeInsight.lineMarkerProvider` extension point.
```xml
<extensions defaultExtensionNs="com.intellij">
<codeInsight.lineMarkerProvider language="JAVA" implementationClass="com.intellij.sdk.language.SimpleLineMarkerProvider"/>
<codeInsight.lineMarkerProvider language="JAVA"
implementationClass="org.intellij.sdk.language.SimpleLineMarkerProvider"/>
</extensions>
```
## 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).
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.

View File

@ -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).

View File

@ -11,10 +11,9 @@ Helper classes and utilities can be embedded in the code generated by Grammar-Ki
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.sdk.language.psi.*;
public class SimplePsiImplUtil {
public static String getKey(SimpleProperty element) {
@ -47,20 +46,20 @@ Compare the last line of the grammar below to the [previous definition](/tutoria
```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="com.simpleplugin.psi.impl.SimplePsiImplUtil"
psiImplUtilClass="org.intellij.sdk.language.psi.impl.SimplePsiImplUtil"
}
simpleFile ::= item_*
@ -76,6 +75,6 @@ After making changes to the grammar, regenerate the parser and PSI classes.
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/src/main/java/com/intellij/sdk/language/SimpleUtil.java %}
{% include /code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleUtil.java %}
```

View File

@ -13,26 +13,26 @@ The `SimpleElementFactory` is updated to include two new methods to support the
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/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 `SimpleCreatePropertyQuickFix` will create 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`](/code_samples/conditional_operator_intention).
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/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
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.
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/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
Open the test [Java file](/tutorials/custom_language_support/annotator.md#run-the-project) in an IDE Development Instance running the `simple_language` plugin.
Open the test [Java file](/tutorials/custom_language_support/annotator.md#run-the-project) in an IDE Development Instance running the `simple_language_plugin`.
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.
@ -40,7 +40,7 @@ Choose "Create Property".
![Quick Fix](img/quick_fix.png){:width="800px"}
The IDE will open the `test.simple` file and add `website.url` as a new key.
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"}

View File

@ -18,7 +18,7 @@ The `SimpleNamedElementImpl` class implements the `SimpleNamedElement` interface
![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 will get added to the PSI class for Simple language.
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
@ -57,42 +57,64 @@ public class SimplePsiImplUtil {
## 10.3. Define an Element Factory
The `SimpleElementFactory` provides methods for creating `SimpleFile`.
```java
{% include /code_samples/simple_language/src/main/java/com/intellij/sdk/language/psi/SimpleElementFactory.java %}
package org.intellij.sdk.language.psi;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
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 SimpleFile createFile(Project project, String text) {
String name = "dummy.simple";
return (SimpleFile) PsiFileFactory.getInstance(project).
createFileFromText(name, SimpleFileType.INSTANCE, text);
}
}
```
## 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 line below.
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**.
Right-click on the `Simple.bnf` file and select **Generate Parser Code**.
```java
property ::= (KEY? SEPARATOR VALUE?) | KEY {mixin="com.intellij.sdk.language.psi.impl.SimpleNamedElementImpl"
implements="com.intellij.sdk.language.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]
}
```
## 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/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 the `simple_language` plugin to provide references to Simple language from elements in other languages such as Java.
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/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
The `SimpleReferenceContributor` implementation is registered with the IntelliJ Platform using the `psi.referenceContributor` extension point.
```xml
<extensions defaultExtensionNs="com.intellij">
<psi.referenceContributor implementation="com.intellij.sdk.language.SimpleReferenceContributor"/>
<psi.referenceContributor implementation="org.intellij.sdk.language.SimpleReferenceContributor"/>
</extensions>
```
## 10.8. Run the Project
Rebuild the project, and run `simple_language` in a Development Instance.
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:
![Reference Contributor](img/reference_contributor.png){:width="800px"}
@ -102,23 +124,24 @@ The [Rename refactoring](https://www.jetbrains.com/help/idea/rename-refactorings
![Rename](img/rename.png){:width="800px"}
## 10.9. Define a Refactoring Support Provider
To allow in-place refactoring it is specified explicitly in 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/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
The `SimpleRefactoringSupportProvider` implementation is registered with the IntelliJ Platform using the `lang.refactoringSupport` extension point.
The `SimpleRefactoringSupportProvider` implementation is registered with the IntelliJ Platform in the plugin configuration file using the `lang.refactoringSupport` extension point.
```xml
<extensions defaultExtensionNs="com.intellij">
<lang.refactoringSupport language="Simple" implementationClass="com.intellij.sdk.language.SimpleRefactoringSupportProvider"/>
<lang.refactoringSupport language="Simple"
implementationClass="org.intellij.sdk.language.SimpleRefactoringSupportProvider"/>
</extensions>
```
## 10.11. Run the Project
Rebuild the project, and run `simple_language` in a Development Instance.
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){:width="800px"}

View File

@ -9,18 +9,18 @@ Creating a structure view factory allows showing the structure of any file in a
{:toc}
## 14.1. Define a Structure View Factory
The structure view factory implements [`PsiStructureViewFactory`](upsource:///community/platform/editor-ui-api/src/com/intellij/lang/PsiStructureViewFactory.java).
The `getStructureViewBuilder()` implementation reuses the IntelliJ Platform class [`TreeBasedStructureViewBuilder`](upsource:///community/platform/editor-ui-api/src/com/intellij/ide/structureView/TreeBasedStructureViewBuilder.java).
At this point the project will not compile until `SimpleStructureViewModel` is implemented below.
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/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
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:///community/platform/editor-ui-api/src/com/intellij/ide/structureView/StructureViewModelBase.java), an implementation that links the model to a text editor.
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/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
@ -28,19 +28,20 @@ The `SimpleStructureViewElement` implements [`StructureViewTreeElement`](upsourc
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/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
The `SimpleStructureViewFactory` implementation is registered with the IntelliJ Platform in `plugin.xml` using the `lang.psiStructureViewFactory` extension point.
The `SimpleStructureViewFactory` implementation is registered with the IntelliJ Platform in the plugin configuration file using the `lang.psiStructureViewFactory` extension point.
```xml
<extensions defaultExtensionNs="com.intellij">
<lang.psiStructureViewFactory language="Simple" implementationClass="com.intellij.sdk.language.SimpleStructureViewFactory"/>
<lang.psiStructureViewFactory language="Simple"
implementationClass="org.intellij.sdk.language.SimpleStructureViewFactory"/>
</extensions>
```
## 14.5. Run the Project
Rebuild the project, and run `simple_language` in a Development Instance.
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:

View File

@ -4,7 +4,7 @@ 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` code sample.
The `SimpleSyntaxHighlighter`, `SimpleSyntaxHighlighterFactory`, and `SimpleColorSettingsPage` discussed on this page are demonstrated in the `simple_language_plugin` code sample.
* bullet list
{:toc}
@ -12,43 +12,45 @@ The `SimpleSyntaxHighlighter`, `SimpleSyntaxHighlighterFactory`, and `SimpleColo
## 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, only one scheme is defined.
For the Simple language, define only one scheme.
```java
{% include /code_samples/simple_language/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
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/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
The factory is registered with the IntelliJ Platform using the plugin configuration file.
Register the factory with the IntelliJ Platform in the plugin configuration file.
```xml
<extensions defaultExtensionNs="com.intellij">
<lang.syntaxHighlighterFactory language="Simple" implementationClass="com.intellij.sdk.language.SimpleSyntaxHighlighterFactory"/>
<lang.syntaxHighlighterFactory language="Simple"
implementationClass="org.intellij.sdk.language.SimpleSyntaxHighlighterFactory"/>
</extensions>
```
### 5.4. 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.
The colors for Simple Language Key, Separator, and Value highlighting default to the IDE _Language Defaults_ for Keyword, Braces and Operators, and String, respectively.
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){: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` extends `ColorSettingsPage`.
The `SimpleColorSettingsPage` implements [`ColorSettingsPage`](upsource:///platform/lang-api/src/com/intellij/openapi/options/colors/ColorSettingsPage.java).
```java
{% include /code_samples/simple_language/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
The settings page for Simple language colors is registered in the plugin configuration file as an extension.
The settings page for Simple language colors gets registered as an extension in the plugin configuration file.
```xml
<extensions defaultExtensionNs="com.intellij">
<colorSettingsPage implementation="com.intellij.sdk.language.SimpleColorSettingsPage"/>
<colorSettingsPage implementation="org.intellij.sdk.language.SimpleColorSettingsPage"/>
</extensions>
```

View File

@ -5,7 +5,7 @@ title: Custom Language Support Tutorial
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` code sample.
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)

View File

@ -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.

View File

@ -2,41 +2,39 @@
title: 3. Completion Test
---
This test checks if code completion, 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 an input Simple file `DefaultTestData.simple` for the test.
```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 an input java file `CompleteTestData.java` for the test.
```java
{% include /code_samples/simple_language_plugin/testData/CompleteTestData.java %}
{% include /code_samples/simple_language_plugin/src/test/testData/CompleteTestData.java %}
```
### 3.2. Define a test
## 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, `testCompletion()`.
```java
{% include /code_samples/simple_language_plugin/tests/com/simpleplugin/SimpleCodeInsightTest.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<String> strings = myFixture.getLookupElementStrings();
assertTrue(strings.containsAll(Arrays.asList("key with spaces", "language", "message", "tab", "website")));
assertEquals(5, strings.size());
}
}
```
### 3.3. Run the test
Run the test and make sure it's green.
## 3.3. Run the test
As [before](parsing_test.md#run-the-test), run the test and make sure it's green.

View File

@ -2,103 +2,57 @@
title: 2. Parsing Test
---
The first test checks 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, 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. Define input test data
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
## 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 mangled keys.
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**.
```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 a file *ParsingTestData.simple* 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` &rarr; `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/tests/com/simpleplugin/SimpleParsingTest.java %}
{% include /code_samples/simple_language_plugin/src/test/java/org/intellij/sdk/language/SimpleParsingTest.java %}
```
### 2.5. Run the test
Run the test and make sure it's green.
## 2.5. Run the test
Run the test by:
* Opening the Gradle Tool Window.
* Drill down to the `simple_language_plugin`.
You may need to reimport it as a Gradle project.
* Drill down under `simple_language_plugin` to the *test* task under *verification*.
* Run the *test* task.

View File

@ -2,38 +2,31 @@
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` &rarr; `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` &rarr; `Test Source Root`.
Similarly, mark the `testData` folder as a test resource root via the context menu `Mark Directory As` &rarr; `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
Since 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 we use the utility class [`LightJavaCodeInsightFixtureTestCase`](upsource:///java/testFramework/src/com/intellij/testFramework/fixtures/LightJavaCodeInsightFixtureTestCase.java) as the basis for our 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.
```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.