Search in sources :

Example 76 with VirtualFile

use of com.intellij.openapi.vfs.VirtualFile in project intellij-community by JetBrains.

the class HgDeleteTest method testDeleteUnmodifiedFile.

@Test
public void testDeleteUnmodifiedFile() throws Exception {
    VirtualFile file = createFileInCommand("a.txt", "new file content");
    runHgOnProjectRepo("commit", "-m", "added file");
    deleteFileInCommand(file);
    verify(runHgOnProjectRepo("status"), HgTestOutputParser.removed("a.txt"));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Test(org.testng.annotations.Test)

Example 77 with VirtualFile

use of com.intellij.openapi.vfs.VirtualFile in project intellij-community by JetBrains.

the class HgMoveTest method testMoveUnchangedFile.

@Test
public void testMoveUnchangedFile() throws Exception {
    VirtualFile parent1 = createDirInCommand(myWorkingCopyDir, "com");
    VirtualFile file = createFileInCommand(parent1, "a.txt", "new file content");
    runHgOnProjectRepo("commit", "-m", "added file");
    VirtualFile parent2 = createDirInCommand(myWorkingCopyDir, "org");
    moveFileInCommand(file, parent2);
    verify(runHgOnProjectRepo("status"), HgTestOutputParser.added("org", "a.txt"), HgTestOutputParser.removed("com", "a.txt"));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Test(org.testng.annotations.Test)

Example 78 with VirtualFile

use of com.intellij.openapi.vfs.VirtualFile in project intellij-community by JetBrains.

the class MavenGroovyPomCompletionContributor method fillCompletionVariants.

@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
    final PsiElement position = parameters.getPosition();
    if (!(position instanceof LeafElement))
        return;
    Project project = position.getProject();
    VirtualFile virtualFile = parameters.getOriginalFile().getVirtualFile();
    if (virtualFile == null)
        return;
    MavenProject mavenProject = MavenProjectsManager.getInstance(project).findProject(virtualFile);
    if (mavenProject == null)
        return;
    List<String> methodCallInfo = MavenGroovyPomUtil.getGroovyMethodCalls(position);
    if (methodCallInfo.isEmpty())
        return;
    StringBuilder buf = new StringBuilder();
    for (String s : methodCallInfo) {
        buf.append('<').append(s).append('>');
    }
    for (String s : ContainerUtil.reverse(methodCallInfo)) {
        buf.append('<').append(s).append("/>");
    }
    PsiFile psiFile = PsiFileFactory.getInstance(project).createFileFromText("pom.xml", XMLLanguage.INSTANCE, buf);
    psiFile.putUserData(ORIGINAL_POM_FILE, virtualFile);
    List<Object> variants = ContainerUtil.newArrayList();
    String lastMethodCall = ContainerUtil.getLastItem(methodCallInfo);
    Ref<Boolean> completeDependency = Ref.create(false);
    Ref<Boolean> completeVersion = Ref.create(false);
    psiFile.accept(new PsiRecursiveElementVisitor(true) {

        @Override
        public void visitElement(PsiElement element) {
            super.visitElement(element);
            if (!completeDependency.get() && element.getParent() instanceof XmlTag && "dependency".equals(((XmlTag) element.getParent()).getName())) {
                if ("artifactId".equals(lastMethodCall) || "groupId".equals(lastMethodCall)) {
                    completeDependency.set(true);
                } else if ("version".equals(lastMethodCall) || "dependency".equals(lastMethodCall)) {
                    completeVersion.set(true);
                //completeDependency.set(true);
                }
            }
            if (!completeDependency.get() && !completeVersion.get()) {
                PsiReference[] references = getReferences(element);
                for (PsiReference each : references) {
                    if (each instanceof GenericDomValueReference) {
                        Collections.addAll(variants, each.getVariants());
                    }
                }
            }
        }
    });
    for (Object variant : variants) {
        if (variant instanceof LookupElement) {
            result.addElement((LookupElement) variant);
        } else {
            result.addElement(LookupElementBuilder.create(variant));
        }
    }
    if (completeDependency.get()) {
        MavenProjectIndicesManager indicesManager = MavenProjectIndicesManager.getInstance(project);
        for (String groupId : indicesManager.getGroupIds()) {
            for (String artifactId : indicesManager.getArtifactIds(groupId)) {
                LookupElement builder = LookupElementBuilder.create(groupId + ':' + artifactId).withIcon(AllIcons.Nodes.PpLib).withInsertHandler(MavenDependencyInsertHandler.INSTANCE);
                result.addElement(builder);
            }
        }
    }
    if (completeVersion.get()) {
        consumeDependencyElement(position, closableBlock -> {
            String groupId = null;
            String artifactId = null;
            for (GrMethodCall methodCall : PsiTreeUtil.findChildrenOfType(closableBlock, GrMethodCall.class)) {
                GroovyPsiElement[] arguments = methodCall.getArgumentList().getAllArguments();
                if (arguments.length != 1)
                    continue;
                PsiReference reference = arguments[0].getReference();
                if (reference == null)
                    continue;
                String callExpression = methodCall.getInvokedExpression().getText();
                String argumentValue = reference.getCanonicalText();
                if ("groupId".equals(callExpression)) {
                    groupId = argumentValue;
                } else if ("artifactId".equals(callExpression)) {
                    artifactId = argumentValue;
                }
            }
            completeVersions(result, project, groupId, artifactId, "");
        }, element -> {
            if (element.getParent() instanceof PsiLiteral) {
                Object value = ((PsiLiteral) element.getParent()).getValue();
                if (value == null)
                    return;
                String[] mavenCoordinates = value.toString().split(":");
                if (mavenCoordinates.length < 3)
                    return;
                String prefix = mavenCoordinates[0] + ':' + mavenCoordinates[1] + ':';
                completeVersions(result, project, mavenCoordinates[0], mavenCoordinates[1], prefix);
            }
        });
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GrMethodCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall) MavenProject(org.jetbrains.idea.maven.project.MavenProject) GenericDomValueReference(com.intellij.util.xml.impl.GenericDomValueReference) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) MavenProjectIndicesManager(org.jetbrains.idea.maven.indices.MavenProjectIndicesManager) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) LookupElement(com.intellij.codeInsight.lookup.LookupElement) Project(com.intellij.openapi.project.Project) MavenProject(org.jetbrains.idea.maven.project.MavenProject) LeafElement(com.intellij.psi.impl.source.tree.LeafElement) XmlTag(com.intellij.psi.xml.XmlTag)

Example 79 with VirtualFile

use of com.intellij.openapi.vfs.VirtualFile in project intellij-community by JetBrains.

the class SelectInMavenNavigatorTarget method getMavenProject.

private static MavenProject getMavenProject(SelectInContext context) {
    VirtualFile file = context.getVirtualFile();
    MavenProjectsManager manager = MavenProjectsManager.getInstance(context.getProject());
    Module module = ProjectRootManager.getInstance(context.getProject()).getFileIndex().getModuleForFile(file);
    return module == null ? null : manager.findProject(module);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) Module(com.intellij.openapi.module.Module)

Example 80 with VirtualFile

use of com.intellij.openapi.vfs.VirtualFile in project intellij-community by JetBrains.

the class SvnBranchConfigurationManager method getState.

public ConfigurationBean getState() {
    final ConfigurationBean result = new ConfigurationBean();
    result.myVersion = myConfigurationBean.myVersion;
    final UrlSerializationHelper helper = new UrlSerializationHelper(SvnVcs.getInstance(myProject));
    for (VirtualFile root : myBunch.getMapCopy().keySet()) {
        final String key = root.getPath();
        final SvnBranchConfigurationNew configOrig = myBunch.getConfig(root);
        final SvnBranchConfiguration configuration = new SvnBranchConfiguration(configOrig.getTrunkUrl(), configOrig.getBranchUrls(), configOrig.isUserinfoInUrl());
        result.myConfigurationMap.put(key, helper.prepareForSerialization(configuration));
    }
    result.mySupportsUserInfoFilter = true;
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile)

Aggregations

VirtualFile (com.intellij.openapi.vfs.VirtualFile)5465 File (java.io.File)762 Project (com.intellij.openapi.project.Project)720 Nullable (org.jetbrains.annotations.Nullable)720 NotNull (org.jetbrains.annotations.NotNull)703 PsiFile (com.intellij.psi.PsiFile)571 Module (com.intellij.openapi.module.Module)501 IOException (java.io.IOException)327 ArrayList (java.util.ArrayList)260 Document (com.intellij.openapi.editor.Document)244 PsiElement (com.intellij.psi.PsiElement)209 Test (org.junit.Test)196 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)124 PsiDirectory (com.intellij.psi.PsiDirectory)124 XmlFile (com.intellij.psi.xml.XmlFile)124 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)116 Editor (com.intellij.openapi.editor.Editor)115 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)101 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)91 List (java.util.List)90