use of com.intellij.lang.properties.psi.Property in project intellij-community by JetBrains.
the class FormPropertyUsageTest method doPropertyUsageTest.
private void doPropertyUsageTest(final String propertyFileName) {
PropertiesFile propFile = (PropertiesFile) myPsiManager.findFile(myTestProjectRoot.findChild(propertyFileName));
assertNotNull(propFile);
final Property prop = (Property) propFile.findPropertyByKey("key");
assertNotNull(prop);
final Query<PsiReference> query = ReferencesSearch.search(prop);
final Collection<PsiReference> result = query.findAll();
assertEquals(1, result.size());
verifyReference(result, 0, "form.form", 960);
}
use of com.intellij.lang.properties.psi.Property in project intellij-community by JetBrains.
the class GotoPropertyParentDeclarationHandler method getGotoDeclarationTarget.
@Nullable
@Override
public PsiElement getGotoDeclarationTarget(@Nullable PsiElement sourceElement, Editor editor) {
Property property = findProperty(sourceElement);
if (property == null)
return null;
final String key = property.getKey();
if (key == null)
return null;
PropertiesFile currentFile = PropertiesImplUtil.getPropertiesFile(property.getContainingFile());
if (currentFile == null)
return null;
do {
currentFile = PropertiesUtil.getParent(currentFile, currentFile.getResourceBundle().getPropertiesFiles());
if (currentFile != null) {
final IProperty parent = currentFile.findPropertyByKey(key);
if (parent != null)
return parent.getPsiElement();
} else {
return null;
}
} while (true);
}
use of com.intellij.lang.properties.psi.Property in project intellij-community by JetBrains.
the class PropertiesInheritorsSearcher method processQuery.
@Override
public void processQuery(@NotNull DefinitionsScopedSearch.SearchParameters queryParameters, @NotNull Processor<PsiElement> consumer) {
final PsiElement element = queryParameters.getElement();
Property prop = ReadAction.compute(() -> GotoPropertyParentDeclarationHandler.findProperty(element));
if (prop == null || !(queryParameters.getScope() instanceof GlobalSearchScope)) {
return;
}
ReadAction.run(() -> {
final String key = prop.getKey();
if (!prop.isValid() || key == null)
return;
final PropertiesFile currentFile = PropertiesImplUtil.getPropertiesFile(prop.getContainingFile());
LOG.assertTrue(currentFile != null);
final GlobalSearchScope scope = (GlobalSearchScope) queryParameters.getScope();
currentFile.getResourceBundle().getPropertiesFiles().stream().filter(f -> f.equals(currentFile)).filter(f -> scope.contains(f.getVirtualFile())).filter(f -> PropertiesUtil.getParent(f, Collections.singleton(currentFile)) == currentFile).map(f -> f.findPropertyByKey(key)).filter(Objects::nonNull).map(IProperty::getPsiElement).anyMatch(psiElement -> {
ProgressManager.checkCanceled();
return !consumer.process(psiElement);
});
});
}
use of com.intellij.lang.properties.psi.Property in project intellij-community by JetBrains.
the class PropertiesFileTest method testAddPropertyAfter.
public void testAddPropertyAfter() throws IncorrectOperationException {
final PropertiesFile propertiesFile = PropertiesElementFactory.createPropertiesFile(getProject(), "a=b\nc=d\ne=f");
final Property c = (Property) propertiesFile.findPropertyByKey("c");
WriteCommandAction.runWriteCommandAction(null, () -> {
propertiesFile.addPropertyAfter(myPropertyToAdd, c);
});
assertEquals("a=b\nc=d\nkkk=vvv\ne=f", propertiesFile.getText());
}
use of com.intellij.lang.properties.psi.Property in project intellij-community by JetBrains.
the class PropertiesInspectionSuppressor method isSuppressedFor.
@Override
public boolean isSuppressedFor(@NotNull PsiElement element, @NotNull String toolId) {
Property property = PsiTreeUtil.getParentOfType(element, Property.class, false);
PropertiesFile file;
if (property == null) {
PsiFile containingFile = element.getContainingFile();
if (containingFile instanceof PropertiesFile) {
file = (PropertiesFile) containingFile;
} else {
return false;
}
} else {
PsiElement prev = property.getPrevSibling();
while (prev instanceof PsiWhiteSpace || prev instanceof PsiComment) {
if (prev instanceof PsiComment) {
@NonNls String text = prev.getText();
if (text.contains("suppress") && text.contains("\"" + toolId + "\""))
return true;
}
prev = prev.getPrevSibling();
}
file = property.getPropertiesFile();
}
PsiElement leaf = file.getContainingFile().findElementAt(0);
while (leaf instanceof PsiWhiteSpace) leaf = leaf.getNextSibling();
while (leaf instanceof PsiComment) {
@NonNls String text = leaf.getText();
if (text.contains("suppress") && text.contains("\"" + toolId + "\"") && text.contains("file")) {
return true;
}
leaf = leaf.getNextSibling();
if (leaf instanceof PsiWhiteSpace)
leaf = leaf.getNextSibling();
// comment before first property get bound to the file, not property
if (leaf instanceof PropertiesList && leaf.getFirstChild() == property && text.contains("suppress") && text.contains("\"" + toolId + "\"")) {
return true;
}
}
return false;
}
Aggregations