@NotNull
  private MostlySingularMultiMap<String, AnnotationData> getDataFromFile(
      @NotNull final PsiFile file) {
    Pair<MostlySingularMultiMap<String, AnnotationData>, Long> cached =
        annotationFileToDataAndModStamp.get(file);
    final long fileModificationStamp = file.getModificationStamp();
    if (cached != null && cached.getSecond() == fileModificationStamp) {
      return cached.getFirst();
    }
    DataParsingSaxHandler handler = new DataParsingSaxHandler(file);
    try {
      SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
      saxParser.parse(new InputSource(new StringReader(escapeAttributes(file.getText()))), handler);
    } catch (IOException e) {
      LOG.error(e);
    } catch (ParserConfigurationException e) {
      LOG.error(e);
    } catch (SAXException e) {
      LOG.error(e);
    }

    Pair<MostlySingularMultiMap<String, AnnotationData>, Long> pair =
        Pair.create(handler.getResult(), file.getModificationStamp());
    annotationFileToDataAndModStamp.put(file, pair);

    return pair.first;
  }
Exemplo n.º 2
0
 public String diagnoseNull() {
   final PsiFile file =
       ApplicationManager.getApplication()
           .runReadAction(
               new Computable<PsiFile>() {
                 @Override
                 public PsiFile compute() {
                   return getFile();
                 }
               });
   try {
     PsiElement element =
         ApplicationManager.getApplication()
             .runReadAction(
                 new NullableComputable<PsiElement>() {
                   @Override
                   public PsiElement compute() {
                     return restoreFromStubIndex(
                         (PsiFileWithStubSupport) file, myIndex, myElementType, true);
                   }
                 });
     return "No diagnostics, element="
         + element
         + "@"
         + (element == null ? 0 : System.identityHashCode(element));
   } catch (AssertionError e) {
     String msg = e.getMessage();
     msg +=
         file == null
             ? "\n no PSI file"
             : "\n current file stamp=" + (short) file.getModificationStamp();
     final Document document =
         FileDocumentManager.getInstance().getCachedDocument(myVirtualFile);
     if (document != null) {
       msg += "\n committed=" + PsiDocumentManager.getInstance(myProject).isCommitted(document);
       msg += "\n saved=" + !FileDocumentManager.getInstance().isDocumentUnsaved(document);
     }
     return msg;
   }
 }