@NotNull private static XmlFileHeader calcXmlFileHeader(final XmlFile file) { if (file instanceof PsiFileEx && ((PsiFileEx) file).isContentsLoaded() && file.getNode().isParsed()) { return computeHeaderByPsi(file); } if (!XmlUtil.isStubBuilding() && file.getFileType() == XmlFileType.INSTANCE) { VirtualFile virtualFile = file.getVirtualFile(); if (virtualFile instanceof VirtualFileWithId) { ObjectStubTree tree = StubTreeLoader.getInstance().readFromVFile(file.getProject(), virtualFile); if (tree != null) { Stub root = tree.getRoot(); if (root instanceof FileStub) { return ((FileStub) root).getHeader(); } } } } if (!file.isValid()) return XmlFileHeader.EMPTY; return NanoXmlUtil.parseHeader(file); }
@Override @NotNull public XmlFileHeader getXmlFileHeader(XmlFile file) { return file.isValid() ? ourRootTagCache.get(ROOT_TAG_NS_KEY, file, null).getValue() : XmlFileHeader.EMPTY; }
@Override public boolean deannotate( @NotNull final PsiModifierListOwner listOwner, @NotNull final String annotationFQN) { try { final List<XmlFile> files = findExternalAnnotationsXmlFiles(listOwner); if (files == null) { return false; } for (XmlFile file : files) { if (!file.isValid()) { continue; } final XmlDocument document = file.getDocument(); if (document == null) { continue; } final XmlTag rootTag = document.getRootTag(); if (rootTag == null) { continue; } final String externalName = getExternalName(listOwner, false); final String oldExternalName = getNormalizedExternalName(listOwner); for (final XmlTag tag : rootTag.getSubTags()) { final String className = tag.getAttributeValue("name"); if (!Comparing.strEqual(className, externalName) && !Comparing.strEqual(className, oldExternalName)) { continue; } for (XmlTag annotationTag : tag.getSubTags()) { if (!Comparing.strEqual(annotationTag.getAttributeValue("name"), annotationFQN)) { continue; } if (ReadonlyStatusHandler.getInstance(myPsiManager.getProject()) .ensureFilesWritable(file.getVirtualFile()) .hasReadonlyFiles()) { return false; } try { annotationTag.delete(); if (tag.getSubTags().length == 0) { tag.delete(); } } catch (IncorrectOperationException e) { LOG.error(e); } return true; } return false; } } return false; } finally { dropCache(); } }
private boolean processExistingExternalAnnotations( @NotNull final PsiModifierListOwner listOwner, @NotNull final String annotationFQN, @NotNull final Processor<XmlTag> annotationTagProcessor) { try { final List<XmlFile> files = findExternalAnnotationsXmlFiles(listOwner); if (files == null) { notifyAfterAnnotationChanging(listOwner, annotationFQN, false); return false; } boolean processedAnything = false; for (final XmlFile file : files) { if (!file.isValid()) { continue; } if (ReadonlyStatusHandler.getInstance(myPsiManager.getProject()) .ensureFilesWritable(file.getVirtualFile()) .hasReadonlyFiles()) { continue; } final XmlDocument document = file.getDocument(); if (document == null) { continue; } final XmlTag rootTag = document.getRootTag(); if (rootTag == null) { continue; } final String externalName = getExternalName(listOwner, false); final String oldExternalName = getNormalizedExternalName(listOwner); for (final XmlTag tag : rootTag.getSubTags()) { final String className = StringUtil.unescapeXml(tag.getAttributeValue("name")); if (!Comparing.strEqual(className, externalName) && !Comparing.strEqual(className, oldExternalName)) { continue; } for (final XmlTag annotationTag : tag.getSubTags()) { if (!Comparing.strEqual(annotationTag.getAttributeValue("name"), annotationFQN)) { continue; } CommandProcessor.getInstance() .executeCommand( myPsiManager.getProject(), new Runnable() { @Override public void run() { try { annotationTagProcessor.process(annotationTag); commitChanges(file); } catch (IncorrectOperationException e) { LOG.error(e); } } }, ExternalAnnotationsManagerImpl.class.getName(), null); processedAnything = true; } } } notifyAfterAnnotationChanging(listOwner, annotationFQN, processedAnything); return processedAnything; } finally { dropCache(); } }