Java Code Examples for com.intellij.lang.ASTNode

The following examples show how to use com.intellij.lang.ASTNode. These examples are extracted from open source projects. 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 Project: consulo   Source File: CompositeElement.java    License: 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 2
Source Project: intellij-haxe   Source File: HXMLPsiImplUtil.java    License: 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 3
Source Project: intellij-haxe   Source File: HaxeFoldingBuilder.java    License: 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 4
Source Project: consulo   Source File: PsiEquivalenceUtil.java    License: 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 5
Source Project: intellij   Source File: FuncallExpression.java    License: 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 6
@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 7
Source Project: consulo   Source File: PsiViewerDialog.java    License: 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 8
Source Project: jenkinsfile-idea-plugin   Source File: JenkinsTypes.java    License: 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 9
Source Project: intellij-latte   Source File: LattePsiImplUtil.java    License: 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 Project: consulo   Source File: ASTShallowComparator.java    License: 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 11
@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 12
Source Project: intellij-haxe   Source File: AbstractHaxeNamedComponent.java    License: 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 13
Source Project: consulo-csharp   Source File: CSharpFileStubElementType.java    License: 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 14
Source Project: intellij-xquery   Source File: XQueryModuleDeclImpl.java    License: Apache License 2.0 4 votes vote down vote up
public XQueryModuleDeclImpl(ASTNode node) {
  super(node);
}
 
Example 15
Source Project: consulo   Source File: AnnotationHolderImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Annotation createInfoAnnotation(@Nonnull ASTNode node, String message) {
  assertMyFile(node.getPsi());
  return createAnnotation(HighlightSeverity.INFORMATION, node.getTextRange(), message);
}
 
Example 16
Source Project: consulo   Source File: AstBufferUtil.java    License: Apache License 2.0 4 votes vote down vote up
public static String getTextSkippingWhitespaceComments(@Nonnull ASTNode element) {
  int length = toBuffer(element, null, 0, true);
  char[] buffer = new char[length];
  toBuffer(element, buffer, 0, true);
  return StringFactory.createShared(buffer);
}
 
Example 17
Source Project: BashSupport   Source File: BashAssignmentListImpl.java    License: Apache License 2.0 4 votes vote down vote up
public BashAssignmentListImpl(ASTNode node) {
    super(node, "assignment list");
}
 
Example 18
Source Project: Intellij-Plugin   Source File: GaugeFoldingBuilder.java    License: Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public String getPlaceholderText(@NotNull ASTNode astNode) {
    return " ...";
}
 
Example 19
Source Project: idea-php-typo3-plugin   Source File: FluidBlockWithInjection.java    License: MIT License 4 votes vote down vote up
protected FluidBlockWithInjection(AbstractXmlTemplateFormattingModelBuilder builder, @NotNull ASTNode node, @Nullable Wrap wrap, @Nullable Alignment alignment, CodeStyleSettings settings, XmlFormattingPolicy xmlFormattingPolicy, Indent indent) {
    super(builder, node, wrap, alignment, settings, xmlFormattingPolicy, indent);

    this.myInjectedBlockBuilder = new FluidBlockWithInjectionBuilder(settings);
}
 
Example 20
Source Project: protobuf-jetbrains-plugin   Source File: FieldNode.java    License: Apache License 2.0 4 votes vote down vote up
public FieldNode(@NotNull ASTNode node) {
    super(node);
}
 
Example 21
public CypherPatternElementImpl(@NotNull ASTNode node) {
  super(node);
}
 
Example 22
public CypherQueryOptionsImpl(@NotNull ASTNode node) {
  super(node);
}
 
Example 23
Source Project: bamboo-soy   Source File: AtInjectMixin.java    License: Apache License 2.0 4 votes vote down vote up
public AtInjectMixin(@NotNull ASTNode node) {
  super(node);
}
 
Example 24
public GraphQLInlineFragmentImpl(ASTNode node) {
  super(node);
}
 
Example 25
Source Project: consulo-csharp   Source File: CSharpTupleElementImpl.java    License: Apache License 2.0 4 votes vote down vote up
public CSharpTupleElementImpl(@Nonnull ASTNode node)
{
	super(node);
}
 
Example 26
Source Project: JetBrains-NASM-Language   Source File: NASMBitShiftRExprImpl.java    License: MIT License 4 votes vote down vote up
public NASMBitShiftRExprImpl(@NotNull ASTNode node) {
  super(node);
}
 
Example 27
Source Project: JetBrains-NASM-Language   Source File: NASMDataElementImpl.java    License: MIT License 4 votes vote down vote up
public NASMDataElementImpl(@NotNull ASTNode node) {
  super(node);
}
 
Example 28
public JSGraphQLEndpointPropertyPsiElement(@NotNull ASTNode node) {
	super(node);
}
 
Example 29
Source Project: bamboo-soy   Source File: IdentifierDefinitionMixin.java    License: Apache License 2.0 4 votes vote down vote up
IdentifierDefinitionMixin(@NotNull ASTNode node) {
  super(node);
}
 
Example 30
public CypherPropertyExpressionImpl(@NotNull ASTNode node) {
  super(node);
}