Package com.dmarcotte.handlebars.psi.impl

Source Code of com.dmarcotte.handlebars.psi.impl.HbSimpleInverseImpl

package com.dmarcotte.handlebars.psi.impl;

import com.dmarcotte.handlebars.HbIcons;
import com.dmarcotte.handlebars.parsing.HbTokenTypes;
import com.dmarcotte.handlebars.psi.HbSimpleInverse;
import com.intellij.lang.ASTNode;
import com.intellij.psi.tree.TokenSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;

public class HbSimpleInverseImpl extends HbPlainMustacheImpl implements HbSimpleInverse {
  public HbSimpleInverseImpl(@NotNull ASTNode astNode) {
    super(astNode);
  }

  /**
   * Uses "else" as the name for this element if the "else" syntax is used,
   * and uses no name (i.e. the "{^}" icon is the representative) in the simple
   * inverse case
   */
  @Override
  public String getName() {
    ASTNode elseNode = getElseNode();
    if (elseNode != null) {
      return elseNode.getText();
    }
    return ""; // no name for "{{^}}" expressions
  }

  @Nullable
  @Override
  public Icon getIcon(@IconFlags int flags) {
    if (getElseNode() != null) {
      return HbIcons.OPEN_MUSTACHE;
    }
    return HbIcons.OPEN_INVERSE;
  }

  /**
   * If this element was created from an "{{else}}" expression, it will have an {@link HbTokenTypes#ELSE} child.
   * Otherwise, it was created from "{{^}}"
   *
   * @return the {@link HbTokenTypes#ELSE} element if it exists, null otherwise
   */
  private ASTNode getElseNode() {
    ASTNode[] elseChildren = getNode().getChildren(TokenSet.create(HbTokenTypes.ELSE));
    if (elseChildren != null && elseChildren.length > 0) {
      return elseChildren[0];
    }
    return null;
  }
}
TOP

Related Classes of com.dmarcotte.handlebars.psi.impl.HbSimpleInverseImpl

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.