From b802144e48b58f13e60db2f779bae3c6ab7c79b2 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Tue, 2 May 2017 18:11:15 +0300 Subject: [PATCH] cleanup --- .../BaseExternalAnnotationsManager.java | 20 ++++--------------- .../com/intellij/ide/caches/FileContent.java | 10 ++-------- .../psi/stubs/StubTreeLoaderImpl.java | 7 +++---- .../util/indexing/FileBasedIndexImpl.java | 5 ++--- .../encoding/ChangeFileEncodingAction.java | 2 -- .../newvfs/persistent/PersistentFSImpl.java | 16 +++++++-------- 6 files changed, 18 insertions(+), 42 deletions(-) diff --git a/java/java-psi-impl/src/com/intellij/codeInsight/BaseExternalAnnotationsManager.java b/java/java-psi-impl/src/com/intellij/codeInsight/BaseExternalAnnotationsManager.java index ab6d9130aca9..70aa35f0f85c 100644 --- a/java/java-psi-impl/src/com/intellij/codeInsight/BaseExternalAnnotationsManager.java +++ b/java/java-psi-impl/src/com/intellij/codeInsight/BaseExternalAnnotationsManager.java @@ -15,7 +15,6 @@ */ package com.intellij.codeInsight; -import com.intellij.lang.PsiBuilder; import com.intellij.lang.java.parser.JavaParser; import com.intellij.lang.java.parser.JavaParserUtil; import com.intellij.openapi.diagnostic.Logger; @@ -64,7 +63,7 @@ public abstract class BaseExternalAnnotationsManager extends ExternalAnnotations public BaseExternalAnnotationsManager(@NotNull PsiManager psiManager) { myPsiManager = psiManager; - LowMemoryWatcher.register(() -> dropCache(), psiManager.getProject()); + LowMemoryWatcher.register(this::dropCache, psiManager.getProject()); } @Nullable @@ -154,14 +153,8 @@ public abstract class BaseExternalAnnotationsManager extends ExternalAnnotations SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); saxParser.parse(new InputSource(new CharSequenceReader(escapeAttributes(file.getViewProvider().getContents()))), handler); } - catch (IOException e) { - LOG.error(e); - } - catch (ParserConfigurationException e) { - LOG.error(e); - } - catch (SAXException e) { - LOG.error(e); + catch (IOException | ParserConfigurationException | SAXException e) { + LOG.error(file.getViewProvider().getVirtualFile().getPath(), e); } MostlySingularMultiMap result = handler.getResult(); @@ -389,12 +382,7 @@ public abstract class BaseExternalAnnotationsManager extends ExternalAnnotations } } - private static final JavaParserUtil.ParserWrapper ANNOTATION = new JavaParserUtil.ParserWrapper() { - @Override - public void parse(final PsiBuilder builder) { - JavaParser.INSTANCE.getDeclarationParser().parseAnnotation(builder); - } - }; + private static final JavaParserUtil.ParserWrapper ANNOTATION = JavaParser.INSTANCE.getDeclarationParser()::parseAnnotation; private class DataParsingSaxHandler extends DefaultHandler { private final MostlySingularMultiMap myData = new MostlySingularMultiMap<>(); diff --git a/platform/core-api/src/com/intellij/ide/caches/FileContent.java b/platform/core-api/src/com/intellij/ide/caches/FileContent.java index 12a97cbd3b08..caddb3366e3f 100644 --- a/platform/core-api/src/com/intellij/ide/caches/FileContent.java +++ b/platform/core-api/src/com/intellij/ide/caches/FileContent.java @@ -36,20 +36,14 @@ public class FileContent extends UserDataHolderBase { myVirtualFile = virtualFile; } - public void cache() throws IOException { - getBytes(); - getLength(); - getTimeStamp(); - isWritable(); - } - @NotNull public byte[] getBytes() throws IOException { if (myCachedBytes == null) { if (myVirtualFile.isValid()) { myCachedTimeStamp = myVirtualFile.getTimeStamp(); myCachedBytes = myVirtualFile.contentsToByteArray(false); - } else { + } + else { myCachedTimeStamp = -1; myCachedBytes = ArrayUtil.EMPTY_BYTE_ARRAY; } diff --git a/platform/lang-impl/src/com/intellij/psi/stubs/StubTreeLoaderImpl.java b/platform/lang-impl/src/com/intellij/psi/stubs/StubTreeLoaderImpl.java index 62140709e320..0c38523229df 100644 --- a/platform/lang-impl/src/com/intellij/psi/stubs/StubTreeLoaderImpl.java +++ b/platform/lang-impl/src/com/intellij/psi/stubs/StubTreeLoaderImpl.java @@ -44,7 +44,7 @@ import java.util.List; */ public class StubTreeLoaderImpl extends StubTreeLoader { private static final Logger LOG = Logger.getInstance("#com.intellij.psi.stubs.StubTreeLoaderImpl"); - private static volatile boolean ourStubReloadingProhibited = false; + private static volatile boolean ourStubReloadingProhibited; @Override @Nullable @@ -57,9 +57,8 @@ public class StubTreeLoaderImpl extends StubTreeLoader { try { byte[] content = vFile.contentsToByteArray(); vFile.setPreloadedContentHint(content); - final FileContent fc; try { - fc = new FileContentImpl(vFile, content); + final FileContent fc = new FileContentImpl(vFile, content); fc.putUserData(IndexingDataKeys.PROJECT, project); if (psiFile != null && !vFile.getFileType().isBinary()) { fc.putUserData(IndexingDataKeys.FILE_TEXT_CONTENT_KEY, psiFile.getViewProvider().getContents()); @@ -130,7 +129,7 @@ public class StubTreeLoaderImpl extends StubTreeLoader { checkDeserializationCreatesNoPsi(tree); return tree; } - else if (size != 0) { + if (size != 0) { return processError(vFile, "Twin stubs: " + vFile.getPresentableUrl() + " has " + size + " stub versions. Should only have one. id=" + id, null); } diff --git a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java index a613026cf7d4..98144aa97a5d 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java @@ -1486,10 +1486,9 @@ public class FileBasedIndexImpl extends FileBasedIndex implements BaseComponent, private void doIndexFileContent(@Nullable Project project, @NotNull final com.intellij.ide.caches.FileContent content) { final VirtualFile file = content.getVirtualFile(); - - final FileType fileType = file.getFileType(); - final Project finalProject = project == null ? ProjectUtil.guessProjectForFile(file) : project; myFileTypeManager.freezeFileTypeTemporarilyIn(file, () -> { + final FileType fileType = file.getFileType(); + final Project finalProject = project == null ? ProjectUtil.guessProjectForFile(file) : project; PsiFile psiFile = null; FileContentImpl fc = null; int inputId = -1; diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/encoding/ChangeFileEncodingAction.java b/platform/platform-impl/src/com/intellij/openapi/vfs/encoding/ChangeFileEncodingAction.java index 271625054c58..26aeadf16127 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/encoding/ChangeFileEncodingAction.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/encoding/ChangeFileEncodingAction.java @@ -111,8 +111,6 @@ public class ChangeFileEncodingAction extends AnAction implements DumbAware { final Document document, final byte[] bytes, @Nullable final String clearItemText) { - final String text = document == null ? null : document.getText(); - return new ChooseFileEncodingAction(myFile) { @Override public void update(final AnActionEvent e) { diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFSImpl.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFSImpl.java index 0b32d8e8166f..478a6e658aec 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFSImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFSImpl.java @@ -519,15 +519,13 @@ public class PersistentFSImpl extends PersistentFS implements ApplicationCompone return content; } - else { - try { - assert length >= 0 : file; - return FileUtil.loadBytes(contentStream, (int)length); - } - catch (IOException e) { - FSRecords.handleError(e); - return ArrayUtil.EMPTY_BYTE_ARRAY; - } + try { + assert length >= 0 : file; + return FileUtil.loadBytes(contentStream, (int)length); + } + catch (IOException e) { + FSRecords.handleError(e); + return ArrayUtil.EMPTY_BYTE_ARRAY; } }