@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; }
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; }
@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); }
@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(); }
@Override public void contributeMetaData(MetaDataRegistrar registrar) { registrar.registerMetaData( new AndFilter( new ClassFilter(RncDocument.class), new MyRncNamespaceFilter(XmlUtil.HTML_URI, XmlUtil.XHTML_URI)), RelaxedHtmlFromRngNSDescriptor.class ); }
public RncCompletionData() { declareFinalScope(RncElement.class); final CompletionVariant variant = new CompletionVariant(new AndFilter( new ElementFilter() { @Override public boolean isAcceptable(Object element, PsiElement context) { return true; } @Override public boolean isClassAcceptable(Class hintClass) { return PsiElement.class.isAssignableFrom(hintClass); } }, new PatternFilter(or( psiElement().afterLeaf(psiElement(RncTokenTypes.KEYWORD_DEFAULT)), not( or( psiElement().inside(psiElement(RncTokenTypes.LITERAL)), psiElement().afterLeaf(psiElement().withElementType(RncTokenTypes.KEYWORDS)) ) ) )) )); variant.includeScopeClass(LeafPsiElement.class, true); variant.addCompletion(new KeywordGetter()); registerVariant(variant); }
private static void registerMetaData() { final MetaDataRegistrar registrar = MetaDataRegistrar.getInstance(); registrar.registerMetaData( new AndFilter( new NamespaceFilter(RNG_NAMESPACE), new ClassFilter(XmlDocument.class) ), RngNsDescriptor.class); registrar.registerMetaData( new ClassFilter(RncDocument.class), RngNsDescriptor.class); 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); return domElement instanceof RngDefine; } return false; } @Override public boolean isClassAcceptable(Class hintClass) { return XmlTag.class.isAssignableFrom(hintClass); } }, RngDefineMetaData.class); }
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(); }
public RncCompletionData() { declareFinalScope(RncElement.class); final CompletionVariant variant = new CompletionVariant(new AndFilter( new ElementFilter() { public boolean isAcceptable(Object element, PsiElement context) { return true; } public boolean isClassAcceptable(Class hintClass) { return PsiElement.class.isAssignableFrom(hintClass); } }, new PatternFilter(or( psiElement().afterLeaf(psiElement(RncTokenTypes.KEYWORD_DEFAULT)), not( or( psiElement().inside(psiElement(RncTokenTypes.LITERAL)), psiElement().afterLeaf(psiElement().withElementType(RncTokenTypes.KEYWORDS)) ) ) )) )); variant.includeScopeClass(LeafPsiElement.class, true); variant.addCompletion(new KeywordGetter()); registerVariant(variant); }
private static void registerMetaData() { final MetaDataRegistrar registrar = MetaDataRegistrar.getInstance(); registrar.registerMetaData( new AndFilter( new NamespaceFilter(RNG_NAMESPACE), new ClassFilter(XmlDocument.class) ), RngNsDescriptor.class); registrar.registerMetaData( new ClassFilter(RncDocument.class), RngNsDescriptor.class); 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); return domElement instanceof RngDefine; } return false; } public boolean isClassAcceptable(Class hintClass) { return XmlTag.class.isAssignableFrom(hintClass); } }, RngDefineMetaData.class); }
private static void registerMetaData() { final MetaDataRegistrar registrar = MetaDataRegistrar.getInstance(); registrar.registerMetaData(new AndFilter(new NamespaceFilter(RNG_NAMESPACE), new ClassFilter(XmlDocument.class)), RngNsDescriptor.class); registrar.registerMetaData(new ClassFilter(RncDocument.class), RngNsDescriptor.class); 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); return domElement instanceof RngDefine; } return false; } @Override public boolean isClassAcceptable(Class hintClass) { return XmlTag.class.isAssignableFrom(hintClass); } }, RngDefineMetaData.class); }
@Override public void contributeMetaData(final MetaDataRegistrar registrar) { { registrar.registerMetaData(new AndFilter(new NamespaceFilter(XmlUtil.SCHEMA_URIS), new ClassFilter(XmlDocument.class)), SchemaNSDescriptor.class); registrar.registerMetaData(new AndFilter(XmlTagFilter.INSTANCE, new NamespaceFilter(XmlUtil.SCHEMA_URIS), new XmlTextFilter("schema")), SchemaNSDescriptor.class); } { registrar.registerMetaData(new OrFilter(new AndFilter(new ContentFilter(new OrFilter(new ClassFilter(XmlElementDecl.class), new ClassFilter(XmlEntityDecl.class), new ClassFilter (XmlConditionalSection.class), new ClassFilter(XmlEntityRef.class))), new ClassFilter(XmlDocument.class)), new ClassFilter(XmlMarkupDecl.class)), XmlNSDescriptorImpl.class); } { registrar.registerMetaData(new AndFilter(XmlTagFilter.INSTANCE, new NamespaceFilter(XmlUtil.SCHEMA_URIS), new XmlTextFilter("element")), XmlElementDescriptorImpl.class); } { registrar.registerMetaData(new AndFilter(XmlTagFilter.INSTANCE, new NamespaceFilter(XmlUtil.SCHEMA_URIS), new XmlTextFilter("attribute")), XmlAttributeDescriptorImpl.class); } { registrar.registerMetaData(new ClassFilter(XmlElementDecl.class), com.intellij.xml.impl.dtd.XmlElementDescriptorImpl.class); } { registrar.registerMetaData(new ClassFilter(XmlAttributeDecl.class), com.intellij.xml.impl.dtd.XmlAttributeDescriptorImpl.class); } { registrar.registerMetaData(new AndFilter(new ClassFilter(XmlDocument.class), new TargetNamespaceFilter(XmlUtil.XHTML_URI), new NamespaceFilter(XmlUtil.SCHEMA_URIS)), RelaxedHtmlFromSchemaNSDescriptor.class); } { registrar.registerMetaData(new AndFilter(XmlTagFilter.INSTANCE, new NamespaceFilter(XmlUtil.SCHEMA_URIS), new XmlTextFilter("complexType", "simpleType", "group", "attributeGroup")), NamedObjectDescriptor.class); } }
@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; }
@Override public void registerReferenceProviders(@NotNull final PsiReferenceRegistrar registrar) { final IdReferenceProvider idReferenceProvider = new IdReferenceProvider(); XmlUtil.registerXmlAttributeValueReferenceProvider(registrar, idReferenceProvider.getIdForAttributeNames(), idReferenceProvider.getIdForFilter(), true, idReferenceProvider, PsiReferenceRegistrar.DEFAULT_PRIORITY); final DtdReferencesProvider dtdReferencesProvider = new DtdReferencesProvider(); //registerReferenceProvider(null, XmlEntityDecl.class,dtdReferencesProvider); registrar.registerReferenceProvider(PlatformPatterns.psiElement(XmlEntityRef.class), dtdReferencesProvider); registrar.registerReferenceProvider(PlatformPatterns.psiElement(XmlDoctype.class), dtdReferencesProvider); registrar.registerReferenceProvider(PlatformPatterns.psiElement(XmlElementDecl.class), dtdReferencesProvider); registrar.registerReferenceProvider(PlatformPatterns.psiElement(XmlAttlistDecl.class), dtdReferencesProvider); registrar.registerReferenceProvider(PlatformPatterns.psiElement(XmlElementContentSpec.class), dtdReferencesProvider); registrar.registerReferenceProvider(PlatformPatterns.psiElement(XmlToken.class), dtdReferencesProvider); registrar.registerReferenceProvider(xmlAttributeValue(), new ArbitraryPlaceUrlReferenceProvider(), PsiReferenceRegistrar.LOWER_PRIORITY); URIReferenceProvider uriProvider = new URIReferenceProvider(); XmlUtil.registerXmlAttributeValueReferenceProvider(registrar, null, dtdReferencesProvider.getSystemReferenceFilter(), uriProvider); XmlUtil.registerXmlAttributeValueReferenceProvider(registrar, new String[]{"href"}, new ScopeFilter(new ParentElementFilter(new AndFilter(new AndFilter(XmlTagFilter.INSTANCE, new XmlTextFilter("include")), new NamespaceFilter(XmlUtil.XINCLUDE_URI)), 2)), true, new XmlBaseReferenceProvider(true)); registrar.registerReferenceProvider(xmlAttributeValue().withLocalName("base").withNamespace(XmlUtil.XML_NAMESPACE_URI), new XmlBaseReferenceProvider(false)); XmlUtil.registerXmlAttributeValueReferenceProvider(registrar, new String[]{MicrodataUtil.ITEM_TYPE}, null, new MicrodataReferenceProvider()); final SchemaReferencesProvider schemaReferencesProvider = new SchemaReferencesProvider(); XmlUtil.registerXmlAttributeValueReferenceProvider(registrar, schemaReferencesProvider.getCandidateAttributeNamesForSchemaReferences(), new ScopeFilter(new ParentElementFilter(new NamespaceFilter(XmlUtil.SCHEMA_URIS), 2)), schemaReferencesProvider); registrar.registerReferenceProvider(xmlAttributeValue(xmlAttribute().withNamespace(XmlUtil.XML_SCHEMA_INSTANCE_URI)). withLocalName("type"), schemaReferencesProvider); registrar.registerReferenceProvider(xmlAttributeValue(xmlAttribute().withNamespace(XmlUtil.XML_SCHEMA_INSTANCE_URI)). withLocalName("noNamespaceSchemaLocation", "schemaLocation"), uriProvider); registrar.registerReferenceProvider(xmlAttributeValue().withLocalName("schemaLocation", "namespace"). withSuperParent(2, xmlTag().withNamespace(XmlUtil.SCHEMA_URIS).withLocalName("import", "include", "redefine")), uriProvider); XmlUtil.registerXmlAttributeValueReferenceProvider(registrar, null, URIReferenceProvider.ELEMENT_FILTER, true, uriProvider); XmlUtil.registerXmlAttributeValueReferenceProvider(registrar, new String[]{"encoding"}, new ScopeFilter(new ParentElementFilter(new ClassFilter(XmlProcessingInstruction.class))), true, new XmlEncodingReferenceProvider()); registrar.registerReferenceProvider(xmlAttributeValue(), new XmlPrefixReferenceProvider()); registrar.registerReferenceProvider(xmlAttributeValue(), new XmlEnumeratedValueReferenceProvider(), PsiReferenceRegistrar.LOWER_PRIORITY); registrar.registerReferenceProvider(xmlTag(), XmlEnumeratedValueReferenceProvider.forTags(), PsiReferenceRegistrar.LOWER_PRIORITY); registrar.registerReferenceProvider(xmlAttributeValue().withLocalName("source").withSuperParent(2, xmlTag().withLocalName("documentation").withNamespace(XmlUtil.SCHEMA_URIS)), new PsiReferenceProvider() { @NotNull @Override public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) { return new PsiReference[]{new WebReference(element)}; } }); }
private static Set<LookupElement> completeFinalReference(final PsiElement element, PsiJavaCodeReferenceElement reference, ElementFilter filter, final JavaSmartCompletionParameters parameters) { final Set<PsiField> used = parameters.getParameters().getInvocationCount() < 2 ? findConstantsUsedInSwitch(element) : Collections.<PsiField>emptySet(); final Set<LookupElement> elements = JavaSmartCompletionContributor.completeReference(element, reference, new AndFilter(filter, new ElementFilter() { @Override public boolean isAcceptable(Object o, PsiElement context) { if(o instanceof CandidateInfo) { final CandidateInfo info = (CandidateInfo) o; final PsiElement member = info.getElement(); final PsiType expectedType = parameters.getExpectedType(); if(expectedType.equals(PsiType.VOID)) { return member instanceof PsiMethod; } //noinspection SuspiciousMethodCalls if(member instanceof PsiEnumConstant && used.contains(CompletionUtil.getOriginalOrSelf(member))) { return false; } return AssignableFromFilter.isAcceptable(member, element, expectedType, info.getSubstitutor()); } return false; } @Override public boolean isClassAcceptable(Class hintClass) { return true; } }), false, true, parameters.getParameters(), PrefixMatcher.ALWAYS_TRUE); for(LookupElement lookupElement : elements) { if(lookupElement.getObject() instanceof PsiMethod) { final JavaMethodCallElement item = lookupElement.as(JavaMethodCallElement.CLASS_CONDITION_KEY); if(item != null) { final PsiMethod method = (PsiMethod) lookupElement.getObject(); if(SmartCompletionDecorator.hasUnboundTypeParams(method, parameters.getExpectedType())) { item.setInferenceSubstitutor(SmartCompletionDecorator.calculateMethodReturnTypeSubstitutor(method, parameters.getExpectedType()), element); } } } } return elements; }