Search in sources :

Example 1 with PropertiesFileImpl

use of com.intellij.lang.properties.psi.impl.PropertiesFileImpl in project intellij-community by JetBrains.

the class WrongPropertyKeyValueDelimiterInspection method buildVisitor.

@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
    if (!(holder.getFile() instanceof PropertiesFileImpl)) {
        return PsiElementVisitor.EMPTY_VISITOR;
    }
    final PropertiesCodeStyleSettings codeStyleSettings = PropertiesCodeStyleSettings.getInstance(holder.getProject());
    final char codeStyleKeyValueDelimiter = codeStyleSettings.getDelimiter();
    return new PsiElementVisitor() {

        @Override
        public void visitElement(PsiElement element) {
            if (element instanceof PropertyImpl) {
                final char delimiter = ((PropertyImpl) element).getKeyValueDelimiter();
                if (delimiter != codeStyleKeyValueDelimiter) {
                    holder.registerProblem(element, PropertiesBundle.message("wrong.property.key.value.delimiter.inspection.display.name"), new ReplaceKeyValueDelimiterQuickFix(element));
                }
            }
        }
    };
}
Also used : PropertiesCodeStyleSettings(com.intellij.lang.properties.psi.codeStyle.PropertiesCodeStyleSettings) PropertyImpl(com.intellij.lang.properties.psi.impl.PropertyImpl) PropertiesFileImpl(com.intellij.lang.properties.psi.impl.PropertiesFileImpl) PsiElementVisitor(com.intellij.psi.PsiElementVisitor) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with PropertiesFileImpl

use of com.intellij.lang.properties.psi.impl.PropertiesFileImpl in project intellij-community by JetBrains.

the class AlphaUnsortedPropertiesFileInspection method buildVisitor.

@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
    return new PsiElementVisitor() {

        @Override
        public void visitFile(PsiFile file) {
            final PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile(file);
            if (!(propertiesFile instanceof PropertiesFileImpl)) {
                return;
            }
            for (AlphaUnsortedPropertiesFileInspectionSuppressor filter : AlphaUnsortedPropertiesFileInspectionSuppressor.EP_NAME.getExtensions()) {
                if (filter.suppressInspectionFor(propertiesFile)) {
                    return;
                }
            }
            final ResourceBundle resourceBundle = propertiesFile.getResourceBundle();
            final String resourceBundleBaseName = resourceBundle.getBaseName();
            if (!isResourceBundleAlphaSortedExceptOneFile(resourceBundle, propertiesFile)) {
                final List<PropertiesFile> allFiles = resourceBundle.getPropertiesFiles();
                holder.registerProblem(file, String.format(MESSAGE_TEMPLATE_WHOLE_RESOURCE_BUNDLE, resourceBundleBaseName), ProblemHighlightType.INFO, new PropertiesSorterQuickFix(true, allFiles.toArray(new PropertiesFile[allFiles.size()])));
                return;
            }
            if (!propertiesFile.isAlphaSorted()) {
                holder.registerProblem(file, "Properties file is alphabetically unsorted", ProblemHighlightType.INFO, new PropertiesSorterQuickFix(true, propertiesFile));
            }
        }
    };
}
Also used : PsiFile(com.intellij.psi.PsiFile) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) ResourceBundle(com.intellij.lang.properties.ResourceBundle) PsiElementVisitor(com.intellij.psi.PsiElementVisitor) PropertiesFileImpl(com.intellij.lang.properties.psi.impl.PropertiesFileImpl) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PropertiesFileImpl (com.intellij.lang.properties.psi.impl.PropertiesFileImpl)2 PsiElementVisitor (com.intellij.psi.PsiElementVisitor)2 NotNull (org.jetbrains.annotations.NotNull)2 ResourceBundle (com.intellij.lang.properties.ResourceBundle)1 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)1 PropertiesCodeStyleSettings (com.intellij.lang.properties.psi.codeStyle.PropertiesCodeStyleSettings)1 PropertyImpl (com.intellij.lang.properties.psi.impl.PropertyImpl)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1