Search in sources :

Example 61 with Location

use of com.intellij.execution.Location in project intellij-plugins by JetBrains.

the class CfmlRunConfigurationProducer method setupConfigurationFromContext.

@Override
protected boolean setupConfigurationFromContext(CfmlRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    final Location location = context.getLocation();
    if (!(location instanceof PsiLocation))
        return false;
    final VirtualFile file;
    PsiElement element = location.getPsiElement();
    final PsiFile containingFile = element.getContainingFile();
    if (isValid(containingFile)) {
        file = containingFile.getVirtualFile();
        sourceElement.set(containingFile);
    } else {
        return false;
    }
    if (!FileTypeManager.getInstance().isFileOfType(file, ScratchFileType.INSTANCE)) {
        final VirtualFile root = ProjectRootManager.getInstance(element.getProject()).getFileIndex().getContentRootForFile(file);
        if (root == null)
            return false;
    }
    if (configuration == null) {
        return false;
    }
    CfmlRunnerParameters params = configuration.getRunnerParameters();
    String urlStr = configuration.getRunnerParameters().getUrl();
    String serverUrl;
    if (!urlStr.isEmpty()) {
        //generated from default run configuration
        try {
            URL url = new URL(urlStr);
            serverUrl = url.getProtocol() + "://" + url.getAuthority();
        } catch (MalformedURLException e) {
            LOG.error(CfmlBundle.message("cfml.producer.error.url", urlStr));
            return false;
        }
    } else {
        // if default configuration is not defined
        serverUrl = DEFAULT_HOST;
        configuration.setFromDefaultHost(true);
    }
    String path = buildPageUrl(context, file);
    //check that serverUrl ends with '/' and fix it if neccessary
    if (StringUtil.endsWith(serverUrl, "/") && !StringUtil.startsWith(path, "/")) {
        params.setUrl(serverUrl + path);
    } else if (!StringUtil.endsWith(serverUrl, "/") && !StringUtil.startsWith(path, "/")) {
        params.setUrl(serverUrl + "/" + path);
    } else if (!StringUtil.endsWith(serverUrl, "/") && StringUtil.startsWith(path, "/")) {
        params.setUrl(serverUrl + path);
    } else if (StringUtil.endsWith(serverUrl, "/") && StringUtil.startsWith(path, "/")) {
        params.setUrl(serverUrl + path.substring(1, path.length()));
    }
    configuration.setName(generateName(containingFile));
    return true;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MalformedURLException(java.net.MalformedURLException) PsiLocation(com.intellij.execution.PsiLocation) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) URL(java.net.URL) PsiLocation(com.intellij.execution.PsiLocation) Location(com.intellij.execution.Location)

Example 62 with Location

use of com.intellij.execution.Location in project intellij-plugins by JetBrains.

the class DartTestLocationProviderTest method doTest.

private void doTest(@NotNull final String locationHint, @NotNull final String fileContents) {
    final int caretOffset = fileContents.indexOf("<caret>");
    assertTrue(caretOffset != -1);
    final String realContents = fileContents.substring(0, caretOffset) + fileContents.substring(caretOffset + "<caret>".length());
    myFixture.configureByText("test.dart", realContents);
    final PsiFile file = myFixture.getFile();
    final PsiElement elementAtOffset = file.findElementAt(caretOffset);
    final PsiElement targetId = elementAtOffset == null ? null : elementAtOffset.getParent();
    final List<Location> locations = DartTestLocationProvider.INSTANCE.getLocationForTest(file, locationHint);
    assertEquals(1, locations.size());
    final Location location = locations.get(0);
    final PsiElement element = location.getPsiElement();
    final DartId foundId = PsiTreeUtil.findChildOfType(element, DartId.class);
    assertEquals(targetId, foundId);
}
Also used : PsiFile(com.intellij.psi.PsiFile) DartId(com.jetbrains.lang.dart.psi.DartId) PsiElement(com.intellij.psi.PsiElement) Location(com.intellij.execution.Location)

Aggregations

Location (com.intellij.execution.Location)62 PsiElement (com.intellij.psi.PsiElement)20 PsiClass (com.intellij.psi.PsiClass)19 VirtualFile (com.intellij.openapi.vfs.VirtualFile)18 PsiMemberParameterizedLocation (com.intellij.execution.junit2.PsiMemberParameterizedLocation)17 PsiLocation (com.intellij.execution.PsiLocation)16 MethodLocation (com.intellij.execution.junit2.info.MethodLocation)16 Project (com.intellij.openapi.project.Project)15 Module (com.intellij.openapi.module.Module)13 PsiMethod (com.intellij.psi.PsiMethod)11 PsiFile (com.intellij.psi.PsiFile)8 Nullable (org.jetbrains.annotations.Nullable)8 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)7 SMTestProxy (com.intellij.execution.testframework.sm.runner.SMTestProxy)6 ArrayList (java.util.ArrayList)6 NotNull (org.jetbrains.annotations.NotNull)6 PatternConfigurationProducer (com.intellij.execution.junit.PatternConfigurationProducer)5 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)3 AbstractTestProxy (com.intellij.execution.testframework.AbstractTestProxy)3 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)3