use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-community by JetBrains.
the class AntDomProperty method getNavigationElement.
public PsiElement getNavigationElement(final String propertyName) {
DomTarget domTarget = DomTarget.getTarget(this);
if (domTarget == null) {
final GenericAttributeValue<String> environment = getEnvironment();
if (environment.getRawText() != null) {
domTarget = DomTarget.getTarget(this, environment);
}
if (domTarget == null) {
final GenericAttributeValue<String> resource = getResource();
if (resource.getRawText() != null) {
domTarget = DomTarget.getTarget(this, resource);
}
}
}
if (domTarget != null) {
final PsiElement psi = PomService.convertToPsi(domTarget);
if (psi != null) {
return psi;
}
}
final PsiFileSystemItem psiFile = getFile().getValue();
if (psiFile != null) {
final String prefix = getPropertyPrefixValue();
String _propertyName = propertyName;
if (prefix != null) {
if (!propertyName.startsWith(prefix)) {
return null;
}
_propertyName = propertyName.substring(prefix.length());
}
final PropertiesFile pf = toPropertiesFile(psiFile);
if (pf != null) {
final IProperty property = pf.findPropertyByKey(_propertyName);
return property != null ? property.getPsiElement() : null;
}
}
return null;
}
use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-community by JetBrains.
the class I18nizeTest method doTest.
private void doTest(@NonNls String ext) throws Exception {
configureByFile(getBasePath() + "/before" + getTestName(false) + "." + ext);
I18nizeAction action = new I18nizeAction();
DataContext dataContext = DataManager.getInstance().getDataContext(myEditor.getComponent());
AnActionEvent event = AnActionEvent.createFromAnAction(action, null, "place", dataContext);
action.update(event);
@NonNls String afterFile = getBasePath() + "/after" + getTestName(false) + "." + ext;
boolean afterFileExists = new File(PathManagerEx.getTestDataPath() + afterFile).exists();
I18nQuickFixHandler handler = I18nizeAction.getHandler(event);
try {
if (handler != null) {
handler.checkApplicability(getFile(), getEditor());
}
} catch (IncorrectOperationException e) {
event.getPresentation().setEnabled(false);
}
assertEquals(afterFileExists, event.getPresentation().isEnabled());
if (afterFileExists) {
PsiLiteralExpression literalExpression = I18nizeAction.getEnclosingStringLiteral(getFile(), getEditor());
assertNotNull(handler);
ApplicationManager.getApplication().runWriteAction(() -> handler.performI18nization(getFile(), getEditor(), literalExpression, Collections.<PropertiesFile>emptyList(), "key1", "value1", "i18nizedExpr", PsiExpression.EMPTY_ARRAY, JavaI18nUtil.DEFAULT_PROPERTY_CREATION_HANDLER));
checkResultByFile(afterFile);
}
}
use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-community by JetBrains.
the class FormPropertyUsageTest method doPropertyFileUsageTest.
private void doPropertyFileUsageTest(final String fileName) {
PropertiesFile propFile = (PropertiesFile) myPsiManager.findFile(myTestProjectRoot.findChild(fileName));
assertNotNull(propFile);
final Query<PsiReference> query = ReferencesSearch.search(propFile.getContainingFile());
final Collection<PsiReference> result = query.findAll();
assertEquals(1, result.size());
verifyReference(result, 0, "form.form", 949);
}
use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-community by JetBrains.
the class ResourceBundleUtil method getResourceBundleFromDataContext.
/**
* Tries to derive {@link ResourceBundle resource bundle} related to the given context.
*
* @param dataContext target context
* @return {@link ResourceBundle resource bundle} related to the given context if any;
* {@code null} otherwise
*/
@Nullable
public static ResourceBundle getResourceBundleFromDataContext(@NotNull DataContext dataContext) {
PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(dataContext);
//rename property
if (element instanceof IProperty)
return null;
final ResourceBundle[] bundles = ResourceBundle.ARRAY_DATA_KEY.getData(dataContext);
if (bundles != null && bundles.length == 1)
return bundles[0];
VirtualFile virtualFile = CommonDataKeys.VIRTUAL_FILE.getData(dataContext);
if (virtualFile == null) {
return null;
}
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
if (virtualFile instanceof ResourceBundleAsVirtualFile && project != null) {
return ((ResourceBundleAsVirtualFile) virtualFile).getResourceBundle();
}
if (project != null) {
final PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile);
if (psiFile instanceof PropertiesFile) {
return ((PropertiesFile) psiFile).getResourceBundle();
}
}
return null;
}
use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-community by JetBrains.
the class CustomResourceBundlePropertiesFileNode method update.
@Override
public void update(PresentationData data) {
super.update(data);
final PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile(getValue());
assert propertiesFile != null;
final ResourceBundle resourceBundle = propertiesFile.getResourceBundle();
data.setLocationString(PropertiesBundle.message("project.view.resource.bundle.tree.node.text", resourceBundle.getBaseName()));
}
Aggregations