Java 类com.intellij.psi.TokenType 实例源码

项目:AppleScript-IDEA    文件:AbstractDictionaryConstantSpecifier.java   
@Override
public List<PsiElement> getIdentifiers() {
  final List<PsiElement> result = new ArrayList<>();
  PsiElement psiChild = getFirstChild();
  if (psiChild == null) {
    result.add(this);
    return result;
  }
  while (psiChild != null) {
    if (psiChild.getNode().getElementType() != TokenType.WHITE_SPACE) {
      result.add(psiChild);
    }
    psiChild = psiChild.getNextSibling();
  }
  return result;
}
项目:AppleScript-IDEA    文件:DictionaryCompositeNameImpl.java   
@Override
public List<PsiElement> getIdentifiers() {
  final List<PsiElement> result = new ArrayList<>();
  PsiElement psiChild = getFirstChild();
  if (psiChild == null) {
    result.add(this);
    return result;
  }
  while (psiChild != null) {
    if (psiChild.getNode().getElementType() != TokenType.WHITE_SPACE) {
      result.add(psiChild);
    }
    psiChild = psiChild.getNextSibling();
  }
  return result;
}
项目:greycat-idea-plugin    文件:GCMBlock.java   
@Override
protected List<Block> buildChildren() {
    List<Block> blocks = new ArrayList<Block>();
    Alignment innerBodyAlignment = Alignment.createAlignment();
    ASTNode child = getNode().getFirstChildNode();
    while (child != null) {
        if (child.getElementType() != TokenType.WHITE_SPACE) {
            if (child.getElementType() == GCMTypes.PROP) {
                blocks.add(new GCMBlock(child, innerBodyAlignment, getWrap()));
            } else {
                blocks.add(new GCMBlock(child, getAlignment(), getWrap()));
            }
        }
        child = child.getTreeNext();
    }
    return blocks;
}
项目:bamboo-soy    文件:SoyLexer.java   
@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;
  });
}
项目:intellij-postfix-templates    文件:CptSyntaxHighlighter.java   
@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;
    }
}
项目:hybris-integration-intellij-idea-plugin    文件:FlexibleSearchBlock.java   
@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;
}
项目:intellij-crystal    文件:CrystalSyntaxHighlighter.java   
@NotNull
@Override
public TextAttributesKey[] getTokenHighlights(IElementType tokenType) {
    if (tokenType.equals(CrystalTypes.SEPARATOR)) {
        return SEPARATOR_KEYS;
    } else if (tokenType.equals(CrystalTypes.KEY)) {
        return KEY_KEYS;
    } else if (tokenType.equals(CrystalTypes.VALUE)) {
        return VALUE_KEYS;
    } else if (tokenType.equals(CrystalTypes.COMMENT)) {
        return COMMENT_KEYS;
    } else if (tokenType.equals(TokenType.BAD_CHARACTER)) {
        return BAD_CHAR_KEYS;
    } else {
        return EMPTY_KEYS;
    }
}
项目:sercapnp    文件:CapnpSyntaxHighlighter.java   
@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;
    }
}
项目:intellij-csv-validator    文件:CsvSyntaxHighlighter.java   
@NotNull
@Override
public TextAttributesKey[] getTokenHighlights(IElementType tokenType) {
    if (tokenType.equals(CsvTypes.COMMA)) {
        return COMMA_KEYS;
    } else if (tokenType.equals(CsvTypes.QUOTE)) {
        return QUOTE_KEYS;
    } else if (tokenType.equals(CsvTypes.TEXT)) {
        return TEXT_KEYS;
    } else if (tokenType.equals(CsvTypes.ESCAPED_TEXT)) {
        return ESCAPED_TEXT_KEYS;
    } else if (tokenType.equals(TokenType.BAD_CHARACTER)) {
        return BAD_CHAR_KEYS;
    } else {
        return EMPTY_KEYS;
    }
}
项目:intellij-csv-validator    文件:CsvIntentionHelper.java   
public static PsiElement getParentFieldElement(PsiElement element) {
    if (getElementType(element) == TokenType.WHITE_SPACE) {
        if (getElementType(element.getParent()) == CsvTypes.FIELD) {
            element = element.getParent();
        } else if (getElementType(element.getPrevSibling()) == CsvTypes.FIELD) {
            element = element.getPrevSibling();
        } else {
            element = null;
        }
    } else {
        while (element != null && CsvIntentionHelper.getElementType(element) != CsvTypes.FIELD) {
            element = element.getParent();
        }
    }
    return element;
}
项目:cup-plugin    文件:CupSyntaxHighlighter.java   
@NotNull
@Override
public TextAttributesKey[] getTokenHighlights(IElementType tokenType) {
    if (tokenType.equals(CupTypes.LINE_COMMENT)) {
        return pack(LINE_COMMENT);
    } else if (tokenType.equals(CupTypes.BLOCK_COMMENT)) {
        return pack(BLOCK_COMMENT);
    } else if (tokenType.equals(TokenType.BAD_CHARACTER)) {
        return pack(ILLEGAL);
    } else if (KEYWORDS.contains(tokenType)) {
        return pack(KEYWORD);
    } else if (tokenType.equals(CupTypes.COMMA)) {
        return pack(COMMA);
    } else if (tokenType.equals(CupTypes.SEMI)) {
        return pack(SEMI);
    } else if (tokenType.equals(CupTypes.CCEQ) || tokenType.equals(CupTypes.BAR) || tokenType.equals(CupTypes.COLON)) {
        return pack(PUNCTUATION);
    }
    return EMPTY;
}
项目:protobuf-jetbrains-plugin    文件:ProtoFoldingBuilder.java   
private static PsiElement findFurthestSiblingOfSameType(@NotNull PsiElement anchor, boolean after) {
    ASTNode node = anchor.getNode();
    final IElementType expectedType = node.getElementType();
    ASTNode lastSeen = node;
    while (node != null) {
        final IElementType elementType = node.getElementType();
        if (elementType == expectedType) {
            lastSeen = node;
        } else if (elementType == TokenType.WHITE_SPACE) {
            if (expectedType == token(LINE_COMMENT)
                    && node.getText().indexOf('\n', 1) != -1) {
                break;
            }
        } else if (!COMMENT_TOKEN_SET.contains(elementType) || COMMENT_TOKEN_SET.contains(expectedType)) {
            break;
        }
        node = after ? node.getTreeNext() : node.getTreePrev();
    }
    return lastSeen.getPsi();
}
项目:dotplugin    文件:DotBlock.java   
@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 DotBlock(child, Wrap.createWrap(WrapType.NONE, false), null,
                    spacingBuilder);
            if (block.getTextRange().getLength() > 0) {
                blocks.add(block);
            }
        }
        child = child.getTreeNext();
    }

    return blocks;
}
项目:Null-Engine    文件:NullShaderSyntaxHighlighter.java   
/**
 * Returns the list of text attribute keys used for highlighting the specified token type. The attributes of all attribute keys
 * returned for the token type are successively merged to obtain the color and attributes of the token.
 *
 * @param tokenType The token type for which the highlighting is requested.
 * @return The array of text attribute keys.
 */
@NotNull
@Override
public TextAttributesKey[] getTokenHighlights(IElementType tokenType) {
    if (tokenType.equals(TokenType.BAD_CHARACTER) || tokenType.equals(RESERVED))
        return BAD_CHARACTER_KEYS;
    else if (tokenType.equals(BLOCK_START) || tokenType.equals(BLOCK_END) || tokenType.equals(BLOCK_NAME))
        return BLOCK_KEYS;
    else if (SyntaxTokens.KEYWORDS.contains(tokenType))
        return KEYWORD_KEYS;
    else if (SyntaxTokens.TYPES.contains(tokenType))
        return TYPE_KEYS;
    else if (SyntaxTokens.NUMBERS.contains(tokenType))
        return NUMBER_KEYS;
    else if (SyntaxTokens.STORAGE_QUALIFERS.contains(tokenType))
        return STORAGE_QUALIFIER_KEYS;
    else if (tokenType.equals(BOOL))
        return BOOLEAN_KEYS;
    else if (SyntaxTokens.VERSIONS.contains(tokenType))
        return VERSION_KEYS;
    else if (SyntaxTokens.PREPROCESSORS.contains(tokenType))
        return PREPROCESSOR_KEYS;
    else if (tokenType.equals(NullShaderTypes.COMMENT))
        return COMMENT_KEYS;
    return EMPY_KEYS;
}
项目:ion-intellij-plugin    文件:IonBlock.java   
@SuppressWarnings("ConstantConditions")
@Override
protected List<Block> buildChildren() {
    List<Block> blocks = new ArrayList<Block>();
    if (myNode.getElementType() == STRUCT) {
        goDeep(blocks, myNode, myAlignment, Alignment.createAlignment(), false, pairContainers);
    } else if (myNode.getElementType() == ARRAY) {
        goDeep(blocks, myNode, myAlignment, Alignment.createAlignment(), false, arrayContainers);
    } else if (myNode.getElementType() == EXPRESSION) {
        goDeep(blocks, myNode, myAlignment, Alignment.createAlignment(), false, expressionContainers);
    } else {

        ASTNode child = myNode.getFirstChildNode();
        while (child != null) {
            if (child.getElementType() != TokenType.WHITE_SPACE) {
                Block block = new IonBlock(child, Wrap.createWrap(WrapType.NORMAL, false), myAlignment, spacingBuilder, settings);
                blocks.add(block);
            }
            child = child.getTreeNext();
        }
    }
    return blocks;
}
项目:intellij-ce-playground    文件:MethodElement.java   
@Override
public void deleteChildInternal(@NotNull ASTNode child) {
  if (child.getElementType() == CODE_BLOCK) {
    final ASTNode prevWS = TreeUtil.prevLeaf(child);
    if (prevWS != null && prevWS.getElementType() == TokenType.WHITE_SPACE) {
      removeChild(prevWS);
    }
    super.deleteChildInternal(child);
    final CharTable treeCharTab = SharedImplUtil.findCharTableByTree(this);
    LeafElement semicolon = Factory.createSingleLeafElement(SEMICOLON, ";", 0, 1, treeCharTab, getManager());
    addInternal(semicolon, semicolon, null, Boolean.TRUE);
  }
  else {
    super.deleteChildInternal(child);
  }
}
项目:intellij-ce-playground    文件:JavaFormattingModelBuilder.java   
/**
 * Checks if previous non-white space leaf of the given node is error element and combines formatting range relevant for it
 * with the range of the given node.
 * 
 * @param node  target node
 * @return      given node range if there is no error-element before it; combined range otherwise
 */
@Nullable
private static TextRange combineWithErrorElementIfPossible(@NotNull ASTNode node) {
  if (node.getElementType() == TokenType.ERROR_ELEMENT) {
    return node.getTextRange();
  }
  final ASTNode prevLeaf = FormatterUtil.getPreviousLeaf(node, TokenType.WHITE_SPACE);
  if (prevLeaf == null || prevLeaf.getElementType() != TokenType.ERROR_ELEMENT) {
    return node.getTextRange();
  }

  final TextRange range = doGetRangeAffectingIndent(prevLeaf);
  if (range == null) {
    return node.getTextRange();
  }
  else {
    return new TextRange(range.getStartOffset(), node.getTextRange().getEndOffset());
  } 
}
项目:intellij-ce-playground    文件:PsiBuilderImpl.java   
@Override
public boolean hashCodesEqual(@NotNull final ASTNode n1, @NotNull final LighterASTNode n2) {
  if (n1 instanceof LeafElement && n2 instanceof Token) {
    boolean isForeign1 = n1 instanceof ForeignLeafPsiElement;
    boolean isForeign2 = n2.getTokenType() instanceof ForeignLeafType;
    if (isForeign1 != isForeign2) return false;

    if (isForeign1) {
      return n1.getText().equals(((ForeignLeafType)n2.getTokenType()).getValue());
    }

    return ((LeafElement)n1).textMatches(((Token)n2).getText());
  }

  if (n1 instanceof PsiErrorElement && n2.getTokenType() == TokenType.ERROR_ELEMENT) {
    final PsiErrorElement e1 = (PsiErrorElement)n1;
    if (!Comparing.equal(e1.getErrorDescription(), getErrorMessage(n2))) return false;
  }

  return ((TreeElement)n1).hc() == ((Node)n2).hc();
}
项目:intellij-ce-playground    文件:FormatterUtil.java   
@Nullable
private static ASTNode getWsCandidate(@Nullable ASTNode node) {
  if (node == null) return null;
  ASTNode treePrev = node.getTreePrev();
  if (treePrev != null) {
    if (treePrev.getElementType() == TokenType.WHITE_SPACE) {
      return treePrev;
    }
    else if (treePrev.getTextLength() == 0) {
      return getWsCandidate(treePrev);
    }
    else {
      return node;
    }
  }
  final ASTNode treeParent = node.getTreeParent();

  if (treeParent == null || treeParent.getTreeParent() == null) {
    return node;
  }
  else {
    return getWsCandidate(treeParent);
  }
}
项目:intellij-ce-playground    文件:LeafPatcher.java   
@Override
public void visitLeaf(LeafElement leaf) {
  String leafText = leaf instanceof ForeignLeafPsiElement ? "" : leaf.getText();
  catLeafs.append(leafText);
  final TextRange leafRange = leaf.getTextRange();

  StringBuilder leafEncodedText = constructTextFromHostPSI(leafRange.getStartOffset(), leafRange.getEndOffset());

  if (leaf.getElementType() == TokenType.WHITE_SPACE && prevElementTail != null) {
    // optimization: put all garbage into whitespace
    leafEncodedText.insert(0, prevElementTail);
    newTexts.remove(prevElement);
    storeUnescapedTextFor(prevElement, null);
  }
  if (!Comparing.equal(leafText, leafEncodedText)) {
    newTexts.put(leaf, leafEncodedText.toString());
    storeUnescapedTextFor(leaf, leafText);
  }
  prevElementTail = StringUtil.startsWith(leafEncodedText, leafText) && leafEncodedText.length() != leafText.length() ?
                    leafEncodedText.substring(leafText.length()) : null;
  prevElement = leaf;
}
项目:intellij-ce-playground    文件:JsonPsiUtil.java   
/**
 * Find the furthest sibling element with the same type as given anchor.
 * <p/>
 * Ignore white spaces for any type of element except {@link com.intellij.json.JsonElementTypes#LINE_COMMENT}
 * where non indentation white space (that has new line in the middle) will stop the search.
 *
 * @param anchor element to start from
 * @param after  whether to scan through sibling elements forward or backward
 * @return described element or anchor if search stops immediately
 */
@NotNull
public static PsiElement findFurthestSiblingOfSameType(@NotNull PsiElement anchor, boolean after) {
  ASTNode node = anchor.getNode();
  // Compare by node type to distinguish between different types of comments
  final IElementType expectedType = node.getElementType();
  ASTNode lastSeen = node;
  while (node != null) {
    final IElementType elementType = node.getElementType();
    if (elementType == expectedType) {
      lastSeen = node;
    }
    else if (elementType == TokenType.WHITE_SPACE) {
      if (expectedType == JsonElementTypes.LINE_COMMENT && node.getText().indexOf('\n', 1) != -1) {
        break;
      }
    }
    else if (!JSON_COMMENTARIES.contains(elementType) || JSON_COMMENTARIES.contains(expectedType)) {
      break;
    }
    node = after ? node.getTreeNext() : node.getTreePrev();
  }
  return lastSeen.getPsi();
}
项目:intellij-ce-playground    文件:CommandLineParserUtil.java   
static void bound_argument(@NotNull final PsiBuilder b, final int i) {
  final IElementType tokenType = b.getTokenType();
  final IElementType leftElement = b.rawLookup(-1);
  final IElementType rightElement = b.rawLookup(1);
  if (leftElement == null || TokenType.WHITE_SPACE.equals(leftElement)) {
    return;
  }

  /**
   * At '=' position: if no whitespace to left and right, we move to argument.
   * And we report error if whitespace to the left.
   */
  if (tokenType == CommandLineElementTypes.EQ) {
    if (leftElement.equals(CommandLineElementTypes.LONG_OPTION_NAME_TOKEN)) {
      if (rightElement == null || TokenType.WHITE_SPACE.equals(rightElement)) {
        b.error("Space between argument is its value is unexpected");
      }
      b.advanceLexer();
    }
  }
}
项目:intellij-ce-playground    文件:XmlElementImpl.java   
@Nullable
protected static String getNameFromEntityRef(final CompositeElement compositeElement, final IElementType xmlEntityDeclStart) {
  final ASTNode node = compositeElement.findChildByType(xmlEntityDeclStart);
  if (node == null) return null;
  ASTNode name = node.getTreeNext();

  if (name != null && name.getElementType() == TokenType.WHITE_SPACE) {
    name = name.getTreeNext();
  }

  if (name != null && name.getElementType() == XmlElementType.XML_ENTITY_REF) {
    final StringBuilder builder = new StringBuilder();

    ((XmlElement)name.getPsi()).processElements(new PsiElementProcessor() {
      @Override
      public boolean execute(@NotNull final PsiElement element) {
        builder.append(element.getText());
        return true;
      }
    }, name.getPsi());
    if (builder.length() > 0) return builder.toString();
  }
  return null;
}
项目:intellij-ce-playground    文件:XmlBuilderDriver.java   
private void processPrologNode(PsiBuilder psiBuilder,
                               XmlBuilder builder,
                               FlyweightCapableTreeStructure<LighterASTNode> structure,
                               LighterASTNode prolog) {
  final Ref<LighterASTNode[]> prologChildren = new Ref<LighterASTNode[]>(null);
  final int prologChildrenCount = structure.getChildren(structure.prepareForGetChildren(prolog), prologChildren);
  for (int i = 0; i < prologChildrenCount; i++) {
    LighterASTNode node = prologChildren.get()[i];
    IElementType type = node.getTokenType();
    if (type == XmlElementType.XML_DOCTYPE) {
      processDoctypeNode(builder, structure, node);
      break;
    }
    if (type == TokenType.ERROR_ELEMENT) {
      processErrorNode(psiBuilder, node, builder);
    }
  }
}
项目:intellij-ce-playground    文件:XmlBlock.java   
private List<Block> splitAttribute(ASTNode node, XmlFormattingPolicy formattingPolicy) {
  final ArrayList<Block> result = new ArrayList<Block>(3);
  ASTNode child = node.getFirstChildNode();
  while (child != null) {
    if (child.getElementType() == XmlTokenType.XML_ATTRIBUTE_VALUE_START_DELIMITER ||
        child.getElementType() == XmlTokenType.XML_ATTRIBUTE_VALUE_END_DELIMITER) {
      result.add(new XmlBlock(child, null, null, formattingPolicy, null, null, isPreserveSpace()));
    }
    else if (!child.getPsi().getLanguage().isKindOf(XMLLanguage.INSTANCE) && containsOuterLanguageElement(child)) {
      // Fix for EA-20311:
      // In case of another embedded language create a splittable XML block which can be
      // merged with other language's code blocks.
      createLeafBlocks(child, result);
    }
    else if (child.getElementType() != TokenType.ERROR_ELEMENT || child.getFirstChildNode() != null) {
      result.add(new ReadOnlyBlock(child));
    }
    child = child.getTreeNext();
  }
  return result;
}
项目:intellij-ce-playground    文件:XmlBlock.java   
private void createLeafBlocks(ASTNode node, List<Block> result) {
  if (node instanceof OuterLanguageElement) {
    processChild(result, node, null, null, null);
    return;
  }

  ASTNode child = node.getFirstChildNode();
  if (child == null && !(node instanceof PsiWhiteSpace) && node.getElementType() != TokenType.ERROR_ELEMENT && node.getTextLength() > 0) {
    result.add(new ReadOnlyBlock(node));
    return;
  }
  while (child != null) {
    createLeafBlocks(child, result);
    child = child.getTreeNext();
  }
}
项目:intellij-ce-playground    文件:ProguardSyntaxHighlighter.java   
@NotNull
@Override
public TextAttributesKey[] getTokenHighlights(IElementType tokenType) {
  // Return the appropriate text attributes depending on the type of token.
  if (tokenType.equals(ProguardTypes.LINE_CMT)) {
    return COMMENTS_KEY;
  }
  if (tokenType.equals(TokenType.BAD_CHARACTER)) {
    return BAD_CHARS_KEY;
  }
  if (tokenType.equals(ProguardTypes.JAVA_DECL)) {
    return CLASS_SPEC_KEY;
  }
  if (tokenType.equals(ProguardTypes.CLOSE_BRACE) || tokenType.equals(ProguardTypes.OPEN_BRACE)) {
    return OPERATOR_KEY;
  }
  if (tokenType.equals(ProguardTypes.FLAG_NAME)) {
    return FLAG_NAME_KEY;
  }
  if (tokenType.equals(ProguardTypes.FLAG_ARG)) {
    return FLAG_ARG_KEY;
  }

  return EMPTY_KEY;
}
项目:intellij-ce-playground    文件:PropertiesFileImpl.java   
@Override
@NotNull
public PsiElement addPropertyAfter(@NotNull final IProperty property, @Nullable final IProperty anchor) throws IncorrectOperationException {
  final TreeElement copy = ChangeUtil.copyToElement(property.getPsiElement());
  List<IProperty> properties = getProperties();
  ASTNode anchorBefore = anchor == null ? properties.isEmpty() ? null : properties.get(0).getPsiElement().getNode()
                         : anchor.getPsiElement().getNode().getTreeNext();
  if (anchorBefore != null) {
    if (anchorBefore.getElementType() == TokenType.WHITE_SPACE) {
      anchorBefore = anchorBefore.getTreeNext();
    }
  }
  if (anchorBefore == null && haveToAddNewLine()) {
    insertLineBreakBefore(null);
  }
  getPropertiesList().addChild(copy, anchorBefore);
  if (anchorBefore != null) {
    insertLineBreakBefore(anchorBefore);
  }
  return copy.getPsi();
}
项目:intellij-ce-playground    文件:GrBracesSurrounder.java   
@Override
protected GroovyPsiElement doSurroundElements(PsiElement[] elements, PsiElement context) throws IncorrectOperationException {
  GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(elements[0].getProject());

  final PsiElement e0 = elements[0];
  final PsiElement parent = e0.getParent();

  final GrCodeBlock block;
  if (parent instanceof GrControlStatement) {
    block = factory.createMethodBodyFromText("\n");
    final PsiElement prev = e0.getPrevSibling();
    if (prev != null && prev.getNode().getElementType().equals(GroovyTokenTypes.mNLS)) {
      final ASTNode parentNode = e0.getParent().getNode();
      parentNode.addLeaf(TokenType.WHITE_SPACE, " ", prev.getNode());
      parentNode.removeChild(prev.getNode());
    }
  }
  else {
    block = factory.createClosureFromText("{}");
  }

  GroovyManyStatementsSurrounder.addStatements(block, elements);
  return block;
}
项目:epigraph    文件:LexerTest.java   
private void testInput(String input, IElementType... expected) throws IOException {
  SchemaLexer lex = new SchemaLexer();
  lex.reset(input, 0, input.length(), SchemaLexer.YYINITIAL);

  List<IElementType> actual = new ArrayList<>();

  StringBuilder debug = new StringBuilder();
  IElementType e = lex.advance();
  while (e != null) {
    if (e != TokenType.WHITE_SPACE) {
      Assert.assertTrue("Got zero-length token '" + e + "' at " + lex.getTokenEnd(), lex.yylength() > 0);
      debug.append(e).append("\n");
      actual.add(e);
    }
    e = lex.advance();
  }

  Assert.assertArrayEquals(debug.toString(), actual.toArray(), expected);
}
项目:epigraph    文件:AddRetroAction.java   
@Override
public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException {
  if (element.getNode().getElementType() == TokenType.WHITE_SPACE) element = PsiTreeUtil.prevVisibleLeaf(element);

  SchemaValueTypeRef valueTypeRef = PsiTreeUtil.getParentOfType(element, SchemaValueTypeRef.class);
  if (valueTypeRef != null) {
    int endOffset = valueTypeRef.getNode().getTextRange().getEndOffset();
    editor.getCaretModel().moveToOffset(endOffset);
    EditorModificationUtil.insertStringAtCaret(editor, " default ");

    ApplicationManager.getApplication().invokeLater(() -> {
      AnActionEvent event = AnActionEvent.createFromDataContext("AddDefaultAction",
          new Presentation(), ((EditorEx) editor).getDataContext());

      new CodeCompletionAction().actionPerformed(event);
    });
  }
}
项目:epigraph    文件:LineCommentBlock.java   
@Override
public Indent getIndent() {
  // This is a special case - comment block that is located at the very start of the line. We don't reformat such a blocks

  ASTNode previous = myNode.getTreePrev();

  // logic taken from AbstractJavaBlock: 783

  CharSequence prevChars;
  if (previous != null && previous.getElementType() == TokenType.WHITE_SPACE && (prevChars = previous.getChars()).length() > 0
      && prevChars.charAt(prevChars.length() - 1) == '\n') {
    return Indent.getNoneIndent();
  }

  return super.getIndent();
}
项目:AppleScript-IDEA    文件:AppleScriptFormattingModelBuilder.java   
@Override
protected String replaceWithPsiInLeaf(TextRange textRange, String whiteSpace, ASTNode leafElement) {
  if (!myCanModifyAllWhiteSpaces) {
    if (AppleScriptPsiImplUtil.isWhiteSpaceOrNls(leafElement)) return null;
  }

  IElementType elementTypeToUse = TokenType.WHITE_SPACE;
  ASTNode prevNode = TreeUtil.prevLeaf(leafElement);
  if (prevNode != null && AppleScriptPsiImplUtil.isWhiteSpaceOrNls(prevNode)) {
    elementTypeToUse = prevNode.getElementType();
  }
  FormatterUtil.replaceWhiteSpace(whiteSpace, leafElement, elementTypeToUse, textRange);
  return whiteSpace;
}
项目:AppleScript-IDEA    文件:AppleScriptLexerTest.java   
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);
}
项目:greycat-idea-plugin    文件:GCMSyntaxHighlighter.java   
@NotNull
@Override
public final TextAttributesKey[] getTokenHighlights(IElementType tokenType) {
    /* Entities OPERATIONS */
    if (KEYWORD_SET.contains(tokenType)) {
        return KEYWORD_KEYS;
    }
    if (SEPARATOR_SET.contains(tokenType)) {
        return SEPARATOR_KEYS;
    }
    /* Basic elem */

    if (tokenType.equals(GCMTypes.ANNOTATION)) {
        return ANNOTATION_KEYS;
    }
    if (tokenType.equals(GCMTypes.IDENT)) {
        return IDENT_KEYS;
    }
    if (tokenType.equals(GCMTypes.NUMBER)) {
        return NUMBER_KEYS;
    }
    if (tokenType.equals(GCMTypes.LINE_COMMENT) | tokenType.equals(GCMTypes.BLOCK_COMMENT)) {
        return COMMENT_KEYS;
    }
    if (tokenType.equals(GCMTypes.STRING)) {
        return STRING_KEYS;
    }
    if (tokenType.equals(TokenType.BAD_CHARACTER)) {
        return BAD_CHAR_KEYS;
    }
    return EMPTY_KEYS;

}
项目:intellij-postfix-templates    文件:CptBlock.java   
@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;
}
项目:hybris-integration-intellij-idea-plugin    文件:FlexibleSearchSyntaxHighlighter.java   
@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;
    }
}
项目:idea-onescript    文件:OneScriptSyntaxHighlighter.java   
@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];
    }
}
项目:intellij-csv-validator    文件:CsvBlock.java   
@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;
}
项目:intellij-csv-validator    文件:CsvBlockField.java   
@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;
}