Java Code Examples for com.intellij.lang.ASTNode.getElementType()

The following are Jave code examples for showing how to use getElementType() of the com.intellij.lang.ASTNode class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: intellij-csv-validator   File: CsvFormatHelper.java   Source Code and License Vote up 6 votes
public static Map<Integer, CsvColumnInfo<ASTNode>> createColumnInfoMap(ASTNode root, CodeStyleSettings settings) {
    Map<Integer, CsvColumnInfo<ASTNode>> columnInfoMap = new HashMap<>();
    ASTNode child = root.getFirstChildNode();
    while (child != null) {
        if (child.getElementType() == CsvTypes.RECORD) {
            Integer column = 0;
            ASTNode subChild = child.getFirstChildNode();
            while (subChild != null) {
                if (subChild.getElementType() == CsvTypes.FIELD) {
                    int length = getTextLength(subChild, settings);
                    if (!columnInfoMap.containsKey(column)) {
                        columnInfoMap.put(column, new CsvColumnInfo(column, length));
                    } else if (columnInfoMap.get(column).getMaxLength() < length) {
                        columnInfoMap.get(column).setMaxLength(length);
                    }
                    columnInfoMap.get(column).addElement(subChild);
                    ++column;
                }
                subChild = subChild.getTreeNext();
            }
        }
        child = child.getTreeNext();
    }
    return columnInfoMap;
}
 
Example 2
Project: greycat-idea-plugin   File: GCMFoldingBuilder.java   Source Code and License Vote up 6 votes
private void appendDescriptors(final ASTNode node, final Document document, final List<FoldingDescriptor> descriptors) {
    if (node.getElementType() == GCMTypes.CLASS_DECLARATION || node.getElementType() == GCMTypes.CUSTOM_TYPE_DECLARATION) {
        TextRange fullRange = node.getTextRange();
        if (fullRange.getEndOffset() - fullRange.getStartOffset() > 0) {

            try {
                int startOffset = fullRange.getStartOffset() + document.getText(fullRange).indexOf("{") + 1;
                int endOffset = fullRange.getEndOffset() - 1;
                if (startOffset < endOffset) {
                    TextRange shortRange = new TextRange(startOffset, fullRange.getEndOffset() - 1);
                    if (shortRange.getEndOffset() - shortRange.getStartOffset() > 1) {
                        descriptors.add(new FoldingDescriptor(node, shortRange));
                    }
                }
            } catch (Throwable e) {

            }
        }
    }
    ASTNode child = node.getFirstChildNode();
    while (child != null) {
        appendDescriptors(child, document, descriptors);
        child = child.getTreeNext();
    }
}
 
Example 3
Project: hybris-integration-intellij-idea-plugin   File: FlexibleSearchBlock.java   Source Code and License Vote up 6 votes
@Override
protected List<Block> buildChildren() {
    List<Block> blocks = new ArrayList<>();
    ASTNode child = myNode.getFirstChildNode();
    while (child != null) {
        if (child.getElementType() != TokenType.WHITE_SPACE) {

            Block block = new FlexibleSearchBlock(
                child,
                Wrap.createWrap(WrapType.NONE, false),
                null,
                spacingBuilder
            );

            blocks.add(block);
        }
        child = child.getTreeNext();
    }
    return blocks;
}
 
Example 4
Project: intellij-crystal   File: CrystalTypes.java   Source Code and License Vote up 5 votes
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 5
Project: AppleScript-IDEA   File: AppleScriptPsiImplUtil.java   Source Code and License Vote up 5 votes
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 6
Project: intellij-csv-validator   File: CsvBlock.java   Source Code and License Vote up 5 votes
@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 7
Project: reasonml-idea-plugin   File: FoldingBuilder.java   Source Code and License Vote up 5 votes
@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 8
Project: idea-php-dotenv-plugin   File: DotEnvTypes.java   Source Code and License Vote up 5 votes
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 9
Project: intellij-postfix-templates   File: CptTypes.java   Source Code and License Vote up 5 votes
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 10
Project: intellij-postfix-templates   File: CptBlock.java   Source Code and License Vote up 5 votes
@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 11
Project: intellij-csv-validator   File: CsvBlockField.java   Source Code and License Vote up 5 votes
@Override
protected List<Block> buildChildren() {
    ASTNode node = this.getNode().getFirstChildNode();
    List<Block> blocks = new ArrayList<>();
    while (node != null) {
        if (node.getElementType() != TokenType.WHITE_SPACE) {
            CsvBlockElement block = new CsvBlockElement(node, formattingInfo, this);
            blocks.add(block);
        }
        node = node.getTreeNext();
    }
    return blocks;
}
 
Example 12
Project: AppleScript-IDEA   File: AppleScriptSpacingProcessor.java   Source Code and License Vote up 4 votes
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 13
Project: Goal-Intellij-Plugin   File: ActionSpecTypes.java   Source Code and License Vote up 4 votes
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 14
Project: reasonml-idea-plugin   File: PsiElementFactory.java   Source Code and License Vote up 4 votes
public static PsiElement createElement(MlTypes types, ASTNode node) {
    IElementType type = node.getElementType();

    if (type == types.EXTERNAL_EXPRESSION) {
        return new PsiExternalImpl(types, node);
    } else if (type == types.EXCEPTION_EXPRESSION) {
        return new PsiExceptionImpl(node);
    } else if (type == types.EXCEPTION_NAME) {
        return new PsiExceptionNameImpl(node);
    } else if (type == types.OPEN_EXPRESSION) {
        return new PsiOpenImpl(types, node);
    } else if (type == types.INCLUDE_EXPRESSION) {
        return new PsiIncludeImpl(types, node);
    } else if (type == types.TYPE_EXPRESSION) {
        return new PsiTypeImpl(types, node);
    } else if (type == types.TYPE_CONSTR_NAME) {
        return new PsiTypeNameImpl(types, node);
    } else if (type == types.MODULE_EXPRESSION) {
        return new PsiModuleImpl(node);
    } else if (type == types.MODULE_NAME) {
        return new PsiModuleNameImpl(types, node);
    } else if (type == types.MODULE_PATH) {
        return new PsiModulePath(node);
    } else if (type == types.LET_EXPRESSION) {
        return new PsiLetImpl(node);
    } else if (type == types.VAL_EXPRESSION) {
        return new PsiValImpl(types, node);
    } else if (type == types.ANNOTATION_EXPRESSION) {
        return new PsiAnnotation(node);
    } else if (type == types.FUN_BODY) {
        return new PsiFunBody(node);
    } else if (type == types.LET_BINDING) {
        return new PsiLetBinding(node);
    } else if (type == types.MACRO_NAME) {
        return new PsiMacroName(node);
    } else if (type == types.SCOPED_EXPR || type == types.OBJECT_EXPR || type == types.PATTERN_MATCH_EXPR) {
        return new PsiScopedExpr(node);
    } else if (type == types.SIG_SCOPE) {
        return new PsiSignatureImpl(node);
    } else if (type == types.TAG_START) {
        return new PsiTagStart(node);
    } else if (type == types.TAG_PROPERTY) {
        return new PsiTagPropertyImpl(types, node);
    } else if (type == types.TAG_CLOSE) {
        return new PsiTagClose(node);
    } else if (type == types.VAR_NAME) {
        return new PsiVarNameImpl(types, node);
    }

    return new PsiToken(node);
}
 
Example 15
Project: hybris-integration-intellij-idea-plugin   File: ColumnsAlignmentStrategy.java   Source Code and License Vote up 4 votes
@Contract(pure = true)
private boolean isNewColumn(@Nullable final ASTNode currentNode) {
    return null != currentNode && ImpexTypes.VALUE_GROUP == currentNode.getElementType();
}
 
Example 16
Project: hybris-integration-intellij-idea-plugin   File: ColumnsAlignmentStrategy.java   Source Code and License Vote up 4 votes
@Contract(pure = true)
private boolean isNewLine(@Nullable final ASTNode currentNode) {
    return null != currentNode
           && ImpexTypes.VALUE_GROUP == currentNode.getElementType()
           && isStartOfValueLine(currentNode);
}
 
Example 17
Project: hybris-integration-intellij-idea-plugin   File: ImpexTypes.java   Source Code and License Vote up 4 votes
public static PsiElement createElement(ASTNode node) {
  IElementType type = node.getElementType();
   if (type == ANY_ATTRIBUTE_NAME) {
    return new ImpexAnyAttributeNameImpl(node);
  }
  else if (type == ANY_ATTRIBUTE_VALUE) {
    return new ImpexAnyAttributeValueImpl(node);
  }
  else if (type == ANY_HEADER_MODE) {
    return new ImpexAnyHeaderModeImpl(node);
  }
  else if (type == ANY_HEADER_PARAMETER_NAME) {
    return new ImpexAnyHeaderParameterNameImpl(node);
  }
  else if (type == ATTRIBUTE) {
    return new ImpexAttributeImpl(node);
  }
  else if (type == BEAN_SHELL) {
    return new ImpexBeanShellImpl(node);
  }
  else if (type == COMMENT) {
    return new ImpexCommentImpl(node);
  }
  else if (type == FULL_HEADER_PARAMETER) {
    return new ImpexFullHeaderParameterImpl(node);
  }
  else if (type == FULL_HEADER_TYPE) {
    return new ImpexFullHeaderTypeImpl(node);
  }
  else if (type == HEADER_LINE) {
    return new ImpexHeaderLineImpl(node);
  }
  else if (type == HEADER_TYPE_NAME) {
    return new ImpexHeaderTypeNameImpl(node);
  }
  else if (type == MACRO_DECLARATION) {
    return new ImpexMacroDeclarationImpl(node);
  }
  else if (type == MACRO_NAME_DEC) {
    return new ImpexMacroNameDecImpl(node);
  }
  else if (type == MACRO_USAGE_DEC) {
    return new ImpexMacroUsageDecImpl(node);
  }
  else if (type == MODIFIERS) {
    return new ImpexModifiersImpl(node);
  }
  else if (type == PARAMETER) {
    return new ImpexParameterImpl(node);
  }
  else if (type == PARAMETERS) {
    return new ImpexParametersImpl(node);
  }
  else if (type == ROOT_MACRO_USAGE) {
    return new ImpexRootMacroUsageImpl(node);
  }
  else if (type == STRING) {
    return new ImpexStringImpl(node);
  }
  else if (type == SUB_PARAMETERS) {
    return new ImpexSubParametersImpl(node);
  }
  else if (type == VALUE) {
    return new ImpexValueImpl(node);
  }
  else if (type == VALUE_GROUP) {
    return new ImpexValueGroupImpl(node);
  }
  else if (type == VALUE_LINE) {
    return new ImpexValueLineImpl(node);
  }
  throw new AssertionError("Unknown element type: " + type);
}
 
Example 18
Project: Goal-Intellij-Plugin   File: TestTypes.java   Source Code and License Vote up 4 votes
public static PsiElement createElement(ASTNode node) {
  IElementType type = node.getElementType();
   if (type == AGENT_DEF) {
    return new TestAgentDefImpl(node);
  }
  else if (type == BASIC_TERM) {
    return new TestBasicTermImpl(node);
  }
  else if (type == EVENTUALLY_RULE) {
    return new TestEventuallyRuleImpl(node);
  }
  else if (type == FILE_REFERENCE) {
    return new TestFileReferenceImpl(node);
  }
  else if (type == IDENTIFIER) {
    return new TestIdentifierImpl(node);
  }
  else if (type == LEADSTO_RULE) {
    return new TestLeadstoRuleImpl(node);
  }
  else if (type == LIST) {
    return new TestListImpl(node);
  }
  else if (type == MOOD) {
    return new TestMoodImpl(node);
  }
  else if (type == NUMBER) {
    return new TestNumberImpl(node);
  }
  else if (type == PREDICATE) {
    return new TestPredicateImpl(node);
  }
  else if (type == QUERY) {
    return new TestQueryImpl(node);
  }
  else if (type == QUERY_LIST) {
    return new TestQueryListImpl(node);
  }
  else if (type == RULE) {
    return new TestRuleImpl(node);
  }
  else if (type == STRING) {
    return new TestStringImpl(node);
  }
  else if (type == TERM) {
    return new TestTermImpl(node);
  }
  else if (type == TERM_LIST) {
    return new TestTermListImpl(node);
  }
  else if (type == TEST_MODULE) {
    return new TestTestModuleImpl(node);
  }
  else if (type == TIMEOUT_DEF) {
    return new TestTimeoutDefImpl(node);
  }
  else if (type == USAGE) {
    return new TestUsageImpl(node);
  }
  else if (type == USE_CLAUSE) {
    return new TestUseClauseImpl(node);
  }
  throw new AssertionError("Unknown element type: " + type);
}
 
Example 19
Project: hybris-integration-intellij-idea-plugin   File: ImpexBlock.java   Source Code and License Vote up 4 votes
@Override
protected List<Block> buildChildren() {
    final List<Block> blocks = new ArrayList<Block>();

    final AlignmentStrategy alignmentStrategy = getAlignmentStrategy();
    alignmentStrategy.processNode(myNode);

    ASTNode currentNode = myNode.getFirstChildNode();

    while (null != currentNode) {

        // Unpack 'Value Line' as columns will not be aligned if they do not share the same parent
        if (ImpexTypes.VALUE_LINE == currentNode.getElementType()) {
            currentNode = currentNode.getFirstChildNode();
        }

        alignmentStrategy.processNode(currentNode);

        if (isNotWhitespaceOrNewLine(currentNode)
            && !isCurrentNodeHasParentValue(currentNode)) {

            final Block block = new ImpexBlock(
                currentNode,
                null,
                alignmentStrategy.getAlignment(currentNode),
                spacingBuilder
            );

            blocks.add(block);
        }

        // Unpack Value Line
        if (isEndOfValueLine(currentNode)) {
            currentNode = currentNode.getTreeParent().getTreeNext();
        } else {
            currentNode = currentNode.getTreeNext();
        }
    }

    return blocks;
}
 
Example 20
Project: hybris-integration-intellij-idea-plugin   File: ColumnsAlignmentStrategy.java   Source Code and License Vote up 4 votes
@Contract(pure = true)
private boolean isHeaderLine(@Nullable final ASTNode currentNode) {
    return null != currentNode && ImpexTypes.HEADER_LINE == currentNode.getElementType();
}