Java 类com.intellij.psi.filters.ElementFilter 实例源码

项目:intellij-ce-playground    文件:RecursionWeigher.java   
@Nullable
static ElementFilter recursionFilter(PsiElement element) {
  if (PsiJavaPatterns.psiElement().afterLeaf(PsiKeyword.RETURN).inside(PsiReturnStatement.class).accepts(element)) {
    return new ExcludeDeclaredFilter(ElementClassFilter.METHOD);
  }

  if (PsiJavaPatterns.psiElement().inside(
    StandardPatterns.or(
      PsiJavaPatterns.psiElement(PsiAssignmentExpression.class),
      PsiJavaPatterns.psiElement(PsiVariable.class))).
      andNot(PsiJavaPatterns.psiElement().afterLeaf(".")).accepts(element)) {
    return new AndFilter(new ExcludeSillyAssignment(),
                                                 new ExcludeDeclaredFilter(new ClassFilter(PsiVariable.class)));
  }
  return null;
}
项目:intellij-ce-playground    文件:PyMetaClassCompletionContributor.java   
public static FilterPattern hasLanguageLevel(@NotNull final Processor<LanguageLevel> processor) {
  return new FilterPattern(new ElementFilter() {
    @Override
    public boolean isAcceptable(Object element, @Nullable PsiElement context) {
      if (element instanceof PsiElement) {
        return processor.process(LanguageLevel.forElement((PsiElement)element));
      }
      return false;
    }

    @Override
    public boolean isClassAcceptable(Class hintClass) {
      return true;
    }
  });
}
项目:intellij-ce-playground    文件:DomMetaDataContributor.java   
@Override
public void contributeMetaData(MetaDataRegistrar registrar) {
  registrar.registerMetaData(new ElementFilter() {
    @Override
    public boolean isAcceptable(Object element, PsiElement context) {
      if (element instanceof XmlTag) {
        final XmlTag tag = (XmlTag)element;
        final DomElement domElement = DomManager.getDomManager(tag.getProject()).getDomElement(tag);
        if (domElement != null) {
          return domElement.getGenericInfo().getNameDomElement(domElement) != null;
        }
      }
      return false;
    }

    @Override
    public boolean isClassAcceptable(Class hintClass) {
      return XmlTag.class.isAssignableFrom(hintClass);
    }
  }, DomMetaData.class);
}
项目:intellij-ce-playground    文件:IdReferenceProvider.java   
public ElementFilter getIdForFilter() {
  return new ElementFilter() {
    @Override
    public boolean isAcceptable(Object element, PsiElement context) {
      final PsiElement grandParent = ((PsiElement)element).getParent().getParent();
      if (grandParent instanceof XmlTag) {
        final XmlTag tag = (XmlTag)grandParent;

        if (!tag.getNamespacePrefix().isEmpty()) {
          return true;
        }
      }
      return false;
    }

    @Override
    public boolean isClassAcceptable(Class hintClass) {
      return true;
    }
  };
}
项目:intellij-ce-playground    文件:XmlUtil.java   
public static void registerXmlAttributeValueReferenceProvider(PsiReferenceRegistrar registrar,
                                                              @Nullable @NonNls String[] attributeNames,
                                                              @Nullable ElementFilter elementFilter,
                                                              boolean caseSensitive,
                                                              @NotNull PsiReferenceProvider provider,
                                                              double priority) {
  if (attributeNames == null) {
    registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().and(new FilterPattern(elementFilter)), provider, priority);
    return;
  }

  final StringPattern namePattern = caseSensitive
                                    ? StandardPatterns.string().oneOf(attributeNames)
                                    : StandardPatterns.string().oneOfIgnoreCase(attributeNames);
  registrar
    .registerReferenceProvider(XmlPatterns.xmlAttributeValue().withLocalName(namePattern).and(new FilterPattern(elementFilter)), provider,
                               priority);
}
项目:intellij-ce-playground    文件:XmlUtil.java   
public static void registerXmlTagReferenceProvider(PsiReferenceRegistrar registrar,
                                                   @NonNls String[] names,
                                                   @Nullable ElementFilter elementFilter,
                                                   boolean caseSensitive,
                                                   @NotNull PsiReferenceProvider provider) {
  if (names == null) {
    registrar.registerReferenceProvider(XmlPatterns.xmlTag().and(new FilterPattern(elementFilter)), provider,
                                        PsiReferenceRegistrar.DEFAULT_PRIORITY);
    return;
  }


  final StringPattern namePattern =
    caseSensitive ? StandardPatterns.string().oneOf(names) : StandardPatterns.string().oneOfIgnoreCase(names);
  registrar.registerReferenceProvider(XmlPatterns.xmlTag().withLocalName(namePattern).and(new FilterPattern(elementFilter)), provider,
                                      PsiReferenceRegistrar.DEFAULT_PRIORITY);
}
项目:intellij-ce-playground    文件:HtmlCompletionData.java   
@Override
protected ElementFilter createAttributeValueCompletionFilter() {
  return new ElementFilter() {
    @Override
    public boolean isAcceptable(Object element, PsiElement context) {
      if (isStyleAttributeContext(context)) return false;
      if ( isScriptContext((PsiElement)element) ) return false;
      return true;
    }

    @Override
    public boolean isClassAcceptable(Class hintClass) {
      return true;
    }
  };
}
项目:intellij-ce-playground    文件:JavaReferenceContributor.java   
public void registerReferenceProviders(@NotNull final PsiReferenceRegistrar registrar) {

    final JavaClassListReferenceProvider classListProvider = new JavaClassListReferenceProvider();
    registrar.registerReferenceProvider(xmlAttributeValue(), classListProvider, PsiReferenceRegistrar.LOWER_PRIORITY);
    registrar.registerReferenceProvider(xmlTag(), classListProvider, PsiReferenceRegistrar.LOWER_PRIORITY);

    final PsiReferenceProvider filePathReferenceProvider = new FilePathReferenceProvider();
    registrar.registerReferenceProvider(PlatformPatterns.psiElement(PsiLiteralExpression.class).and(new FilterPattern(new ElementFilter() {
      public boolean isAcceptable(Object element, PsiElement context) {
        PsiLiteralExpression literalExpression = (PsiLiteralExpression) context;
        final Map<String, Object> annotationParams = new HashMap<String, Object>();
        annotationParams.put(AnnotationUtil.PROPERTY_KEY_RESOURCE_BUNDLE_PARAMETER, null);
        return !JavaI18nUtil.mustBePropertyKey(context.getProject(), literalExpression, annotationParams);
      }

      public boolean isClassAcceptable(Class hintClass) {
        return true;
      }
    })), filePathReferenceProvider);
    registrar.registerReferenceProvider(PlatformPatterns.psiElement(PsiDocToken.class),
                                        CommentsReferenceContributor.COMMENTS_REFERENCE_PROVIDER_TYPE.getProvider());
  }
项目:intellij-ocaml    文件:OCamlCompletionContributor.java   
@NotNull
private ElementPattern isPossibleHere(@NotNull final String keyword) {
    return new FilterPattern(new ElementFilter() {
        public boolean isAcceptable(final Object element, final PsiElement context) {
            final CompletionParameters parameters = getCompletionParameters(element);
            if (parameters == null) return false;

            final PsiElement dummyElement = createDummyElement(parameters, keyword, false);
            return dummyElement != null && isCorrect(dummyElement);
        }

        public boolean isClassAcceptable(@NotNull final Class hintClass) {
            return true;
        }
    });
}
项目:tools-idea    文件:RecursionWeigher.java   
@Nullable
static ElementFilter recursionFilter(PsiElement element) {
  if (PsiJavaPatterns.psiElement().afterLeaf(PsiKeyword.RETURN).inside(PsiReturnStatement.class).accepts(element)) {
    return new ExcludeDeclaredFilter(ElementClassFilter.METHOD);
  }

  if (PsiJavaPatterns.psiElement().inside(
    StandardPatterns.or(
      PsiJavaPatterns.psiElement(PsiAssignmentExpression.class),
      PsiJavaPatterns.psiElement(PsiVariable.class))).
      andNot(PsiJavaPatterns.psiElement().afterLeaf(".")).accepts(element)) {
    return new AndFilter(new ExcludeSillyAssignment(),
                                                 new ExcludeDeclaredFilter(new ClassFilter(PsiVariable.class)));
  }
  return null;
}
项目:tools-idea    文件:JavaNoVariantsDelegator.java   
private static Set<LookupElement> suggestQualifierItems(CompletionParameters parameters,
                                                        PsiJavaCodeReferenceElement qualifier,
                                                        ElementFilter filter) {
  String referenceName = qualifier.getReferenceName();
  if (referenceName == null) {
    return Collections.emptySet();
  }

  PrefixMatcher qMatcher = new CamelHumpMatcher(referenceName);
  Set<LookupElement> plainVariants =
    JavaSmartCompletionContributor.completeReference(qualifier, qualifier, filter, true, true, parameters, qMatcher);

  for (PsiClass aClass : PsiShortNamesCache.getInstance(qualifier.getProject()).getClassesByName(referenceName, qualifier.getResolveScope())) {
    plainVariants.add(JavaClassNameCompletionContributor.createClassLookupItem(aClass, true));
  }

  if (!plainVariants.isEmpty()) {
    return plainVariants;
  }

  final Set<LookupElement> allClasses = new LinkedHashSet<LookupElement>();
  JavaClassNameCompletionContributor.addAllClasses(parameters.withPosition(qualifier.getReferenceNameElement(), qualifier.getTextRange().getEndOffset()),
                                                   true, qMatcher, new CollectConsumer<LookupElement>(allClasses));
  return allClasses;
}
项目:tools-idea    文件:JavaSmartCompletionContributor.java   
@Nullable
private static ElementFilter getReferenceFilter(PsiElement element) {
  //throw new foo
  if (AFTER_THROW_NEW.accepts(element)) {
    return new ElementExtractorFilter(THROWABLE_TYPE_FILTER);
  }

  //new xxx.yyy
  if (psiElement().afterLeaf(psiElement().withText(".")).withSuperParent(2, psiElement(PsiNewExpression.class)).accepts(element)) {
    if (((PsiNewExpression)element.getParent().getParent()).getClassReference() == element.getParent()) {
      return new GeneratorFilter(AssignableGroupFilter.class, new ExpectedTypesGetter());
    }
  }

  return null;
}
项目:tools-idea    文件:DomMetaDataContributor.java   
@Override
public void contributeMetaData(MetaDataRegistrar registrar) {
  registrar.registerMetaData(new ElementFilter() {
    public boolean isAcceptable(Object element, PsiElement context) {
      if (element instanceof XmlTag) {
        final XmlTag tag = (XmlTag)element;
        final DomElement domElement = DomManager.getDomManager(tag.getProject()).getDomElement(tag);
        if (domElement != null) {
          return domElement.getGenericInfo().getNameDomElement(domElement) != null;
        }
      }
      return false;
    }

    public boolean isClassAcceptable(Class hintClass) {
      return XmlTag.class.isAssignableFrom(hintClass);
    }
  }, DomMetaData.class);
}
项目:tools-idea    文件:XmlUtil.java   
public static void registerXmlAttributeValueReferenceProvider(PsiReferenceRegistrar registrar,
                                                              @Nullable @NonNls String[] attributeNames,
                                                              @Nullable ElementFilter elementFilter,
                                                              boolean caseSensitive,
                                                              @NotNull PsiReferenceProvider provider,
                                                              double priority) {
  if (attributeNames == null) {
    registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().and(new FilterPattern(elementFilter)), provider, priority);
    return;
  }

  final StringPattern namePattern = caseSensitive
                                    ? StandardPatterns.string().oneOf(attributeNames)
                                    : StandardPatterns.string().oneOfIgnoreCase(attributeNames);
  registrar
    .registerReferenceProvider(XmlPatterns.xmlAttributeValue().withLocalName(namePattern).and(new FilterPattern(elementFilter)), provider,
                               priority);
}
项目:tools-idea    文件:XmlUtil.java   
public static void registerXmlTagReferenceProvider(PsiReferenceRegistrar registrar,
                                                   @NonNls String[] names,
                                                   @Nullable ElementFilter elementFilter,
                                                   boolean caseSensitive,
                                                   @NotNull PsiReferenceProvider provider) {
  if (names == null) {
    registrar.registerReferenceProvider(XmlPatterns.xmlTag().and(new FilterPattern(elementFilter)), provider,
                                        PsiReferenceRegistrar.DEFAULT_PRIORITY);
    return;
  }


  final StringPattern namePattern =
    caseSensitive ? StandardPatterns.string().oneOf(names) : StandardPatterns.string().oneOfIgnoreCase(names);
  registrar.registerReferenceProvider(XmlPatterns.xmlTag().withLocalName(namePattern).and(new FilterPattern(elementFilter)), provider,
                                      PsiReferenceRegistrar.DEFAULT_PRIORITY);
}
项目:tools-idea    文件:HtmlCompletionData.java   
protected ElementFilter createTagCompletionFilter() {
  return new ElementFilter() {
    public boolean isAcceptable(Object element, PsiElement context) {
      String name = ((XmlTag)context).getName();

      if (element instanceof PsiElement && 
          ((PsiElement)element).getParent() == context) {
        return true;
      }

      if (equalNames(name, STYLE_TAG) ||
          equalNames(name,SCRIPT_TAG)) {
        return false;
      }

      if ( isStyleAttributeContext((PsiElement)element) ) return false;
      return true;
    }

    public boolean isClassAcceptable(Class hintClass) {
      return true;
    }
  };
}
项目:tools-idea    文件:IdReferenceProvider.java   
public ElementFilter getIdForFilter() {
  return new ElementFilter() {
    public boolean isAcceptable(Object element, PsiElement context) {
      final PsiElement grandParent = ((PsiElement)element).getParent().getParent();
      if (grandParent instanceof XmlTag) {
        final XmlTag tag = (XmlTag)grandParent;

        if (tag.getNamespacePrefix().length() > 0) {
          return true;
        }
      }
      return false;
    }

    public boolean isClassAcceptable(Class hintClass) {
      return true;
    }
  };
}
项目:tools-idea    文件:JavaReferenceContributor.java   
public void registerReferenceProviders(final PsiReferenceRegistrar registrar) {

    final JavaClassListReferenceProvider classListProvider = new JavaClassListReferenceProvider();
    registrar.registerReferenceProvider(xmlAttributeValue(), classListProvider, PsiReferenceRegistrar.LOWER_PRIORITY);
    registrar.registerReferenceProvider(xmlTag(), classListProvider, PsiReferenceRegistrar.LOWER_PRIORITY);

    final PsiReferenceProvider filePathReferenceProvider = new FilePathReferenceProvider();
    registrar.registerReferenceProvider(PlatformPatterns.psiElement(PsiLiteralExpression.class).and(new FilterPattern(new ElementFilter() {
      public boolean isAcceptable(Object element, PsiElement context) {
        PsiLiteralExpression literalExpression = (PsiLiteralExpression) context;
        final Map<String, Object> annotationParams = new HashMap<String, Object>();
        annotationParams.put(AnnotationUtil.PROPERTY_KEY_RESOURCE_BUNDLE_PARAMETER, null);
        return !JavaI18nUtil.mustBePropertyKey(context.getProject(), literalExpression, annotationParams);
      }

      public boolean isClassAcceptable(Class hintClass) {
        return true;
      }
    })), filePathReferenceProvider);
  }
项目:emberjs-plugin    文件:EmberJSReferencesContributor.java   
private static PsiElementPattern.Capture<JSLiteralExpression> literalInProperty(final String propertyName) {
    return PlatformPatterns.psiElement(JSLiteralExpression.class).and(new FilterPattern(new ElementFilter() {
        @Override
        public boolean isAcceptable(Object element, @Nullable PsiElement context) {
            if (element instanceof JSLiteralExpression) {
                final JSLiteralExpression literal = (JSLiteralExpression)element;
                if (literal.isQuotedLiteral()) {
                    final PsiElement parent = literal.getParent();
                    if (parent instanceof JSProperty && propertyName.equals(((JSProperty)parent).getName())) {
                        return EmberIndexUtil.hasEmberJS(literal.getProject());
                    }
                }
            }
            return false;
        }

        @Override
        public boolean isClassAcceptable(Class hintClass) {
            return true;
        }
    }));
}
项目:consulo-xml    文件:XmlUtil.java   
public static void registerXmlAttributeValueReferenceProvider(PsiReferenceRegistrar registrar,
        @Nullable @NonNls String[] attributeNames,
        @Nullable ElementFilter elementFilter,
        boolean caseSensitive,
        @NotNull PsiReferenceProvider provider,
        double priority)
{
    if(attributeNames == null)
    {
        registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().and(new FilterPattern(elementFilter)), provider, priority);
        return;
    }

    final StringPattern namePattern = caseSensitive ? StandardPatterns.string().oneOf(attributeNames) : StandardPatterns.string().oneOfIgnoreCase(attributeNames);
    registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().withLocalName(namePattern).and(new FilterPattern(elementFilter)), provider, priority);
}
项目:consulo-xml    文件:XmlUtil.java   
public static void registerXmlTagReferenceProvider(PsiReferenceRegistrar registrar,
        @NonNls String[] names,
        @Nullable ElementFilter elementFilter,
        boolean caseSensitive,
        @NotNull PsiReferenceProvider provider)
{
    if(names == null)
    {
        registrar.registerReferenceProvider(XmlPatterns.xmlTag().and(new FilterPattern(elementFilter)), provider, PsiReferenceRegistrar.DEFAULT_PRIORITY);
        return;
    }


    final StringPattern namePattern = caseSensitive ? StandardPatterns.string().oneOf(names) : StandardPatterns.string().oneOfIgnoreCase(names);
    registrar.registerReferenceProvider(XmlPatterns.xmlTag().withLocalName(namePattern).and(new FilterPattern(elementFilter)), provider, PsiReferenceRegistrar.DEFAULT_PRIORITY);
}
项目:consulo-xml    文件:IdReferenceProvider.java   
public ElementFilter getIdForFilter() {
  return new ElementFilter() {
    public boolean isAcceptable(Object element, PsiElement context) {
      final PsiElement grandParent = ((PsiElement)element).getParent().getParent();
      if (grandParent instanceof XmlTag) {
        final XmlTag tag = (XmlTag)grandParent;

        if (tag.getNamespacePrefix().length() > 0) {
          return true;
        }
      }
      return false;
    }

    public boolean isClassAcceptable(Class hintClass) {
      return true;
    }
  };
}
项目:consulo-java    文件:SuperCalls.java   
static Set<LookupElement> suggestQualifyingSuperCalls(PsiElement element,
        PsiJavaReference javaReference,
        ElementFilter elementFilter,
        JavaCompletionProcessor.Options options,
        Condition<String> nameCondition)
{
    Set<LookupElement> set = ContainerUtil.newLinkedHashSet();
    for(final String className : getContainingClassNames(element))
    {
        PsiReferenceExpression fakeSuper = JavaCompletionUtil.createReference(className + ".super.rulez", element);
        PsiElement leaf = ObjectUtils.assertNotNull(fakeSuper.getReferenceNameElement());

        JavaCompletionProcessor superProcessor = new JavaCompletionProcessor(leaf, elementFilter, options, nameCondition);
        fakeSuper.processVariants(superProcessor);

        for(CompletionElement completionElement : superProcessor.getResults())
        {
            for(LookupElement item : JavaCompletionUtil.createLookupElements(completionElement, javaReference))
            {
                set.add(withQualifiedSuper(className, item));
            }
        }
    }
    return set;
}
项目:consulo-java    文件:JavaCompletionContributor.java   
private static ElementFilter createAnnotationFilter(PsiElement position)
{
    OrFilter orFilter = new OrFilter(ElementClassFilter.CLASS, ElementClassFilter.PACKAGE_FILTER, new AndFilter(new ClassFilter(PsiField.class), new ModifierFilter(PsiModifier.STATIC,
            PsiModifier.FINAL)));
    if(psiElement().insideStarting(psiNameValuePair()).accepts(position))
    {
        orFilter.addFilter(new ClassFilter(PsiAnnotationMethod.class)
        {
            @Override
            public boolean isAcceptable(Object element, PsiElement context)
            {
                return element instanceof PsiAnnotationMethod && PsiUtil.isAnnotationMethod((PsiElement) element);
            }
        });
    }
    return orFilter;
}
项目:consulo-java    文件:JavaKeywordCompletion.java   
@NotNull
@Override
protected ElementFilter compute()
{
    return new OrFilter(new AndFilter(new LeftNeighbour(new OrFilter(new AndFilter(new TextFilter("{", "}", ";", ":", "else"), new NotFilter(new SuperParentFilter(new ClassFilter
            (PsiAnnotation.class)))), new ElementFilter()
    {
        @Override
        public boolean isAcceptable(Object element, @Nullable PsiElement context)
        {
            return ((PsiElement) element).getText().endsWith("*/");
        }

        @Override
        public boolean isClassAcceptable(Class hintClass)
        {
            return true;
        }
    }, new ClassFilter(OuterLanguageElement.class), new AndFilter(new TextFilter(")"), new NotFilter(new OrFilter(new ParentElementFilter(new ClassFilter(PsiExpressionList.class)), new
            ParentElementFilter(new ClassFilter(PsiParameterList.class)), new ParentElementFilter(new ClassFilter(PsiTypeCastExpression.class))))))), new NotFilter(new TextFilter("."))),
            START_OF_CODE_FRAGMENT);
}
项目:consulo-java    文件:JavaReferenceContributor.java   
public void registerReferenceProviders(final PsiReferenceRegistrar registrar) {

    final JavaClassListReferenceProvider classListProvider = new JavaClassListReferenceProvider();
    registrar.registerReferenceProvider(xmlAttributeValue(), classListProvider, PsiReferenceRegistrar.LOWER_PRIORITY);
    registrar.registerReferenceProvider(xmlTag(), classListProvider, PsiReferenceRegistrar.LOWER_PRIORITY);

    final PsiReferenceProvider filePathReferenceProvider = new FilePathReferenceProvider();
    registrar.registerReferenceProvider(PlatformPatterns.psiElement(PsiLiteralExpression.class).and(new FilterPattern(new ElementFilter() {
      public boolean isAcceptable(Object element, PsiElement context) {
        PsiLiteralExpression literalExpression = (PsiLiteralExpression) context;
        final Map<String, Object> annotationParams = new HashMap<String, Object>();
        annotationParams.put(AnnotationUtil.PROPERTY_KEY_RESOURCE_BUNDLE_PARAMETER, null);
        return !JavaI18nUtil.mustBePropertyKey(context.getProject(), literalExpression, annotationParams);
      }

      public boolean isClassAcceptable(Class hintClass) {
        return true;
      }
    })), filePathReferenceProvider);
  }
项目:intellij-ce-playground    文件:ConflictFilterProcessor.java   
public ConflictFilterProcessor(String name,
                               @NotNull ElementFilter filter,
                               @NotNull PsiConflictResolver[] resolvers,
                               @NotNull List<CandidateInfo> container,
                               @NotNull PsiElement place,
                               PsiFile placeFile) {
  super(filter, container);
  myResolvers = resolvers;
  myName = name;
  myPlace = place;
  myPlaceFile = placeFile;
}
项目:intellij-ce-playground    文件:JavaNoVariantsDelegator.java   
private static void suggestChainedCalls(CompletionParameters parameters, CompletionResultSet result, PsiElement position) {
  PsiElement parent = position.getParent();
  if (!(parent instanceof PsiJavaCodeReferenceElement) || parent.getParent() instanceof PsiImportStatementBase) {
    return;
  }
  PsiElement qualifier = ((PsiJavaCodeReferenceElement)parent).getQualifier();
  if (!(qualifier instanceof PsiJavaCodeReferenceElement) ||
      ((PsiJavaCodeReferenceElement)qualifier).isQualified()) {
    return;
  }
  PsiElement target = ((PsiJavaCodeReferenceElement)qualifier).resolve();
  if (target != null && !(target instanceof PsiPackage)) {
    return;
  }

  PsiFile file = position.getContainingFile();
  if (file instanceof PsiJavaCodeReferenceCodeFragment) {
    return;
  }

  String fullPrefix = parent.getText().substring(0, parameters.getOffset() - parent.getTextRange().getStartOffset());
  CompletionResultSet qualifiedCollector = result.withPrefixMatcher(fullPrefix);
  ElementFilter filter = JavaCompletionContributor.getReferenceFilter(position);
  for (LookupElement base : suggestQualifierItems(parameters, (PsiJavaCodeReferenceElement)qualifier, filter)) {
    PsiType type = JavaCompletionUtil.getLookupElementType(base);
    if (type != null && !PsiType.VOID.equals(type)) {
      PsiReferenceExpression ref = ReferenceExpressionCompletionContributor.createMockReference(position, type, base);
      if (ref != null) {
        for (final LookupElement item : JavaSmartCompletionContributor.completeReference(position, ref, filter, true, true, parameters,
                                                                                         result.getPrefixMatcher())) {
          qualifiedCollector.addElement(JavaCompletionUtil.highlightIfNeeded(null, new JavaChainLookupElement(base, item), item.getObject(), position));
        }
      }
    }
  }
}
项目:intellij-ce-playground    文件:JavaNoVariantsDelegator.java   
private static Set<LookupElement> suggestQualifierItems(CompletionParameters parameters,
                                                        PsiJavaCodeReferenceElement qualifier,
                                                        ElementFilter filter) {
  String referenceName = qualifier.getReferenceName();
  if (referenceName == null) {
    return Collections.emptySet();
  }

  PrefixMatcher qMatcher = new CamelHumpMatcher(referenceName);
  Set<LookupElement> plainVariants =
    JavaSmartCompletionContributor.completeReference(qualifier, qualifier, filter, true, true, parameters, qMatcher);

  for (PsiClass aClass : PsiShortNamesCache.getInstance(qualifier.getProject()).getClassesByName(referenceName, qualifier.getResolveScope())) {
    plainVariants.add(JavaClassNameCompletionContributor.createClassLookupItem(aClass, true));
  }

  if (!plainVariants.isEmpty()) {
    return plainVariants;
  }

  final Set<LookupElement> allClasses = new LinkedHashSet<LookupElement>();
  PsiElement qualifierName = qualifier.getReferenceNameElement();
  if (qualifierName != null) {
    JavaClassNameCompletionContributor.addAllClasses(parameters.withPosition(qualifierName, qualifierName.getTextRange().getEndOffset()),
                                                     true, qMatcher, new CollectConsumer<LookupElement>(allClasses));
  }
  return allClasses;
}
项目:intellij-ce-playground    文件:JavaSmartCompletionContributor.java   
@Nullable
private static ElementFilter getClassReferenceFilter(PsiElement element) {
  //throw new foo
  if (AFTER_THROW_NEW.accepts(element)) {
    return THROWABLES_FILTER;
  }

  //throws list
  PsiMethod method = PsiTreeUtil.getParentOfType(element, PsiMethod.class);
  if (method != null && PsiTreeUtil.isAncestor(method.getThrowsList(), element, true)) {
    return THROWABLES_FILTER;
  }

  //new xxx.yyy
  if (psiElement().afterLeaf(psiElement().withText(".")).withSuperParent(2, psiElement(PsiNewExpression.class)).accepts(element)) {
    if (((PsiNewExpression)element.getParent().getParent()).getClassReference() == element.getParent()) {
      PsiType[] types = ExpectedTypesGetter.getExpectedTypes(element, false);
      return new OrFilter(ContainerUtil.map2Array(types, ElementFilter.class, new Function<PsiType, ElementFilter>() {
        @Override
        public ElementFilter fun(PsiType type) {
          return new AssignableFromFilter(type);
        }
      }));
    }
  }

  return null;
}
项目:intellij-ce-playground    文件:FilterPattern.java   
public FilterPattern(@Nullable final ElementFilter filter) {
  super(new InitialPatternCondition<Object>(Object.class) {
    @Override
    public boolean accepts(@Nullable final Object o, final ProcessingContext context) {
      return filter == null ||
             o != null &&
             filter.isClassAcceptable(o.getClass()) &&
             filter.isAcceptable(o, o instanceof PsiElement ? (PsiElement)o : null);
    }
  });
  myFilter = filter;
}
项目:intellij-ce-playground    文件:MetaRegistry.java   
/**
 * @see com.intellij.psi.meta.MetaDataContributor
 * @deprecated
 */
public static <T extends PsiMetaData> void addMetadataBinding(ElementFilter filter,
                                                              Class<T> aMetadataClass,
                                                              Disposable parentDisposable) {
  final MyBinding binding = new MyBinding(filter, aMetadataClass);
  addBinding(binding);
  Disposer.register(parentDisposable, new Disposable() {
    @Override
    public void dispose() {
      ourBindings.remove(binding);
    }
  });
}
项目:intellij-ce-playground    文件:CompletionVariant.java   
void addReferenceCompletions(PsiReference reference, PsiElement position, Set<LookupElement> set, final PsiFile file,
                                    final CompletionData completionData){
  for (final CompletionVariantItem ce : myCompletionsList) {
    if(ce.myCompletion instanceof ElementFilter){
      final ElementFilter filter = (ElementFilter)ce.myCompletion;
      completionData.completeReference(reference, position, set, ce.myTailType, file, filter, this);
    }
  }
}
项目:intellij-ce-playground    文件:CompletionVariant.java   
boolean hasReferenceFilter(){
  for (final CompletionVariantItem item: myCompletionsList) {
    if (item.myCompletion instanceof ElementFilter) {
      return true;
    }
  }
  return false;
}
项目:intellij-ce-playground    文件:CompletionVariant.java   
boolean hasKeywordCompletions(){
  for (final CompletionVariantItem item : myCompletionsList) {
    if (!(item.myCompletion instanceof ElementFilter)) {
      return true;
    }
  }
  return false;
}
项目:intellij-ce-playground    文件:XmlUtil.java   
public static void registerXmlAttributeValueReferenceProvider(PsiReferenceRegistrar registrar,
                                                              @Nullable @NonNls String[] attributeNames,
                                                              @Nullable ElementFilter elementFilter,
                                                              boolean caseSensitive,
                                                              @NotNull PsiReferenceProvider provider) {
  registerXmlAttributeValueReferenceProvider(registrar, attributeNames, elementFilter, caseSensitive, provider,
                                             PsiReferenceRegistrar.DEFAULT_PRIORITY);
}
项目:intellij-ce-playground    文件:HtmlCompletionData.java   
@Override
protected ElementFilter createXmlEntityCompletionFilter() {
  if (isCaseInsensitive()) {
    return new AndFilter(
      new OrFilter (
        new XmlTokenTypeFilter(XmlTokenType.XML_DATA_CHARACTERS),
        new XmlTokenTypeFilter(XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN)
      ),
      new TextContainFilter("&")
    );
  }

  return super.createXmlEntityCompletionFilter();
}
项目:intellij-ce-playground    文件:HtmlCompletionData.java   
@Override
protected ElementFilter createTagCompletionFilter() {
  return new ElementFilter() {
    @Override
    public boolean isAcceptable(Object element, PsiElement context) {
      String name = ((XmlTag)context).getName();

      if (element instanceof PsiElement && 
          ((PsiElement)element).getParent() == context) {
        return true;
      }

      if (equalNames(name, HtmlUtil.STYLE_TAG_NAME) ||
          equalNames(name, HtmlUtil.SCRIPT_TAG_NAME)) {
        return false;
      }

      if ( isStyleAttributeContext((PsiElement)element) ) return false;
      return true;
    }

    @Override
    public boolean isClassAcceptable(Class hintClass) {
      return true;
    }
  };
}
项目:intellij-ce-playground    文件:HtmlCompletionData.java   
@Override
protected ElementFilter createAttributeCompletionFilter() {
  return new ElementFilter() {
    @Override
    public boolean isAcceptable(Object element, PsiElement context) {
      if (isStyleAttributeContext(context)) return false;
      return true;
    }

    @Override
    public boolean isClassAcceptable(Class hintClass) {
      return true;
    }
  };
}
项目:intellij-ce-playground    文件:DtdReferencesProvider.java   
public ElementFilter getSystemReferenceFilter() {
  return new ElementFilter() {
    @Override
    public boolean isAcceptable(Object element, PsiElement context) {
      final PsiElement parent = context.getParent();

      if((parent instanceof XmlEntityDecl &&
         !((XmlEntityDecl)parent).isInternalReference()
         )
        ) {
        PsiElement prevSibling = context.getPrevSibling();
        if (prevSibling instanceof PsiWhiteSpace) {
          prevSibling = prevSibling.getPrevSibling();
        }

        if (prevSibling instanceof XmlToken &&
            ((XmlToken)prevSibling).getTokenType() == XmlTokenType.XML_DOCTYPE_SYSTEM ||
            prevSibling instanceof XmlAttributeValue
          ) {
          return true;
        }
      }

      return false;
    }

    @Override
    public boolean isClassAcceptable(Class hintClass) {
      return true;
    }
  };
}