Package com.intellij.psi.tree

Source Code of com.intellij.psi.tree.IChameleonElementType

/*
* Copyright 2000-2007 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.psi.tree;

import com.intellij.lang.*;
import com.intellij.openapi.project.Project;
import com.intellij.peer.PeerFactory;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NonNls;

/**
* A token type which represents a fragment of text (possibly in a different language)
* which is not parsed during the current lexer or parser pass and can be parsed later when
* its contents is requested.
*
* @author ik
*/

public class IChameleonElementType extends IElementType {
  public IChameleonElementType(@NonNls String debugName) {
    this(debugName, null);
  }

  public IChameleonElementType(@NonNls String debugName, Language language) {
    super(debugName, language);
  }

  public IChameleonElementType(@NonNls String debugName, Language language, boolean register) {
    super(debugName, language, register);
  }

  /**
   * Parses the contents of the specified chameleon node and returns the AST tree
   * representing the parsed contents.
   *
   * @param chameleon the node to parse.
   * @return the parsed contents of the node.
   */
  public ASTNode parseContents(ASTNode chameleon) {
    final PeerFactory factory = PeerFactory.getInstance();
    final PsiElement parentElement = chameleon.getTreeParent().getPsi();
    final Project project = parentElement.getManager().getProject();

    final LanguageDialect langDialect = parentElement.getContainingFile().getLanguageDialect();
    final PsiBuilder builder = factory.createBuilder(
      chameleon,
      null,
      langDialect != null ? langDialect:getLanguage(),
      chameleon.getText(),
      project
    );

    final PsiParser parser = getLanguage().getParserDefinition().createParser(project);
    return parser.parse(this, builder).getFirstChildNode();
  }

  /**
   * Checks if the specified character sequence can be parsed as a valid content of the
   * chameleon node.
   *
   * @param buffer  the content to parse.
   * @param project the project containing the content.
   * @return true if the content is valid, false if not
   */

  public boolean isParsable(CharSequence buffer, final Project project) {
    return false;
  }
}
TOP

Related Classes of com.intellij.psi.tree.IChameleonElementType

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.