/*
 * Copyright 2016 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.gradle.api.tasks.diagnostics.internal.graph.nodes;

import com.google.common.base.Joiner;
import com.google.common.collect.Sets;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.Dependency;
import org.gradle.api.artifacts.DependencySet;
import org.gradle.api.artifacts.ProjectDependency;

import javax.annotation.Nullable;
import java.util.Collections;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class UnresolvableConfigurationResult extends AbstractRenderableDependency {

    public static UnresolvableConfigurationResult of(Configuration configuration) {
        return new UnresolvableConfigurationResult(
            configuration.getClass().getName() + configuration.hashCode(),
            configuration.getName(),
            configuration.getDescription(),
            unresolvableChildren(configuration)
        );
    }

    private static Set<? extends RenderableDependency> unresolvableChildren(Configuration configuration) {
        final DependencySet dependencies = configuration.getDependencies();
        if (dependencies.isEmpty()) {
            return Collections.emptySet();
        }
        Set<UnresolvableRenderableDependency> children = Sets.newLinkedHashSet();
        for (final Dependency dependency : dependencies) {
            children.add(new UnresolvableRenderableDependency(
                dependency.getClass().getName() + dependency.hashCode(),
                (dependency instanceof ProjectDependency)
                    ? projectDependencyLabel((ProjectDependency) dependency)
                    : moduleDependencyLabel(dependency)
            ));
        }
        return children;
    }

    private static String projectDependencyLabel(ProjectDependency dependency) {
        return "project " + dependency.getName();
    }

    private static String moduleDependencyLabel(Dependency dependency) {
        return Joiner.on(":").join(
            Stream.of(dependency.getGroup(), dependency.getName(), dependency.getVersion())
                .filter(Objects::nonNull)
                .collect(Collectors.toList())
        );
    }

    private final Object id;
    private final String name;
    @Nullable
    private final String description;
    private final Set<? extends RenderableDependency> children;

    private UnresolvableConfigurationResult(
        Object id,
        String name,
        @Nullable String description,
        Set<? extends RenderableDependency> children
    ) {
        this.id = id;
        this.name = name;
        this.description = description;
        this.children = children;
    }

    @Override
    public Object getId() {
        return id;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public String getDescription() {
        return description + "(n)";
    }

    @Override
    public ResolutionState getResolutionState() {
        return ResolutionState.UNRESOLVED;
    }

    @Override
    public Set<? extends RenderableDependency> getChildren() {
        return children;
    }

    private static final class UnresolvableRenderableDependency extends AbstractRenderableDependency {

        private final Object id;
        private final String name;

        public UnresolvableRenderableDependency(Object id, String name) {
            this.id = id;
            this.name = name;
        }

        @Override
        public Object getId() {
            return id;
        }

        @Override
        public String getName() {
            return name;
        }
    }
}

@@ -944,42 +944,8 @@
 y;%0A%0A
-import javax.annotation.Nullable;%0A
 impo
@@ -1424,52 +1424,8 @@
 (),%0A
-            configuration.getDescription(),%0A
     
@@ -2795,60 +2795,8 @@
 me;%0A
-    @Nullable%0A    private final String description;%0A
     
@@ -2855,16 +2855,16 @@
 ildren;%0A
+
 %0A    pri
@@ -2945,46 +2945,8 @@
 me,%0A
-        @Nullable String description,%0A
     
@@ -3054,48 +3054,8 @@
 me;%0A
-        this.description = description;%0A
     
@@ -3195,32 +3195,32 @@
 ing getName() %7B%0A
+
         return n
@@ -3235,102 +3235,8 @@
  %7D%0A%0A
-    @Override%0A    public String getDescription() %7B%0A        return description + %22(n)%22;%0A    %7D%0A%0A
     

Remove useless override in UnresolvableConfigurationResult