Search in sources :

Example 76 with PropertiesFile

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;
}
Also used : IProperty(com.intellij.lang.properties.IProperty) DomTarget(com.intellij.util.xml.DomTarget) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) PsiElement(com.intellij.psi.PsiElement)

Example 77 with PropertiesFile

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);
    }
}
Also used : I18nizeAction(com.intellij.codeInspection.i18n.I18nizeAction) NonNls(org.jetbrains.annotations.NonNls) DataContext(com.intellij.openapi.actionSystem.DataContext) PsiLiteralExpression(com.intellij.psi.PsiLiteralExpression) I18nQuickFixHandler(com.intellij.codeInspection.i18n.I18nQuickFixHandler) IncorrectOperationException(com.intellij.util.IncorrectOperationException) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) File(java.io.File)

Example 78 with PropertiesFile

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);
}
Also used : PsiReference(com.intellij.psi.PsiReference) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile)

Example 79 with PropertiesFile

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) IProperty(com.intellij.lang.properties.IProperty) ResourceBundle(com.intellij.lang.properties.ResourceBundle) PsiFile(com.intellij.psi.PsiFile) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 80 with PropertiesFile

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()));
}
Also used : PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) ResourceBundle(com.intellij.lang.properties.ResourceBundle)

Aggregations

PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)143 IProperty (com.intellij.lang.properties.IProperty)44 PsiFile (com.intellij.psi.PsiFile)42 VirtualFile (com.intellij.openapi.vfs.VirtualFile)22 ResourceBundle (com.intellij.lang.properties.ResourceBundle)19 PsiElement (com.intellij.psi.PsiElement)19 NotNull (org.jetbrains.annotations.NotNull)19 Nullable (org.jetbrains.annotations.Nullable)18 Property (com.intellij.lang.properties.psi.Property)15 Project (com.intellij.openapi.project.Project)10 XmlPropertiesFile (com.intellij.lang.properties.xml.XmlPropertiesFile)9 PsiDirectory (com.intellij.psi.PsiDirectory)8 IncorrectOperationException (com.intellij.util.IncorrectOperationException)8 THashSet (gnu.trove.THashSet)8 ArrayList (java.util.ArrayList)7 Module (com.intellij.openapi.module.Module)6 PsiFileSystemItem (com.intellij.psi.PsiFileSystemItem)6 HashSet (com.intellij.util.containers.HashSet)6 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)5 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)5