Java Code Examples for com.intellij.psi.tree.IElementType

The following are top voted examples for showing how to use com.intellij.psi.tree.IElementType. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: AppleScript-IDEA   File: ScopeUtil.java   Source Code and License 6 votes vote down vote up
@Nullable
public static PsiElement getMaxLocalScopeForTargetOrReference(PsiElement element) {
  if (element == null) {
    return null;
  }
  PsiElement currentScope;
  if (element instanceof AppleScriptTargetVariable
          || element instanceof AppleScriptReferenceElement) {
    //local scope: handler definition, current file, object declaration
    currentScope = element.getContext();
    boolean roofReached = false;
    while (!roofReached && currentScope != null) {
      IElementType elementType = currentScope.getNode().getElementType();
      roofReached = HANDLER_DEFINITIONS.contains(elementType)
              || elementType == AppleScriptParserDefinition.FILE
              || element == AppleScriptTypes.OBJECT_TARGET_PROPERTY_DECLARATION;//todo to check this
      currentScope = roofReached ? currentScope : currentScope.getContext();
    }
    return currentScope;
  }
  return null;
}
 
Example 2
Project: AppleScript-IDEA   File: KeywordCompletionContributor.java   Source Code and License 6 votes vote down vote up
public KeywordCompletionContributor() {

    extend(CompletionType.BASIC, psiElement().inFile(StandardPatterns.instanceOf(AppleScriptFile.class)),
        new CompletionProvider<CompletionParameters>() {
          @Override
          protected void addCompletions(@NotNull CompletionParameters completionParameters,
                                        ProcessingContext processingContext,
                                        @NotNull CompletionResultSet completionResultSet) {
            PsiFile file = completionParameters.getOriginalFile();
            if (!(file instanceof AppleScriptFile)) return;
            PsiElement position = completionParameters.getPosition();
            if (position instanceof PsiComment) return;

            ASTNode node = position.getNode();
            if (node.getElementType() == AppleScriptTypes.STRING_LITERAL) return;

            for (IElementType kwElem : AppleScriptTokenTypesSets.KEYWORDS.getTypes()) {
              completionResultSet.addElement(LookupElementBuilder
                  .create(kwElem.toString().toLowerCase().replaceAll("_", " ")).bold()
                  .withTypeText("keyword", true));
            }
          }
        });
  }
 
Example 3
Project: AppleScript-IDEA   File: AppleScriptPairedBraceMatcher.java   Source Code and License 6 votes vote down vote up
@Override
public boolean isRBraceToken(HighlighterIterator iterator, CharSequence fileText, FileType fileType) {
  BracePair pair = findPair(false, iterator, fileText, fileType);
  if (pair == null) return false;
  if (pair.getRightBraceType() != AppleScriptTypes.END)
    return super.isRBraceToken(iterator, fileText, fileType);//true;

  boolean result = false;
  int count = 0;
  while (true) {
    iterator.retreat();
    count++;
    if (iterator.atEnd()) break;
    IElementType eType = iterator.getTokenType();
    if (eType == AppleScriptTypes.NLS || eType == AppleScriptTypes.BLOCK_BODY)
      result = true;
    else break;
  }
  while (count-- > 0) iterator.advance();
  return result;
}
 
Example 4
Project: reasonml-idea-plugin   File: CommonParser.java   Source Code and License 6 votes vote down vote up
@Override
public void parseLight(IElementType elementType, PsiBuilder builder) {
    builder = adapt_builder_(elementType, builder, this, null);
    PsiBuilder.Marker m = enter_section_(builder, 0, _COLLAPSE_, null);


    ParserState parserState = new ParserState(new ParserScope(file, m_types.FILE_MODULE, null));
    parseFile(builder, parserState);

    // if we have a scope at last position in file, without SEMI, we need to handle it here
    if (!parserState.scopes.empty()) {
        ParserScope scope = parserState.scopes.pop();
        while (scope != null) {
            scope.end();
            scope = parserState.scopes.empty() ? null : parserState.scopes.pop();
        }
    }

    new ParserScope(file, m_types.FILE_MODULE, null).end();

    exit_section_(builder, 0, m, elementType, true, true, TRUE_CONDITION);
}
 
Example 5
Project: reasonml-idea-plugin   File: RmlParser.java   Source Code and License 6 votes vote down vote up
private void parseLt(PsiBuilder builder, ParserState parserState) {
    // Can be a symbol or a JSX tag
    IElementType nextTokenType = builder.rawLookup(1);
    if (nextTokenType == m_types.LIDENT || nextTokenType == m_types.UIDENT) {
        // Surely a tag
        builder.remapCurrentToken(m_types.TAG_LT);
        parserState.currentScope = markScope(builder, parserState.scopes, startTag, m_types.TAG_START, groupExpression, m_types.TAG_LT);
        parserState.currentScope.complete = true;

        builder.advanceLexer();
        parserState.dontMove = true;
        builder.remapCurrentToken(m_types.TAG_NAME);
    } else if (nextTokenType == m_types.SLASH) {
        builder.remapCurrentToken(m_types.TAG_LT);
        parserState.currentScope = markScope(builder, parserState.scopes, closeTag, m_types.TAG_CLOSE, any, m_types.TAG_LT);
        parserState.currentScope.complete = true;
    }
}
 
Example 6
Project: reasonml-idea-plugin   File: FoldingBuilder.java   Source Code and License 6 votes vote down vote up
@NotNull
@Override
public FoldingDescriptor[] buildFoldRegions(@NotNull PsiElement root, @NotNull Document document, boolean quick) {
    List<FoldingDescriptor> descriptors = new ArrayList<>();

    PsiTreeUtil.processElements(root, element -> {
        IElementType elementType = element.getNode().getElementType();
        MlTypes types = elementType.getLanguage() == RmlLanguage.INSTANCE ? RmlTypes.INSTANCE : OclTypes.INSTANCE;
        if (types.COMMENT == elementType) {
            FoldingDescriptor fold = fold(element);
            if (fold != null) {
                descriptors.add(fold);
            }
        } else if (types.TYPE_EXPRESSION == elementType) {
            foldType(descriptors, (PsiType) element);
        } else if (types.LET_EXPRESSION == elementType) {
            foldLet(descriptors, (PsiLet) element);
        } else if (types.MODULE_EXPRESSION == elementType) {
            foldModule(descriptors, (PsiModule) element);
        }
        return true;
    });

    return descriptors.toArray(new FoldingDescriptor[descriptors.size()]);
}
 
Example 7
Project: bamboo-soy   File: SoyLexer.java   Source Code and License 6 votes vote down vote up
@Override
public MergeFunction getMergeFunction() {
  return ((final IElementType type, final Lexer originalLexer) -> {
    if (type == SoyTypes.OTHER || type == TokenType.WHITE_SPACE) {
      IElementType returnType =  type;
      while (originalLexer.getTokenType() == SoyTypes.OTHER
          || originalLexer.getTokenType() == TokenType.WHITE_SPACE) {
        if (originalLexer.getTokenType() == SoyTypes.OTHER) {
          returnType = SoyTypes.OTHER;
        }
        originalLexer.advance();
      }
      return returnType;
    }

    return type;
  });
}
 
Example 8
Project: idea-php-dotenv-plugin   File: JsPsiHelper.java   Source Code and License 6 votes vote down vote up
/**
 * @param psiElement checking element
 * @return true if this is process.env.*** variable
 */
public static boolean checkPsiElement(@NotNull PsiElement psiElement) {
    if(!(psiElement instanceof LeafPsiElement)) {
        return false;
    }

    IElementType elementType = ((LeafPsiElement) psiElement).getElementType();
    if(!elementType.toString().equals("JS:IDENTIFIER")) {
        return false;
    }

    PsiElement parent = psiElement.getParent();
    if(!(parent instanceof JSReferenceExpression)) {
        return false;
    }

    return ((JSReferenceExpression) parent).getCanonicalText().startsWith("process.env");
}
 
Example 9
Project: intellij-postfix-templates   File: CptSyntaxHighlighter.java   Source Code and License 6 votes vote down vote up
@NotNull
@Override
public TextAttributesKey[] getTokenHighlights(IElementType tokenType) {
	if (tokenType.equals(CptTypes.SEPARATOR) || tokenType.equals(CptTypes.MAP)) {
		return SEPARATOR_KEYS;
	} else if (tokenType.equals(CptTypes.TEMPLATE_NAME)) {
		return TEMPLATE_NAME_KEYS;
	} else if (tokenType.equals(CptTypes.CLASS_NAME)) {
		return CLASS_NAME_KEYS;
	} else if (tokenType.equals(CptTypes.TEMPLATE_DESCRIPTION)) {
		return TEMPLATE_DESCRIPTION_KEYS;
	} else if (tokenType.equals(CptTypes.TEMPLATE_CODE)) {
		return TEMPLATE_CODE_KEYS;
	} else if (TEMPLATE_VARIABLE_PARTS.contains(tokenType)) {
		return TEMPLATE_VARIABLE_KEYS;
	} else if (tokenType.equals(CptTypes.TEMPLATE_ESCAPE)) {
		return TEMPLATE_ESCAPE_KEYS;
	} else if (tokenType.equals(CptTypes.COMMENT)) {
		return COMMENT_KEYS;
	} else if (tokenType.equals(TokenType.BAD_CHARACTER)) {
		return BAD_CHAR_KEYS;
	} else {
		return EMPTY_KEYS;
	}
}
 
Example 10
Project: hybris-integration-intellij-idea-plugin   File: CommonPsiUtils.java   Source Code and License 6 votes vote down vote up
@NotNull
@Contract(pure = true)
public static List<PsiElement> findChildrenByIElementType(
    @NotNull final PsiElement element,
    @NotNull final IElementType elementType
) {
    Validate.notNull(element);
    Validate.notNull(elementType);

    List<PsiElement> result = Collections.emptyList();
    ASTNode child = element.getNode().getFirstChildNode();

    while (child != null) {
        if (elementType == child.getElementType()) {
            if (result.isEmpty()) {
                result = new ArrayList<PsiElement>();
            }
            result.add(child.getPsi());
        }
        child = child.getTreeNext();
    }

    return result;
}
 
Example 11
Project: hybris-integration-intellij-idea-plugin   File: ImpexAnyHeaderParameterNameMixin.java   Source Code and License 6 votes vote down vote up
@NotNull
@Override
public final PsiReference[] getReferences() {
    final IElementType leafType = Optional.ofNullable(getFirstChild())
                                          .map(PsiElement::getNode)
                                          .map(ASTNode::getElementType)
                                          .orElse(null);

    if (ImpexTypes.MACRO_USAGE.equals(leafType)) {
        return new PsiReference[]{new ImpexMacrosReferenceBase(this)};
    }

    //optimisation: dont even try for macro's and documents
    if (!ImpexTypes.HEADER_PARAMETER_NAME.equals(leafType)) {
        return PsiReference.EMPTY_ARRAY;
    }
    if (myReference == null) {
        myReference = new TypeSystemAttributeReference(this);
    }
    return new PsiReference[]{myReference};
}
 
Example 12
Project: sercapnp   File: CapnpSyntaxHighlighter.java   Source Code and License 6 votes vote down vote up
@NotNull
@Override
public TextAttributesKey[] getTokenHighlights(IElementType tokenType) {
    if (tokenType.equals(CapnpTypes.SEPARATOR)) {
        return SEPARATOR_KEYS;

    } else if (tokenType.equals(CapnpTypes.IDENTIFIER)){
        return IDENTIFIER_KEYS;
    } else if (tokenType.equals(CapnpTypes.KEYWORD)) {
        return KEY_KEYS;
    } else if (tokenType.equals(CapnpTypes.TYPE)) {
        return TYPE_KEYS;
    } else if (tokenType.equals(CapnpTypes.COMMENT)) {
        return COMMENT_KEYS;
    } else if (tokenType.equals(TokenType.BAD_CHARACTER)) {
        return BAD_CHAR_KEYS;
    } else {
        return EMPTY_KEYS;
    }
}
 
Example 13
Project: AppleScript-IDEA   File: AppleScriptComponentScopeResolver.java   Source Code and License 5 votes vote down vote up
@Nullable
private PsiElement getHandlerDefinitionScope(PsiElement scopeElement) {
  PsiElement currentScope = scopeElement;
  while (currentScope != null) {
    IElementType elementType = currentScope.getNode().getElementType();
    if (HANDLER_DEFINITIONS.contains(elementType)) {
      return currentScope;
    }
    currentScope = currentScope.getContext();
  }
  return null;
}
 
Example 14
Project: AppleScript-IDEA   File: AppleScriptComponentScopeResolver.java   Source Code and License 5 votes vote down vote up
private boolean isInsideHandlerDefinition(PsiElement context) {
  while (context != null) {
    IElementType elementType = context.getNode().getElementType();
    if (HANDLER_DEFINITIONS.contains(elementType)) {
      return true;
    }
    context = context.getContext();
  }
  return false;
}
 
Example 15
Project: AppleScript-IDEA   File: AppleScriptGeneratedParserUtil.java   Source Code and License 5 votes vote down vote up
/**
 * @return true if this is the application reference of a &lt;tell&gt; or &lt;using terms
 * from&gt; statements
 */
public static boolean isTellStatementStart(PsiBuilder b, int l) {
  if (!isInTellStatement(b, l + 1)) return false;
  int i = -1;
  IElementType prevElem = b.rawLookup(i);
  while (prevElem == com.intellij.psi.TokenType.WHITE_SPACE || prevElem == MY
          || prevElem == APPLICATION || prevElem == STRING_LITERAL || prevElem == null
          || prevElem == ID) {
    prevElem = b.rawLookup(--i);
  }
  return prevElem == TELL
          || (b.getUserData(IS_PARSING_USING_TERMS_FROM_STATEMENT) == Boolean.TRUE)
          && prevElem == FROM;
}
 
Example 16
Project: AppleScript-IDEA   File: AppleScriptIndentProcessor.java   Source Code and License 5 votes vote down vote up
Indent getChildIndent(final ASTNode node) {
  final IElementType elementType = node.getElementType();

  if (elementType == BLOCK_BODY || elementType == TOP_BLOCK_BODY || elementType == SCRIPT_BODY) {
    return Indent.getNormalIndent();
  }

  return Indent.getNoneIndent();
}
 
Example 17
Project: AppleScript-IDEA   File: AppleScriptWrappingProcessor.java   Source Code and License 5 votes vote down vote up
Wrap createChildWrap(ASTNode child, Wrap defaultWrap, Wrap childWrap) {
  final IElementType childType = child.getElementType();
  final IElementType elementType = myNode.getElementType();

  if (childType == COMMA) return defaultWrap;

  return defaultWrap;
}
 
Example 18
Project: AppleScript-IDEA   File: AppleScriptNamesValidator.java   Source Code and License 5 votes vote down vote up
private IElementType getTokenType(String name) {
  AppleScriptLexerAdapter lexer = new AppleScriptLexerAdapter();
  lexer.start(name);
  IElementType tt = lexer.getTokenType();
  lexer.advance();
  return lexer.getTokenType() == null ? tt : null;
}
 
Example 19
Project: AppleScript-IDEA   File: AppleScriptPsiImplUtil.java   Source Code and License 5 votes vote down vote up
public static String getSelectorName(AppleScriptArgumentSelector argumentSelector) {
  final StringBuilder result = new StringBuilder();
  ASTNode child = argumentSelector.getNode().getFirstChildNode();
  while (child != null) {
    final IElementType tt = child.getElementType();
    if (tt == AppleScriptTypes.IDENTIFIER || tt == AppleScriptTypes.COLON) {
      result.append(child.getText());
    }
    child = child.getTreeNext();
  }
  return result.toString();
}
 
Example 20
Project: AppleScript-IDEA   File: AppleScriptLexerTest.java   Source Code and License 5 votes vote down vote up
public void testLexerTest() {
  AppleScriptLexerAdapter lexer = new AppleScriptLexerAdapter();
  CharSequence ch = "the \"My string\"";
  lexer.start(ch);
  IElementType tt = lexer.getTokenType();
  assertTrue(tt == AppleScriptTypes.THE_KW);
  lexer.advance();
  tt = lexer.getTokenType();
  assertTrue(tt == TokenType.WHITE_SPACE);
  lexer.advance();
  tt = lexer.getTokenType();
  assertTrue(tt == AppleScriptTypes.STRING_LITERAL);
}
 
Example 21
Project: reasonml-idea-plugin   File: CommonParser.java   Source Code and License 5 votes vote down vote up
@Override
@NotNull
public ASTNode parse(@NotNull IElementType elementType, @NotNull PsiBuilder builder) {
    //builder.setDebugMode(true);

    //System.out.println("start parsing");
    //long start = System.currentTimeMillis();

    parseLight(elementType, builder);
    ASTNode treeBuilt = builder.getTreeBuilt();

    //long end = System.currentTimeMillis();
    //System.out.println("end parsing in " + (end - start) + "ms");
    return treeBuilt;
}
 
Example 22
Project: reasonml-idea-plugin   File: RmlParser.java   Source Code and License 5 votes vote down vote up
private void parseLBracket(PsiBuilder builder, ParserState parserState) {
    IElementType nextTokenType = builder.rawLookup(1);
    if (nextTokenType == m_types.ARROBASE) {
        parserState.currentScope = markScope(builder, parserState.scopes, annotation, m_types.ANNOTATION_EXPRESSION, scopeExpression, m_types.LBRACKET);
    } else if (nextTokenType == m_types.PERCENT) {
        parserState.currentScope = markScope(builder, parserState.scopes, macro, m_types.MACRO_EXPRESSION, scopeExpression, m_types.LBRACKET);
    } else {
        parserState.currentScope = markScope(builder, parserState.scopes, bracket, m_types.SCOPED_EXPR, scopeExpression, m_types.LBRACKET);
    }
}
 
Example 23
Project: reasonml-idea-plugin   File: OclParser.java   Source Code and License 5 votes vote down vote up
private void parseLBracket(PsiBuilder builder, ParserState parserState) {
    IElementType nextTokenType = builder.rawLookup(1);
    if (nextTokenType == m_types.ARROBASE) {
        // This is an annotation
        parserState.currentScope = markScope(builder, parserState.scopes, annotation, m_types.ANNOTATION_EXPRESSION, scopeExpression, m_types.LBRACKET);
    } else {
        parserState.currentScope = markScope(builder, parserState.scopes, bracket, m_types.SCOPED_EXPR, scopeExpression, m_types.LBRACKET);
    }
}
 
Example 24
Project: reasonml-idea-plugin   File: ParserState.java   Source Code and License 5 votes vote down vote up
@Nullable
public ParserScope endUntilScopeExpression(IElementType scopeElementType) {
    ParserScope scope = null;

    if (!scopes.empty()) {
        scope = scopes.peek();
        while (scope != null && scope.scopeType != scopeExpression && (scopeElementType == null || scope.scopeElementType != scopeElementType)) {
            scopes.pop().end();
            scope = getLatestScope();
        }
    }

    return scope;
}
 
Example 25
Project: reasonml-idea-plugin   File: FoldingBuilder.java   Source Code and License 5 votes vote down vote up
@Nullable
@Override
public String getPlaceholderText(@NotNull ASTNode node) {
    IElementType elementType = node.getElementType();
    if (elementType == RmlTypes.INSTANCE.COMMENT) {
        return "/*...*/";
    } else if (elementType == OclTypes.INSTANCE.COMMENT) {
        return "(*...*)";
    }

    return "{...}";
}
 
Example 26
Project: intellij-csv-validator   File: CsvBlock.java   Source Code and License 5 votes vote down vote up
@Override
protected List<Block> buildChildren() {
    List<ASTNode> todoNodes = new ArrayList<>();
    List<Block> blocks = new ArrayList<>();
    todoNodes.add(getNode().getFirstChildNode());
    CsvBlockField currentField = null;
    while (todoNodes.size() > 0) {
        ASTNode node = todoNodes.remove(todoNodes.size() - 1);
        if (node == null) {
            continue;
        }
        
        IElementType elementType = node.getElementType();
        todoNodes.add(node.getTreeNext());
        if (elementType == CsvTypes.RECORD) {
            todoNodes.add(node.getFirstChildNode());
        } else if (elementType == CsvTypes.FIELD) {
            currentField = new CsvBlockField(node, formattingInfo);
            if (currentField.getTextLength() > 0) {
                blocks.add(currentField);
            }
        } else if (elementType == CsvTypes.COMMA || elementType == CsvTypes.CRLF) {
            blocks.add(new CsvBlockElement(node, formattingInfo, currentField));
        } else if (elementType != TokenType.WHITE_SPACE && node.getTextLength() > 0) {
            blocks.add(new CsvDummyBlock(node, formattingInfo));
        }
    }
    return blocks;
}
 
Example 27
Project: Goal-Intellij-Plugin   File: PrologTypes.java   Source Code and License 5 votes vote down vote up
public static PsiElement createElement(ASTNode node) {
  IElementType type = node.getElementType();
   if (type == CALLABLE) {
    return new PrologCallableImpl(node);
  }
  else if (type == CLAUSE) {
    return new PrologClauseImpl(node);
  }
  else if (type == DIRECTIVE_CLAUSE) {
    return new PrologDirectiveClauseImpl(node);
  }
  else if (type == LIST) {
    return new PrologListImpl(node);
  }
  else if (type == NUMBER) {
    return new PrologNumberImpl(node);
  }
  else if (type == OPERATOR) {
    return new PrologOperatorImpl(node);
  }
  else if (type == PREDICATE) {
    return new PrologPredicateImpl(node);
  }
  else if (type == PREDICATE_SPEC) {
    return new PrologPredicateSpecImpl(node);
  }
  else if (type == STRING) {
    return new PrologStringImpl(node);
  }
  else if (type == TERM) {
    return new PrologTermImpl(node);
  }
  else if (type == TERM_LIST) {
    return new PrologTermListImpl(node);
  }
  else if (type == VARIABLE_LIST) {
    return new PrologVariableListImpl(node);
  }
  throw new AssertionError("Unknown element type: " + type);
}
 
Example 28
Project: bamboo-soy   File: SoyParserUtil.java   Source Code and License 5 votes vote down vote up
@Override
public int getEdgePosition(List<IElementType> tokens, boolean atStreamEdge,
    TokenTextGetter getter) {
  int newLinesFound = 0;
  for (int i = tokens.size() - 1; i > 0; i--) {
    if (tokens.get(i) == DOC_COMMENT_BLOCK) {
      return i;
    }
    newLinesFound += countNewlines(getter.get(i));
    if (newLinesFound > 1) {
      break;
    }
  }
  return tokens.size();
}
 
Example 29
Project: bamboo-soy   File: SoyParserUtil.java   Source Code and License 5 votes vote down vote up
/**
 * Matches a closing tag iff there is frame in the stack which it may close.
 */
public static boolean parseEndOfStatementBlock(PsiBuilder builder, int level) {
  if (!nextTokenIs(builder, "", LBRACE_SLASH, LBRACE_LBRACE_SLASH)) {
    return false;
  }
  Marker marker = enter_section_(builder);
  boolean r = consumeToken(builder, LBRACE_SLASH) || consumeToken(builder, LBRACE_LBRACE_SLASH);

  IElementType block = null;
  for (IElementType token : closingTokenToBlock.keySet()) {
    if (consumeToken(builder, token)) {
      block = closingTokenToBlock.get(token);
      break;
    }
  }
  if (block == null) {
    // None of the expected closing tags found.
    exit_section_(builder, marker, null, false);
    return false;
  }

  Frame frame = ErrorState.get(builder).currentFrame;
  while (frame != null) {
    if (frame.elementType == block) {
      // Found a frame that matches the closing tag.
      exit_section_(builder, marker, null, true);
      return true;
    }
    frame = frame.parentFrame;
  }

  // No matching frame found.
  exit_section_(builder, marker, null, false);
  return false;
}
 
Example 30
Project: idea-php-dotenv-plugin   File: DotEnvTypes.java   Source Code and License 5 votes vote down vote up
public static PsiElement createElement(ASTNode node) {
  IElementType type = node.getElementType();
   if (type == COMMENT) {
    return new DotEnvCommentImpl(node);
  }
  else if (type == EMPTY_LINE) {
    return new DotEnvEmptyLineImpl(node);
  }
  else if (type == PROPERTY) {
    return new DotEnvPropertyImpl(node);
  }
  throw new AssertionError("Unknown element type: " + type);
}
 
Example 31
Project: intellij-csv-validator   File: CsvStructureViewElement.java   Source Code and License 5 votes vote down vote up
protected PsiElement createEmptyPsiField() {
    final String text = "<undefined>";
    final IElementType type = CsvTypes.FIELD;
    final Project project = this.element.getProject();
    final PsiManager psiManager = PsiManager.getInstance(project);
    final DummyHolder dummyHolder = DummyHolderFactory.createHolder(psiManager, null);
    final FileElement fileElement = dummyHolder.getTreeElement();
    final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(CsvLanguage.INSTANCE);
    final Lexer lexer = parserDefinition.createLexer(project);
    final PsiBuilder psiBuilder = PsiBuilderFactory.getInstance().createBuilder(project, fileElement, lexer, CsvLanguage.INSTANCE, text);
    final ASTNode node = parserDefinition.createParser(project).parse(type, psiBuilder);
    fileElement.rawAddChildren((com.intellij.psi.impl.source.tree.TreeElement)node);
    return node.getPsi();
}
 
Example 32
Project: EmojiPrefix   File: EmojiResourceParser.java   Source Code and License 5 votes vote down vote up
public void parseLight(IElementType t, PsiBuilder b) {
  boolean r;
  b = adapt_builder_(t, b, this, null);
  Marker m = enter_section_(b, 0, _COLLAPSE_, null);
  if (t == PROPERTY) {
    r = property(b, 0);
  }
  else {
    r = parse_root_(t, b, 0);
  }
  exit_section_(b, 0, m, t, r, true, TRUE_CONDITION);
}
 
Example 33
Project: EmojiPrefix   File: EmojiResourceTypes.java   Source Code and License 5 votes vote down vote up
public static PsiElement createElement(ASTNode node) {
  IElementType type = node.getElementType();
   if (type == PROPERTY) {
    return new EmojiResourcePropertyImpl(node);
  }
  throw new AssertionError("Unknown element type: " + type);
}
 
Example 34
Project: EmojiPrefix   File: EmojiResourceSyntaxHighlighter.java   Source Code and License 5 votes vote down vote up
@NotNull
@Override
public TextAttributesKey[] getTokenHighlights(IElementType type) {
	if (textAttrMap.containsKey(type)) {
		return textAttrMap.get(type);
	}
	return EMPTY_KEYS;
}
 
Example 35
Project: intellij-postfix-templates   File: CptParser.java   Source Code and License 5 votes vote down vote up
public void parseLight(IElementType t, PsiBuilder b) {
  boolean r;
  b = adapt_builder_(t, b, this, null);
  Marker m = enter_section_(b, 0, _COLLAPSE_, null);
  if (t == MAPPING) {
    r = mapping(b, 0);
  }
  else if (t == MAPPINGS) {
    r = mappings(b, 0);
  }
  else if (t == REPLACEMENT) {
    r = replacement(b, 0);
  }
  else if (t == TEMPLATE) {
    r = template(b, 0);
  }
  else if (t == TEMPLATE_CODE_G) {
    r = templateCodeG(b, 0);
  }
  else if (t == TEMPLATE_VARIABLE) {
    r = templateVariable(b, 0);
  }
  else if (t == TEMPLATE_VARIABLE_EXPRESSION_G) {
    r = templateVariableExpressionG(b, 0);
  }
  else if (t == TEMPLATE_VARIABLE_NAME_G) {
    r = templateVariableNameG(b, 0);
  }
  else if (t == TEMPLATE_VARIABLE_VALUE_G) {
    r = templateVariableValueG(b, 0);
  }
  else {
    r = parse_root_(t, b, 0);
  }
  exit_section_(b, 0, m, t, r, true, TRUE_CONDITION);
}
 
Example 36
Project: intellij-postfix-templates   File: CptTypes.java   Source Code and License 5 votes vote down vote up
public static PsiElement createElement(ASTNode node) {
  IElementType type = node.getElementType();
   if (type == MAPPING) {
    return new CptMappingImpl(node);
  }
  else if (type == MAPPINGS) {
    return new CptMappingsImpl(node);
  }
  else if (type == REPLACEMENT) {
    return new CptReplacementImpl(node);
  }
  else if (type == TEMPLATE) {
    return new CptTemplateImpl(node);
  }
  else if (type == TEMPLATE_CODE_G) {
    return new CptTemplateCodeGImpl(node);
  }
  else if (type == TEMPLATE_VARIABLE) {
    return new CptTemplateVariableImpl(node);
  }
  else if (type == TEMPLATE_VARIABLE_EXPRESSION_G) {
    return new CptTemplateVariableExpressionGImpl(node);
  }
  else if (type == TEMPLATE_VARIABLE_NAME_G) {
    return new CptTemplateVariableNameGImpl(node);
  }
  else if (type == TEMPLATE_VARIABLE_VALUE_G) {
    return new CptTemplateVariableValueGImpl(node);
  }
  throw new AssertionError("Unknown element type: " + type);
}
 
Example 37
Project: intellij-postfix-templates   File: CptBlock.java   Source Code and License 5 votes vote down vote up
@Override
protected List<Block> buildChildren() {
	List<Block> blocks = new ArrayList<>();
	ASTNode child = myNode.getFirstChildNode();
	while (child != null) {
		final IElementType elementType = child.getElementType();

		final Indent indent = elementType == CptTypes.MAPPINGS
			? Indent.getNormalIndent()
			: Indent.getNoneIndent();

		final Indent childIndent = _Set(CptTypes.TEMPLATE,CptTypes.MAPPINGS, CptTypes.MAPPING, CptTypes.REPLACEMENT,
			CptTypes.TEMPLATE_ESCAPE, CptTypes.TEMPLATE_CODE, CptTypes.TEMPLATE_VARIABLE).contains(elementType)
			? Indent.getNormalIndent()
			: Indent.getNoneIndent();

		if (elementType != TokenType.WHITE_SPACE) {
			Alignment alignment = null; //Alignment.createAlignment();

			/*
			if (elementType == CptTypes.MAP) {
				alignment = mapAlignment;
			}
			*/

			Block block = new CptBlock(child, Wrap.createWrap(WrapType.NONE, false), indent, childIndent, alignment, spacingBuilder);
			blocks.add(block);
		}

		child = child.getTreeNext();
	}
	return blocks;
}
 
Example 38
Project: hybris-integration-intellij-idea-plugin   File: FlexibleSearchSyntaxHighlighter.java   Source Code and License 5 votes vote down vote up
@NotNull
@Override
public TextAttributesKey[] getTokenHighlights(IElementType tokenType) {
    if (KEYWORD_TOKEN_SET.contains(tokenType)) {
        return KEYWORD_KEYS;
    } else if (tokenType.equals(FlexibleSearchTypes.STRING)) {
        return STRING_KEYS;
    } else if (SYMBOL_TOKEN_SET.contains(tokenType)) {
        return SYMBOL_KEYS;
    } else if (COLUMN_TOKEN_SET.contains(tokenType)) {
        return COLUMN_KEYS;
    } else if (TABLE_NAME_TOKEN_SET.contains(tokenType)) {
        return TABLE_KEYS;
    } else if (BRACES_TOKEN_SET.contains(tokenType)) {
        return BRACES_KEYS;
    } else if (BRACKETS_TOKEN_SET.contains(tokenType)) {
        return BRACKETS_KEYS;
    } else if (PARENTHESES_TOKEN_SET.contains(tokenType)) {
        return PARENTHESES_KEYS;
    } else if (tokenType.equals(FlexibleSearchTypes.NUMBER)) {
        return NUMBER_KEYS;
    } else if (tokenType.equals(FlexibleSearchParserDefinition.COMMENT)) {
        return COMMENT_KEYS;
    } else if (tokenType.equals(TokenType.BAD_CHARACTER)) {
        return BAD_CHARACTER_KEYS;
    } else {
        return EMPTY_KEYS;
    }
}
 
Example 39
Project: intellij-csv-validator   File: CsvValidationInspection.java   Source Code and License 5 votes vote down vote up
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
    return new PsiElementVisitor() {
        @Override
        public void visitElement(PsiElement element) {
            if (element == null || !holder.getFile().getLanguage().isKindOf(CsvLanguage.INSTANCE)) {
                return;
            }
            
            IElementType elementType = CsvIntentionHelper.getElementType(element);
            PsiElement firstChild = element.getFirstChild();
            PsiElement nextSibling = element.getNextSibling();
            if (elementType == TokenType.ERROR_ELEMENT && CsvIntentionHelper.getElementType(firstChild) == TokenType.BAD_CHARACTER) {
                if (firstChild.getText().equals("\"")) {
                    holder.registerProblem(element, UNESCAPED_SEQUENCE, fixUnescapedSequence);
                } else {
                    holder.registerProblem(element, SEPARATOR_MISSING, fixSeparatorMissing);
                    holder.registerProblem(element, UNESCAPED_SEQUENCE, fixUnescapedSequence);
                }
            } else if ((elementType == CsvTypes.TEXT || elementType == CsvTypes.ESCAPED_TEXT)
                    && CsvIntentionHelper.getElementType(nextSibling) == TokenType.ERROR_ELEMENT
                    && nextSibling.getFirstChild() == null) {
                holder.registerProblem(element, CLOSING_QUOTE_MISSING, fixClosingQuoteMissing);
            }
        }
    };
}
 
Example 40
Project: intellij-crystal   File: CrystalTypes.java   Source Code and License 5 votes vote down vote up
public static PsiElement createElement(ASTNode node) {
  IElementType type = node.getElementType();
   if (type == PROPERTY) {
    return new CrystalPropertyImpl(node);
  }
  throw new AssertionError("Unknown element type: " + type);
}
 
Example 41
Project: idea-onescript   File: OneScriptSyntaxHighlighter.java   Source Code and License 5 votes vote down vote up
@NotNull
@Override
public TextAttributesKey[] getTokenHighlights(IElementType iElementType) {
    if (iElementType.equals(OneScriptTypes.COMMENT)) {
        return COMMENT_KEYS;
    } else if (iElementType.equals(TokenType.BAD_CHARACTER)) {
        return BAD_CHAR_KEYS;
    } else if (iElementType.equals(OneScriptTypes.STRING)
            || iElementType.equals(OneScriptTypes.STRINGSTART)
            || iElementType.equals(OneScriptTypes.STRINGPART)
            || iElementType.equals(OneScriptTypes.STRINGTAIL)) {
        return STRING_KEYS;
    } else if (iElementType.equals(OneScriptTypes.DATETIME)) {
        return DATETIME_KEYS;
    } else if (iElementType.equals(OneScriptTypes.COMPILER_DIRECTIVE)) {
        return COMPILER_DIRECTIVE_KEYS;
    } else if (iElementType.equals(OneScriptTypes.USING)) {
        return USING_DIRECTIVE_KEYS;
    } else if (iElementType.equals(OneScriptTypes.PREPROCESSOR)) {
        return PREPROCESSOR_DIRECTIVE_KEYS;
    } else if (iElementType.equals(OneScriptTypes.BOOLEAN_TRUE)
            || iElementType.equals(OneScriptTypes.BOOLEAN_FALSE)
            || iElementType.equals(OneScriptTypes.UNDEFINED)
            || iElementType.equals(OneScriptTypes.NULL)) {
        return LITERAL_CONSTANT_KEYS;
    } else if (iElementType.toString().endsWith("_KEYWORD")) {
        return KEYWORD_KEYS;
    } else {
        return new TextAttributesKey[0];
    }
}
 
Example 42
Project: intellij-csv-validator   File: CsvBlock.java   Source Code and License 4 votes vote down vote up
public final IElementType getElementType() {
    return getNode().getElementType();
}
 
Example 43
Project: TS-IJ   File: TSBraceMatcher.java   Source Code and License 4 votes vote down vote up
@Override
public boolean isPairedBracesAllowedBeforeType(@NotNull IElementType lbraceType, @Nullable IElementType contextType) {
    return true;
}
 
Example 44
Project: AppleScript-IDEA   File: AppleScriptSpacingProcessor.java   Source Code and License 4 votes vote down vote up
Spacing getSpacing(@Nullable AppleScriptBlock child1, @NotNull AppleScriptBlock child2) {
  if (child1 == null) {
    return null;
  }
  final ASTNode node = child2.getNode();
  _init(node);

  final ASTNode node1 = child1.getNode();
  final IElementType type1 = node1.getElementType();
  final ASTNode node2 = child2.getNode();
  final IElementType parent2 = node2.getTreeParent().getElementType();
  final IElementType type2 = node2.getElementType();

  if (LCURLY == type1 || RCURLY == type2) return Spacing.createSpacing(0, 0, 0, true, 0);

  // handlerCall(params)
  if (LPAREN == type2 && HANDLER_POSITIONAL_PARAMETERS_CALL_EXPRESSION == parent2) {
    return addSingleSpaceIf(mySettings.SPACE_BEFORE_METHOD_CALL_PARENTHESES, false);
  }
  if (LPAREN == type2 && HANDLER_POSITIONAL_PARAMETERS_DEFINITION == parent2) {
    return addSingleSpaceIf(mySettings.SPACE_BEFORE_METHOD_PARENTHESES, false);
  }

  if (IF == type1 && LPAREN == type2) {
    return addSingleSpaceIf(mySettings.SPACE_BEFORE_IF_PARENTHESES, false);
  }

  if (LPAREN == type1 || RPAREN == type2) return Spacing.createSpacing(0, 0, 0, true, 0);

  if (COMMA == type2) return Spacing.createSpacing(0, 0, 0, true, 0);

  if (type1 == IDENTIFIER && type2 == HANDLER_PARAMETER_LABEL) {
    return Spacing.createSpacing(1, 1, 0, true, 0);
  }

  if (type2 == COLON) return Spacing.createSpacing(0, 0, 0, true, 0);

  if ((KEYWORDS.contains(type1) || HANDLER_PARAMETER_LABEL == type1) && NLS != type2) {
    return Spacing.createSpacing(1, 1, 0, true, 0);
  }
  if (BAND == type1 || BAND == type2) {
    return Spacing.createSpacing(1, 1, 0, true, 0);
  }

  return null;
}
 
Example 45
Project: Goal-Intellij-Plugin   File: ActionSpecTypes.java   Source Code and License 4 votes vote down vote up
public static PsiElement createElement(ASTNode node) {
  IElementType type = node.getElementType();
   if (type == ACTION_SPEC) {
    return new ActionSpecActionSpecImpl(node);
  }
  else if (type == AS_CLAUSE) {
    return new ActionSpecAsClauseImpl(node);
  }
  else if (type == ATOM_IDENTIFIER) {
    return new ActionSpecAtomIdentifierImpl(node);
  }
  else if (type == BASIC_TERM) {
    return new ActionSpecBasicTermImpl(node);
  }
  else if (type == CALLABLE) {
    return new ActionSpecCallableImpl(node);
  }
  else if (type == FILE_REFERENCE) {
    return new ActionSpecFileReferenceImpl(node);
  }
  else if (type == IDENTIFIER) {
    return new ActionSpecIdentifierImpl(node);
  }
  else if (type == LIST) {
    return new ActionSpecListImpl(node);
  }
  else if (type == NUMBER) {
    return new ActionSpecNumberImpl(node);
  }
  else if (type == OPERATOR) {
    return new ActionSpecOperatorImpl(node);
  }
  else if (type == PREDICATE) {
    return new ActionSpecPredicateImpl(node);
  }
  else if (type == STRING) {
    return new ActionSpecStringImpl(node);
  }
  else if (type == TERM) {
    return new ActionSpecTermImpl(node);
  }
  else if (type == TERM_LIST) {
    return new ActionSpecTermListImpl(node);
  }
  else if (type == USAGE) {
    return new ActionSpecUsageImpl(node);
  }
  else if (type == USE_CLAUSE) {
    return new ActionSpecUseClauseImpl(node);
  }
  throw new AssertionError("Unknown element type: " + type);
}
 
Example 46
Project: AppleScript-IDEA   File: AppleScriptNamesValidator.java   Source Code and License 4 votes vote down vote up
private boolean isKeyword(String name) {
  IElementType tokenType = getTokenType(name);
  return AppleScriptTokenTypesSets.KEYWORDS.contains(tokenType);
}
 
Example 47
Project: AppleScript-IDEA   File: AppleScriptPairedBraceMatcher.java   Source Code and License 4 votes vote down vote up
@Override
public boolean isPairedBracesAllowedBeforeType(@NotNull IElementType lbraceType, @Nullable IElementType
    contextType) {
  return true;
}
 
Example 48
Project: AppleScript-IDEA   File: AppleScriptSyntaxHighlighter.java   Source Code and License 4 votes vote down vote up
@NotNull
@Override
public TextAttributesKey[] getTokenHighlights(IElementType tokenType) {
  return pack(ATTRIBUTES.get(tokenType));
}
 
Example 49
Project: AppleScript-IDEA   File: AppleScriptCommenter.java   Source Code and License 4 votes vote down vote up
@Nullable
@Override
public IElementType getLineCommentTokenType() {
  return null;
}
 
Example 50
Project: AppleScript-IDEA   File: AppleScriptCommenter.java   Source Code and License 4 votes vote down vote up
@Nullable
@Override
public IElementType getBlockCommentTokenType() {
  return null;
}
 
Example 51
Project: AppleScript-IDEA   File: AppleScriptCommenter.java   Source Code and License 4 votes vote down vote up
@Nullable
@Override
public IElementType getDocumentationCommentTokenType() {
  return null;
}
 
Example 52
Project: AppleScript-IDEA   File: AppleScriptParser.java   Source Code and License 4 votes vote down vote up
public ASTNode parse(IElementType t, PsiBuilder b) {
  parseLight(t, b);
  return b.getTreeBuilt();
}
 
Example 53
Project: AppleScript-IDEA   File: AppleScriptParser.java   Source Code and License 4 votes vote down vote up
protected boolean parse_root_(IElementType t, PsiBuilder b, int l) {
  return appleScriptFile(b, l + 1);
}
 
Example 54
Project: Goal-Intellij-Plugin   File: ModuleParser.java   Source Code and License 4 votes vote down vote up
protected boolean parse_root_(IElementType t, PsiBuilder b, int l) {
  return moduleFile(b, l + 1);
}
 
Example 55
Project: reasonml-idea-plugin   File: CommonParser.java   Source Code and License 4 votes vote down vote up
protected ParserScope markComplete(PsiBuilder builder, Stack<ParserScope> scopes, ParserScopeEnum resolution, IElementType tokenType) {
    ParserScope scope = mark(builder, scopes, resolution, tokenType);
    scope.complete = true;
    return scope;
}
 
Example 56
Project: reasonml-idea-plugin   File: CommonParser.java   Source Code and License 4 votes vote down vote up
protected ParserScope markScope(PsiBuilder builder, Stack<ParserScope> scopes, ParserScopeEnum resolution, IElementType tokenType, ParserScopeType scopeType, IElementType scopeElementType) {
    ParserScope scope = mark(builder, scopes, resolution, tokenType);
    scope.scopeType = scopeType;
    scope.scopeElementType = scopeElementType;
    return scope;
}
 
Example 57
Project: reasonml-idea-plugin   File: CommonParser.java   Source Code and License 4 votes vote down vote up
protected ParserScope markCompleteScope(PsiBuilder builder, Stack<ParserScope> scopes, ParserScopeEnum resolution, IElementType tokenType, ParserScopeType scopeType, IElementType scopeElementType) {
    ParserScope scope = markScope(builder, scopes, resolution, tokenType, scopeType, scopeElementType);
    scope.complete = true;
    return scope;
}
 
Example 58
Project: reasonml-idea-plugin   File: CommonParser.java   Source Code and License 4 votes vote down vote up
protected boolean wrapWith(IElementType elementType, PsiBuilder builder) {
    PsiBuilder.Marker mark = builder.mark();
    advance(builder);
    mark.done(elementType);
    return true;
}
 
Example 59
Project: reasonml-idea-plugin   File: RmlParser.java   Source Code and License 4 votes vote down vote up
@Override
protected void parseFile(PsiBuilder builder, ParserState parserState) {
    IElementType tokenType = null;

    int c = current_position_(builder);
    while (true) {
        parserState.previousTokenType = tokenType;
        tokenType = builder.getTokenType();
        if (tokenType == null) {
            break;
        }

        if (tokenType == m_types.SEMI) {
            parseSemi(builder, parserState);
        } else if (tokenType == m_types.EQ) {
            parseEq(parserState);
        } else if (tokenType == m_types.ARROW) {
            parseArrow(builder, parserState);
        } else if (tokenType == m_types.TRY) {
            parseTry(builder, parserState);
        } else if (tokenType == m_types.SWITCH) {
            parseSwitch(builder, parserState);
        } else if (tokenType == m_types.LIDENT) {
            parseLIdent(builder, parserState);
        } else if (tokenType == m_types.UIDENT) {
            parseUIdent(builder, parserState);
        } else if (tokenType == m_types.ARROBASE) {
            parseArrobase(builder, parserState);
        } else if (tokenType == m_types.PERCENT) {
            parsePercent(builder, parserState);
        }
        // ( ... )
        else if (tokenType == m_types.LPAREN) {
            parseLParen(builder, parserState);
        } else if (tokenType == m_types.RPAREN) {
            parseRParen(builder, parserState);
        }
        // { ... }
        else if (tokenType == m_types.LBRACE) {
            parseLBrace(builder, parserState);
        } else if (tokenType == m_types.RBRACE) {
            parseRBrace(builder, parserState);
        }
        // [ ... ]
        else if (tokenType == m_types.LBRACKET) {
            parseLBracket(builder, parserState);
        } else if (tokenType == m_types.RBRACKET) {
            parseRBracket(builder, parserState);
        }
        // < ... >
        else if (tokenType == m_types.LT) {
            parseLt(builder, parserState);
        } else if (tokenType == m_types.GT || tokenType == m_types.TAG_AUTO_CLOSE) {
            parseGtAutoClose(builder, parserState);
        }
        // Starts an expression
        else if (tokenType == m_types.OPEN) {
            parseOpen(builder, parserState);
        } else if (tokenType == m_types.EXTERNAL) {
            parseExternal(builder, parserState);
        } else if (tokenType == m_types.TYPE) {
            parseType(builder, parserState);
        } else if (tokenType == m_types.MODULE) {
            parseModule(builder, parserState);
        } else if (tokenType == m_types.LET) {
            parseLet(builder, parserState);
        }

        if (parserState.dontMove) {
            parserState.dontMove = false;
        } else {
            builder.advanceLexer();
        }

        if (!empty_element_parsed_guard_(builder, "reasonFile", c)) {
            break;
        }

        c = builder.rawTokenIndex();
    }
}
 
Example 60
Project: Goal-Intellij-Plugin   File: MasParser.java   Source Code and License 4 votes vote down vote up
public void parseLight(IElementType t, PsiBuilder b) {
  boolean r;
  b = adapt_builder_(t, b, this, null);
  Marker m = enter_section_(b, 0, _COLLAPSE_, null);
  if (t == AGENT_BLOCK) {
    r = agentBlock(b, 0);
  }
  else if (t == CONSTRAINT) {
    r = constraint(b, 0);
  }
  else if (t == CONSTRAINT_LIST) {
    r = constraintList(b, 0);
  }
  else if (t == ENTITY) {
    r = entity(b, 0);
  }
  else if (t == ENVIRONMENT_PROPERTY) {
    r = environmentProperty(b, 0);
  }
  else if (t == ENVIRONMENT_PROPERTY_LIST) {
    r = environmentPropertyList(b, 0);
  }
  else if (t == ENVIRONMENT_SPEC) {
    r = environmentSpec(b, 0);
  }
  else if (t == IDENTIFIER) {
    r = identifier(b, 0);
  }
  else if (t == INSTRUCTION) {
    r = instruction(b, 0);
  }
  else if (t == INSTRUCTION_LIST) {
    r = instructionList(b, 0);
  }
  else if (t == LAUNCH_POLICY) {
    r = launchPolicy(b, 0);
  }
  else if (t == LAUNCH_RULE) {
    r = launchRule(b, 0);
  }
  else if (t == MAS_FILE) {
    r = masFile(b, 0);
  }
  else if (t == MODULE_ID) {
    r = moduleId(b, 0);
  }
  else if (t == MODULE_STRING) {
    r = moduleString(b, 0);
  }
  else if (t == NUMBER_LITERAL) {
    r = numberLiteral(b, 0);
  }
  else if (t == SIMPLE_IDENTIFIER) {
    r = simpleIdentifier(b, 0);
  }
  else if (t == STRING) {
    r = string(b, 0);
  }
  else if (t == USE_CASE) {
    r = useCase(b, 0);
  }
  else if (t == USE_CLAUSE) {
    r = useClause(b, 0);
  }
  else {
    r = parse_root_(t, b, 0);
  }
  exit_section_(b, 0, m, t, r, true, TRUE_CONDITION);
}