Search in sources :

Example 1 with PropertyImpl

use of com.intellij.lang.properties.psi.impl.PropertyImpl 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)

Example 2 with PropertyImpl

use of com.intellij.lang.properties.psi.impl.PropertyImpl 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 3 with PropertyImpl

use of com.intellij.lang.properties.psi.impl.PropertyImpl in project azure-tools-for-java by Microsoft.

the class SpringPropertiesLineMarkerProvider method getLineMarkerInfo.

@Override
@Nullable
public LineMarkerInfo<PsiElement> getLineMarkerInfo(@Nonnull PsiElement element) {
    if (!(element instanceof PropertyImpl)) {
        return null;
    }
    final String propKey = ((PropertyImpl) element).getKey();
    final String propVal = ((PropertyImpl) element).getValue();
    final Module module = ModuleUtil.findModuleForFile(element.getContainingFile().getVirtualFile(), element.getProject());
    if (Objects.isNull(module)) {
        return null;
    }
    final ImmutablePair<String, String> keyProp = new ImmutablePair<>(propKey, propVal);
    final List<Connection<?, ?>> connections = element.getProject().getService(ConnectionManager.class).getConnectionsByConsumerId(module.getName());
    for (final Connection<?, ?> connection : connections) {
        final List<Pair<String, String>> properties = SpringSupported.getProperties(connection);
        if (!properties.isEmpty() && properties.get(0).equals(keyProp)) {
            final Resource<?> r = connection.getResource();
            return new LineMarkerInfo<>(element, element.getTextRange(), AzureIcons.getIcon("/icons/connector/connect.svg"), element2 -> String.format("%s (%s)", r.getName(), r.getDefinition().getTitle()), new SpringDatasourceNavigationHandler(r), GutterIconRenderer.Alignment.LEFT, () -> "");
        }
    }
    return null;
}
Also used : Connection(com.microsoft.azure.toolkit.intellij.connector.Connection) PropertyImpl(com.intellij.lang.properties.psi.impl.PropertyImpl) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) ConnectionManager(com.microsoft.azure.toolkit.intellij.connector.ConnectionManager) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) Module(com.intellij.openapi.module.Module) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) Pair(org.apache.commons.lang3.tuple.Pair) Nullable(javax.annotation.Nullable)

Example 4 with PropertyImpl

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

the class PropertiesAnnotator method annotate.

public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
    if (!(element instanceof IProperty))
        return;
    final Property property = (Property) element;
    PropertiesFile propertiesFile = property.getPropertiesFile();
    Collection<IProperty> others = propertiesFile.findPropertiesByKey(property.getUnescapedKey());
    ASTNode keyNode = ((PropertyImpl) property).getKeyNode();
    if (others.size() != 1) {
        Annotation annotation = holder.createErrorAnnotation(keyNode, PropertiesBundle.message("duplicate.property.key.error.message"));
        annotation.registerFix(PropertiesQuickFixFactory.getInstance().createRemovePropertyFix(property));
    }
    highlightTokens(property, keyNode, holder, new PropertiesHighlighter());
    ASTNode valueNode = ((PropertyImpl) property).getValueNode();
    if (valueNode != null) {
        highlightTokens(property, valueNode, holder, new PropertiesValueHighlighter());
    }
}
Also used : ASTNode(com.intellij.lang.ASTNode) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) PropertyImpl(com.intellij.lang.properties.psi.impl.PropertyImpl) Property(com.intellij.lang.properties.psi.Property) Annotation(com.intellij.lang.annotation.Annotation) PropertiesValueHighlighter(com.intellij.lang.properties.editor.PropertiesValueHighlighter)

Example 5 with PropertyImpl

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

the class TrailingSpacesInPropertyInspection method checkFile.

public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
    if (!(file instanceof PropertiesFile))
        return null;
    final List<IProperty> properties = ((PropertiesFile) file).getProperties();
    final List<ProblemDescriptor> descriptors = new SmartList<>();
    for (IProperty property : properties) {
        ProgressManager.checkCanceled();
        final PropertyImpl propertyImpl = (PropertyImpl) property;
        for (ASTNode node : ContainerUtil.ar(propertyImpl.getKeyNode(), propertyImpl.getValueNode())) {
            if (node != null) {
                PsiElement key = node.getPsi();
                TextRange textRange = getTrailingSpaces(key, myIgnoreVisibleSpaces);
                if (textRange != null) {
                    descriptors.add(manager.createProblemDescriptor(key, textRange, "Trailing spaces", ProblemHighlightType.GENERIC_ERROR_OR_WARNING, true, new RemoveTrailingSpacesFix(myIgnoreVisibleSpaces)));
                }
            }
        }
    }
    return descriptors.toArray(new ProblemDescriptor[descriptors.size()]);
}
Also used : IProperty(com.intellij.lang.properties.IProperty) ASTNode(com.intellij.lang.ASTNode) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) PropertyImpl(com.intellij.lang.properties.psi.impl.PropertyImpl) TextRange(com.intellij.openapi.util.TextRange) SmartList(com.intellij.util.SmartList) PsiElement(com.intellij.psi.PsiElement)

Aggregations

PropertyImpl (com.intellij.lang.properties.psi.impl.PropertyImpl)5 ASTNode (com.intellij.lang.ASTNode)2 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)2 PropertiesCodeStyleSettings (com.intellij.lang.properties.psi.codeStyle.PropertiesCodeStyleSettings)2 PsiElement (com.intellij.psi.PsiElement)2 LineMarkerInfo (com.intellij.codeInsight.daemon.LineMarkerInfo)1 Annotation (com.intellij.lang.annotation.Annotation)1 IProperty (com.intellij.lang.properties.IProperty)1 PropertiesValueHighlighter (com.intellij.lang.properties.editor.PropertiesValueHighlighter)1 Property (com.intellij.lang.properties.psi.Property)1 PropertiesFileImpl (com.intellij.lang.properties.psi.impl.PropertiesFileImpl)1 Module (com.intellij.openapi.module.Module)1 TextRange (com.intellij.openapi.util.TextRange)1 PsiElementVisitor (com.intellij.psi.PsiElementVisitor)1 SmartList (com.intellij.util.SmartList)1 Connection (com.microsoft.azure.toolkit.intellij.connector.Connection)1 ConnectionManager (com.microsoft.azure.toolkit.intellij.connector.ConnectionManager)1 Nullable (javax.annotation.Nullable)1 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)1 Pair (org.apache.commons.lang3.tuple.Pair)1