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: 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 #2
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 #3
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 #4
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 #5
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 #6
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 #7
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 #8
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 #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: 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 #11
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 #12
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 #13
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 #14
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 #15
Source File: AnnotationHolderImpl.java    From consulo with 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 File: AstBufferUtil.java    From consulo with 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 File: BashAssignmentListImpl.java    From BashSupport with Apache License 2.0 4 votes vote down vote up
public BashAssignmentListImpl(ASTNode node) {
    super(node, "assignment list");
}
 
Example #18
Source File: GaugeFoldingBuilder.java    From Intellij-Plugin with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public String getPlaceholderText(@NotNull ASTNode astNode) {
    return " ...";
}
 
Example #19
Source File: FluidBlockWithInjection.java    From idea-php-typo3-plugin with 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 File: FieldNode.java    From protobuf-jetbrains-plugin with Apache License 2.0 4 votes vote down vote up
public FieldNode(@NotNull ASTNode node) {
    super(node);
}
 
Example #21
Source File: CypherPatternElementImpl.java    From jetbrains-plugin-graph-database-support with Apache License 2.0 4 votes vote down vote up
public CypherPatternElementImpl(@NotNull ASTNode node) {
  super(node);
}
 
Example #22
Source File: CypherQueryOptionsImpl.java    From jetbrains-plugin-graph-database-support with Apache License 2.0 4 votes vote down vote up
public CypherQueryOptionsImpl(@NotNull ASTNode node) {
  super(node);
}
 
Example #23
Source File: AtInjectMixin.java    From bamboo-soy with Apache License 2.0 4 votes vote down vote up
public AtInjectMixin(@NotNull ASTNode node) {
  super(node);
}
 
Example #24
Source File: GraphQLInlineFragmentImpl.java    From js-graphql-intellij-plugin with MIT License 4 votes vote down vote up
public GraphQLInlineFragmentImpl(ASTNode node) {
  super(node);
}
 
Example #25
Source File: CSharpTupleElementImpl.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
public CSharpTupleElementImpl(@Nonnull ASTNode node)
{
	super(node);
}
 
Example #26
Source File: NASMBitShiftRExprImpl.java    From JetBrains-NASM-Language with MIT License 4 votes vote down vote up
public NASMBitShiftRExprImpl(@NotNull ASTNode node) {
  super(node);
}
 
Example #27
Source File: NASMDataElementImpl.java    From JetBrains-NASM-Language with MIT License 4 votes vote down vote up
public NASMDataElementImpl(@NotNull ASTNode node) {
  super(node);
}
 
Example #28
Source File: JSGraphQLEndpointPropertyPsiElement.java    From js-graphql-intellij-plugin with MIT License 4 votes vote down vote up
public JSGraphQLEndpointPropertyPsiElement(@NotNull ASTNode node) {
	super(node);
}
 
Example #29
Source File: IdentifierDefinitionMixin.java    From bamboo-soy with Apache License 2.0 4 votes vote down vote up
IdentifierDefinitionMixin(@NotNull ASTNode node) {
  super(node);
}
 
Example #30
Source File: CypherPropertyExpressionImpl.java    From jetbrains-plugin-graph-database-support with Apache License 2.0 4 votes vote down vote up
public CypherPropertyExpressionImpl(@NotNull ASTNode node) {
  super(node);
}