Search in sources :

Example 41 with Module

use of com.intellij.openapi.module.Module in project intellij-community by JetBrains.

the class DomFileDescriptionTest method testChangeCustomDomness.

public void testChangeCustomDomness() throws Throwable {
    getDomManager().registerFileDescription(new DomFileDescription<MyElement>(MyElement.class, "xxx") {

        @Override
        public boolean isMyFile(@NotNull final XmlFile file, @Nullable final Module module) {
            return file.getText().contains("foo");
        }
    }, myDisposable);
    final XmlFile file = (XmlFile) createFile("xxx.xml", "<xxx zzz=\"foo\"><boy/><boy/><xxx/>");
    final MyElement boy = getDomManager().getFileElement(file, MyElement.class).getRootElement().getBoys().get(0);
    new WriteCommandAction(getProject()) {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            file.getDocument().getRootTag().setAttribute("zzz", "bar");
        }
    }.execute();
    assertFalse(getDomManager().isDomFile(file));
    assertFalse(boy.isValid());
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) XmlFile(com.intellij.psi.xml.XmlFile) Module(com.intellij.openapi.module.Module) Result(com.intellij.openapi.application.Result)

Example 42 with Module

use of com.intellij.openapi.module.Module in project intellij-community by JetBrains.

the class DomBasicsTest method testCopyingFromNonEmptyToEmpty.

public void testCopyingFromNonEmptyToEmpty() throws Throwable {
    Module module = new MockModule(getTestRootDisposable());
    final MyElement element1 = getDomManager().createMockElement(MyElement.class, module, false);
    final MyElement element2 = getDomManager().createMockElement(MyElement.class, module, false);
    element2.ensureTagExists();
    assertNull(element2.getChild().getChild().getGenericValue().getStringValue());
    element1.getChild().getChild().getGenericValue().setStringValue("abc");
    new WriteCommandAction(getProject()) {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            element2.copyFrom(element1);
        }
    }.execute();
    assertEquals("abc", element2.getChild().getChild().getGenericValue().getStringValue());
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) MockModule(com.intellij.mock.MockModule) MockModule(com.intellij.mock.MockModule) Module(com.intellij.openapi.module.Module) Result(com.intellij.openapi.application.Result)

Example 43 with Module

use of com.intellij.openapi.module.Module in project intellij-community by JetBrains.

the class XmlTagImpl method getImplicitNamespaceDescriptor.

@Nullable
private XmlNSDescriptor getImplicitNamespaceDescriptor(String ns) {
    PsiFile file = getContainingFile();
    if (file == null)
        return null;
    Module module = ModuleUtilCore.findModuleForPsiElement(file);
    if (module != null) {
        for (ImplicitNamespaceDescriptorProvider provider : Extensions.getExtensions(ImplicitNamespaceDescriptorProvider.EP_NAME)) {
            XmlNSDescriptor nsDescriptor = provider.getNamespaceDescriptor(module, ns, file);
            if (nsDescriptor != null)
                return nsDescriptor;
        }
    }
    return null;
}
Also used : ImplicitNamespaceDescriptorProvider(com.intellij.javaee.ImplicitNamespaceDescriptorProvider) XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) Module(com.intellij.openapi.module.Module) Nullable(org.jetbrains.annotations.Nullable)

Example 44 with Module

use of com.intellij.openapi.module.Module in project intellij-community by JetBrains.

the class AntTasksProvider method getAntObjects.

private static Map<String, Class> getAntObjects(final GroovyFile groovyFile) {
    final Project project = groovyFile.getProject();
    final Module module = ModuleUtilCore.findModuleForPsiElement(groovyFile);
    Set<VirtualFile> jars = new HashSet<>();
    if (module != null) {
        ContainerUtil.addAll(jars, OrderEnumerator.orderEntries(module).getAllLibrariesAndSdkClassesRoots());
    }
    if (groovyFile.isScript() && GroovyScriptUtil.getScriptType(groovyFile) instanceof GantScriptType) {
        jars.addAll(GantScriptType.additionalScopeFiles(groovyFile));
    }
    final ArrayList<URL> urls = new ArrayList<>();
    for (VirtualFile jar : jars) {
        VirtualFile localFile = PathUtil.getLocalFile(jar);
        if (localFile.getFileSystem() instanceof LocalFileSystem) {
            urls.add(VfsUtilCore.convertToURL(localFile.getUrl()));
        }
    }
    AntClassLoader loader;
    synchronized (ourLock) {
        final Map<List<URL>, AntClassLoader> map = CachedValuesManager.getManager(project).getParameterizedCachedValue(project, KEY, PROVIDER, false, project);
        loader = map.get(urls);
        if (loader == null) {
            map.put(urls, loader = new AntClassLoader(urls));
        }
    }
    return loader.getAntObjects();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) URL(java.net.URL) Project(com.intellij.openapi.project.Project) ReflectedProject(com.intellij.lang.ant.ReflectedProject) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) Module(com.intellij.openapi.module.Module)

Example 45 with Module

use of com.intellij.openapi.module.Module in project intellij-community by JetBrains.

the class GantScriptType method additionalScopeFiles.

public static List<VirtualFile> additionalScopeFiles(@NotNull GroovyFile file) {
    final Module module = ModuleUtilCore.findModuleForPsiElement(file);
    if (module != null) {
        final String sdkHome = GantUtils.getSdkHomeFromClasspath(module);
        if (sdkHome != null) {
            return Collections.emptyList();
        }
    }
    final GantSettings gantSettings = GantSettings.getInstance(file.getProject());
    final VirtualFile home = gantSettings.getSdkHome();
    if (home == null) {
        return Collections.emptyList();
    }
    return gantSettings.getClassRoots();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Module(com.intellij.openapi.module.Module)

Aggregations

Module (com.intellij.openapi.module.Module)1911 VirtualFile (com.intellij.openapi.vfs.VirtualFile)585 Project (com.intellij.openapi.project.Project)381 NotNull (org.jetbrains.annotations.NotNull)331 Nullable (org.jetbrains.annotations.Nullable)268 File (java.io.File)185 PsiFile (com.intellij.psi.PsiFile)147 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)134 ArrayList (java.util.ArrayList)118 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)112 Sdk (com.intellij.openapi.projectRoots.Sdk)95 PsiElement (com.intellij.psi.PsiElement)89 PsiDirectory (com.intellij.psi.PsiDirectory)77 ModuleManager (com.intellij.openapi.module.ModuleManager)65 PsiClass (com.intellij.psi.PsiClass)65 IOException (java.io.IOException)61 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)57 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)57 List (java.util.List)57 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)51