Search in sources :

Example 1 with PropertiesCodeStyleSettings

use of com.intellij.lang.properties.psi.codeStyle.PropertiesCodeStyleSettings 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 PropertiesCodeStyleSettings

use of com.intellij.lang.properties.psi.codeStyle.PropertiesCodeStyleSettings in project intellij-community by JetBrains.

the class PropertiesFileTest method testNonDefaultKeyValueDelimiter.

public void testNonDefaultKeyValueDelimiter() {
    final PropertiesCodeStyleSettings codeStyleSettings = PropertiesCodeStyleSettings.getInstance(getProject());
    codeStyleSettings.KEY_VALUE_DELIMITER_CODE = 1;
    final PropertyImpl property = (PropertyImpl) PropertiesElementFactory.createProperty(getProject(), "xxx", "yyy", null);
    final char delimiter = property.getKeyValueDelimiter();
    assertEquals(':', delimiter);
    assertEquals("xxx:yyy", property.getPsiElement().getText());
    codeStyleSettings.KEY_VALUE_DELIMITER_CODE = 0;
}
Also used : PropertiesCodeStyleSettings(com.intellij.lang.properties.psi.codeStyle.PropertiesCodeStyleSettings) PropertyImpl(com.intellij.lang.properties.psi.impl.PropertyImpl)

Aggregations

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