@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 XmlAttributeDecl[] getAttributeDecls() { final List<XmlAttributeDecl> result = new ArrayList<XmlAttributeDecl>(); processElements(new FilterElementProcessor(new ClassFilter(XmlAttributeDecl.class), result) { @Override public boolean execute(@NotNull final PsiElement element) { if (element instanceof XmlAttributeDecl) { if (element.getNextSibling() == null && element.getChildren().length == 1) { return true; } return super.execute(element); } return true; } }, this); return result.toArray(new XmlAttributeDecl[result.size()]); }
private CachedValue<Map<String, XmlElementDescriptor>> doBuildDeclarationMap() { return CachedValuesManager.getManager(myElement.getProject()).createCachedValue(new CachedValueProvider<Map<String, XmlElementDescriptor>>() { public Result<Map<String, XmlElementDescriptor>> compute() { final List<XmlElementDecl> result = new ArrayList<XmlElementDecl>(); myElement.processElements(new FilterElementProcessor(new ClassFilter(XmlElementDecl.class), result), getDeclaration()); final Map<String, XmlElementDescriptor> ret = new LinkedHashMap<String, XmlElementDescriptor>((int)(result.size() * 1.5)); for (final XmlElementDecl xmlElementDecl : result) { final String name = xmlElementDecl.getName(); if (name != null) { if (!ret.containsKey(name)) { ret.put(name, new XmlElementDescriptorImpl(xmlElementDecl)); } } } return new Result<Map<String, XmlElementDescriptor>>(ret, myDescriptorFile); } }, false); }
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); }
private CachedValue<Map<String, XmlElementDescriptor>> doBuildDeclarationMap() { return CachedValuesManager.getManager(myElement.getProject()).createCachedValue(new CachedValueProvider<Map<String, XmlElementDescriptor>>() { @Override public Result<Map<String, XmlElementDescriptor>> compute() { final List<XmlElementDecl> result = new ArrayList<XmlElementDecl>(); myElement.processElements(new FilterElementProcessor(new ClassFilter(XmlElementDecl.class), result), getDeclaration()); final Map<String, XmlElementDescriptor> ret = new LinkedHashMap<String, XmlElementDescriptor>((int)(result.size() * 1.5)); Set<PsiFile> dependencies = new THashSet<PsiFile>(1); dependencies.add(myDescriptorFile); for (final XmlElementDecl xmlElementDecl : result) { final String name = xmlElementDecl.getName(); if (name != null) { if (!ret.containsKey(name)) { ret.put(name, new XmlElementDescriptorImpl(xmlElementDecl)); // if element descriptor was produced from entity reference use proper dependency PsiElement dependingElement = xmlElementDecl.getUserData(XmlElement.DEPENDING_ELEMENT); if (dependingElement != null) { PsiFile dependingElementContainingFile = dependingElement.getContainingFile(); if (dependingElementContainingFile != null) dependencies.add(dependingElementContainingFile); } } } } return new Result<Map<String, XmlElementDescriptor>>(ret, dependencies.toArray()); } }, false); }
@Override public void contributeMetaData(MetaDataRegistrar registrar) { registrar.registerMetaData( new AndFilter( new ClassFilter(RncDocument.class), new MyRncNamespaceFilter(XmlUtil.HTML_URI, XmlUtil.XHTML_URI)), RelaxedHtmlFromRngNSDescriptor.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); }
public XmlAttributeDecl[] getAttributeDecls() { final List<XmlAttributeDecl> result = new ArrayList<XmlAttributeDecl>(); processElements(new FilterElementProcessor(new ClassFilter(XmlAttributeDecl.class), result) { public boolean execute(@NotNull final PsiElement element) { if (element instanceof XmlAttributeDecl) { if (element.getNextSibling() == null && element.getChildren().length == 1) { return true; } return super.execute(element); } return true; } }, this); return result.toArray(new XmlAttributeDecl[result.size()]); }
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 CachedValue<Map<String, XmlElementDescriptor>> doBuildDeclarationMap() { return CachedValuesManager.getManager(myElement.getProject()).createCachedValue(() -> { final List<XmlElementDecl> result = new ArrayList<>(); myElement.processElements(new FilterElementProcessor(new ClassFilter(XmlElementDecl.class), result), getDeclaration()); final Map<String, XmlElementDescriptor> ret = new LinkedHashMap<>((int) (result.size() * 1.5)); Set<PsiFile> dependencies = new THashSet<>(1); dependencies.add(myDescriptorFile); for(final XmlElementDecl xmlElementDecl : result) { final String name = xmlElementDecl.getName(); if(name != null) { if(!ret.containsKey(name)) { ret.put(name, new XmlElementDescriptorImpl(xmlElementDecl)); // if element descriptor was produced from entity reference use proper dependency PsiElement dependingElement = xmlElementDecl.getUserData(XmlElement.DEPENDING_ELEMENT); if(dependingElement != null) { PsiFile dependingElementContainingFile = dependingElement.getContainingFile(); if(dependingElementContainingFile != null) { dependencies.add(dependingElementContainingFile); } } } } } return new CachedValueProvider.Result<>(ret, dependencies.toArray()); }, false); }
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 processVariants(@NotNull PsiScopeProcessor processor) { FilterScopeProcessor proc = new FilterScopeProcessor(new ClassFilter(PsiModifierListOwner.class), processor); PsiScopesUtil.resolveAndWalk(proc, this, null, true); }
private static XmlAttlistDecl[] doCollectAttlistDeclarations(XmlElement xmlElement) { final List<XmlAttlistDecl> result = new ArrayList<XmlAttlistDecl>(); XmlUtil.processXmlElements(xmlElement, new FilterElementProcessor(new ClassFilter(XmlAttlistDecl.class), result), false, false, XmlUtil.getContainingFile(xmlElement)); return result.toArray(new XmlAttlistDecl[result.size()]); }
private static XmlAttlistDecl[] doCollectAttlistDeclarations(XmlElement xmlElement) { final List<XmlAttlistDecl> result = new ArrayList<>(); XmlUtil.processXmlElements(xmlElement, new FilterElementProcessor(new ClassFilter(XmlAttlistDecl.class), result), false, false, XmlUtil.getContainingFile(xmlElement)); return result.toArray(new XmlAttlistDecl[result.size()]); }
@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)}; } }); }
@Override public void processVariants(PsiScopeProcessor processor) { FilterScopeProcessor proc = new FilterScopeProcessor(new ClassFilter(PsiModifierListOwner.class), processor); PsiScopesUtil.resolveAndWalk(proc, this, null, true); }