public DomFileEditor(final DomElement element, final String name, final T component) {
   this(
       element.getManager().getProject(),
       DomUtil.getFile(element).getVirtualFile(),
       name,
       component);
 }
  /**
   * Gets the current namespace for the given element.
   *
   * @param psiElement Current element.
   * @return {@code null} on XML errors or if {@link #matchesResultType(String)} returns {@code
   *     false}.
   */
  @Nullable
  protected final String getNamespace(@NotNull final PsiElement psiElement) {
    final DomElement resultElement = DomUtil.getDomElement(psiElement);
    if (resultElement == null) {
      return null; // XML syntax error
    }

    assert resultElement instanceof HasResultType
        : "not instance of HasResultType: " + resultElement + ", text: " + psiElement.getText();

    final ResultType effectiveResultType = ((HasResultType) resultElement).getEffectiveResultType();
    if (effectiveResultType == null) {
      return null;
    }

    final String resultType = effectiveResultType.getName().getStringValue();
    if (resultType == null || !matchesResultType(resultType)) {
      return null;
    }

    final StrutsPackage strutsPackage = resultElement.getParentOfType(StrutsPackage.class, true);
    if (strutsPackage == null) {
      return null; // XML syntax error
    }

    return strutsPackage.searchNamespace();
  }
 @Override
 public boolean isAvailableForElement(@NotNull DomElement el) {
   DomElement root = DomUtil.getFileElement(el).getRootElement();
   return root.getModule() != null
       && root instanceof MavenDomProjectModel
       && isAvailableForModel((MavenDomProjectModel) root);
 }
  public static DomFileEditor createDomFileEditor(
      final String name,
      @Nullable final Icon icon,
      final DomElement element,
      final Factory<? extends CommittablePanel> committablePanel) {

    final XmlFile file = DomUtil.getFile(element);
    final Factory<BasicDomElementComponent> factory =
        new Factory<BasicDomElementComponent>() {
          @Override
          public BasicDomElementComponent create() {

            CaptionComponent captionComponent = new CaptionComponent(name, icon);
            captionComponent.initErrorPanel(element);
            BasicDomElementComponent component =
                createComponentWithCaption(committablePanel.create(), captionComponent, element);
            Disposer.register(component, captionComponent);
            return component;
          }
        };
    return new DomFileEditor<BasicDomElementComponent>(
        file.getProject(), file.getVirtualFile(), name, factory) {
      @Override
      public JComponent getPreferredFocusedComponent() {
        return null;
      }
    };
  }
 @Override
 public Module getModule() {
   final DomFileElement<DomElement> fileElement = DomUtil.getFileElement(getInvocationElement());
   if (fileElement == null) {
     final XmlElement xmlElement = getInvocationElement().getXmlElement();
     return xmlElement == null ? null : ModuleUtilCore.findModuleForPsiElement(xmlElement);
   }
   return fileElement.isValid() ? fileElement.getRootElement().getModule() : null;
 }
        private void highlightNotUsedAnymore(
            GenericAttributeValue attributeValue, DomElementAnnotationHolder holder) {
          if (!DomUtil.hasXml(attributeValue)) {
            return;
          }

          final Annotation annotation =
              holder.createAnnotation(
                  attributeValue, HighlightSeverity.WARNING, "Not used anymore");
          annotation.setHighlightType(ProblemHighlightType.LIKE_DEPRECATED);
        }
 @Nullable
 private AntDomMacroDef getParentMacrodef() {
   final PsiElement element = getElement();
   if (element == null) {
     return null;
   }
   final DomElement domElement = DomUtil.getDomElement(element);
   if (domElement == null) {
     return null;
   }
   return domElement.getParentOfType(AntDomMacroDef.class, false);
 }
 @Override
 protected void wrapValueSetting(
     @NotNull final DomElement domElement, final Runnable valueSetter) {
   if (domElement.isValid()) {
     new WriteCommandAction(getProject(), DomUtil.getFile(domElement)) {
       @Override
       protected void run(@NotNull final Result result) throws Throwable {
         valueSetter.run();
       }
     }.execute();
     fireChanged();
   }
 }
  public static void addTypeAndClassifierAndVersion(
      @NotNull InsertionContext context,
      @NotNull MavenDomDependency dependency,
      @NotNull String groupId,
      @NotNull String artifactId) {
    if (!StringUtil.isEmpty(dependency.getVersion().getStringValue())) return;

    Project project = context.getProject();

    if (!isInsideManagedDependency(dependency)) {
      MavenDomProjectModel model =
          DomUtil.<MavenDomProjectModel>getFileElement(dependency).getRootElement();
      MavenDomDependency managedDependency =
          findManagedDependency(model, project, groupId, artifactId);
      if (managedDependency != null) {
        if (dependency.getClassifier().getXmlTag() == null
            && dependency.getType().getXmlTag() == null) {
          String classifier = managedDependency.getClassifier().getRawText();
          if (StringUtil.isNotEmpty(classifier)) {
            dependency.getClassifier().setStringValue(classifier);
          }
          String type = managedDependency.getType().getRawText();
          if (StringUtil.isNotEmpty(type)) {
            dependency.getType().setStringValue(type);
          }
        }
        return;
      }
    }

    MavenProjectIndicesManager manager = MavenProjectIndicesManager.getInstance(project);

    Set<String> versions = manager.getVersions(groupId, artifactId);
    if (versions.size() == 1) {
      dependency.getVersion().setStringValue(ContainerUtil.getFirstItem(versions));
      return;
    }

    dependency.getVersion().setStringValue("");

    int versionPosition =
        dependency.getVersion().getXmlTag().getValue().getTextRange().getStartOffset();

    context.getEditor().getCaretModel().moveToOffset(versionPosition);

    if (versions.size() > 0) {
      invokeCompletion(context, CompletionType.BASIC);
    }
  }
  @Nullable
  public static MavenDomProjectModel findParent(
      @NotNull MavenDomParent mavenDomParent, Project project) {
    if (!DomUtil.hasXml(mavenDomParent)) return null;

    MavenId id =
        new MavenId(
            mavenDomParent.getGroupId().getStringValue(),
            mavenDomParent.getArtifactId().getStringValue(),
            mavenDomParent.getVersion().getStringValue());
    MavenProject mavenProject = MavenProjectsManager.getInstance(project).findProject(id);

    return mavenProject != null
        ? MavenDomUtil.getMavenDomProjectModel(project, mavenProject.getFile())
        : null;
  }
    @Nullable
    public T process(@NotNull MavenDomProjectModel projectDom) {
      MavenDomParent parent = projectDom.getMavenParent();
      MavenParentDesc parentDesc = null;
      if (DomUtil.hasXml(parent)) {
        String parentGroupId = parent.getGroupId().getStringValue();
        String parentArtifactId = parent.getArtifactId().getStringValue();
        String parentVersion = parent.getVersion().getStringValue();
        String parentRelativePath = parent.getRelativePath().getStringValue();
        if (StringUtil.isEmptyOrSpaces(parentRelativePath)) parentRelativePath = "../pom.xml";
        MavenId parentId = new MavenId(parentGroupId, parentArtifactId, parentVersion);
        parentDesc = new MavenParentDesc(parentId, parentRelativePath);
      }

      return process(
          myManager.getGeneralSettings(), MavenDomUtil.getVirtualFile(projectDom), parentDesc);
    }
        private void annotateExtension(Extension extension, DomElementAnnotationHolder holder) {
          final ExtensionPoint extensionPoint = extension.getExtensionPoint();
          if (extensionPoint == null) {
            return;
          }
          final GenericAttributeValue<PsiClass> interfaceAttribute = extensionPoint.getInterface();
          if (!DomUtil.hasXml(interfaceAttribute)) {
            return;
          }

          final PsiClass value = interfaceAttribute.getValue();
          if (value != null && value.isDeprecated()) {
            final Annotation annotation =
                holder.createAnnotation(extension, HighlightSeverity.WARNING, "Deprecated EP");
            annotation.setHighlightType(ProblemHighlightType.LIKE_DEPRECATED);
          }
        }
  public DomElementsToggleAction(final DomModelTreeView treeView, final Class aClass) {
    myTreeView = treeView;
    myClass = aClass;

    Icon myIcon = ElementPresentationManager.getIcon(myClass);
    if (myIcon == null) {
      myIcon = AllIcons.Nodes.Pointcut;
    }
    this.myIcon = myIcon;

    myText = TypePresentationService.getService().getTypePresentableName(myClass);

    if (getHiders() == null)
      DomUtil.getFile(myTreeView.getRootElement())
          .putUserData(AbstractDomElementNode.TREE_NODES_HIDERS_KEY, new HashMap<>());

    if (getHiders().get(myClass) == null) getHiders().put(myClass, true);
  }
  public static MavenDomParent updateMavenParent(
      MavenDomProjectModel mavenModel, MavenProject parentProject) {
    MavenDomParent result = mavenModel.getMavenParent();

    VirtualFile pomFile = DomUtil.getFile(mavenModel).getVirtualFile();
    Project project = mavenModel.getXmlElement().getProject();

    MavenId parentId = parentProject.getMavenId();
    result.getGroupId().setStringValue(parentId.getGroupId());
    result.getArtifactId().setStringValue(parentId.getArtifactId());
    result.getVersion().setStringValue(parentId.getVersion());

    if (!Comparing.equal(pomFile.getParent().getParent(), parentProject.getDirectoryFile())) {
      result
          .getRelativePath()
          .setValue(PsiManager.getInstance(project).findFile(parentProject.getFile()));
    }

    return result;
  }
 public PsiElement resolve(PsiReference psiReference, boolean incompleteCode) {
   final PsiElement element = psiReference.getElement();
   if (element == null) {
     return null;
   }
   final DomElement domElement = DomUtil.getDomElement(element);
   if (domElement == null) {
     return null;
   }
   final AntDomMacroDef macrodef = domElement.getParentOfType(AntDomMacroDef.class, false);
   if (macrodef == null) {
     return null;
   }
   final String name =
       AntStringResolver.computeString(domElement, psiReference.getCanonicalText());
   for (AntDomMacrodefAttribute attribute : macrodef.getMacroAttributes()) {
     if (name.equals(attribute.getName().getStringValue())) {
       final DomTarget target = DomTarget.getTarget(attribute);
       return target != null ? PomService.convertToPsi(target) : null;
     }
   }
   return null;
 }
  public DomElementsErrorPanel(final DomElement... domElements) {
    assert domElements.length > 0;

    myDomElements = domElements;
    final DomManager domManager = domElements[0].getManager();
    myProject = domManager.getProject();
    myAnnotationsManager =
        (DomElementAnnotationsManagerImpl) DomElementAnnotationsManager.getInstance(myProject);

    setPreferredSize(getDimension());

    myErrorStripeRenderer = new DomElementsTrafficLightRenderer(DomUtil.getFile(domElements[0]));
    Disposer.register(this, myErrorStripeRenderer);

    addUpdateRequest();
    domManager.addDomEventListener(
        new DomChangeAdapter() {
          protected void elementChanged(DomElement element) {
            addUpdateRequest();
          }
        },
        this);
  }
 public static boolean isMavenProperty(PsiElement target) {
   XmlTag tag = PsiTreeUtil.getParentOfType(target, XmlTag.class, false);
   if (tag == null) return false;
   return DomUtil.findDomElement(tag, MavenDomProperties.class) != null;
 }
 public final boolean isMockElement(DomElement element) {
   return DomUtil.getFile(element).getUserData(MOCK) != null;
 }
 @NotNull
 public final DomElement getResolvingScope(GenericDomValue element) {
   final DomFileDescription description = DomUtil.getFileElement(element).getFileDescription();
   return description.getResolveScope(element);
 }
 @Override
 @NotNull
 public final XmlFile getFile() {
   return DomUtil.getFile(getInvocationElement());
 }
 @Nullable
 public final DomElement getIdentityScope(DomElement element) {
   final DomFileDescription description = DomUtil.getFileElement(element).getFileDescription();
   return description.getIdentityScope(element);
 }
 private Map<Class, Boolean> getHiders() {
   return DomUtil.getFile(myTreeView.getRootElement())
       .getUserData(BaseDomElementNode.TREE_NODES_HIDERS_KEY);
 }
 protected boolean isRightFile(final VirtualFile file) {
   return myRootElement == null
       || (myRootElement.isValid()
           && file.equals(DomUtil.getFile(myRootElement).getVirtualFile()));
 }
 protected DomElement getParentDomElement(Project project, Editor editor, PsiFile file) {
   DomElement el = DomUtil.getContextElement(editor);
   return DomUtil.getFileElement(el).getRootElement();
 }
 @Nullable
 public static VirtualFile getVirtualFile(@NotNull DomElement element) {
   PsiFile psiFile = DomUtil.getFile(element);
   return getVirtualFile(psiFile);
 }
  // See
  // org.apache.maven.project.interpolation.AbstractStringBasedModelInterpolator.createValueSources()
  @Nullable
  protected PsiElement doResolve() {
    boolean hasPrefix = false;
    String unprefixed = myText;

    if (myText.startsWith("pom.")) {
      unprefixed = myText.substring("pom.".length());
      hasPrefix = true;
    } else if (myText.startsWith("project.")) {
      unprefixed = myText.substring("project.".length());
      hasPrefix = true;
    }

    MavenProject mavenProject = myMavenProject;

    while (unprefixed.startsWith("parent.")) {
      if (unprefixed.equals("parent.groupId")
          || unprefixed.equals("parent.artifactId")
          || unprefixed.equals("parent.version")
          || unprefixed.equals("parent.relativePath")) {
        break;
      }

      MavenId parentId = mavenProject.getParentId();
      if (parentId == null) return null;

      mavenProject = myProjectsManager.findProject(parentId);
      if (mavenProject == null) return null;

      unprefixed = unprefixed.substring("parent.".length());
    }

    if (unprefixed.equals("basedir")
        || (hasPrefix && mavenProject == myMavenProject && unprefixed.equals("baseUri"))) {
      return getBaseDir(mavenProject);
    }

    if (myText.equals(TIMESTAMP_PROP)) {
      return myElement;
    }

    if (hasPrefix) {
      MavenDomProjectModel domProjectModel =
          MavenDomUtil.getMavenDomProjectModel(myProject, mavenProject.getFile());
      if (domProjectModel != null) {
        PsiElement res =
            resolveModelProperty(domProjectModel, unprefixed, new HashSet<DomElement>());
        if (res != null) {
          return res;
        }
      }
    }

    // todo resolve properties from config.
    MavenRunnerSettings runnerSettings = MavenRunner.getInstance(myProject).getSettings();
    if (runnerSettings.getMavenProperties().containsKey(myText)
        || runnerSettings.getVmOptions().contains("-D" + myText + '=')) {
      return myElement;
    }
    if (MavenUtil.getPropertiesFromMavenOpts().containsKey(myText)) {
      return myElement;
    }

    MavenDomProfile profile = DomUtil.findDomElement(myElement, MavenDomProfile.class);
    if (profile != null) {
      PsiElement result =
          MavenDomProjectProcessorUtils.findProperty(profile.getProperties(), myText);
      if (result != null) return result;
    }

    if (myProjectDom != null) {
      PsiElement result =
          MavenDomProjectProcessorUtils.searchProperty(myText, myProjectDom, myProject);
      if (result != null) return result;
    }

    MavenPropertiesVirtualFileSystem mavenPropertiesVirtualFileSystem =
        MavenPropertiesVirtualFileSystem.getInstance();

    IProperty property = mavenPropertiesVirtualFileSystem.findSystemProperty(myProject, myText);
    if (property != null) return property.getPsiElement();

    if (myText.startsWith("env.")) {
      property =
          mavenPropertiesVirtualFileSystem.findEnvProperty(
              myProject, myText.substring("env.".length()));
      if (property != null) return property.getPsiElement();
    }

    String textWithEnv = "env." + myText;

    property = mavenPropertiesVirtualFileSystem.findSystemProperty(myProject, textWithEnv);
    if (property != null) return property.getPsiElement();

    property = mavenPropertiesVirtualFileSystem.findEnvProperty(myProject, textWithEnv);
    if (property != null) return property.getPsiElement();

    if (!hasPrefix) {
      MavenDomProjectModel domProjectModel =
          MavenDomUtil.getMavenDomProjectModel(myProject, mavenProject.getFile());
      if (domProjectModel != null) {
        PsiElement res =
            resolveModelProperty(domProjectModel, unprefixed, new HashSet<DomElement>());
        if (res != null) {
          return res;
        }
      }
    }

    if (myText.startsWith("settings.")) {
      return resolveSettingsModelProperty();
    }

    return null;
  }