@Nullable private ApplicationDictionary createDictionaryFromInfo(final @NotNull DictionaryInfo dInfo) { if (!dInfo.isInitialized()) { //dictionary terms must be ridden from the dictionary file before creating a PSI for it LOG.error("Attempt to create dictionary for not initialized Dictionary Info for application" + dInfo.getApplicationName()); return null; } String applicationName = dInfo.getApplicationName(); VirtualFile vFile = LocalFileSystem.getInstance().findFileByIoFile(dInfo.getDictionaryFile()); if (vFile != null && vFile.isValid()) { PsiFile psiFile = PsiManager.getInstance(project).findFile(vFile); XmlFile xmlFile = (XmlFile) psiFile; if (xmlFile != null) { ApplicationDictionary dictionary = new ApplicationDictionaryImpl(project, xmlFile, applicationName, dInfo.getApplicationFile()); dictionaryMap.put(applicationName, dictionary); return dictionary; } } LOG.warn("Failed to create dictionary from info for application: " + applicationName + ". Reason: file is null"); return null; }
private static List<XmlTag> getComponentDeclarations(String componentValue, String componentType, ID<String, Void> id, Project project, ComponentMatcher componentMatcher) { List<XmlTag> results = new ArrayList<XmlTag>(); Collection<VirtualFile> containingFiles = FileBasedIndex.getInstance() .getContainingFiles( id, componentValue, GlobalSearchScope.allScope(project) ); PsiManager psiManager = PsiManager.getInstance(project); for (VirtualFile virtualFile: containingFiles) { XmlFile xmlFile = (XmlFile)psiManager.findFile(virtualFile); if (xmlFile == null) { continue; } XmlTag rootTag = xmlFile.getRootTag(); if (rootTag == null) { continue; } collectComponentDeclarations(rootTag, results, componentValue, componentType, componentMatcher); } return results; }
public static List<XmlFile> getLayoutFiles(Project project, @Nullable String fileName) { List<XmlFile> results = new ArrayList<XmlFile>(); Collection<VirtualFile> xmlFiles = FilenameIndex.getAllFilesByExt(project, "xml"); PsiManager psiManager = PsiManager.getInstance(project); for (VirtualFile xmlFile: xmlFiles) { if (isLayoutFile(xmlFile)) { if (fileName != null && !xmlFile.getNameWithoutExtension().equals(fileName)) { continue; } PsiFile file = psiManager.findFile(xmlFile); if (file != null) { results.add((XmlFile)file); } } } return results; }
@Override protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) { PsiElement position = parameters.getPosition().getOriginalElement(); if (position == null) { return; } List<XmlFile> targets = LayoutIndex.getLayoutFiles(position.getProject()); if (targets.size() > 0) { for (XmlFile file : targets) { result.addElement( LookupElementBuilder .create(file.getVirtualFile().getNameWithoutExtension()) .withIcon(PhpIcons.XML_TAG_ICON) ); } } }
public static List<XmlTag> getClassConfigurations(PhpClass phpClass) { String classFqn = phpClass.getPresentableFQN(); Collection<VirtualFile> containingFiles = FileBasedIndex.getInstance() .getContainingFiles(KEY, classFqn, GlobalSearchScope.allScope(phpClass.getProject()) ); PsiManager psiManager = PsiManager.getInstance(phpClass.getProject()); List<XmlTag> tags = new ArrayList<XmlTag>(); for (VirtualFile virtualFile: containingFiles) { XmlFile file = (XmlFile)psiManager.findFile(virtualFile); if (file == null) { continue; } XmlTag rootTag = file.getRootTag(); fillRelatedTags(classFqn, rootTag, tags); } return tags; }
/** * Get list of Web API routes associated with the provided method. * * Parent classes are not taken into account. */ public static List<XmlTag> getWebApiRoutes(Method method) { List<XmlTag> tags = new ArrayList<>(); if (!method.getAccess().isPublic()) { return tags; } PhpClass phpClass = method.getContainingClass(); String methodFqn = method.getName(); if (phpClass == null) { return tags; } String classFqn = phpClass.getPresentableFQN(); Collection<VirtualFile> containingFiles = FileBasedIndex .getInstance().getContainingFiles(KEY, classFqn, GlobalSearchScope.allScope(phpClass.getProject())); PsiManager psiManager = PsiManager.getInstance(phpClass.getProject()); for (VirtualFile virtualFile : containingFiles) { XmlFile file = (XmlFile) psiManager.findFile(virtualFile); if (file == null) { continue; } XmlTag rootTag = file.getRootTag(); fillRelatedTags(classFqn, methodFqn, rootTag, tags); } return tags; }
@NotNull @Override public DataIndexer<String, Void, FileContent> getIndexer() { return inputData -> { Map<String, Void> map = new HashMap<>(); PsiFile psiFile = inputData.getPsiFile(); if (!Settings.isEnabled(psiFile.getProject())) { return map; } if (psiFile instanceof PhpFile) { grabEventNamesFromPhpFile((PhpFile) psiFile, map); } else if (psiFile instanceof XmlFile) { grabEventNamesFromXmlFile((XmlFile) psiFile, map); } return map; }; }
@Override public String getMagentoName() { if (moduleName != null) { return moduleName; } PsiDirectory configurationDir = directory.findSubdirectory(CONFIGURATION_PATH); if (configurationDir != null) { PsiFile configurationFile = configurationDir.findFile("module.xml"); if (configurationFile != null && configurationFile instanceof XmlFile) { XmlTag rootTag = ((XmlFile) configurationFile).getRootTag(); if (rootTag != null) { XmlTag module = rootTag.findFirstSubTag("module"); if (module != null && module.getAttributeValue("name") != null) { moduleName = module.getAttributeValue("name"); return moduleName; } } } } return DEFAULT_MODULE_NAME; }
public TSStructureViewTreeModel( @NotNull XmlFile file, @NotNull Function<DomElement, DomService.StructureViewMode> descriptor, @Nullable Editor editor ) { super( file, DomElementsNavigationManager.getManager(file.getProject()) .getDomElementsNavigateProvider(DomElementsNavigationManager.DEFAULT_PROVIDER_NAME), descriptor, editor ); myNavigationProvider = DomElementsNavigationManager.getManager(file.getProject()) .getDomElementsNavigateProvider(DomElementsNavigationManager.DEFAULT_PROVIDER_NAME); myDescriptor = descriptor; }
@Override @NotNull public StructureViewTreeElement getRoot() { XmlFile myFile = getPsiFile(); final DomFileElement<DomElement> fileElement = DomManager.getDomManager(myFile.getProject()).getFileElement( myFile, DomElement.class ); return fileElement == null ? new XmlFileTreeElement(myFile) : new TSStructureTreeElement( fileElement.getRootElement().createStableCopy(), myDescriptor, myNavigationProvider ); }
public void testTagData2() throws Exception { String s1 = "<a><b>\nSomeDataHere"; String s2 = "\n</b></a>"; prepareFile(s1, s2); PsiElement element1 = ((XmlFile)myDummyFile).getDocument().getRootTag(); insert("x"); insert(" "); insert("xxxxx"); insert("\n"); insert("xxxxx"); assertSame(element1, ((XmlFile)myDummyFile).getDocument().getRootTag()); }
private static void doRenameXmlAttributeValue(@NotNull XmlAttributeValue value, String newName, UsageInfo[] infos, @Nullable RefactoringElementListener listener) throws IncorrectOperationException { LOG.assertTrue(value.isValid()); renameAll(value, infos, newName, value.getValue()); PsiManager psiManager = value.getManager(); LOG.assertTrue(psiManager != null); XmlFile file = (XmlFile)PsiFileFactory.getInstance(psiManager.getProject()).createFileFromText("dummy.xml", XMLLanguage.INSTANCE, "<a attr=\"" + newName + "\"/>"); @SuppressWarnings("ConstantConditions") PsiElement element = value.replace(file.getRootTag().getAttributes()[0].getValueElement()); if (listener != null) { listener.elementRenamed(element); } }
@NotNull private static List<DomElement> getFlowsInScope(Project project, GlobalSearchScope searchScope) { final List<DomElement> result = new ArrayList<>(); final Collection<VirtualFile> files = FileTypeIndex.getFiles(StdFileTypes.XML, searchScope); final DomManager manager = DomManager.getDomManager(project); for (VirtualFile file : files) { final PsiFile xmlFile = PsiManager.getInstance(project).findFile(file); if (isMuleFile(xmlFile)) { final DomFileElement<Mule> fileElement = manager.getFileElement((XmlFile) xmlFile, Mule.class); if (fileElement != null) { final Mule rootElement = fileElement.getRootElement(); result.addAll(rootElement.getFlows()); result.addAll(rootElement.getSubFlows()); } } } return result; }
@Override protected RunnerAndConfigurationSettings findExistingByElement(Location location, @NotNull List<RunnerAndConfigurationSettings> existingConfigurations, ConfigurationContext context) { final XmlFile file = PsiTreeUtil.getParentOfType(location.getPsiElement(), XmlFile.class, false); if (file != null && file.isPhysical() && XsltSupport.isXsltFile(file)) { for (RunnerAndConfigurationSettings existingConfiguration : existingConfigurations) { final RunConfiguration configuration = existingConfiguration.getConfiguration(); if (configuration instanceof XsltRunConfiguration) { if (file.getVirtualFile().getPath().replace('/', File.separatorChar) .equals(((XsltRunConfiguration)configuration).getXsltFile())) { return existingConfiguration; } } } } return null; }
@Nullable protected String doValidateWithData() { String rootElementName = getElementName(); if (rootElementName == null || rootElementName.length() == 0) { return XmlBundle.message("schema2.instance.no.valid.root.element.name.validation.error"); } final PsiFile psiFile = findFile(getUrl().getText()); if (psiFile instanceof XmlFile) { final XmlTag tag = getRootTag(psiFile); if (tag != null) { final XmlElementDescriptor descriptor = Xsd2InstanceUtils.getDescriptor(tag, rootElementName); if (descriptor == null) { return XmlBundle.message("schema2.instance.no.valid.root.element.name.validation.error"); } } } final String fileName = getOutputFileName(); if (fileName == null || fileName.length() == 0) { return XmlBundle.message("schema2.instance.output.file.name.is.empty.validation.problem"); } return null; }
private static Set<String> getIds(@Nullable XmlFile psiFile) { final Set<String> result = new HashSet<String>(); if (psiFile == null) { return result; } psiFile.accept(new XmlRecursiveElementVisitor() { @Override public void visitXmlTag(XmlTag tag) { super.visitXmlTag(tag); String id = tag.getAttributeValue("id", SdkConstants.ANDROID_URI); if (id != null) { result.add(id.substring(getPrefix(id).length())); } } }); return result; }
@NotNull @Override public Collection<Html5SectionTreeElement> provideNodes(@NotNull final TreeElement node) { if (!(node instanceof HtmlFileTreeElement)) return Collections.emptyList(); final XmlFile xmlFile = ((HtmlFileTreeElement)node).getElement(); final XmlDocument document = xmlFile == null ? null : xmlFile.getDocument(); if (document == null) return Collections.emptyList(); final List<XmlTag> rootTags = new ArrayList<XmlTag>(); document.processElements(new FilterElementProcessor(XmlTagFilter.INSTANCE, rootTags), document); final Collection<Html5SectionTreeElement> result = new ArrayList<Html5SectionTreeElement>(); for (XmlTag tag : rootTags) { result.addAll(Html5SectionsProcessor.processAndGetRootSections(tag)); } return result; }
public static boolean doIsMyFile(final XmlFile file, final String[] resourceTypes) { return ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() { @Override public Boolean compute() { if (file.getProject().isDisposed()) { return false; } for (String resourceType : resourceTypes) { if (AndroidResourceUtil.isInResourceSubdirectory(file, resourceType)) { return AndroidFacet.getInstance(file) != null; } } return false; } }); }
@Nullable public static Navigatable createNavigatableForPom(final Project project, final VirtualFile file) { if (file == null || !file.isValid()) return null; final PsiFile result = PsiManager.getInstance(project).findFile(file); return result == null ? null : new NavigatableAdapter() { public void navigate(boolean requestFocus) { int offset = 0; if (result instanceof XmlFile) { final XmlDocument xml = ((XmlFile)result).getDocument(); if (xml != null) { final XmlTag rootTag = xml.getRootTag(); if (rootTag != null) { final XmlTag[] id = rootTag.findSubTags(ARTIFACT_ID, rootTag.getNamespace()); if (id.length > 0) { offset = id[0].getValue().getTextRange().getStartOffset(); } } } } navigate(project, file, offset, requestFocus); } }; }
public void testRootFragment() throws Exception { @SuppressWarnings("SpellCheckingInspection") VirtualFile virtualFile = myFixture.copyFileToProject("xmlpull/root_fragment.xml", "res/layout/root_fragment.xml"); assertNotNull(virtualFile); PsiFile psiFile = PsiManager.getInstance(getProject()).findFile(virtualFile); assertTrue(psiFile instanceof XmlFile); XmlFile xmlFile = (XmlFile)psiFile; LayoutPsiPullParser parser = LayoutPsiPullParser.create(xmlFile, new RenderLogger("test", myModule)); assertEquals(START_TAG, parser.nextTag()); assertEquals("FrameLayout", parser.getName()); // Automatically inserted surrounding the <include> assertEquals(7, parser.getAttributeCount()); assertEquals("@+id/item_list", parser.getAttributeValue(ANDROID_URI, ATTR_ID)); assertEquals("com.unit.test.app.ItemListFragment", parser.getAttributeValue(ANDROID_URI, ATTR_NAME)); assertEquals("fill_parent", parser.getAttributeValue(ANDROID_URI, "layout_width")); assertEquals("fill_parent", parser.getAttributeValue(ANDROID_URI, "layout_height")); assertEquals(START_TAG, parser.nextTag()); assertEquals("include", parser.getName()); assertEquals(null, parser.getAttributeValue(ANDROID_URI, ATTR_ID)); //noinspection ConstantConditions assertEquals("@android:layout/list_content", parser.getAttributeValue(null, ATTR_LAYOUT)); assertEquals("fill_parent", parser.getAttributeValue(ANDROID_URI, "layout_width")); assertEquals("fill_parent", parser.getAttributeValue(ANDROID_URI, "layout_height")); assertEquals(END_TAG, parser.nextTag()); }
@Override @Nullable public StructureViewBuilder getStructureViewBuilder(final PsiFile psiFile) { if (!(psiFile instanceof XmlFile)) { return null; } StructureViewBuilder builder = getStructureViewBuilderForExtensions(psiFile); if (builder != null) { return builder; } for (XmlStructureViewBuilderProvider xmlStructureViewBuilderProvider : getStructureViewBuilderProviders()) { final StructureViewBuilder structureViewBuilder = xmlStructureViewBuilderProvider.createStructureViewBuilder((XmlFile)psiFile); if (structureViewBuilder != null) { return structureViewBuilder; } } return new TreeBasedStructureViewBuilder() { @Override @NotNull public StructureViewModel createStructureViewModel(@Nullable Editor editor) { return new XmlStructureViewTreeModel((XmlFile)psiFile, editor); } }; }
@Nullable @Override public MyHost collectInformation(@NotNull PsiFile file) { if (!(file instanceof XmlFile)) return null; final XmlDocument document = ((XmlFile)file).getDocument(); if (document == null) return null; XmlTag rootTag = document.getRootTag(); XmlNSDescriptor nsDescriptor = rootTag == null ? null : rootTag.getNSDescriptor(rootTag.getNamespace(), false); if (nsDescriptor instanceof Validator) { //noinspection unchecked MyHost host = new MyHost(); ((Validator<XmlDocument>)nsDescriptor).validate(document, host); return host; } return null; }
@Override public void actionPerformed(AnActionEvent e) { super.actionPerformed(e); psiFile = e.getData(LangDataKeys.PSI_FILE); if (psiFile.getFileType() == StdFileTypes.XML) { xmlFile = (XmlFile) psiFile; String folderName = psiFile.getParent().getName(); String bucket = null; if (folderName.startsWith(VALUES_PREFIX)) { bucket = folderName.substring(VALUES_PREFIX.length()); } else if (folderName.equalsIgnoreCase(VALUES_PREFIX.substring(0, VALUES_PREFIX.length() - 1))) { bucket = Constants.MDPI; } if (bucket != null) { currentBucketIndex = getBucketIndex(psiFile); showScaleDialog(bucket, currentBucketIndex != -1); } } }
@NotNull @Override public SearchScope getLocalUseScope() { final XmlTag tag = getTag(); if (!tag.isValid()) { return getDefaultUseScope(); } final XsltTemplate template = getTemplate(); if (template == null) { return getDefaultUseScope(); } if (template.getName() == null) { return getDefaultUseScope(); } final XmlFile file = (XmlFile)tag.getContainingFile(); if (!XsltIncludeIndex.processBackwardDependencies(file, new CommonProcessors.FindFirstProcessor<XmlFile>())) { // processor found something return getDefaultUseScope(); } return new LocalSearchScope(file); }
public static boolean isInXmlContext(Lookup lookup) { if (!lookup.isCompletion()) return false; PsiElement psiElement = lookup.getPsiElement(); PsiFile file = lookup.getPsiFile(); if (!(file instanceof XmlFile) && psiElement != null) { file = psiElement.getContainingFile(); } if (file instanceof XmlFile) { if (psiElement != null) { PsiElement elementToTest = psiElement; if (elementToTest instanceof PsiWhiteSpace) { elementToTest = elementToTest.getParent(); // JSPX has whitespace with language Java } final Language language = elementToTest.getLanguage(); if (!(language instanceof XMLLanguage)) { return false; } } return true; } return false; }
public void testInsertAtOffset() throws Exception { new WriteCommandAction(getProject()) { @Override protected void run(@NotNull final Result result) throws Throwable { String xml = "<root>0123456789</root>"; XmlFile file = (XmlFile)PsiFileFactory.getInstance(getProject()) .createFileFromText("foo.xml", StdFileTypes.XML, xml, (long)1, true, false); //System.out.println(DebugUtil.psiToString(file, false)); XmlTag root = file.getDocument().getRootTag(); final XmlText text1 = root.getValue().getTextElements()[0]; assertFalse(CodeEditUtil.isNodeGenerated(root.getNode())); final XmlText text = text1; final XmlElement element = text.insertAtOffset(XmlElementFactory.getInstance(getProject()).createTagFromText("<bar/>"), 5); assertNotNull(element); assertTrue(element instanceof XmlText); assertEquals("01234", element.getText()); assertEquals("<root>01234<bar/>56789</root>", text.getContainingFile().getText()); } }.execute(); }
public static boolean isSettingsFile(PsiFile file) { if (!(file instanceof XmlFile)) return false; String name = file.getName(); if (!name.equals(MavenConstants.SETTINGS_XML)) return false; XmlTag rootTag = ((XmlFile)file).getRootTag(); if (rootTag == null || !"settings".equals(rootTag.getName())) return false; String xmlns = rootTag.getAttributeValue("xmlns"); if (xmlns != null) { return xmlns.contains("maven"); } boolean hasTag = false; for (PsiElement e = rootTag.getFirstChild(); e != null; e = e.getNextSibling()) { if (e instanceof XmlTag) { if (SUBTAGS_IN_SETTINGS_FILE.contains(((XmlTag)e).getName())) return true; hasTag = true; } } return !hasTag; }
protected void checkDomElement(DomElement element, DomElementAnnotationHolder holder, DomHighlightingHelper helper) { if (element instanceof AntDomProperty) { final AntDomProperty property = (AntDomProperty)element; final GenericAttributeValue<PsiFileSystemItem> fileValue = property.getFile(); final String fileName = fileValue.getStringValue(); if (fileName != null) { final PropertiesFile propertiesFile = property.getPropertiesFile(); if (propertiesFile == null) { final PsiFileSystemItem file = fileValue.getValue(); if (file instanceof XmlFile) { holder.createProblem(fileValue, AntBundle.message("file.type.xml.not.supported", fileName)); } else if (file instanceof PsiFile) { holder.createProblem(fileValue, AntBundle.message("file.type.not.supported", fileName)); } else { holder.createProblem(fileValue, AntBundle.message("file.doesnt.exist", fileName)); } } } } }
private static void assignLayout( @NotNull final Project project, @NotNull final XmlFile file, @NotNull final String activityName, @NotNull final String layout) { WriteCommandAction<Void> action = new WriteCommandAction<Void>(project, "Assign Preview Layout", file) { @Override protected void run(@NotNull Result<Void> result) throws Throwable { SuppressLintIntentionAction.ensureNamespaceImported(getProject(), file, TOOLS_URI); Collection<XmlTag> xmlTags = PsiTreeUtil.findChildrenOfType(file, XmlTag.class); for (XmlTag tag : xmlTags) { if (tag.getName().equals(VIEW_FRAGMENT) ) { String name = tag.getAttributeValue(ATTR_CLASS); if (name == null || name.isEmpty()) { name = tag.getAttributeValue(ATTR_NAME, ANDROID_URI); } if (activityName.equals(name)) { tag.setAttribute(ATTR_LAYOUT, TOOLS_URI, layout); } } } } }; action.execute(); }
/** * Get the value of an attribute in the {@link com.intellij.psi.xml.XmlFile} safely (meaning it will acquire the read lock first). */ @Nullable public static String getRootTagAttributeSafely(@NotNull final XmlFile file, @NotNull final String attribute, @Nullable final String namespace) { Application application = ApplicationManager.getApplication(); if (!application.isReadAccessAllowed()) { return application.runReadAction(new Computable<String>() { @Nullable @Override public String compute() { return getRootTagAttributeSafely(file, attribute, namespace); } }); } else { XmlTag tag = file.getRootTag(); if (tag != null) { XmlAttribute attr = namespace != null ? tag.getAttribute(attribute, namespace) : tag.getAttribute(attribute); if (attr != null) { return attr.getValue(); } } return null; } }
private void syncWithReadPermission() { ApplicationManager.getApplication().assertReadAccessAllowed(); List<Manifest> manifests = Lists.newArrayListWithExpectedSize(myManifestFiles.size()); for (VirtualFile f : myManifestFiles) { PsiFile psiFile = PsiManager.getInstance(myModule.getProject()).findFile(f); if (psiFile instanceof XmlFile) { Manifest m = AndroidUtils.loadDomElementWithReadPermission(myModule.getProject(), (XmlFile)psiFile, Manifest.class); // If the file reported as a manifest is invalid, m will be null. if (m != null) { manifests.add(m); } } } myManifestsRef.set(manifests); }
@Nullable public static Set<Define> resolve(Grammar scope, final String value) { final Map<String, Set<Define>> map = getAllVariants(scope); if (map == null) { return null; } final Set<Define> set = map.get(value); // actually we should always do this, but I'm a bit afraid of the performance impact if (set == null || set.size() == 0) { final PsiElement element = scope.getPsiElement(); if (element != null) { final PsiFile file = element.getContainingFile(); if (file instanceof XmlFile) { final BackwardDefinitionResolver resolver = new BackwardDefinitionResolver(value); RelaxIncludeIndex.processBackwardDependencies((XmlFile)file, resolver); return resolver.getResult(); } } } return set; }
@Override public void processDynamicElements(@NotNull PsiType qualifierType, PsiClass aClass, @NotNull PsiScopeProcessor processor, @NotNull PsiElement place, @NotNull ResolveState state) { PsiElement pomElement = aClass.getContainingFile().getContext(); if (pomElement == null) return; PsiFile pomFile = pomElement.getContainingFile(); if (!(pomFile instanceof XmlFile)) return; DomManager domManager = DomManager.getDomManager(pomElement.getProject()); if (!(domManager.getDomFileDescription((XmlFile)pomFile) instanceof MavenDomProjectModelDescription)) { return; } DynamicMemberUtils.process(processor, false, place, CLASS_SOURCE); }
@Nullable protected M computeCombinedModel(@NotNull Scope scope) { final List<M> models = getAllModels(scope); switch (models.size()) { case 0: return null; case 1: return models.get(0); } final Set<XmlFile> configFiles = new LinkedHashSet<XmlFile>(); final LinkedHashSet<DomFileElement<T>> list = new LinkedHashSet<DomFileElement<T>>(models.size()); for (M model: models) { final Set<XmlFile> files = model.getConfigFiles(); for (XmlFile file: files) { ContainerUtil.addIfNotNull(getDomRoot(file), list); } configFiles.addAll(files); } final DomFileElement<T> mergedModel = getModelMerger().mergeModels(DomFileElement.class, list); final M firstModel = models.get(0); return createCombinedModel(configFiles, mergedModel, firstModel, scope); }
@Nullable public XmlFile getContextFile(@Nullable final XmlFile file) { if (file == null) { return null; } final VirtualFile context = myAntFileToContextFileMap.get(file.getVirtualFile()); if (context == null) { return null; } final PsiFile psiFile = PsiManager.getInstance(getProject()).findFile(context); if (!(psiFile instanceof XmlFile)) { return null; } final XmlFile xmlFile = (XmlFile)psiFile; return AntDomFileDescription.isAntFile(xmlFile)? xmlFile : null; }
public void testCheckNamespace() throws Throwable { getDomManager().registerFileDescription(new DomFileDescription<NamespacedElement>(NamespacedElement.class, "xxx", "bar"){ @Override protected void initializeFileDescription() { registerNamespacePolicy("foo", "bar"); } }, myDisposable); final PsiFile file = createFile("xxx.xml", "<xxx/>"); assertFalse(getDomManager().isDomFile(file)); new WriteCommandAction(getProject()) { @Override protected void run(@NotNull Result result) throws Throwable { ((XmlFile)file).getDocument().getRootTag().setAttribute("xmlns", "bar"); } }.execute(); assertTrue(getDomManager().isDomFile(file)); }
public Collection<PsiElement> getEventElements(final String name, final GlobalSearchScope scope) { Collection<PsiElement> result = new ArrayList<>(); Collection<VirtualFile> virtualFiles = FileBasedIndex.getInstance().getContainingFiles(EventNameIndex.KEY, name, scope); for (VirtualFile virtualFile : virtualFiles) { XmlFile xmlFile = (XmlFile) PsiManager.getInstance(project).findFile(virtualFile); Collection<XmlAttributeValue> valueElements = XmlPsiTreeUtil .findAttributeValueElements(xmlFile, "event", "name", name); result.addAll(valueElements); } return result; }
@NotNull @Override public DataIndexer<String, String, FileContent> getIndexer() { return inputData -> { Map<String, String> map = new THashMap<>(); PsiFile psiFile = inputData.getPsiFile(); if (!Settings.isEnabled(psiFile.getProject())) { return map; } if (psiFile instanceof XmlFile) { XmlDocument xmlDocument = ((XmlFile) psiFile).getDocument(); if (xmlDocument != null) { XmlTag xmlRootTag = xmlDocument.getRootTag(); if (xmlRootTag != null) { for (XmlTag virtualTypeTag : xmlRootTag.findSubTags("virtualType")) { String name = virtualTypeTag.getAttributeValue("name"); String type = virtualTypeTag.getAttributeValue("type"); if (name != null && type != null && !name.isEmpty() && !type.isEmpty()) { map.put(name, type); } } } } } return map; }; }
@NotNull @Override public DataIndexer<String, Void, FileContent> getIndexer() { return inputData -> { Map<String, Void> map = new HashMap<>(); PsiFile psiFile = inputData.getPsiFile(); if (!Settings.isEnabled(psiFile.getProject())) { return map; } if (!(psiFile instanceof XmlFile)) { return map; } XmlDocument document = ((XmlFile) psiFile).getDocument(); if (document == null) { return map; } XmlTag xmlTags[] = PsiTreeUtil.getChildrenOfType(psiFile.getFirstChild(), XmlTag.class); if (xmlTags == null) { return map; } for (XmlTag xmlTag : xmlTags) { if (xmlTag.getName().equals("routes")) { for (XmlTag routeNode : xmlTag.findSubTags("route")) { for (XmlTag serviceNode : routeNode.findSubTags("service")) { String typeName = serviceNode.getAttributeValue("class"); if (typeName != null) { map.put(PhpLangUtil.toPresentableFQN(typeName), null); } } } } } return map; }; }
private void grabEventNamesFromXmlFile(XmlFile file, Map<String, Void> map) { XmlDocument xmlDocument = file.getDocument(); if (xmlDocument != null) { XmlTag xmlRootTag = xmlDocument.getRootTag(); if (xmlRootTag != null) { for (XmlTag eventTag : xmlRootTag.findSubTags("event")) { String name = eventTag.getAttributeValue("name"); if (name != null && !name.isEmpty()) { map.put(name, null); } } } } }