diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/JShellFileImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/JShellFileImpl.java index 09f7b6ffec74..abe9952f2c26 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/JShellFileImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/JShellFileImpl.java @@ -53,6 +53,7 @@ public class JShellFileImpl extends PsiJavaFileBaseImpl implements PsiJShellFile return JShellFileType.INSTANCE; } + @Override public boolean isPhysical() { return getViewProvider().isPhysical(); } diff --git a/java/jsp-base-openapi/src/com/intellij/psi/jsp/BaseJspFile.java b/java/jsp-base-openapi/src/com/intellij/psi/jsp/BaseJspFile.java index 117362f401d1..8d15022ada72 100644 --- a/java/jsp-base-openapi/src/com/intellij/psi/jsp/BaseJspFile.java +++ b/java/jsp-base-openapi/src/com/intellij/psi/jsp/BaseJspFile.java @@ -46,9 +46,11 @@ public interface BaseJspFile extends XmlFile { */ PsiFile getErrorPage(); + @Override @NotNull JspxFileViewProvider getViewProvider(); + @Override @NotNull XmlTag getRootTag(); } diff --git a/platform/core-api/src/com/intellij/psi/PsiCheckedRenameElement.java b/platform/core-api/src/com/intellij/psi/PsiCheckedRenameElement.java index 6886753a0e4e..f22983e11df7 100644 --- a/platform/core-api/src/com/intellij/psi/PsiCheckedRenameElement.java +++ b/platform/core-api/src/com/intellij/psi/PsiCheckedRenameElement.java @@ -27,7 +27,7 @@ public interface PsiCheckedRenameElement extends PsiNamedElement { * and throws an exception if the rename is not possible. Does not actually modify anything. * * @param name the new name to check the renaming possibility for. - * @throws com.intellij.util.IncorrectOperationException if the rename is not supported or not possible for some reason. + * @throws IncorrectOperationException if the rename is not supported or not possible for some reason. */ void checkSetName(String name) throws IncorrectOperationException; } diff --git a/platform/core-api/src/com/intellij/psi/PsiElement.java b/platform/core-api/src/com/intellij/psi/PsiElement.java index 47189975efad..2beaf4a36685 100644 --- a/platform/core-api/src/com/intellij/psi/PsiElement.java +++ b/platform/core-api/src/com/intellij/psi/PsiElement.java @@ -50,8 +50,7 @@ public interface PsiElement extends UserDataHolder, Iconable { * Returns the project to which the PSI element belongs. * * @return the project instance. - * @throws PsiInvalidElementAccessException - * if this element is invalid + * @throws PsiInvalidElementAccessException if this element is invalid */ @NotNull @Contract(pure=true) diff --git a/platform/core-api/src/com/intellij/psi/PsiFile.java b/platform/core-api/src/com/intellij/psi/PsiFile.java index d3a93b8a7873..131ec416950b 100644 --- a/platform/core-api/src/com/intellij/psi/PsiFile.java +++ b/platform/core-api/src/com/intellij/psi/PsiFile.java @@ -27,8 +27,8 @@ import org.jetbrains.annotations.NotNull; * for high-level overview. * * @see com.intellij.openapi.actionSystem.LangDataKeys#PSI_FILE - * @see com.intellij.psi.PsiElement#getContainingFile() - * @see PsiManager#findFile(com.intellij.openapi.vfs.VirtualFile) + * @see PsiElement#getContainingFile() + * @see PsiManager#findFile(VirtualFile) * @see PsiDocumentManager#getPsiFile(com.intellij.openapi.editor.Document) */ public interface PsiFile extends PsiFileSystemItem { @@ -60,7 +60,7 @@ public interface PsiFile extends PsiFileSystemItem { * of the content of the file. Note that it is not related to the file modification time. * * @return the modification stamp value - * @see com.intellij.openapi.vfs.VirtualFile#getModificationStamp() + * @see VirtualFile#getModificationStamp() */ long getModificationStamp(); diff --git a/platform/core-api/src/com/intellij/psi/PsiNamedElement.java b/platform/core-api/src/com/intellij/psi/PsiNamedElement.java index aeb57578ede6..ad8c4c98d6a9 100644 --- a/platform/core-api/src/com/intellij/psi/PsiNamedElement.java +++ b/platform/core-api/src/com/intellij/psi/PsiNamedElement.java @@ -33,7 +33,8 @@ public interface PsiNamedElement extends PsiElement { * * @return the element name. */ - @Nullable String getName(); + @Nullable + String getName(); /** * Renames the element. diff --git a/platform/core-impl/src/com/intellij/psi/impl/file/impl/FileManagerImpl.java b/platform/core-impl/src/com/intellij/psi/impl/file/impl/FileManagerImpl.java index de5092a27de0..35f32547fab0 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/file/impl/FileManagerImpl.java +++ b/platform/core-impl/src/com/intellij/psi/impl/file/impl/FileManagerImpl.java @@ -213,12 +213,11 @@ public class FileManagerImpl implements FileManager { if (fileViewProvider == null) { myVFileToViewProviderMap.remove(virtualFile); } + else if (virtualFile instanceof LightVirtualFile) { + virtualFile.putUserData(myPsiHardRefKey, fileViewProvider); + } else { - if (virtualFile instanceof LightVirtualFile) { - virtualFile.putUserData(myPsiHardRefKey, fileViewProvider); - } else { - myVFileToViewProviderMap.put(virtualFile, fileViewProvider); - } + myVFileToViewProviderMap.put(virtualFile, fileViewProvider); } } } diff --git a/platform/core-impl/src/com/intellij/psi/impl/source/PsiFileImpl.java b/platform/core-impl/src/com/intellij/psi/impl/source/PsiFileImpl.java index c173e25e1382..d87c48aa2a84 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/source/PsiFileImpl.java +++ b/platform/core-impl/src/com/intellij/psi/impl/source/PsiFileImpl.java @@ -1108,7 +1108,7 @@ public abstract class PsiFileImpl extends ElementBase implements PsiFileEx, PsiF if (!useStrongRefs()) { synchronized (myPsiLock) { for (PsiFile root : myViewProvider.getAllFiles()) { - if ((root instanceof PsiFileImpl)) { + if (root instanceof PsiFileImpl) { ((PsiFileImpl)root).switchToStrongRefs(); } } diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/PostprocessReformattingAspect.java b/platform/lang-impl/src/com/intellij/psi/impl/source/PostprocessReformattingAspect.java index afacc5c11e58..f0850f5a0a03 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/source/PostprocessReformattingAspect.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/source/PostprocessReformattingAspect.java @@ -52,7 +52,6 @@ import com.intellij.psi.impl.source.codeStyle.CodeFormatterFacade; import com.intellij.psi.impl.source.codeStyle.IndentHelperImpl; import com.intellij.psi.impl.source.tree.*; import com.intellij.util.LocalTimeCounter; -import com.intellij.util.containers.ContainerUtilRt; import com.intellij.util.text.CharArrayUtil; import com.intellij.util.text.TextRangeUtil; import org.jetbrains.annotations.NonNls; @@ -73,7 +72,7 @@ public class PostprocessReformattingAspect implements PomModelAspect { private static final boolean STORE_REFORMAT_ORIGINATOR_STACKTRACE = ApplicationManager.getApplication().isInternal(); } - private final ThreadLocal myContext = ThreadLocal.withInitial(() -> new Context()); + private final ThreadLocal myContext = ThreadLocal.withInitial(Context::new); public PostprocessReformattingAspect(Project project, PsiManager psiManager, TreeAspect treeAspect,final CommandProcessor processor) { myProject = project; @@ -155,7 +154,7 @@ public class PostprocessReformattingAspect implements PomModelAspect { doPostponedFormatting(); } else { - application.runWriteAction(() -> doPostponedFormatting()); + application.runWriteAction((Runnable)this::doPostponedFormatting); } } } @@ -286,7 +285,7 @@ public class PostprocessReformattingAspect implements PomModelAspect { break; } if (sb.length() > 0) sb.append(", "); - sb.append(node.getElementType().toString()).append(node.getTextRange()); + sb.append(node.getElementType()).append(node.getTextRange()); count ++; } return sb.toString(); @@ -335,12 +334,12 @@ public class PostprocessReformattingAspect implements PomModelAspect { } } - final TreeSet postProcessTasks = new TreeSet<>(); - Collection toDispose = ContainerUtilRt.newArrayList(); + Collection toDispose = Collections.emptyList(); try { // process all roots in viewProvider to find marked for reformat before elements and create appropriate range markers + Set postProcessTasks = new TreeSet<>(); handleReformatMarkers(key, postProcessTasks); - toDispose.addAll(postProcessTasks); + toDispose = new ArrayList<>(postProcessTasks); // then we create ranges by changed nodes. One per node. There ranges can intersect. Ranges are sorted by end offset. if (astNodes != null) createActionsMap(astNodes, key, postProcessTasks); @@ -374,9 +373,9 @@ public class PostprocessReformattingAspect implements PomModelAspect { } } - private void reparseByTextIfNeeded(@NotNull FileViewProvider key, Document document) { + private void reparseByTextIfNeeded(@NotNull FileViewProvider viewProvider, @NotNull Document document) { if (PsiDocumentManager.getInstance(myProject).isCommitted(document)) { - for (PsiFile file : key.getAllFiles()) { + for (PsiFile file : viewProvider.getAllFiles()) { if (file.getUserData(REPARSE_PENDING) != null) { ((PsiDocumentManagerBase)PsiDocumentManager.getInstance(myProject)).reparseFileFromText((PsiFileImpl)file); file.putUserData(REPARSE_PENDING, null); @@ -479,13 +478,7 @@ public class PostprocessReformattingAspect implements PomModelAspect { rangeMarker = document.createRangeMarker(newStart, newEnd); } - if (withLeadingWhitespace) { - accumulatedTask = new ReformatWithHeadingWhitespaceTask(rangeMarker); - } - else { - accumulatedTask = new ReformatTask(rangeMarker); - - } + accumulatedTask = withLeadingWhitespace ? new ReformatWithHeadingWhitespaceTask(rangeMarker) : new ReformatTask(rangeMarker); } else if (currentTask instanceof ReindentTask) { iterator.remove(); @@ -501,10 +494,10 @@ public class PostprocessReformattingAspect implements PomModelAspect { } } - final List result = new ArrayList<>(); Collections.reverse(freeFormattingActions); Collections.reverse(indentActions); + List result = new ArrayList<>(); if (!freeFormattingActions.isEmpty()) { FormatTextRanges ranges = new FormatTextRanges(); for (PostprocessFormattingTask action : freeFormattingActions) { @@ -538,7 +531,7 @@ public class PostprocessReformattingAspect implements PomModelAspect { private static void createActionsMap(@NotNull List astNodes, @NotNull FileViewProvider provider, - @NotNull final TreeSet rangesToProcess) { + @NotNull Collection rangesToProcess) { final Set nodesToProcess = new HashSet<>(astNodes); final Document document = provider.getDocument(); if (document == null) { @@ -679,7 +672,7 @@ public class PostprocessReformattingAspect implements PomModelAspect { private abstract static class PostprocessFormattingTask implements Comparable, Segment, Disposable { @NotNull private final RangeMarker myRange; - public PostprocessFormattingTask(@NotNull RangeMarker rangeMarker) { + PostprocessFormattingTask(@NotNull RangeMarker rangeMarker) { myRange = rangeMarker; } @@ -722,13 +715,13 @@ public class PostprocessReformattingAspect implements PomModelAspect { } private static class ReformatTask extends PostprocessFormattingTask { - public ReformatTask(@NotNull RangeMarker rangeMarker) { + ReformatTask(@NotNull RangeMarker rangeMarker) { super(rangeMarker); } } private static class ReformatWithHeadingWhitespaceTask extends PostprocessFormattingTask { - public ReformatWithHeadingWhitespaceTask(@NotNull RangeMarker rangeMarker) { + ReformatWithHeadingWhitespaceTask(@NotNull RangeMarker rangeMarker) { super(rangeMarker); } } @@ -736,12 +729,12 @@ public class PostprocessReformattingAspect implements PomModelAspect { private static class ReindentTask extends PostprocessFormattingTask { private final int myOldIndent; - public ReindentTask(@NotNull RangeMarker rangeMarker, int oldIndent) { + ReindentTask(@NotNull RangeMarker rangeMarker, int oldIndent) { super(rangeMarker); myOldIndent = oldIndent; } - public int getOldIndent() { + int getOldIndent() { return myOldIndent; } } @@ -753,7 +746,7 @@ public class PostprocessReformattingAspect implements PomModelAspect { private class ReformatRangesAction implements PostponedAction { private final FormatTextRanges myRanges; - public ReformatRangesAction(@NotNull FormatTextRanges ranges) { + ReformatRangesAction(@NotNull FormatTextRanges ranges) { myRanges = ranges; } @@ -812,8 +805,8 @@ public class PostprocessReformattingAspect implements PomModelAspect { } private static class Context { - private int myPostponedCounter = 0; - private int myDisabledCounter = 0; + private int myPostponedCounter; + private int myDisabledCounter; private final Set myUpdatedProviders = new HashSet<>(); private final Map> myReformatElements = new HashMap<>(); } diff --git a/platform/util-rt/src/com/intellij/util/containers/ContainerUtilRt.java b/platform/util-rt/src/com/intellij/util/containers/ContainerUtilRt.java index f6741f52c85b..b54095b07982 100644 --- a/platform/util-rt/src/com/intellij/util/containers/ContainerUtilRt.java +++ b/platform/util-rt/src/com/intellij/util/containers/ContainerUtilRt.java @@ -322,7 +322,7 @@ public class ContainerUtilRt { } @Override - public boolean containsAll(Collection c) { + public boolean containsAll(@NotNull Collection c) { return c.isEmpty(); } @@ -335,7 +335,7 @@ public class ContainerUtilRt { @Override @Contract(pure = true) public boolean equals(Object o) { - return (o instanceof List) && ((List)o).isEmpty(); + return o instanceof List && ((List)o).isEmpty(); } @Override diff --git a/platform/util/src/com/intellij/util/containers/ContainerUtil.java b/platform/util/src/com/intellij/util/containers/ContainerUtil.java index ced245f4fb97..48b8af3059b0 100644 --- a/platform/util/src/com/intellij/util/containers/ContainerUtil.java +++ b/platform/util/src/com/intellij/util/containers/ContainerUtil.java @@ -1431,7 +1431,7 @@ public class ContainerUtil extends ContainerUtilRt { throw new ConcurrentModificationException("The list has changed. Its size was " + finalSize + "; now it's " + from); } } - throw new IndexOutOfBoundsException("index: " + index + "size: " + size()); + throw new IndexOutOfBoundsException("index: " + index + "; size: " + size()); } @Override diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/psi/impl/XPathElementImpl.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/psi/impl/XPathElementImpl.java index 728bbee7c3d3..890c5527c52c 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/psi/impl/XPathElementImpl.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/psi/impl/XPathElementImpl.java @@ -44,6 +44,7 @@ public class XPathElementImpl extends ASTWrapperPsiElement implements XPathEleme return name.substring(name.lastIndexOf('.') + 1) + ": " + getText(); } + @Override public PsiElement addBefore(@NotNull PsiElement psiElement, final PsiElement anchor) throws IncorrectOperationException { final ASTNode node = getNode(); final ASTNode child = psiElement.getNode(); @@ -52,6 +53,7 @@ public class XPathElementImpl extends ASTWrapperPsiElement implements XPathEleme return node.getPsi(); } + @Override public PsiElement addAfter(@NotNull PsiElement psiElement, final PsiElement anchor) throws IncorrectOperationException { final ASTNode astNode = anchor.getNode(); assert astNode != null; diff --git a/python/ipnb/src/org/jetbrains/plugins/ipnb/psi/IpnbPyFragment.java b/python/ipnb/src/org/jetbrains/plugins/ipnb/psi/IpnbPyFragment.java index b9a740d7a86a..9f6d428fbd4f 100644 --- a/python/ipnb/src/org/jetbrains/plugins/ipnb/psi/IpnbPyFragment.java +++ b/python/ipnb/src/org/jetbrains/plugins/ipnb/psi/IpnbPyFragment.java @@ -49,12 +49,14 @@ public class IpnbPyFragment extends PyFileImpl { return clone; } + @Override @NotNull public FileViewProvider getViewProvider() { if (myViewProvider != null) return myViewProvider; return super.getViewProvider(); } + @Override public boolean isPhysical() { return myPhysical; } diff --git a/python/src/com/jetbrains/python/psi/impl/PyExpressionCodeFragmentImpl.java b/python/src/com/jetbrains/python/psi/impl/PyExpressionCodeFragmentImpl.java index e0464cab6926..d8bc6fab87d5 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyExpressionCodeFragmentImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyExpressionCodeFragmentImpl.java @@ -59,12 +59,14 @@ public class PyExpressionCodeFragmentImpl extends PyFileImpl implements PyExpres return myContext != null && myContext.isValid() ? myContext : super.getContext(); } + @Override @NotNull public FileViewProvider getViewProvider() { if(myViewProvider != null) return myViewProvider; return super.getViewProvider(); } + @Override public boolean isPhysical() { return myPhysical; } diff --git a/python/src/com/jetbrains/python/psi/impl/PyListLiteralExpressionImpl.java b/python/src/com/jetbrains/python/psi/impl/PyListLiteralExpressionImpl.java index cee81b15f6ea..685f3b229327 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyListLiteralExpressionImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyListLiteralExpressionImpl.java @@ -50,12 +50,14 @@ public class PyListLiteralExpressionImpl extends PySequenceExpressionImpl implem } } + @Override public PsiElement addAfter(@NotNull PsiElement psiElement, PsiElement afterThis) throws IncorrectOperationException { checkPyExpression(psiElement); checkPyExpression(afterThis); return PyElementGenerator.getInstance(getProject()).insertItemIntoList(this, (PyExpression)afterThis, (PyExpression)psiElement); } + @Override public PsiElement addBefore(@NotNull PsiElement psiElement, PsiElement beforeThis) throws IncorrectOperationException { checkPyExpression(psiElement); return PyElementGenerator.getInstance(getProject()).insertItemIntoList(this, null, (PyExpression)psiElement);