This commit is contained in:
Alexey Kudravtsev
2019-03-25 13:32:16 +03:00
parent 516c50d8ee
commit d51c7419c5
14 changed files with 52 additions and 41 deletions
@@ -202,7 +202,7 @@ class PackagePrefixFileSystemItemImpl extends PsiElementBase implements PsiFileS
}
@Override
public boolean processChildren(final PsiElementProcessor<PsiFileSystemItem> processor) {
public boolean processChildren(@NotNull final PsiElementProcessor<PsiFileSystemItem> processor) {
if (myIndex == myPackages.length - 1) {
return myDirectory.processChildren(processor);
}
@@ -135,7 +135,7 @@ public class MockPsiDirectory extends MockPsiElement implements PsiDirectory {
}
@Override
public boolean processChildren(final PsiElementProcessor<PsiFileSystemItem> processor) {
public boolean processChildren(@NotNull final PsiElementProcessor<PsiFileSystemItem> processor) {
throw new UnsupportedOperationException("Method processChildren is not yet implemented in " + getClass().getName());
}
@@ -36,8 +36,9 @@ public interface PsiFileSystemItem extends PsiCheckedRenameElement, NavigatableP
VirtualFile getVirtualFile();
@Override
@NotNull @NonNls
@NotNull
@NonNls
String getName();
boolean processChildren(PsiElementProcessor<PsiFileSystemItem> processor);
boolean processChildren(@NotNull PsiElementProcessor<PsiFileSystemItem> processor);
}
@@ -671,7 +671,7 @@ public class PsiUtilCore {
}
@Override
public boolean processChildren(PsiElementProcessor<PsiFileSystemItem> processor) {
public boolean processChildren(@NotNull PsiElementProcessor<PsiFileSystemItem> processor) {
throw createException();
}
@@ -55,7 +55,7 @@ public class PsiBinaryFileImpl extends PsiElementBase implements PsiBinaryFile,
}
@Override
public boolean processChildren(final PsiElementProcessor<PsiFileSystemItem> processor) {
public boolean processChildren(@NotNull final PsiElementProcessor<PsiFileSystemItem> processor) {
return true;
}
@@ -172,7 +172,7 @@ public class PsiDirectoryImpl extends PsiElementBase implements PsiDirectory, Qu
}
@Override
public boolean processChildren(PsiElementProcessor<PsiFileSystemItem> processor) {
public boolean processChildren(@NotNull PsiElementProcessor<PsiFileSystemItem> processor) {
checkValid();
for (VirtualFile vFile : myFile.getChildren()) {
@@ -124,7 +124,7 @@ public abstract class PsiFileImpl extends ElementBase implements PsiFileEx, PsiF
}
@Override
public boolean processChildren(final PsiElementProcessor<PsiFileSystemItem> processor) {
public boolean processChildren(@NotNull final PsiElementProcessor<PsiFileSystemItem> processor) {
return true;
}
@@ -42,7 +42,7 @@ public abstract class LightPsiFileImpl extends PsiElementBase implements PsiFile
}
@Override
public boolean processChildren(final PsiElementProcessor<PsiFileSystemItem> processor) {
public boolean processChildren(@NotNull final PsiElementProcessor<PsiFileSystemItem> processor) {
return true;
}
@@ -125,7 +125,7 @@ public class VfsImplUtil {
@Nullable
private static Pair<NewVirtualFile, Iterable<String>> prepare(@NotNull NewVirtualFileSystem vfs, @NotNull String path) {
String normalizedPath = normalize(vfs, path);
String normalizedPath = vfs.normalize(path);
if (StringUtil.isEmptyOrSpaces(normalizedPath)) {
return null;
}
@@ -63,7 +63,7 @@ public class MockPsiFile extends MockPsiElement implements PsiFile {
}
@Override
public boolean processChildren(final PsiElementProcessor<PsiFileSystemItem> processor) {
public boolean processChildren(@NotNull final PsiElementProcessor<PsiFileSystemItem> processor) {
return true;
}
@@ -45,7 +45,8 @@ public interface PropertiesFile {
/**
* @return All properties found in this file.
*/
@NotNull List<IProperty> getProperties();
@NotNull
List<IProperty> getProperties();
/**
*
@@ -57,13 +58,16 @@ public interface PropertiesFile {
IProperty findPropertyByKey(@NotNull @NonNls String key);
/**
* @param key
* @return All properties found in this file with the name specified.
*/
@NotNull List<IProperty> findPropertiesByKey(@NotNull @NonNls String key);
@NotNull
List<IProperty> findPropertiesByKey(@NotNull @NonNls String key);
@NotNull ResourceBundle getResourceBundle();
@NotNull Locale getLocale();
@NotNull
ResourceBundle getResourceBundle();
@NotNull
Locale getLocale();
/**
* Adds property to the end of the file.
@@ -71,12 +75,12 @@ public interface PropertiesFile {
* @param property to add. Typically you create the property via {@link PropertiesElementFactory}.
* @return newly added property.
* It is this value you use to do actual PSI work, e.g. call {@link PsiElement#delete()} to remove this property from the file.
* @throws IncorrectOperationException
* @deprecated
* @deprecated use {@link #addProperty(String, String)} instead
* @see #addProperty(String, String)
*/
@Deprecated
@NotNull PsiElement addProperty(@NotNull IProperty property) throws IncorrectOperationException;
@NotNull
PsiElement addProperty(@NotNull IProperty property) throws IncorrectOperationException;
/**
* Adds property to the the file after the specified property.
@@ -88,9 +92,9 @@ public interface PropertiesFile {
* @param anchor property after which to add the new property
* @return newly added property.
* It is this value you use to do actual PSI work, e.g. call {@link PsiElement#delete()} to remove this property from the file.
* @throws IncorrectOperationException
*/
@NotNull PsiElement addPropertyAfter(@NotNull IProperty property, @Nullable IProperty anchor) throws IncorrectOperationException;
@NotNull
PsiElement addPropertyAfter(@NotNull IProperty property, @Nullable IProperty anchor) throws IncorrectOperationException;
/**
* Adds property to the the file after the specified property.
@@ -100,18 +104,21 @@ public interface PropertiesFile {
* @param value of a property to add.
* @param anchor property after which to add the new property
* @return newly added property.
* @throws IncorrectOperationException
*/
IProperty addPropertyAfter(String key, String value, IProperty anchor) throws IncorrectOperationException;
@NotNull
IProperty addPropertyAfter(@NotNull String key, @NotNull String value, IProperty anchor) throws IncorrectOperationException;
IProperty addProperty(String key, String value);
@NotNull
IProperty addProperty(@NotNull String key, @NotNull String value);
/**
* @return Property key to the property value map.
* Do not modify this map. It's no use anyway.
*/
@NotNull Map<String,String> getNamesMap();
@NotNull
Map<String,String> getNamesMap();
@NotNull
String getName();
VirtualFile getVirtualFile();
@@ -121,6 +128,7 @@ public interface PropertiesFile {
*/
PsiDirectory getParent();
@NotNull
Project getProject();
String getText();
@@ -67,7 +67,8 @@ public class PropertiesFileImpl extends PsiFileBase implements PropertiesFile {
if (stub != null) {
PropertiesListStub propertiesListStub = stub.findChildStubByType(PropertiesElementTypes.PROPERTIES_LIST);
propertiesList = propertiesListStub == null ? null : propertiesListStub.getPsi();
} else {
}
else {
propertiesList = PsiTreeUtil.findChildOfType(this, PropertiesList.class);
}
return Collections.unmodifiableList(PsiTreeUtil.getStubChildrenOfTypeAsList(propertiesList, Property.class));
@@ -123,10 +124,8 @@ public class PropertiesFileImpl extends PsiFileBase implements PropertiesFile {
List<IProperty> properties = getProperties();
ASTNode anchorBefore = anchor == null ? properties.isEmpty() ? null : properties.get(0).getPsiElement().getNode()
: anchor.getPsiElement().getNode().getTreeNext();
if (anchorBefore != null) {
if (anchorBefore.getElementType() == TokenType.WHITE_SPACE) {
anchorBefore = anchorBefore.getTreeNext();
}
if (anchorBefore != null && anchorBefore.getElementType() == TokenType.WHITE_SPACE) {
anchorBefore = anchorBefore.getTreeNext();
}
if (anchorBefore == null && haveToAddNewLine()) {
insertLineBreakBefore(null);
@@ -140,21 +139,22 @@ public class PropertiesFileImpl extends PsiFileBase implements PropertiesFile {
@NotNull
@Override
public IProperty addProperty(String key, String value) {
public IProperty addProperty(@NotNull String key, @NotNull String value) {
return (IProperty)addProperty(PropertiesElementFactory.createProperty(getProject(), key, value, null));
}
@NotNull
@Override
public IProperty addPropertyAfter(String key, String value, @Nullable IProperty anchor) {
public IProperty addPropertyAfter(@NotNull String key, @NotNull String value, @Nullable IProperty anchor) {
return (IProperty)addPropertyAfter(PropertiesElementFactory.createProperty(getProject(), key, value, null), anchor);
}
private void insertLineBreakBefore(final ASTNode anchorBefore) {
private void insertLineBreakBefore(ASTNode anchorBefore) {
ASTNode propertiesList = getPropertiesList();
if (anchorBefore == null && propertiesList.getFirstChildNode() == null) {
getNode().addChild(ASTFactory.whitespace("\n"), propertiesList);
} else {
}
else {
propertiesList.addChild(ASTFactory.whitespace("\n"), anchorBefore);
}
}
@@ -199,14 +199,13 @@ public class PropertiesFileImpl extends PsiFileBase implements PropertiesFile {
return ContainerUtil.getLastItem(properties);
}
@NotNull
private Stream<? extends IProperty> propertiesByKey(@NotNull String key) {
if (shouldReadIndex()) {
return PropertyKeyIndex.getInstance().get(key, getProject(), GlobalSearchScope.fileScope(this)).stream();
}
else {
// see PropertiesElementFactory.createPropertiesFile(Project, Properties, String)
return getProperties().stream().filter(p -> key.equals(p.getUnescapedKey()));
}
// see PropertiesElementFactory.createPropertiesFile(Project, Properties, String)
return getProperties().stream().filter(p -> key.equals(p.getUnescapedKey()));
}
private boolean shouldReadIndex() {
@@ -140,8 +140,9 @@ public class XmlPropertiesFileImpl extends XmlPropertiesFile {
return addPropertyAfter(property.getKey(), property.getValue(), anchor).getPsiElement().getNavigationElement();
}
@NotNull
@Override
public IProperty addPropertyAfter(String key, String value, IProperty anchor) {
public IProperty addPropertyAfter(@NotNull String key, @NotNull String value, IProperty anchor) {
return addPropertyAfter(key, value, anchor, true);
}
@@ -156,7 +157,7 @@ public class XmlPropertiesFileImpl extends XmlPropertiesFile {
@NotNull
@Override
public IProperty addProperty(String key, String value) {
public IProperty addProperty(@NotNull String key, @NotNull String value) {
final XmlTag entry = createPropertyTag(key, value);
synchronized (myLock) {
ensurePropertiesLoaded();
@@ -221,6 +222,7 @@ public class XmlPropertiesFileImpl extends XmlPropertiesFile {
return result;
}
@NotNull
@Override
public String getName() {
return getContainingFile().getName();
@@ -236,6 +238,7 @@ public class XmlPropertiesFileImpl extends XmlPropertiesFile {
return getContainingFile().getParent();
}
@NotNull
@Override
public Project getProject() {
return getContainingFile().getProject();
@@ -314,7 +314,7 @@ public class PropertiesCopyHandler extends CopyHandlerDelegateBase {
}
@Override
public boolean processChildren(PsiElementProcessor<PsiFileSystemItem> processor) {
public boolean processChildren(@NotNull PsiElementProcessor<PsiFileSystemItem> processor) {
for (PropertiesFile propertiesFile : myResourceBundle.getPropertiesFiles()) {
if (!propertiesFile.getContainingFile().processChildren(processor)) {
return false;