/*
 * Copyright (c) 2000-2006 JetBrains s.r.o. All Rights Reserved.
 */
package com.intellij.util.xml;

import com.intellij.openapi.module.Module;
import com.intellij.psi.PsiClass;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.xml.XmlFile;
import com.intellij.psi.xml.XmlTag;
import org.jetbrains.annotations.NotNull;

/**
 * @author peter
 */
public abstract class AbstractConvertContext extends ConvertContext {

  public final PsiClass findClass(String name) {
    if (name == null) return null;
    final XmlFile file = getFile();
    if (name.indexOf('$')>=0) name = name.replace('$', '.');

    final Module module = getModule();
    final PsiClass aClass;
    if (module != null) {
      aClass = file.getManager().findClass(name, GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module));
    }
    else {
      aClass = file.getManager().findClass(name, file.getResolveScope());
    }
    if (aClass != null) {
      assert aClass.isValid() : name;
    }
    return aClass;
  }

  public final XmlTag getTag() {
    return getInvocationElement().getXmlTag();
  }

  @NotNull
  public final XmlFile getFile() {
    return getInvocationElement().getRoot().getFile();
  }

  public Module getModule() {
    return getInvocationElement().getModule();
  }
}

@@ -136,24 +136,69 @@
 ule.Module;%0A
+import com.intellij.openapi.vfs.VirtualFile;%0A
 import com.i
@@ -342,16 +342,56 @@
 XmlTag;%0A
+import com.intellij.psi.xml.XmlElement;%0A
 import o
@@ -777,53 +777,816 @@
     
-if (module != null) %7B%0A      aClass = file.get
+final XmlElement element = getInvocationElement().getXmlElement();%0A    if (module == null && element != null && getPsiManager().isInProject(element)) %7B%0A      final GlobalSearchScope baseScope = GlobalSearchScope.allScope(getPsiManager().getProject());%0A      aClass = getPsiManager().findClass(name, new GlobalSearchScope() %7B%0A%0A        public boolean contains(VirtualFile file) %7B%0A          return baseScope.contains(file);%0A        %7D%0A%0A        public int compare(VirtualFile file1, VirtualFile file2) %7B%0A          return baseScope.compare(file1, file2);%0A        %7D%0A%0A        public boolean isSearchInModuleContent(Module aModule) %7B%0A          return false;%0A        %7D%0A%0A        public boolean isSearchInLibraries() %7B%0A          return true;%0A        %7D%0A      %7D);%0A    %7D%0A    else if (module != null) %7B%0A      aClass = getPsi
 Mana
@@ -1707,24 +1707,22 @@
 Class = 
-file.
 get
+Psi
 Manager(

support units in libraries