com.intellij.psi.PsiWhiteSpace Java Examples

The following examples show how to use com.intellij.psi.PsiWhiteSpace. 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: ErrorFilter.java    From intellij-latte with MIT License 6 votes vote down vote up
public boolean shouldHighlightErrorElement(@NotNull PsiErrorElement element) {
	PsiFile templateLanguageFile = PsiUtilCore.getTemplateLanguageFile(element.getContainingFile());
	if (templateLanguageFile == null) {
		return true;
	}
	Language language = templateLanguageFile.getLanguage();
	if (language != LatteLanguage.INSTANCE) {
		return true;
	}
	if (element.getParent() instanceof XmlElement || element.getParent() instanceof CssElement) {
		return false;
	}
	if (element.getParent().getLanguage() == LatteLanguage.INSTANCE) {
		return true;
	}
	PsiElement nextSibling;
	for (nextSibling = PsiTreeUtil.nextLeaf(element); nextSibling instanceof PsiWhiteSpace; nextSibling = nextSibling.getNextSibling());

	PsiElement psiElement = nextSibling == null ? null : PsiTreeUtil.findCommonParent(nextSibling, element);
	boolean nextIsOuterLanguageElement = nextSibling instanceof OuterLanguageElement || nextSibling instanceof LatteMacroClassic;
	return !nextIsOuterLanguageElement || psiElement == null || psiElement instanceof PsiFile;
}
 
Example #2
Source File: SMTRunnerConsoleProperties.java    From consulo with Apache License 2.0 6 votes vote down vote up
@javax.annotation.Nullable
@Deprecated
protected Navigatable findSuitableNavigatableForLine(@Nonnull Project project, @Nonnull VirtualFile file, int line) {
  // lets find first non-ws psi element

  final Document doc = FileDocumentManager.getInstance().getDocument(file);
  final PsiFile psi = doc == null ? null : PsiDocumentManager.getInstance(project).getPsiFile(doc);
  if (psi == null) {
    return null;
  }

  int offset = doc.getLineStartOffset(line);
  int endOffset = doc.getLineEndOffset(line);
  for (int i = offset + 1; i < endOffset; i++) {
    PsiElement el = psi.findElementAt(i);
    if (el != null && !(el instanceof PsiWhiteSpace)) {
      offset = el.getTextOffset();
      break;
    }
  }

  return new OpenFileDescriptor(project, file, offset);
}
 
Example #3
Source File: SimpleDuplicatesFinder.java    From consulo with Apache License 2.0 6 votes vote down vote up
public SimpleDuplicatesFinder(@Nonnull final PsiElement statement1,
                              @Nonnull final PsiElement statement2,
                              Collection<String> variables,
                              AbstractVariableData[] variableData) {
  myOutputVariables = variables;
  myParameters = new HashSet<>();
  for (AbstractVariableData data : variableData) {
    myParameters.add(data.getOriginalName());
  }
  myPattern = new ArrayList<>();
  PsiElement sibling = statement1;

  do {
    myPattern.add(sibling);
    if (sibling == statement2) break;
    sibling = PsiTreeUtil.skipSiblingsForward(sibling, PsiWhiteSpace.class, PsiComment.class);
  } while (sibling != null);
}
 
Example #4
Source File: RemoveUnusedAtFixBase.java    From bamboo-soy with Apache License 2.0 6 votes vote down vote up
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file)
    throws IncorrectOperationException {
  int offset = editor.getCaretModel().getOffset();
  PsiElement psiElement = file.findElementAt(offset);
  if (psiElement == null || !psiElement.isValid()) {
    return;
  }
  if (psiElement instanceof PsiWhiteSpace && offset > 0) {
    // The caret might be located right after the closing brace and before a newline, in which
    // case the current PsiElement is PsiWhiteSpace.
    psiElement = file.findElementAt(offset - 1);
  }
  AtElementSingle atElementSingle = PsiTreeUtil
      .getParentOfType(psiElement, AtElementSingle.class);
  if (atElementSingle == null) {
    return;
  }
  runFix((T) atElementSingle);
}
 
Example #5
Source File: TwigPattern.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
/**
 * {% include 'foo.html.twig' {'foo': 'foo'} only %}
 */
public static ElementPattern<PsiElement> getIncludeOnlyPattern() {

    // {% set count1 = "var" %}

    //noinspection unchecked
    return PlatformPatterns
        .psiElement(TwigTokenTypes.IDENTIFIER).withText("only")
        .beforeLeafSkipping(
            PlatformPatterns.or(
                PlatformPatterns.psiElement(PsiWhiteSpace.class),
                PlatformPatterns.psiElement(TwigTokenTypes.WHITE_SPACE)
            ),
            PlatformPatterns.psiElement(TwigTokenTypes.STATEMENT_BLOCK_END)
        )
        .withLanguage(TwigLanguage.INSTANCE);
}
 
Example #6
Source File: NodeSpecificHasherBase.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public int getNodeHash(PsiElement node) {
  if (node == null) {
    return 0;
  }
  if (node instanceof PsiWhiteSpace || node instanceof PsiErrorElement) {
    return 0;
  }
  else if (node instanceof LeafElement) {
    if (isToSkipAsLiteral(node)) {
      return 0;
    }
    return node.getText().hashCode();

  }
  return node.getClass().getName().hashCode();
}
 
Example #7
Source File: BuildFileRunLineMarkerContributor.java    From intellij with Apache License 2.0 6 votes vote down vote up
private static FuncallExpression getRuleFuncallExpression(PsiElement element) {
  PsiFile parentFile = element.getContainingFile();
  if (!(parentFile instanceof BuildFile)
      || ((BuildFile) parentFile).getBlazeFileType() != BlazeFileType.BuildPackage) {
    return null;
  }
  if (!(element instanceof LeafElement)
      || element instanceof PsiWhiteSpace
      || element instanceof PsiComment) {
    return null;
  }
  if (!(element.getParent() instanceof ReferenceExpression)) {
    return null;
  }
  PsiElement grandParent = element.getParent().getParent();
  return grandParent instanceof FuncallExpression
          && ((FuncallExpression) grandParent).isTopLevel()
      ? (FuncallExpression) grandParent
      : null;
}
 
Example #8
Source File: ExternalFormatProcessor.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * @param elementToFormat          the element from code file
 * @param range                    the range for formatting
 * @param canChangeWhiteSpacesOnly procedure can change only whitespaces
 * @return the element after formatting
 */
@Nonnull
static PsiElement formatElement(@Nonnull PsiElement elementToFormat, @Nonnull TextRange range, boolean canChangeWhiteSpacesOnly) {
  final PsiFile file = elementToFormat.getContainingFile();
  final Document document = file.getViewProvider().getDocument();
  if (document != null) {
    final TextRange rangeAfterFormat = formatRangeInFile(file, range, canChangeWhiteSpacesOnly);
    if (rangeAfterFormat != null) {
      PsiDocumentManager.getInstance(file.getProject()).commitDocument(document);
      if (!elementToFormat.isValid()) {
        PsiElement elementAtStart = file.findElementAt(rangeAfterFormat.getStartOffset());
        if (elementAtStart instanceof PsiWhiteSpace) {
          elementAtStart = PsiTreeUtil.nextLeaf(elementAtStart);
        }
        if (elementAtStart != null) {
          PsiElement parent = PsiTreeUtil.getParentOfType(elementAtStart, elementToFormat.getClass());
          if (parent != null) {
            return parent;
          }
          return elementAtStart;
        }
      }
    }
  }
  return elementToFormat;
}
 
Example #9
Source File: JSGraphQLEndpointSpellcheckingStrategy.java    From js-graphql-intellij-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public Tokenizer getTokenizer(PsiElement element) {
    if (element instanceof PsiWhiteSpace) {
        return EMPTY_TOKENIZER;
    }
    if (element instanceof PsiNameIdentifierOwner) {
        return new PsiIdentifierOwnerTokenizer();
    }
    if (element.getParent() instanceof PsiNameIdentifierOwner) {
        return EMPTY_TOKENIZER;
    }
    if (element.getNode().getElementType() == JSGraphQLEndpointTokenTypes.IDENTIFIER) {
        return IDENTIFIER_TOKENIZER;
    }
    if (element instanceof PsiComment) {
        if (SuppressionUtil.isSuppressionComment(element)) {
            return EMPTY_TOKENIZER;
        }
        return myCommentTokenizer;
    }
    return EMPTY_TOKENIZER;
}
 
Example #10
Source File: ANTLRv4FoldingBuilder.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@SuppressWarnings("ConstantConditions")
@Nullable
private static TextRange getFileHeader(PsiElement file) {
    PsiElement first = file.getFirstChild();
    if (first instanceof PsiWhiteSpace) first = first.getNextSibling();
    PsiElement element = first;
    while (isComment(element)) {
        element = element.getNextSibling();
        if (element instanceof PsiWhiteSpace) {
            element = element.getNextSibling();
        } else {
            break;
        }
    }
    if (element == null) return null;
    if (element.getPrevSibling() instanceof PsiWhiteSpace) element = element.getPrevSibling();
    if (element == null || element.equals(first)) return null;
    return new UnfairTextRange(first.getTextOffset(), element.getTextOffset());
}
 
Example #11
Source File: JSGraphQLEndpointDocPsiUtil.java    From js-graphql-intellij-plugin with MIT License 6 votes vote down vote up
/**
 * Gets whether the specified comment is considered documentation, i.e. that it's placed directly above a type or field definition
 */
public static boolean isDocumentationComment(PsiElement element) {
	if (element instanceof PsiComment) {
		PsiElement next = element.getNextSibling();
		while (next != null) {
			final boolean isWhiteSpace = next instanceof PsiWhiteSpace;
			if (next instanceof PsiComment || isWhiteSpace) {
				if (isWhiteSpace && StringUtils.countMatches(next.getText(), "\n") > 1) {
					// a blank line before the next element, so this comment is not directly above it
					break;
				}
				next = next.getNextSibling();
			} else {
				break;
			}
		}
		if (next instanceof JSGraphQLEndpointFieldDefinition || next instanceof JSGraphQLEndpointNamedTypeDefinition) {
			return true;
		}
	}
	return false;
}
 
Example #12
Source File: TwigUtil.java    From idea-php-toolbox with MIT License 6 votes vote down vote up
/**
 * Check for {{ include('|')  }}
 *
 * @param functionName twig function name
 */
public static ElementPattern<PsiElement> getPrintBlockFunctionPattern(String... functionName) {
    //noinspection unchecked
    return PlatformPatterns
        .psiElement(TwigTokenTypes.STRING_TEXT)
        .withParent(PlatformPatterns.or(
            PlatformPatterns.psiElement(TwigElementTypes.PRINT_BLOCK),
            PlatformPatterns.psiElement(TwigElementTypes.SET_TAG),
            PlatformPatterns.psiElement(TwigElementTypes.IF_TAG),
            PlatformPatterns.psiElement(TwigElementTypes.FUNCTION_CALL)
        ))
        .afterLeafSkipping(
            PlatformPatterns.or(
                PlatformPatterns.psiElement(TwigTokenTypes.LBRACE),
                PlatformPatterns.psiElement(PsiWhiteSpace.class),
                PlatformPatterns.psiElement(TwigTokenTypes.WHITE_SPACE),
                PlatformPatterns.psiElement(TwigTokenTypes.SINGLE_QUOTE),
                PlatformPatterns.psiElement(TwigTokenTypes.DOUBLE_QUOTE)
            ),
            PlatformPatterns.psiElement(TwigTokenTypes.IDENTIFIER).withText(PlatformPatterns.string().oneOf(functionName))
        )
        .withLanguage(TwigLanguage.INSTANCE);
}
 
Example #13
Source File: SimpleDuplicatesFinder.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
protected SimpleMatch isDuplicateFragment(@Nonnull final PsiElement candidate) {
  if (!canReplace(myReplacement, candidate)) return null;
  for (PsiElement pattern : myPattern) {
    if (PsiTreeUtil.isAncestor(pattern, candidate, false)) return null;
  }
  PsiElement sibling = candidate;
  final ArrayList<PsiElement> candidates = new ArrayList<>();
  for (int i = 0; i != myPattern.size(); ++i) {
    if (sibling == null) return null;

    candidates.add(sibling);
    sibling = PsiTreeUtil.skipSiblingsForward(sibling, PsiWhiteSpace.class, PsiComment.class);
  }
  if (myPattern.size() != candidates.size()) return null;
  if (candidates.size() <= 0) return null;
  final SimpleMatch match = new SimpleMatch(candidates.get(0), candidates.get(candidates.size() - 1));
  for (int i = 0; i < myPattern.size(); i++) {
    if (!matchPattern(myPattern.get(i), candidates.get(i), match)) return null;
  }
  return match;
}
 
Example #14
Source File: PsiElementUtils.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@Nullable
public static PsiElement getNextSiblingAndSkip(@NotNull PsiElement psiElement, @NotNull IElementType find, @NotNull IElementType... skip) {
    for (PsiElement child = psiElement.getNextSibling(); child != null; child = child.getNextSibling()) {
        if(child.getNode().getElementType() == find) {
            return child;
        }

        if(child instanceof PsiWhiteSpace) {
            continue;
        }

        if(!Arrays.asList(skip).contains(child.getNode().getElementType())) {
            return null;
        }
    }

    return null;
}
 
Example #15
Source File: DuplocatorUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static boolean isIgnoredNode(PsiElement element) {
  // ex. "var i = 0" in AS: empty JSAttributeList should be skipped
  /*if (element.getText().length() == 0) {
    return true;
  }*/

  if (element instanceof PsiWhiteSpace || element instanceof PsiErrorElement || element instanceof PsiComment) {
    return true;
  }

  if (!(element instanceof LeafElement)) {
    return false;
  }

  if (CharArrayUtil.containsOnlyWhiteSpaces(element.getText())) {
    return true;
  }

  EquivalenceDescriptorProvider descriptorProvider = EquivalenceDescriptorProvider.getInstance(element);
  if (descriptorProvider == null) {
    return false;
  }

  final IElementType elementType = ((LeafElement)element).getElementType();
  return descriptorProvider.getIgnoredTokens().contains(elementType);
}
 
Example #16
Source File: TwigPattern.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
/**
 * Check for {% if foo is "foo foo" %}
 */
public static ElementPattern<PsiElement> getAfterIsTokenWithOneIdentifierLeafPattern() {
    //noinspection unchecked
    return PlatformPatterns
        .psiElement()
        .afterLeafSkipping(
            PlatformPatterns.or(
                PlatformPatterns.psiElement(PsiWhiteSpace.class),
                PlatformPatterns.psiElement(TwigTokenTypes.WHITE_SPACE)
            ),
            PlatformPatterns.psiElement(TwigTokenTypes.IDENTIFIER).afterLeafSkipping(PlatformPatterns.psiElement(PsiWhiteSpace.class), PlatformPatterns.or(
                PlatformPatterns.psiElement(TwigTokenTypes.IS),
                PlatformPatterns.psiElement(TwigTokenTypes.NOT)
            ))
        )
        .withLanguage(TwigLanguage.INSTANCE);
}
 
Example #17
Source File: TwigUtil.java    From idea-php-toolbox with MIT License 6 votes vote down vote up
/**
 * Check for {{ include('|')  }}
 *
 * @param functionName twig function name
 */
public static ElementPattern<PsiElement> getPrintBlockFunctionPattern(String... functionName) {
    //noinspection unchecked
    return PlatformPatterns
        .psiElement(TwigTokenTypes.STRING_TEXT)
        .withParent(PlatformPatterns.or(
            PlatformPatterns.psiElement(TwigElementTypes.PRINT_BLOCK),
            PlatformPatterns.psiElement(TwigElementTypes.SET_TAG),
            PlatformPatterns.psiElement(TwigElementTypes.IF_TAG),
            PlatformPatterns.psiElement(TwigElementTypes.FUNCTION_CALL)
        ))
        .afterLeafSkipping(
            PlatformPatterns.or(
                PlatformPatterns.psiElement(TwigTokenTypes.LBRACE),
                PlatformPatterns.psiElement(PsiWhiteSpace.class),
                PlatformPatterns.psiElement(TwigTokenTypes.WHITE_SPACE),
                PlatformPatterns.psiElement(TwigTokenTypes.SINGLE_QUOTE),
                PlatformPatterns.psiElement(TwigTokenTypes.DOUBLE_QUOTE)
            ),
            PlatformPatterns.psiElement(TwigTokenTypes.IDENTIFIER).withText(PlatformPatterns.string().oneOf(functionName))
        )
        .withLanguage(TwigLanguage.INSTANCE);
}
 
Example #18
Source File: CustomFoldingSurroundDescriptor.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static boolean isWhiteSpaceWithLineFeed(@Nullable PsiElement element) {
  if (element == null) {
    return false;
  }
  if (element instanceof PsiWhiteSpace) {
    return element.textContains('\n');
  }
  final ASTNode node = element.getNode();
  if (node == null) {
    return false;
  }
  final CharSequence text = node.getChars();
  boolean lineFeedFound = false;
  for (int i = 0; i < text.length(); i++) {
    final char c = text.charAt(i);
    if (!StringUtil.isWhiteSpace(c)) {
      return false;
    }
    lineFeedFound |= c == '\n';
  }
  return lineFeedFound;
}
 
Example #19
Source File: TwigTypeResolveUtil.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
/**
 * Get items before foo.bar.car, foo.bar.car()
 *
 * ["foo", "bar"]
 */
@NotNull
public static Collection<String> formatPsiTypeName(@NotNull PsiElement psiElement) {
    String typeNames = PhpElementsUtil.getPrevSiblingAsTextUntil(psiElement, PlatformPatterns.or(
        PlatformPatterns.psiElement(TwigTokenTypes.LBRACE),
        PlatformPatterns.psiElement(PsiWhiteSpace.class
    )));

    if(typeNames.trim().length() == 0) {
        return Collections.emptyList();
    }

    if(typeNames.endsWith(".")) {
        typeNames = typeNames.substring(0, typeNames.length() -1);
    }

    Collection<String> possibleTypes = new ArrayList<>();
    if(typeNames.contains(".")) {
        possibleTypes.addAll(Arrays.asList(typeNames.split("\\.")));
    } else {
        possibleTypes.add(typeNames);
    }

    return possibleTypes;
}
 
Example #20
Source File: CSharpEnterInDocLineCommentHandler.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Override
@RequiredUIAccess
public Result preprocessEnter(@Nonnull final PsiFile file,
		@Nonnull final Editor editor,
		@Nonnull final Ref<Integer> caretOffsetRef,
		@Nonnull final Ref<Integer> caretAdvance,
		@Nonnull final DataContext dataContext,
		final EditorActionHandler originalHandler)
{
	final int caretOffset = caretOffsetRef.get();
	final Document document = editor.getDocument();
	final PsiElement psiAtOffset = file.findElementAt(caretOffset);
	final PsiElement probablyDocComment = psiAtOffset instanceof PsiWhiteSpace && psiAtOffset.getText().startsWith("\n") ? psiAtOffset.getPrevSibling() : psiAtOffset == null && caretOffset > 0
			&& caretOffset == document.getTextLength() ? file.findElementAt(caretOffset - 1) : psiAtOffset;

	if(probablyDocComment != null && PsiTreeUtil.getParentOfType(probablyDocComment, CSharpDocRoot.class, false) != null)
	{
		document.insertString(caretOffset, DOC_LINE_START + " ");
		caretAdvance.set(4);
		return Result.Default;
	}

	return Result.Continue;
}
 
Example #21
Source File: CS0145.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Override
public void invoke(@Nonnull Project project, Editor editor, PsiFile file) throws IncorrectOperationException
{
	DotNetVariable element = myVariablePointer.getElement();
	if(element == null)
	{
		return;
	}

	PsiDocumentManager.getInstance(project).commitAllDocuments();
	PsiElement constantKeywordElement = element.getConstantKeywordElement();
	if(constantKeywordElement == null)
	{
		return;
	}

	PsiElement nextSibling = constantKeywordElement.getNextSibling();

	constantKeywordElement.delete();
	if(nextSibling instanceof PsiWhiteSpace)
	{
		element.getNode().removeChild(nextSibling.getNode());
	}
}
 
Example #22
Source File: TwigPattern.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
/**
 * {{ form(foo) }}, {{ foo }}
 * NOT: {{ foo.bar }}, {{ 'foo.bar' }}
 */
public static ElementPattern<PsiElement> getCompletablePattern() {
    //noinspection unchecked
    return  PlatformPatterns.psiElement()
        .andNot(
            PlatformPatterns.or(
                PlatformPatterns.psiElement().afterLeaf(PlatformPatterns.psiElement(TwigTokenTypes.DOT)),
                PlatformPatterns.psiElement().afterLeaf(PlatformPatterns.psiElement(TwigTokenTypes.SINGLE_QUOTE)),
                PlatformPatterns.psiElement().afterLeaf(PlatformPatterns.psiElement(TwigTokenTypes.DOUBLE_QUOTE))
            )
        )
        .afterLeafSkipping(
            PlatformPatterns.or(
                PlatformPatterns.psiElement(TwigTokenTypes.LBRACE),
                PlatformPatterns.psiElement(PsiWhiteSpace.class)
            ),
            PlatformPatterns.psiElement()
        )
        .withParent(PlatformPatterns.or(
            PlatformPatterns.psiElement(TwigElementTypes.PRINT_BLOCK),
            PlatformPatterns.psiElement(TwigElementTypes.SET_TAG)
        ))
        .withLanguage(TwigLanguage.INSTANCE);
}
 
Example #23
Source File: CustomFoldingSurroundDescriptor.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public PsiElement[] getElementsToSurround(PsiFile file, int startOffset, int endOffset) {
  if (startOffset >= endOffset - 1) return PsiElement.EMPTY_ARRAY;
  Commenter commenter = LanguageCommenters.INSTANCE.forLanguage(file.getLanguage());
  if (commenter == null || commenter.getLineCommentPrefix() == null) return PsiElement.EMPTY_ARRAY;
  PsiElement startElement = file.findElementAt(startOffset);
  if (startElement instanceof PsiWhiteSpace) startElement = startElement.getNextSibling();
  PsiElement endElement = file.findElementAt(endOffset - 1);
  if (endElement instanceof PsiWhiteSpace) endElement = endElement.getPrevSibling();
  if (startElement != null && endElement != null) {
    if (startElement.getTextRange().getStartOffset() > endElement.getTextRange().getStartOffset()) return PsiElement.EMPTY_ARRAY;
    startElement = findClosestParentAfterLineBreak(startElement);
    if (startElement != null) {
      endElement = findClosestParentBeforeLineBreak(endElement);
      if (endElement != null) {
        PsiElement commonParent = startElement.getParent();
        if (endElement.getParent() == commonParent) {
          if (startElement == endElement) return new PsiElement[] {startElement};
          return new PsiElement[] {startElement, endElement};
        }
      }
    }
  }
  return PsiElement.EMPTY_ARRAY;
}
 
Example #24
Source File: TwigPattern.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
public static ElementPattern<PsiElement> getForTagInVariablePattern() {

        // {% for key, user in "users" %}
        // {% for user in "users" %}
        // {% for user in "users"|slice(0, 10) %}

        //noinspection unchecked
        return PlatformPatterns
            .psiElement(TwigTokenTypes.IDENTIFIER)
            .afterLeafSkipping(
                PlatformPatterns.or(
                    PlatformPatterns.psiElement(PsiWhiteSpace.class),
                    PlatformPatterns.psiElement(TwigTokenTypes.WHITE_SPACE)
                ),
                PlatformPatterns.psiElement(TwigTokenTypes.IN)
            )
            .withLanguage(TwigLanguage.INSTANCE);
    }
 
Example #25
Source File: TwigPattern.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
/**
 * {% FOOBAR "WANTED.html.twig" %}
 */
public static ElementPattern<PsiElement> getTagNameParameterPattern(@NotNull IElementType elementType, @NotNull String tagName) {
    //noinspection unchecked
    return PlatformPatterns
        .psiElement(TwigTokenTypes.STRING_TEXT)
        .withParent(
            PlatformPatterns.psiElement(elementType)
        )
        .afterLeafSkipping(
            PlatformPatterns.or(
                PlatformPatterns.psiElement(PsiWhiteSpace.class),
                PlatformPatterns.psiElement(TwigTokenTypes.WHITE_SPACE),
                PlatformPatterns.psiElement(TwigTokenTypes.SINGLE_QUOTE),
                PlatformPatterns.psiElement(TwigTokenTypes.DOUBLE_QUOTE)
            ),
            PlatformPatterns.psiElement(TwigTokenTypes.TAG_NAME).withText(tagName)
        )
        .withLanguage(TwigLanguage.INSTANCE);
}
 
Example #26
Source File: AMDPsiUtil.java    From needsmoredojo with Apache License 2.0 6 votes vote down vote up
/**
 * gets the next comma after an element OR in the case of the last define in the list it will get whitespace
 * or the bracket.
 *
 * @param start
 * @return
 */
public static PsiElement getNextDefineTerminator(PsiElement start)
{
    PsiElement sibling = start.getNextSibling();
    while(sibling != null && !(sibling instanceof JSLiteralExpression) && !(sibling instanceof JSParameter))
    {
        if(sibling instanceof PsiWhiteSpace)
        {
            return sibling;
        }

        sibling = sibling.getNextSibling();
    }

    return start.getParent().getLastChild();
}
 
Example #27
Source File: TwigPattern.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
/**
 * {% filter foo %}
 */
public static ElementPattern<PsiElement> getFilterTagPattern() {
    //noinspection unchecked
    return
        PlatformPatterns
            .psiElement(TwigTokenTypes.IDENTIFIER)
            .afterLeafSkipping(
                PlatformPatterns.or(
                    PlatformPatterns.psiElement(PsiWhiteSpace.class),
                    PlatformPatterns.psiElement(TwigTokenTypes.WHITE_SPACE)
                ),
                PlatformPatterns.psiElement(TwigTokenTypes.TAG_NAME)
            )
            .withParent(
                PlatformPatterns.psiElement(TwigElementTypes.FILTER_TAG)
            )
            .withLanguage(TwigLanguage.INSTANCE)
        ;
}
 
Example #28
Source File: AnnotationPattern.java    From idea-php-annotation-plugin with MIT License 6 votes vote down vote up
/**
 * matches "@Callback(property="<value>")"
 */
public static ElementPattern<PsiElement> getTextIdentifier() {
    return PlatformPatterns.psiElement(PhpDocTokenTypes.DOC_STRING)
        .withParent(PlatformPatterns.psiElement(StringLiteralExpression.class)
            .afterLeafSkipping(
                PlatformPatterns.or(
                    PlatformPatterns.psiElement(PhpDocTokenTypes.DOC_TEXT).withText(PlatformPatterns.string().containsChars("=")),
                    PlatformPatterns.psiElement(PsiWhiteSpace.class)
                ),
                PlatformPatterns.psiElement(PhpDocTokenTypes.DOC_IDENTIFIER)
            )
            .withParent(PlatformPatterns
                .psiElement(PhpDocElementTypes.phpDocAttributeList)
                .withParent(PlatformPatterns
                    .psiElement(PhpDocElementTypes.phpDocTag)
                )
            )
        );
}
 
Example #29
Source File: TwigPattern.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
public static ElementPattern<PsiElement> getTemplateFileReferenceTagPattern(String... tagNames) {

        // {% include '<xxx>' with {'foo' : bar, 'bar' : 'foo'} %}

        //noinspection unchecked
        return PlatformPatterns
            .psiElement(TwigTokenTypes.STRING_TEXT)
            .afterLeafSkipping(
                PlatformPatterns.or(
                    PlatformPatterns.psiElement(TwigTokenTypes.LBRACE),
                    PlatformPatterns.psiElement(PsiWhiteSpace.class),
                    PlatformPatterns.psiElement(TwigTokenTypes.WHITE_SPACE),
                    PlatformPatterns.psiElement(TwigTokenTypes.SINGLE_QUOTE),
                    PlatformPatterns.psiElement(TwigTokenTypes.DOUBLE_QUOTE)
                ),
                PlatformPatterns.psiElement(TwigTokenTypes.TAG_NAME).withText(PlatformPatterns.string().oneOf(tagNames))
            )
            .withLanguage(TwigLanguage.INSTANCE);
    }
 
Example #30
Source File: TwigPattern.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
/**
 * Check for {% if foo is "foo" %}
 */
public static ElementPattern<PsiElement> getAfterIsTokenPattern() {
    //noinspection unchecked
    return PlatformPatterns
        .psiElement()
        .afterLeafSkipping(
            PlatformPatterns.or(
                PlatformPatterns.psiElement(PsiWhiteSpace.class),
                PlatformPatterns.psiElement(TwigTokenTypes.WHITE_SPACE)
            ),
            PlatformPatterns.or(
                PlatformPatterns.psiElement(TwigTokenTypes.IS),
                PlatformPatterns.psiElement(TwigTokenTypes.NOT)
            )
        )
        .withLanguage(TwigLanguage.INSTANCE);
}