com.intellij.lang.ASTNode Java Examples

The following examples show how to use com.intellij.lang.ASTNode. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ANTLRv4FoldingBuilder.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@SuppressWarnings("SimplifiableIfStatement")
@Override
protected boolean isRegionCollapsedByDefault(@NotNull ASTNode node) {
    final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(node);
    if (element == null) return false;

    ANTLRv4FoldingSettings settings = ANTLRv4FoldingSettings.getInstance();

    if (RULE_BLOCKS.contains(node.getElementType())) return settings.isCollapseRuleBlocks();
    if (node.getElementType() == TOKENSSPEC) return settings.isCollapseTokens();

    if (element instanceof AtAction) return settings.isCollapseActions();

    if (element instanceof ANTLRv4FileRoot) {
        return settings.isCollapseFileHeader();
    }
    if (node.getElementType() == DOC_COMMENT_TOKEN) {

        PsiElement parent = element.getParent();

        if (parent instanceof ANTLRv4FileRoot) {
            PsiElement firstChild = parent.getFirstChild();
            if (firstChild instanceof PsiWhiteSpace) {
                firstChild = firstChild.getNextSibling();
            }
            if (element.equals(firstChild)) {
                return settings.isCollapseFileHeader();
            }
        }
        return settings.isCollapseDocComments();
    }
    if (isComment(element)) {
        return settings.isCollapseComments();
    }
    return false;

}
 
Example #2
Source File: CSharpFileStubElementType.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Override
public StubBuilder getBuilder()
{
	return new DefaultStubBuilder()
	{
		@Nonnull
		@Override
		protected StubElement createStubForFile(@Nonnull PsiFile file)
		{
			if(file instanceof CSharpFileImpl)
			{
				return new CSharpFileStub((CSharpFileImpl) file);
			}
			return super.createStubForFile(file);
		}

		@Override
		public boolean skipChildProcessingWhenBuildingStubs(@Nonnull ASTNode parent, @Nonnull ASTNode node)
		{
			// skip any lazy parseable elements, like preprocessors or code blocks etc
			if(node.getElementType() instanceof ILazyParseableElementType)
			{
				return true;
			}
			return false;
		}
	};
}
 
Example #3
Source File: AbstractHaxeNamedComponent.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
@Nullable
public ASTNode findChildByRole(int role) {
  // assert ChildRole.isUnique(role);
  PsiElement firstChild = getFirstChild();

  if (firstChild == null) return null;

  for (ASTNode child = firstChild.getNode(); child != null; child = child.getTreeNext()) {
    if (getChildRole(child) == role) return child;
  }
  return null;
}
 
Example #4
Source File: HXMLPsiImplUtil.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
public static String getValue(HXMLLib lib) {
  ASTNode node = lib.getNode().findChildByType(HXMLTypes.VALUE);

  if (node != null) {
    return node.getText();
  }
  else {
    return null;
  }
}
 
Example #5
Source File: CompositeElement.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean textContains(char c) {
  for (ASTNode child = getFirstChildNode(); child != null; child = child.getTreeNext()) {
    if (child.textContains(c)) return true;
  }
  return false;
}
 
Example #6
Source File: GLSLParserDefinition.java    From glsl4idea with GNU Lesser General Public License v3.0 5 votes vote down vote up
@NotNull
public PsiElement createElement(ASTNode node) {
    GLSLElement elt = psiFactory.create(node);
    if (elt != null) {
        return elt;
    } else {
        //Logger.getInstance(GLSLParserDefinition.class).warn("Creating default GLSLElementImpl for "+node);
        return new GLSLElementImpl(node);
    }
}
 
Example #7
Source File: HaxeFoldingBuilder.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
private static TextRange buildImportsFoldingTextRange(ASTNode firstNode, ASTNode lastNode) {
  ASTNode nodeStartFrom = UsefulPsiTreeUtil.getNextSiblingSkipWhiteSpacesAndComments(firstNode.getFirstChildNode());
  if (nodeStartFrom == null) {
    nodeStartFrom = firstNode;
  }
  return new TextRange(nodeStartFrom.getStartOffset(), lastNode.getTextRange().getEndOffset());
}
 
Example #8
Source File: ASTShallowComparator.java    From consulo with Apache License 2.0 5 votes vote down vote up
private ThreeState textMatches(ASTNode oldNode, ASTNode newNode) {
  myIndicator.checkCanceled();
  String oldText = TreeUtil.isCollapsedChameleon(oldNode) ? oldNode.getText() : null;
  String newText = TreeUtil.isCollapsedChameleon(newNode) ? newNode.getText() : null;
  if (oldText != null && newText != null) return oldText.equals(newText) ? ThreeState.YES : ThreeState.UNSURE;

  if (oldText != null) {
    return compareTreeToText((TreeElement)newNode, oldText) ? ThreeState.YES : ThreeState.UNSURE;
  }
  if (newText != null) {
    return compareTreeToText((TreeElement)oldNode, newText) ? ThreeState.YES : ThreeState.UNSURE;
  }

  if (oldNode instanceof ForeignLeafPsiElement) {
    return newNode instanceof ForeignLeafPsiElement && oldNode.getText().equals(newNode.getText()) ? ThreeState.YES : ThreeState.NO;
  }

  if (newNode instanceof ForeignLeafPsiElement) return ThreeState.NO;

  if (oldNode instanceof LeafElement) {
    return ((LeafElement)oldNode).textMatches(newNode.getText()) ? ThreeState.YES : ThreeState.NO;
  }
  if (newNode instanceof LeafElement) {
    return ((LeafElement)newNode).textMatches(oldNode.getText()) ? ThreeState.YES : ThreeState.NO;
  }

  if (oldNode instanceof PsiErrorElement && newNode instanceof PsiErrorElement) {
    final PsiErrorElement e1 = (PsiErrorElement)oldNode;
    final PsiErrorElement e2 = (PsiErrorElement)newNode;
    if (!Comparing.equal(e1.getErrorDescription(), e2.getErrorDescription())) return ThreeState.NO;
  }

  return ThreeState.UNSURE;
}
 
Example #9
Source File: LattePsiImplUtil.java    From intellij-latte with MIT License 5 votes vote down vote up
public static @NotNull String getMacroName(LatteMacroTag element) {
	ASTNode nameNode = getMacroNameNode(element);
	if (nameNode != null) {
		return nameNode.getText();
	}
	return createMacroName(element);
}
 
Example #10
Source File: JenkinsTypes.java    From jenkinsfile-idea-plugin with Apache License 2.0 5 votes vote down vote up
public static PsiElement createElement(ASTNode node) {
  IElementType type = node.getElementType();
   if (type == STEP) {
    return new JenkinsStepImpl(node);
  }
  throw new AssertionError("Unknown element type: " + type);
}
 
Example #11
Source File: PsiEquivalenceUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static PsiElement[] getFilteredChildren(@Nonnull final PsiElement element,
                                               @Nullable Condition<PsiElement> isElementSignificantCondition,
                                               boolean areCommentsSignificant) {
  ASTNode[] children1 = element.getNode().getChildren(null);
  ArrayList<PsiElement> array = new ArrayList<PsiElement>();
  for (ASTNode node : children1) {
    final PsiElement child = node.getPsi();
    if (!(child instanceof PsiWhiteSpace) && (areCommentsSignificant || !(child instanceof PsiComment)) &&
        (isElementSignificantCondition == null || isElementSignificantCondition.value(child))) {
      array.add(child);
    }
  }
  return PsiUtilCore.toPsiElementArray(array);
}
 
Example #12
Source File: PsiViewerDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Object getData(@Nonnull @NonNls Key<?> dataId) {
  if (PlatformDataKeys.NAVIGATABLE == dataId) {
    String fqn = null;
    if (myPsiTree.hasFocus()) {
      final TreePath path = myPsiTree.getSelectionPath();
      if (path != null) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent();
        if (!(node.getUserObject() instanceof ViewerNodeDescriptor)) return null;
        ViewerNodeDescriptor descriptor = (ViewerNodeDescriptor)node.getUserObject();
        Object elementObject = descriptor.getElement();
        final PsiElement element = elementObject instanceof PsiElement
                                   ? (PsiElement)elementObject
                                   : elementObject instanceof ASTNode ? ((ASTNode)elementObject).getPsi() : null;
        if (element != null) {
          fqn = element.getClass().getName();
        }
      }
    } else if (myRefs.hasFocus()) {
      final Object value = myRefs.getSelectedValue();
      if (value instanceof String) {
        fqn = (String)value;
      }
    }
    if (fqn != null) {
      return getContainingFileForClass(fqn);
    }
  }
  return null;
}
 
Example #13
Source File: FuncallExpression.java    From intellij with Apache License 2.0 5 votes vote down vote up
/** The function name */
@Nullable
public ASTNode getFunctionNameNode() {
  PsiElement argList = getArgList();
  if (argList != null) {
    // We want the reference expr directly prior to the open parenthesis.
    // This accounts for Skylark native.rule calls.
    PsiElement prev = argList.getPrevSibling();
    if (prev instanceof ReferenceExpression) {
      return prev.getNode();
    }
  }
  return getNode().findChildByType(BuildElementTypes.REFERENCE_EXPRESSION);
}
 
Example #14
Source File: PsiInnerModuleImpl.java    From reasonml-idea-plugin with MIT License 4 votes vote down vote up
public PsiInnerModuleImpl(@NotNull ORTypes types, @NotNull ASTNode node) {
    super(types, node);
}
 
Example #15
Source File: CSharpAsExpressionImpl.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
public CSharpAsExpressionImpl(@Nonnull ASTNode node)
{
	super(node);
}
 
Example #16
Source File: NixExprImpl.java    From nix-idea with Apache License 2.0 4 votes vote down vote up
public NixExprImpl(ASTNode node) {
  super(node);
}
 
Example #17
Source File: GLSLBreakStatement.java    From glsl4idea with GNU Lesser General Public License v3.0 4 votes vote down vote up
public GLSLBreakStatement(@NotNull ASTNode astNode) {
    super(astNode);
}
 
Example #18
Source File: CSharpParameterStubElementType.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public DotNetParameter createElement(@Nonnull ASTNode astNode)
{
	return new CSharpStubParameterImpl(astNode);
}
 
Example #19
Source File: CSharpPreprocessorPragmaImpl.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
public CSharpPreprocessorPragmaImpl(@Nonnull ASTNode node)
{
	super(node);
}
 
Example #20
Source File: Argument.java    From intellij with Apache License 2.0 4 votes vote down vote up
public Positional(ASTNode node) {
  super(node);
}
 
Example #21
Source File: NixEvalExprImpl.java    From nix-idea with Apache License 2.0 4 votes vote down vote up
public NixEvalExprImpl(ASTNode node) {
  super(node);
}
 
Example #22
Source File: XQueryModuleDeclImpl.java    From intellij-xquery with Apache License 2.0 4 votes vote down vote up
public XQueryModuleDeclImpl(ASTNode node) {
  super(node);
}
 
Example #23
Source File: XQueryAxisStepImpl.java    From intellij-xquery with Apache License 2.0 4 votes vote down vote up
public XQueryAxisStepImpl(ASTNode node) {
  super(node);
}
 
Example #24
Source File: WeaveKeyExpressionImpl.java    From mule-intellij-plugins with Apache License 2.0 4 votes vote down vote up
public WeaveKeyExpressionImpl(ASTNode node) {
  super(node);
}
 
Example #25
Source File: WeaveObjectExpressionImpl.java    From mule-intellij-plugins with Apache License 2.0 4 votes vote down vote up
public WeaveObjectExpressionImpl(ASTNode node) {
  super(node);
}
 
Example #26
Source File: MelDoWhileExpressionImpl.java    From mule-intellij-plugins with Apache License 2.0 4 votes vote down vote up
public MelDoWhileExpressionImpl(ASTNode node) {
  super(node);
}
 
Example #27
Source File: CSharpVariableImpl.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
public CSharpVariableImpl(@Nonnull ASTNode node)
{
	super(node);
}
 
Example #28
Source File: MakefilePsiElement.java    From CppTools with Apache License 2.0 4 votes vote down vote up
public MakefilePsiElement(ASTNode astNode) {
  super(astNode);
}
 
Example #29
Source File: AbstractExpression.java    From BashSupport with Apache License 2.0 4 votes vote down vote up
public AbstractExpression(final ASTNode astNode, final String name, Type type) {
    super(astNode, name);
    this.type = type;
}
 
Example #30
Source File: BashWordImpl.java    From BashSupport with Apache License 2.0 4 votes vote down vote up
public BashWordImpl(final ASTNode astNode) {
    super(astNode, "bash combined word");
}