// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.idea.devkit.dom.impl;

import com.intellij.openapi.util.NullableLazyValue;
import com.intellij.openapi.util.VolatileNullableLazyValue;
import com.intellij.util.xml.DomUtil;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.devkit.dom.IdeaPlugin;

/**
 * @author S. Weinreuter
 */
public abstract class IdeaPluginImpl implements IdeaPlugin {

  private final NullableLazyValue<String> myPluginId = new VolatileNullableLazyValue<String>() {
    @Nullable
    @Override
    protected String compute() {
      String pluginId = null;
      if (DomUtil.hasXml(getId())) {
        pluginId = getId().getStringValue();
      }
      else if (DomUtil.hasXml(getName())) {
        pluginId = getName().getStringValue();
      }
      return pluginId != null ? pluginId.trim() : null;
    }
  };

  @Override
  public String getPluginId() {
    return myPluginId.getValue();
  }
}

@@ -283,32 +283,72 @@
 lableLazyValue;%0A
+import com.intellij.psi.xml.XmlElement;%0A
 import com.intel
@@ -1083,11 +1083,224 @@
 e();%0A  %7D
+%0A%0A  @Override%0A  public String toString() %7B%0A    XmlElement xml = getXmlElement();%0A    if (xml != null) %7B%0A      return xml.getContainingFile().getViewProvider().getVirtualFile().getPath();%0A    %7D%0A    return null;%0A  %7D
 %0A%7D%0A

add IdeaPlugin.toString to make debugging easier