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;
}
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);
}
Aggregations