Search in sources :

Example 1 with Connection

use of com.microsoft.azure.toolkit.intellij.connector.Connection 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)

Aggregations

LineMarkerInfo (com.intellij.codeInsight.daemon.LineMarkerInfo)1 PropertyImpl (com.intellij.lang.properties.psi.impl.PropertyImpl)1 Module (com.intellij.openapi.module.Module)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