Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0
div
classnavigation
HTML Table
width100%
Table Row (tr)
Table Cell (td)
Align
alignleft
Previous
span
classsep
|
span
classtext
Syntax Highlighter and Color Settings Page
Table Cell (td)
Align
aligncenter
Top
span
classsep
|
span
classtext
Custom Language Support
Table Cell (td) Align
alignright
Next
span
classsep
|
span
classtext
Annotator Wiki Markup
{div:class=navigation}
{table:width=100%}
 {tr}
  {td} {align:left}[Previous|Syntax Highlighter and Color Settings Page] {span:class=sep}\|{span} {span:class=text}Syntax Highlighter and Color Settings Page{span}{align} {td}
  {td} {align:center}[Top|Custom Language Support] {span:class=sep}\|{span} {span:class=text}Custom Language Support{span}{align} {td}
  {td} {align:right}[Next|Annotator] {span:class=sep}\|{span} {span:class=text}Annotator{span}{align} {td}
 {tr}
{table}
{div}

1. Define helper methods for generated PSI elements

...

Now we tell to use this utility class in the grammar file via

stubParserClass
span
classid
Wiki Markup
{span:class=id}stubParserClass{span}
attribute.

To tell which methods for which PSI classes must be used we specify

span
classid
Wiki Markup
{span:class=id}\{methods=\[...\]\}{span}
for particular rule.

Code Block
{
  parserClass="com.simpleplugin.parser.SimpleParser"

  extends="com.intellij.extapi.psi.ASTWrapperPsiElement"

  psiClassPrefix="Simple"
  psiImplClassSuffix="Impl"
  psiPackage="com.simpleplugin.psi"
  psiImplPackage="com.simpleplugin.psi.impl"

  elementTypeHolderClass="com.simpleplugin.psi.SimpleTypes"
  elementTypeClass="com.simpleplugin.psi.SimpleElementType"
  tokenTypeClass="com.simpleplugin.psi.SimpleTokenType"

  psiImplUtilClass="com.simpleplugin.psi.impl.SimplePsiImplUtil"
}

simpleFile ::= item_*

private item_ ::= (property|COMMENT|CRLF)

property ::= (KEY? SEPARATOR VALUE?) | KEY {methods=[getKey getValue]}

...

Code Block
package com.simpleplugin;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiManager;
import com.intellij.psi.search.FileTypeIndex;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.indexing.FileBasedIndex;
import com.simpleplugin.psi.SimpleFile;
import com.simpleplugin.psi.SimpleProperty;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

public class SimpleUtil {
    public static List<SimpleProperty> findProperties(Project project, String key) {
        List<SimpleProperty> result = null;
        Collection<VirtualFile> virtualFiles = FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, SimpleFileType.INSTANCE,
                GlobalSearchScope.allScope(project));
        for (VirtualFile virtualFile : virtualFiles) {
            SimpleFile simpleFile = (SimpleFile) PsiManager.getInstance(project).findFile(virtualFile);
            if (simpleFile != null) {
                SimpleProperty[] properties = PsiTreeUtil.getChildrenOfType(simpleFile, SimpleProperty.class);
                if (properties != null) {
                    for (SimpleProperty property : properties) {
                        if (key.equals(property.getKey())) {
                            if (result == null) {
                                result = new ArrayList<SimpleProperty>();
                            }
                            result.add(property);
                        }
                    }
                }
            }
        }
        return result != null ? result : Collections.<SimpleProperty>emptyList();
    }

    public static List<SimpleProperty> findProperties(Project project) {
        List<SimpleProperty> result = new ArrayList<SimpleProperty>();
        Collection<VirtualFile> virtualFiles = FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, SimpleFileType.INSTANCE,
                GlobalSearchScope.allScope(project));
        for (VirtualFile virtualFile : virtualFiles) {
            SimpleFile simpleFile = (SimpleFile) PsiManager.getInstance(project).findFile(virtualFile);
            if (simpleFile != null) {
                SimpleProperty[] properties = PsiTreeUtil.getChildrenOfType(simpleFile, SimpleProperty.class);
                if (properties != null) {
                    Collections.addAll(result, properties);
                }
            }
        }
        return result;
    }
}
div
classnavigation
HTML Table
width100%
Table Row (tr)
Table Cell (td)
Align
alignleft
Previous
span
classsep
|
span
classtext
Syntax Highlighter and Color Settings Page
Table Cell (td)
Align
aligncenter
Top
span
classsep
|
span
classtext
Custom Language Support
Table Cell (td) Align
alignright
Next
span
classsep
|
span
classtext
Annotator Wiki Markup
{div:class=navigation}
{table:width=100%}
 {tr}
  {td} {align:left}[Previous|Syntax Highlighter and Color Settings Page] {span:class=sep}\|{span} {span:class=text}Syntax Highlighter and Color Settings Page{span}{align} {td}
  {td} {align:center}[Top|Custom Language Support] {span:class=sep}\|{span} {span:class=text}Custom Language Support{span}{align} {td}
  {td} {align:right}[Next|Annotator] {span:class=sep}\|{span} {span:class=text}Annotator{span}{align} {td}
 {tr}
{table}
{div}