Java 类com.intellij.psi.impl.source.tree.LeafPsiElement 实例源码

项目:ReactPropTypes-Plugin    文件:CommonAction.java   
@NotNull
private List<PropTypeBean>  findPropsNameListWithIdentityReference(String identity, PsiElement psiElement){
  return PsiTreeUtil.findChildrenOfType(psiElement, LeafPsiElement.class)
          .stream()
          .filter(o -> o.getText().equals(identity))
          .filter(o -> o.getElementType().toString().equals("JS:IDENTIFIER"))
          .filter(o -> {
            if(o.getParent() instanceof JSReferenceExpressionImpl){
              JSReferenceExpressionImpl parent = (JSReferenceExpressionImpl) o.getParent();
              if(parent.getTreeNext()!=null && parent.getTreeNext().getElementType().toString().equals("JS:DOT")
                      &&parent.getTreeNext().getTreeNext()!=null){
                return true;
              }
            }
            return  false;
          })
          .map(o -> ((JSReferenceExpressionImpl)o.getParent()).getTreeNext().getTreeNext().getText())
          .distinct()
          .map(o -> new PropTypeBean(o,"any", false))
          .collect(Collectors.toList());
}
项目:yii2support    文件:CompletionContributor.java   
@Override
public boolean invokeAutoPopup(@NotNull PsiElement position, char typeChar) {
    MethodReference reference = PsiTreeUtil.getParentOfType(position, MethodReference.class);
    if (reference != null && ArrayUtil.contains(reference.getName(), ViewsUtil.renderMethods)) {
        if (typeChar == '\'' || typeChar == '"') {
            if (position instanceof LeafPsiElement && position.getText().equals("$view")) {
                return true;
            }
            if (position.getNextSibling() instanceof ParameterList) {
                return true;
            }
        }
    }

    return false;
}
项目:yii2support    文件:CompletionContributor.java   
@Override
public boolean invokeAutoPopup(@NotNull PsiElement position, char typeChar) {
    MethodReference reference = PsiTreeUtil.getParentOfType(position, MethodReference.class);
    if (reference != null && reference.getName() != null && reference.getName().equals("t") && reference.getClassReference() instanceof ClassReference) {
        ClassReference classReference = (ClassReference) reference.getClassReference();
        if (classReference == null || classReference.getName() == null || !classReference.getName().equals("Yii")) {
            return false;
        }
        if (typeChar == '\'' || typeChar == '"') {
            if (position instanceof LeafPsiElement && (position.getText().equals("$category") || position.getText().equals("$message"))) {
                return true;
            }
            if (position.getNextSibling() instanceof ParameterList) {
                return true;
            }
        }
    }

    return false;
}
项目:laravel-insight    文件:BladeFoldingBuilder.java   
private static int calculateEndOffsetReductor(
    @NotNull final PsiElement directive,
    final boolean isDefinitivelyClosing
) {
    if (!isDefinitivelyClosing) {
        final PsiElement directiveWhitespace = directive.getPrevSibling();

        if (directiveWhitespace instanceof LeafPsiElement) {
            final String directiveWhitespaceText = directiveWhitespace.getText();
            final int    lastBreakline           = directiveWhitespaceText.lastIndexOf('\n');

            if (lastBreakline != -1) {
                return directiveWhitespaceText.length() - lastBreakline;
            }
        }
    }

    return 0;
}
项目:idea-php-dotenv-plugin    文件:JsPsiHelper.java   
/**
 * @param psiElement checking element
 * @return true if this is process.env.*** variable
 */
public static boolean checkPsiElement(@NotNull PsiElement psiElement) {
    if(!(psiElement instanceof LeafPsiElement)) {
        return false;
    }

    IElementType elementType = ((LeafPsiElement) psiElement).getElementType();
    if(!elementType.toString().equals("JS:IDENTIFIER")) {
        return false;
    }

    PsiElement parent = psiElement.getParent();
    if(!(parent instanceof JSReferenceExpression)) {
        return false;
    }

    return ((JSReferenceExpression) parent).getCanonicalText().startsWith("process.env");
}
项目:intellij-postfix-templates    文件:CptAnnotator.java   
@Override
public void annotate(@NotNull final PsiElement element, @NotNull AnnotationHolder holder) {
    if (element instanceof LeafPsiElement) {
        final LeafPsiElement psiElement = (LeafPsiElement) element;

        if (psiElement.getElementType().equals(CptTypes.CLASS_NAME)) {
            final String className = element.getText();

            SupportedLanguages.getCptLang(element).ifPresent(lang -> {
                final CptLangAnnotator annotator = lang.getAnnotator();

                if (!annotator.isMatchingType(psiElement, className)) {
                    holder.createErrorAnnotation(element.getTextRange(), "Class not found");
                }
            });
        }
    }
}
项目:hybris-integration-intellij-idea-plugin    文件:ImpexMacrosGoToDeclarationHandler.java   
@Nullable
@Override
public PsiElement getGotoDeclarationTarget(final PsiElement sourceElement, final Editor editor) {
    if (!(sourceElement instanceof LeafPsiElement)
        || !(((LeafPsiElement) sourceElement)
                 .getElementType().equals(ImpexTypes.MACRO_USAGE))) {
        return null;
    }

    final PsiFile originalFile = sourceElement.getContainingFile();

    final Collection<ImpexMacroDeclaration> macroDeclarations =
        PsiTreeUtil.findChildrenOfType(
            originalFile,
            ImpexMacroDeclaration.class
        );

    if (!macroDeclarations.isEmpty()) {
        for (final ImpexMacroDeclaration declaration : macroDeclarations) {
            if (sourceElement.textMatches(declaration.getFirstChild())) {
                return declaration.getFirstChild();
            }
        }
    }
    return null;
}
项目:intellij-nette-tester    文件:TestCaseIsRunInspection.java   
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor problemDescriptor) {
    PsiElement element = problemDescriptor.getPsiElement();
    if ( ! (element instanceof PhpClass)) {
        return;
    }

    PsiFile containingFile = element.getContainingFile();
    PsiDocumentManager manager = PsiDocumentManager.getInstance(project);
    Document document = manager.getDocument(containingFile);

    PhpClass phpClass = (PhpClass) element;
    PsiElement abstractKeyword = PhpPsiElementFactory.createFromText(project, LeafPsiElement.class, "abstract");
    if (abstractKeyword == null) {
        return;
    }

    phpClass.addBefore(abstractKeyword, phpClass.getFirstChild());

    if (document != null) {
        manager.doPostponedOperationsAndUnblockDocument(document);
        TextRange reformatRange = abstractKeyword.getTextRange();
        CodeStyleManager.getInstance(project).reformatText(containingFile, reformatRange.getStartOffset(), reformatRange.getEndOffset());
    }
}
项目:intellij-ce-playground    文件:PyElementGeneratorImpl.java   
@Override
@NotNull
public PsiElement insertItemIntoListRemoveRedundantCommas(
  @NotNull final PyElement list,
  @Nullable final PyExpression afterThis,
  @NotNull final PyExpression toInsert) {
  // TODO: #insertItemIntoList is probably buggy. In such case, fix it and get rid of this method
  final PsiElement result = insertItemIntoList(list, afterThis, toInsert);
  final LeafPsiElement[] leafs = PsiTreeUtil.getChildrenOfType(list, LeafPsiElement.class);
  if (leafs != null) {
    final Deque<LeafPsiElement> commas = Queues.newArrayDeque(Collections2.filter(Arrays.asList(leafs), COMMAS_ONLY));
    if (!commas.isEmpty()) {
      final LeafPsiElement lastComma = commas.getLast();
      if (PsiTreeUtil.getNextSiblingOfType(lastComma, PyExpression.class) == null) { //Comma has no expression after it
        lastComma.delete();
      }
    }
  }

  return result;
}
项目:intellij-ce-playground    文件:GradleGroovyFile.java   
/**
 * Automatically reformats all the Groovy code inside the given closure.
 */
static void reformatClosure(@NotNull GrStatementOwner closure) {
  new ReformatCodeProcessor(closure.getProject(), closure.getContainingFile(), closure.getParent().getTextRange(), false)
      .runWithoutProgress();

  // Now strip out any blank lines. They tend to accumulate otherwise. To do this, we iterate through our elements and find those that
  // consist only of whitespace, and eliminate all double-newline occurrences.
  for (PsiElement psiElement : closure.getChildren()) {
    if (psiElement instanceof LeafPsiElement) {
      String text = psiElement.getText();
      if (StringUtil.isEmptyOrSpaces(text)) {
        String newText = text;
        while (newText.contains("\n\n")) {
          newText = newText.replaceAll("\n\n", "\n");
        }
        if (!newText.equals(text)) {
          ((LeafPsiElement)psiElement).replaceWithText(newText);
        }
      }
    }
  }
}
项目:intellij-ce-playground    文件:GradleGroovyFile.java   
@Override
public void visitElement(final @NotNull PsiElement element) {
  PsiElement e = element;
  while (e.getParent() != null) {
    myString.append("  ");
    e = e.getParent();
  }
  myString.append(element.getClass().getName());
  myString.append(": ");
  myString.append(element.toString());
  if (element instanceof LeafPsiElement) {
    myString.append(" ");
    myString.append(element.getText());
  }
  myString.append("\n");
  super.visitElement(element);
}
项目:intellij-ce-playground    文件:GroovyPatterns.java   
public static GroovyElementPattern.Capture<GrArgumentLabel> namedArgumentLabel(@Nullable final ElementPattern<? extends String> namePattern) {
  return new GroovyElementPattern.Capture<GrArgumentLabel>(new InitialPatternCondition<GrArgumentLabel>(GrArgumentLabel.class) {
    @Override
    public boolean accepts(@Nullable final Object o, final ProcessingContext context) {
      if (o instanceof GrArgumentLabel) {
        PsiElement nameElement = ((GrArgumentLabel)o).getNameElement();
        if (nameElement instanceof LeafPsiElement) {
          IElementType elementType = ((LeafPsiElement)nameElement).getElementType();
          if (elementType == GroovyTokenTypes.mIDENT ||
              CommonClassNames.JAVA_LANG_STRING.equals(TypesUtil.getBoxedTypeName(elementType))) {
            return namePattern == null || namePattern.accepts(((GrArgumentLabel)o).getName());
          }
        }
      }

      return false;
    }
  });
}
项目:intellij-ce-playground    文件:GroovyFoldingBuilder.java   
private static void processImports(final List<FoldingDescriptor> descriptors, GrImportStatement[] imports) {
  if (imports.length < 2) return;

  PsiElement first = imports[0];
  while (first != null) {
    PsiElement marker = first;
    PsiElement next = first.getNextSibling();
    while (next instanceof GrImportStatement || next instanceof LeafPsiElement) {
      if (next instanceof GrImportStatement) marker = next;
      next = next.getNextSibling();
    }
    if (marker != first) {
      int start = first.getTextRange().getStartOffset();
      int end = marker.getTextRange().getEndOffset();
      int tail = "import ".length();
      if (start + tail < end && !JavaFoldingBuilderBase.hasErrorElementsNearby(first.getContainingFile(), start, end)) {
        descriptors.add(new FoldingDescriptor(first.getNode(), new TextRange(start + tail, end)));
      }
    }
    while (!(next instanceof GrImportStatement) && next != null) next = next.getNextSibling();
    first = next;
  }
}
项目:intellij-ce-playground    文件:GroovyBlockGenerator.java   
private void alignSpockTable(List<GrStatement> group) {
  if (group.size() < 2) {
    return;
  }
  GrStatement inner = group.get(0);
  boolean embedded = inner != null && isTablePart(inner);

  GrStatement first = embedded ? inner : group.get(1);
  List<AlignmentProvider.Aligner> alignments = ContainerUtil
    .map2List(getSpockTable(first), new Function<LeafPsiElement, AlignmentProvider.Aligner>() {
      @Override
      public AlignmentProvider.Aligner fun(LeafPsiElement leaf) {
        return myAlignmentProvider.createAligner(leaf, true, Alignment.Anchor.RIGHT);
      }
    });

  int second = embedded ? 1 : 2;
  for (int i = second; i < group.size(); i++) {
    List<LeafPsiElement> table = getSpockTable(group.get(i));
    for (int j = 0; j < Math.min(table.size(), alignments.size()); j++) {
      alignments.get(j).append(table.get(j));
    }
  }
}
项目:orm-intellij    文件:ModifierHighlighterAnnotator.java   
@Override
public void annotate(@NotNull PsiElement psiElement, @NotNull AnnotationHolder annotationHolder)
{
    PsiElement parent = psiElement.getParent();
    IElementType type = psiElement instanceof LeafPsiElement ? psiElement.getNode().getElementType() : null;

    // LBRACE || RBRACE
    if (parent instanceof PhpDocTagModifier && (type == PhpDocTokenTypes.DOC_LBRACE || type == PhpDocTokenTypes.DOC_RBRACE)) {
        annotationHolder.createInfoAnnotation(psiElement, null).setTextAttributes(ModifierHighlighter.BRACES);

    } else if (psiElement instanceof PhpDocTagModifierName) {
        annotationHolder.createInfoAnnotation(psiElement, null).setTextAttributes(ModifierHighlighter.MODIFIER);

    } else if (psiElement instanceof PhpDocTagModifierIdentifier || psiElement instanceof PhpDocTagModifierClassType) {
        annotationHolder.createInfoAnnotation(psiElement, null).setTextAttributes(ModifierHighlighter.IDENTIFIER);
    }
}
项目:js-graphql-intellij-plugin    文件:JSGraphQLStructureViewModel.java   
@Override
public boolean isAlwaysLeaf(StructureViewTreeElement element) {
    if(element instanceof JSGraphQLStructureViewTreeElement) {
        JSGraphQLStructureViewTreeElement treeElement = (JSGraphQLStructureViewTreeElement)element;
        if (treeElement.childrenBase instanceof LeafPsiElement) {
            return true;
        }
        if (treeElement.childrenBase instanceof JSGraphQLNamedPropertyPsiElement) {
            final PsiElement[] children = treeElement.childrenBase.getChildren();
            if (children.length == 0) {
                // field with no sub selections, but we have to check if there's attributes
                final PsiElement nextVisible = PsiTreeUtil.nextVisibleLeaf(treeElement.childrenBase);
                if(nextVisible != null && nextVisible.getNode().getElementType() == JSGraphQLTokenTypes.LPAREN) {
                    return false;
                }
                return true;
            }
            if (children.length == 1 && children[0] instanceof LeafPsiElement) {
                return true;
            }
        }
    }
    return false;
}
项目:spoofax-intellij    文件:MetaborgIdentifierManipulator.java   
@Override
public SpoofaxIdentifier handleContentChange(
        final SpoofaxIdentifier element, final TextRange range, final String newContent) throws
        IncorrectOperationException {

    final String oldText = element.getText();
    final String newText = oldText.substring(
            0,
            range.getStartOffset()
    ) + newContent + oldText.substring(range.getEndOffset());
    final PsiElement child = element.getFirstChild();
    if (child instanceof LeafPsiElement) {
        ((LeafPsiElement)child).replaceWithText(newText);
        return element;
    }
    throw new IncorrectOperationException("Bad PSI.");
}
项目:spoofax-intellij    文件:SpoofaxIdentifierManipulator.java   
@Override
public SpoofaxIdentifier handleContentChange(
        final SpoofaxIdentifier element, final TextRange range, final String newContent) throws
        IncorrectOperationException {

    final String oldText = element.getText();
    final String newText = oldText.substring(
            0,
            range.getStartOffset()
    ) + newContent + oldText.substring(range.getEndOffset());
    final PsiElement child = element.getFirstChild();
    if (!(child instanceof LeafPsiElement)) {
        throw new IncorrectOperationException("Bad PSI.");
    }

    ((LeafPsiElement)child).replaceWithText(newText);
    return element;
}
项目:idea-php-laravel-plugin    文件:TemplateLineMarker.java   
/**
 * Support: @push('foobar')
 */
@NotNull
private Collection<LineMarkerInfo> collectPushOverwrites(@NotNull LeafPsiElement psiElement, @NotNull String sectionName) {
    final List<GotoRelatedItem> gotoRelatedItems = new ArrayList<>();

    BladeTemplateUtil.visitUpPath(psiElement.getContainingFile(), 10, parameter -> {
        if(sectionName.equalsIgnoreCase(parameter.getContent())) {
            gotoRelatedItems.add(new RelatedPopupGotoLineMarker.PopupGotoRelatedItem(parameter.getPsiElement()).withIcon(LaravelIcons.LARAVEL, LaravelIcons.LARAVEL));
        }
    }, BladeTokenTypes.STACK_DIRECTIVE);

    if(gotoRelatedItems.size() == 0) {
        return Collections.emptyList();
    }

    return Collections.singletonList(
        getRelatedPopover("Stack Section", "Stack Overwrites", psiElement, gotoRelatedItems, PhpIcons.OVERRIDES)
    );
}
项目:robot-intellij-plugin    文件:RobotVariableCompletionHelper.java   
private <T extends PsiElement> Set<LookupElement> getLookupElementsFromScalarVariables(LeafPsiElement element,
                                                                                       Class<T> variableClass,
                                                                                       Set<String> includedNormalNames) {
    // List of all scalar elements in scope
    List<T> scalarsInScope = RobotPsiUtil.findVariablesInScope(element, variableClass);
    Set<LookupElement> lookupElements = Sets.newHashSet();
    for (T var: scalarsInScope) {
        Optional<String> variableNameOpt = RobotVariableUtil.getVariableName(var);
        if (!variableNameOpt.isPresent()) {
            continue;
        }
        String variableName = variableNameOpt.get();
        String normalizedVariableName = RobotPsiUtil.normalizeKeywordForIndex(variableName);
        // Remove duplicates
        if (includedNormalNames.contains(normalizedVariableName)) {
            continue;
        }
        LookupElement lookupElement = createLookupElementFromVariableName(variableName);
        lookupElements.add(lookupElement);
        includedNormalNames.add(normalizedVariableName);
    }
    return lookupElements;
}
项目:robot-intellij-plugin    文件:RobotCompletionProvider.java   
@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
    PsiElement element = parameters.getOriginalPosition();
    if (!(element instanceof LeafPsiElement)) {
        return;
    }
    LeafPsiElement leaf = (LeafPsiElement) element;
    if (leaf.getElementType() == RobotTypes.TAG_TOKEN) {
        RobotTagCompletionHelper.INSTANCE.handleCompletions(leaf, parameters, result);
    } else if (leaf.getElementType() == RobotTypes.ROBOT_KEYWORD_TOKEN) {
        RobotKeywordCompletionHelper.INSTANCE.handleCompletions(leaf, parameters, result);
        RobotVariableCompletionHelper.INSTANCE.handleCompletions(leaf, parameters, result);
    } else if (leaf.getElementType() == RobotTypes.ROBOT_KEYWORD_ARG_TOKEN) {
        RobotVariableCompletionHelper.INSTANCE.handleCompletions(leaf, parameters, result);
    } else if (leaf.getElementType() == RobotTypes.VARIABLE_TOKEN || leaf.getElementType() == RobotTypes.ASSIGNMENT_TOKEN){
        RobotVariableCompletionHelper.INSTANCE.handleCompletions(leaf, parameters, result);
    }
}
项目:tools-idea    文件:GroovyBlockGenerator.java   
private void alignSpockTable(List<GrStatement> group) {
  if (group.size() < 2) {
    return;
  }
  GrStatement inner = ((GrLabeledStatement)group.get(0)).getStatement();
  boolean embedded = inner != null && isTablePart(inner);

  GrStatement first = embedded ? inner : group.get(1);
  List<AlignmentProvider.Aligner> alignments = ContainerUtil
    .map2List(getSpockTable(first), new Function<LeafPsiElement, AlignmentProvider.Aligner>() {
      @Override
      public AlignmentProvider.Aligner fun(LeafPsiElement leaf) {
        return myAlignmentProvider.createAligner(leaf, true, Alignment.Anchor.RIGHT);
      }
    });

  int second = embedded ? 1 : 2;
  for (int i = second; i < group.size(); i++) {
    List<LeafPsiElement> table = getSpockTable(group.get(i));
    for (int j = 0; j < Math.min(table.size(), alignments.size()); j++) {
      alignments.get(j).append(table.get(j));
    }
  }
}
项目:tools-idea    文件:GroovyPatterns.java   
public static GroovyElementPattern.Capture<GrArgumentLabel> namedArgumentLabel(@Nullable final ElementPattern<? extends String> namePattern) {
  return new GroovyElementPattern.Capture<GrArgumentLabel>(new InitialPatternCondition<GrArgumentLabel>(GrArgumentLabel.class) {
    public boolean accepts(@Nullable final Object o, final ProcessingContext context) {
      if (o instanceof GrArgumentLabel) {
        PsiElement nameElement = ((GrArgumentLabel)o).getNameElement();
        if (nameElement instanceof LeafPsiElement) {
          IElementType elementType = ((LeafPsiElement)nameElement).getElementType();
          if (elementType == GroovyTokenTypes.mIDENT ||
              CommonClassNames.JAVA_LANG_STRING.equals(TypesUtil.getBoxedTypeName(elementType))) {
            return namePattern == null || namePattern.accepts(((GrArgumentLabel)o).getName());
          }
        }
      }

      return false;
    }
  });
}
项目:tools-idea    文件:GroovyFoldingBuilder.java   
private static void processImports(final List<FoldingDescriptor> descriptors, GrImportStatement[] imports) {
  if (imports.length < 2) return;

  PsiElement first = imports[0];
  while (first != null) {
    PsiElement marker = first;
    PsiElement next = first.getNextSibling();
    while (next instanceof GrImportStatement || next instanceof LeafPsiElement) {
      if (next instanceof GrImportStatement) marker = next;
      next = next.getNextSibling();
    }
    if (marker != first) {
      int start = first.getTextRange().getStartOffset();
      int end = marker.getTextRange().getEndOffset();
      int tail = "import ".length();
      if (start + tail < end && !JavaFoldingBuilderBase.hasErrorElementsNearby(first.getContainingFile(), start, end)) {
        descriptors.add(new FoldingDescriptor(first.getNode(), new TextRange(start + tail, end)));
      }
    }
    while (!(next instanceof GrImportStatement) && next != null) next = next.getNextSibling();
    first = next;
  }
}
项目:StringManipulation    文件:AbstractCaseConvertingAction.java   
private boolean propertiesHandling(Editor editor, DataContext dataContext, SelectionModel selectionModel,
        PsiFile psiFile) {
    PsiElement elementAtCaret = PsiUtilBase.getElementAtCaret(editor);
    if (elementAtCaret instanceof PsiWhiteSpace) {
        return false;
    } else if (elementAtCaret instanceof LeafPsiElement) {
        IElementType elementType = ((LeafPsiElement) elementAtCaret).getElementType();
        if (elementType.toString().equals("Properties:VALUE_CHARACTERS")
                || elementType.toString().equals("Properties:KEY_CHARACTERS")) {
            TextRange textRange = elementAtCaret.getTextRange();
            if (textRange.getLength() == 0) {
                return super.selectSomethingUnderCaret(editor, dataContext, selectionModel);
            }
            selectionModel.setSelection(textRange.getStartOffset(), textRange.getEndOffset());
            return true;
        }
    }
    return false;
}
项目:intellij-haxe    文件:HaxeResolveUtil.java   
public static Set<IElementType> getDeclarationTypes(@Nullable List<HaxeDeclarationAttribute> attributeList) {
  if (attributeList == null || attributeList.isEmpty()) {
    return Collections.emptySet();
  }
  final Set<IElementType> resultSet = new THashSet<IElementType>();
  for (HaxeDeclarationAttribute attribute : attributeList) {
    PsiElement result = attribute.getFirstChild();
    final HaxeAccess access = attribute.getAccess();
    if (access != null) {
      result = access.getFirstChild();
    }
    if (result instanceof LeafPsiElement) {
      resultSet.add(((LeafPsiElement)result).getElementType());
    }
  }
  return resultSet;
}
项目:intellij-xquery    文件:XQueryFormattingBlock.java   
@Nullable
private IElementType getIElementType(int newChildIndex) {
    Block block = getSubBlocks().get(newChildIndex - 1);
    while (block instanceof XQueryFormattingBlock && ! block.getSubBlocks().isEmpty()) {
        List<Block> subBlocks = block.getSubBlocks();
        Block childBlock = subBlocks.get(subBlocks.size() - 1);
        if (! (childBlock instanceof XQueryFormattingBlock)) break;
        else {
            ASTNode node = ((XQueryFormattingBlock) childBlock).getNode();
            PsiElement psi = node.getPsi();
            IElementType elementType = node.getElementType();
            if (elementType instanceof XQueryTokenType) break;
            if (psi instanceof LeafPsiElement || psi instanceof XQueryFunctionName || psi instanceof
                    XQueryVarName || psi instanceof XQueryNamespacePrefix)
                break;
        }
        block = childBlock;
    }
    return block instanceof XQueryFormattingBlock ? ((XQueryFormattingBlock) block).getNode().getElementType() :
            null;
}
项目:intellij-xquery    文件:VariableInsertHandler.java   
private PsiElement findElementBeforeNameFragment(InsertionContext context) {
    final PsiFile file = context.getFile();
    PsiElement element = file.findElementAt(context.getStartOffset() - 1);
    element = getElementInFrontOfWhitespace(file, element);
    if (element instanceof LeafPsiElement
            && ((LeafPsiElement) element).getElementType() == XQueryTypes.COLON) {
        PsiElement elementBeforeColon = file.findElementAt(context.getStartOffset() - 2);
        if (elementBeforeColon != null) {
            element = elementBeforeColon;
            PsiElement beforeElementBeforeColon = file.findElementAt(elementBeforeColon.getTextRange().getStartOffset() - 1);
            if (beforeElementBeforeColon != null) {
                element = getElementInFrontOfWhitespace(file, beforeElementBeforeColon);
            }
        }
    }
    return element;
}
项目:needsmoredojo    文件:DojoUnresolvedVariableInspection.java   
@Override
public boolean isSuppressedFor(@NotNull PsiElement element) {
    Project project = element.getProject();
    DojoSettings settings = ServiceManager.getService(project, DojoSettings.class);
    if(!settings.isNeedsMoreDojoEnabled())
    {
        return super.isSuppressedFor(element);
    }

    if(element instanceof LeafPsiElement)
    {
        LeafPsiElement leafPsiElement = (LeafPsiElement) element;
        if(leafPsiElement.getElementType() == JSTokenTypes.IDENTIFIER &&
                leafPsiElement.getParent() != null &&
                leafPsiElement.getParent().getFirstChild() instanceof JSThisExpression)
        {
            return AttachPointResolver.getGotoDeclarationTargets(element, 0, null).length > 0 || super.isSuppressedFor(element);
        }
    }
    return super.isSuppressedFor(element);
}
项目:consulo-haxe    文件:HaxeResolveUtil.java   
public static Set<IElementType> getDeclarationTypes(@Nullable List<HaxeDeclarationAttribute> attributeList)
{
    if(attributeList == null || attributeList.isEmpty())
    {
        return Collections.emptySet();
    }
    final Set<IElementType> resultSet = new THashSet<IElementType>();
    for(HaxeDeclarationAttribute attribute : attributeList)
    {
        PsiElement result = attribute.getFirstChild();
        final HaxeAccess access = attribute.getAccess();
        if(access != null)
        {
            result = access.getFirstChild();
        }
        if(result instanceof LeafPsiElement)
        {
            resultSet.add(((LeafPsiElement) result).getElementType());
        }
    }
    return resultSet;
}
项目:DeftIDEA    文件:DylanFormattingBlock.java   
private IElementType getIElementType(int newChildIndex) {
  Block block = getSubBlocks().get(newChildIndex - 1);
  while (block instanceof DylanFormattingBlock && !block.getSubBlocks().isEmpty()) {
    List<Block> subBlocks = block.getSubBlocks();
    Block childBlock = subBlocks.get(subBlocks.size() - 1);
    if (!(childBlock instanceof DylanFormattingBlock)) {
      break;
    } else {
      ASTNode node = ((DylanFormattingBlock) childBlock).getNode();
      PsiElement psi = node.getPsi();
      IElementType elementType = node.getElementType();
      if (elementType instanceof DylanTokenType) break;
      if (psi instanceof LeafPsiElement) break;
    }
    block = childBlock;
  }
  return block instanceof DylanFormattingBlock ? ((DylanFormattingBlock) block).getNode().getElementType() : null;
}
项目:consulo    文件:DefaultASTLeafFactory.java   
@Nonnull
@Override
public LeafElement createLeaf(@Nonnull IElementType type, @Nonnull LanguageVersion languageVersion, @Nonnull CharSequence text) {
  final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(type.getLanguage());
  if(parserDefinition != null) {
    if(parserDefinition.getCommentTokens(languageVersion).contains(type)) {
      return new PsiCoreCommentImpl(type, text);
    }
  }

  // this is special case, then type is WHITE_SPACE, but no parser definition
  if(type == TokenType.WHITE_SPACE) {
    return new PsiWhiteSpaceImpl(text);
  }

  if (type instanceof ILeafElementType) {
    return (LeafElement)((ILeafElementType)type).createLeafNode(text);
  }
  return new LeafPsiElement(type, text);
}
项目:laravel-insight    文件:ArrayAdapter.java   
ArrayElement(
    final PsiElement arrayElement,
    final AtomicInteger elementIndex
) {
    if (arrayElement instanceof ArrayHashElement) {
        key = ((ArrayHashElement) arrayElement).getKey();
        value = ((ArrayHashElement) arrayElement).getValue();
    }
    else {
        key = PhpPsiElementFactory.createFromText(arrayElement.getProject(), LeafPsiElement.class, String.valueOf(elementIndex.get()));
        value = ((PhpPsiElement) arrayElement).getFirstPsiChild();
        isIndexed = true;
        elementIndex.incrementAndGet();
    }
}
项目:intellij-postfix-templates    文件:JavaAnnotator.java   
@Override
public boolean isMatchingType(@NotNull LeafPsiElement element, @NotNull String className) {
    return className2exists.computeIfAbsent(className, name -> {
        final Project project = element.getProject();
        return JavaPsiFacade.getInstance(project).findClass(className, GlobalSearchScope.allScope(project)) != null;
    });
}
项目:intellij-postfix-templates    文件:ScalaAnnotator.java   
@Override
public boolean isMatchingType(@NotNull LeafPsiElement element, @NotNull String className) {
    return className2exists.computeIfAbsent(className, name -> {
        final Project project = element.getProject();
        return JavaPsiFacade.getInstance(project).findClass(className, GlobalSearchScope.allScope(project)) != null;
    });
}
项目:GravSupport    文件:SwitchToTemplateLineMarkerProvider.java   
@Override
public boolean isAccepted(PsiElement element) {
    if (isWithinHeader >= 2) return false;
    if (element.getText().contentEquals("---")) {
        isWithinHeader++;
    }
    if (element instanceof LeafPsiElement && element.getText().contains("template")) {
        return true;
    }
    return false;
}
项目:lua-for-idea    文件:LuaDocCompletionData.java   
/**
 * Template to add all standard keywords completions
 *
 * @param filter   - Semantic filter for given keywords
 * @param keywords - Keywords to be completed
 */
private void registerStandardCompletion(ElementFilter filter, String... keywords) {
    LeftNeighbour afterDotFilter = new LeftNeighbour(new PlainTextFilter("."));
    CompletionVariant variant = new CompletionVariant(new AndFilter(new NotFilter(afterDotFilter), filter));
    variant.includeScopeClass(LeafPsiElement.class);
    variant.addCompletionFilter(TrueFilter.INSTANCE);
    addCompletions(variant, keywords);
    registerVariant(variant);
}
项目:elm-plugin    文件:ElmMainCompletionProvider.java   
private static boolean isAfterLowerCaseOrWhiteSpace(PsiElement element) {
    if (!(element instanceof LeafPsiElement)) {
        return false;
    }
    int i = ((LeafPsiElement) element).getStartOffset();
    PsiFile file = element.getContainingFile();
    PsiElement prev = file.findElementAt(i - 1);
    if (!isElementOfType(prev, ElmTypes.DOT) || !(prev instanceof LeafPsiElement)) {
        return false;
    }
    PsiElement prevPrev = file.findElementAt(((LeafPsiElement) prev).getStartOffset() - 1);
    return prevPrev instanceof PsiWhiteSpace || isElementOfType(prevPrev, ElmTypes.LOWER_CASE_IDENTIFIER);
}
项目:bxfs    文件:BxReferencePatterns.java   
/**
 * Capturing second parameter of $APPLICATION->IncludeComponent() call
 */
public static PhpElementPattern.Capture<StringLiteralExpression> bxComponentTemplateReference() {
    return new PhpElementPattern.Capture<StringLiteralExpression>(new InitialPatternCondition<StringLiteralExpression>(StringLiteralExpression.class) {
        @Override
        public boolean accepts(@Nullable Object o, ProcessingContext context) {
            /* LeafPsiElement - это недописанный элемент, которому необходим автокомплит. Сам элемент - его предок. */
            return !(o instanceof LeafPsiElement && !((o = ((LeafPsiElement) o).getParent()) instanceof StringLiteralExpression))
                && isValidComponentCall(o)
                && isParameterDepth(o, 2);
        }
    });
}
项目:camel-idea-plugin    文件:YamlIdeaUtils.java   
@Override
public Optional<String> extractTextFromElement(PsiElement element, boolean concatString, boolean stripWhitespace) {
    // maybe its yaml
    if (element instanceof LeafPsiElement) {
        IElementType type = ((LeafPsiElement) element).getElementType();
        if (type.getLanguage().isKindOf("yaml")) {
            return Optional.ofNullable(element.getText());
        }
    }
    return Optional.empty();
}