当前位置: 首页>>代码示例>>Java>>正文


Java Location.getPsiElement方法代码示例

本文整理汇总了Java中com.intellij.execution.Location.getPsiElement方法的典型用法代码示例。如果您正苦于以下问题:Java Location.getPsiElement方法的具体用法?Java Location.getPsiElement怎么用?Java Location.getPsiElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.execution.Location的用法示例。


在下文中一共展示了Location.getPsiElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: update

import com.intellij.execution.Location; //导入方法依赖的package包/类
@Override
public void update(AnActionEvent e) {
  final Presentation presentation = e.getPresentation();
  presentation.setVisible(false);
  final DataContext dataContext = e.getDataContext();
  final Project project = CommonDataKeys.PROJECT.getData(dataContext);
  if (project != null) {
    final RunConfiguration configuration = RunConfiguration.DATA_KEY.getData(dataContext);
    if (isPatternBasedConfiguration(configuration)) {
      final AbstractTestProxy testProxy = AbstractTestProxy.DATA_KEY.getData(dataContext);
      if (testProxy != null) {
        final Location location = testProxy.getLocation(project, ((T)configuration).getConfigurationModule().getSearchScope());
        if (location != null) {
          final PsiElement psiElement = location.getPsiElement();
          if (psiElement instanceof PsiClass && getPattern((T)configuration).contains(((PsiClass)psiElement).getQualifiedName())) {
            presentation.setVisible(true);
          }
        }
      }
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:AbstractExcludeFromRunAction.java

示例2: getPosition

import com.intellij.execution.Location; //导入方法依赖的package包/类
private static Pair<String, String> getPosition(Location location) {
  final PsiElement psiElement = location.getPsiElement();
  final PsiMethod psiMethod = PsiTreeUtil.getParentOfType(psiElement, PsiMethod.class);
  if (psiMethod != null) {
    final PsiClass containingClass = psiMethod.getContainingClass();
    if (containingClass != null) {
      final TestFramework testFramework = TestFrameworks.detectFramework(containingClass);
      if (testFramework != null) {
        return null;
      }
      final String qualifiedName = containingClass.getQualifiedName();
      if (qualifiedName != null) {
        return Pair.create(qualifiedName, psiMethod.getName());
      }
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:TestDiscoveryConfigurationProducer.java

示例3: getData

import com.intellij.execution.Location; //导入方法依赖的package包/类
@Nullable
public static Object getData(final AbstractTestProxy testProxy, final String dataId, final TestFrameworkRunningModel model) {
  final TestConsoleProperties properties = model.getProperties();
  final Project project = properties.getProject();
  if (testProxy == null) return null;
  if (AbstractTestProxy.DATA_KEY.is(dataId)) return testProxy;
  if (CommonDataKeys.NAVIGATABLE.is(dataId)) return getOpenFileDescriptor(testProxy, model);
  if (CommonDataKeys.PSI_ELEMENT.is(dataId)) {
    final Location location = testProxy.getLocation(project, properties.getScope());
    if (location != null) {
      final PsiElement element = location.getPsiElement();
      return element.isValid() ? element : null;
    }
    else {
      return null;
    }
  }
  if (Location.DATA_KEY.is(dataId)) return testProxy.getLocation(project, properties.getScope());
  if (RunConfiguration.DATA_KEY.is(dataId)) {
    final RunProfile configuration = properties.getConfiguration();
    if (configuration instanceof RunConfiguration) {
      return configuration;
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:TestsUIUtil.java

示例4: findExistingByElement

import com.intellij.execution.Location; //导入方法依赖的package包/类
@Nullable
@Override
protected RunnerAndConfigurationSettings findExistingByElement(Location location,
                                                               @NotNull List<RunnerAndConfigurationSettings> existingConfigurations,
                                                               ConfigurationContext context) {
  PsiElement element = location.getPsiElement();
  if (!(element instanceof PsiDirectory)) return null;
  final VirtualFile vFile = ((PsiDirectory)element).getVirtualFile();
  String path = vFile.getPath();
  for (RunnerAndConfigurationSettings configuration : existingConfigurations) {
    final String scriptName = ((RestRunConfiguration)configuration.getConfiguration()).getInputFile();
    if (FileUtil.toSystemIndependentName(scriptName).equals(FileUtil.toSystemIndependentName(path))) {
      return configuration;
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:SphinxConfigurationProducer.java

示例5: testInnerClass

import com.intellij.execution.Location; //导入方法依赖的package包/类
public void testInnerClass() throws Exception {
  myFixture.addClass("public class TestClass {\n" +
                     "    public static class Tests extends junit.framework.TestCase {\n" +
                     "        public void testFoo() throws Exception {}\n" +
                     "    }\n" +
                     "}");

  final SMTestProxy testProxy = new SMTestProxy("testFoo", false, "java:test://TestClass$Tests.testFoo");
  final Project project = getProject();
  final GlobalSearchScope searchScope = GlobalSearchScope.projectScope(project);
  testProxy.setLocator(JavaTestLocator.INSTANCE);
  Location location = testProxy.getLocation(project, searchScope);
  assertNotNull(location);
  PsiElement element = location.getPsiElement();
  assertTrue(element instanceof PsiMethod);
  String name = ((PsiMethod)element).getName();
  assertEquals(name, "testFoo");
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:JUnitRerunFailedTestsTest.java

示例6: getIndirectlySelectedMethod

import com.intellij.execution.Location; //导入方法依赖的package包/类
/**
 * Get a test method which is considered selected in the given context, belonging to a
 * non-abstract class. The context location may be the method itself, or anywhere inside the
 * method.
 *
 * @param context The context to search for a test method in.
 * @return A test method, or null if none are found.
 */
@Nullable
public static PsiMethod getIndirectlySelectedMethod(@NotNull ConfigurationContext context) {
  final Location<?> contextLocation = context.getLocation();
  if (contextLocation == null) {
    return null;
  }
  Iterator<Location<PsiMethod>> locationIterator =
      contextLocation.getAncestors(PsiMethod.class, false);
  while (locationIterator.hasNext()) {
    Location<PsiMethod> methodLocation = locationIterator.next();
    if (JUnitUtil.isTestMethod(methodLocation)) {
      return methodLocation.getPsiElement();
    }
  }
  return null;
}
 
开发者ID:bazelbuild,项目名称:intellij,代码行数:25,代码来源:TestMethodSelectionUtil.java

示例7: getMainObject

import com.intellij.execution.Location; //导入方法依赖的package包/类
@Nullable
private static ScObject getMainObject(ConfigurationContext context) {
  Location location = context.getLocation();
  if (location == null) {
    return null;
  }
  location = JavaExecutionUtil.stepIntoSingleClass(context.getLocation());
  if (location == null) {
    return null;
  }
  PsiElement element = location.getPsiElement();
  if (!(element.getContainingFile() instanceof ScalaFile)) {
    return null;
  }
  if (!element.isPhysical()) {
    return null;
  }
  return getMainObjectFromElement(element);
}
 
开发者ID:bazelbuild,项目名称:intellij,代码行数:20,代码来源:BlazeScalaMainClassRunConfigurationProducer.java

示例8: getTargetName

import com.intellij.execution.Location; //导入方法依赖的package包/类
@Nullable
private static String getTargetName(Location location) {
  PsiElement parent = location.getPsiElement();
  while (!(parent.getParent() instanceof PsiFile) && parent.getParent() != null) {
    parent = parent.getParent();
  }
  if (parent instanceof GrMethodCallExpression && PsiUtil.isMethodCall((GrMethodCallExpression)parent, "target")) {
    final GrNamedArgument[] args = ((GrMethodCallExpression)parent).getNamedArguments();
    if (args.length == 1) {
      final GrArgumentLabel label = args[0].getLabel();
      if (label != null) {
        return label.getName();
      }
    }
    return null;
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:GantScriptType.java

示例9: getTestPresentation

import com.intellij.execution.Location; //导入方法依赖的package包/类
@Nullable
public static String getTestPresentation(AbstractTestProxy testInfo, Project project, GlobalSearchScope searchScope) {
  final Location location = testInfo.getLocation(project, searchScope);
  final PsiElement element = location != null ? location.getPsiElement() : null;
  if (element instanceof PsiMethod) {
    final PsiClass containingClass = location instanceof MethodLocation ? ((MethodLocation)location).getContainingClass() 
                                                                        : ((PsiMethod)element).getContainingClass();
    if (containingClass != null) {
      final String proxyName = testInfo.getName();
      final String methodName = ((PsiMethod)element).getName();
      return JavaExecutionUtil.getRuntimeQualifiedName(containingClass) + "," + proxyName.substring(proxyName.indexOf(methodName));
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:TestMethods.java

示例10: collectLocationElements

import com.intellij.execution.Location; //导入方法依赖的package包/类
private static PsiElement[] collectLocationElements(LinkedHashSet<String> classes, DataContext dataContext) {
  final Location<?>[] locations = Location.DATA_KEYS.getData(dataContext);
  if (locations != null) {
    List<PsiElement> elements = new ArrayList<PsiElement>();
    for (Location<?> location : locations) {
      final PsiElement psiElement = location.getPsiElement();
      classes.add(getQName(psiElement, location));
      elements.add(psiElement);
    }
    return elements.toArray(new PsiElement[elements.size()]);
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:AbstractPatternBasedConfigurationProducer.java

示例11: includeFailedTestWithDependencies

import com.intellij.execution.Location; //导入方法依赖的package包/类
public static void includeFailedTestWithDependencies(Map<PsiClass, Map<PsiMethod, List<String>>> classes,
                                                     GlobalSearchScope scope,
                                                     Project project,
                                                     AbstractTestProxy proxy) {
  final Location location = proxy.getLocation(project, scope);
  if (location != null) {
    final PsiElement element = location.getPsiElement();
    if (element instanceof PsiMethod && element.isValid()) {
      final PsiMethod psiMethod = (PsiMethod)element;
      PsiClass psiClass = psiMethod.getContainingClass();
      if (psiClass != null && psiClass.hasModifierProperty(PsiModifier.ABSTRACT)) {
        final AbstractTestProxy parent = proxy.getParent();
        final PsiElement elt = parent != null ? parent.getLocation(project, scope).getPsiElement() : null;
        if (elt instanceof PsiClass) {
          psiClass = (PsiClass)elt;
        }
      }
      TestNGTestObject.collectTestMethods(classes, psiClass, psiMethod.getName(), scope);
      Map<PsiMethod, List<String>> psiMethods = classes.get(psiClass);
      if (psiMethods == null) {
        psiMethods = new LinkedHashMap<PsiMethod, List<String>>();
        classes.put(psiClass, psiMethods);
      }
      List<String> strings = psiMethods.get(psiMethod);
      if (strings == null || strings.isEmpty()) {
        strings = new ArrayList<String>();
      }
      setupParameterName(location, strings);
      psiMethods.put(psiMethod, strings);
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:33,代码来源:RerunFailedTestsAction.java

示例12: selectedPsiElement

import com.intellij.execution.Location; //导入方法依赖的package包/类
/**
 * The single selected {@link PsiElement}. Returns null if we're in a SM runner tree UI context
 * (handled by a different producer).
 */
@Nullable
private static PsiElement selectedPsiElement(ConfigurationContext context) {
  List<Location<?>> selectedTestUiElements =
      SmRunnerUtils.getSelectedSmRunnerTreeElements(context);
  if (!selectedTestUiElements.isEmpty()) {
    return null;
  }
  Location<?> location = context.getLocation();
  return location != null ? location.getPsiElement() : null;
}
 
开发者ID:bazelbuild,项目名称:intellij,代码行数:15,代码来源:BlazePyTestConfigurationProducer.java

示例13: selectedPsiElement

import com.intellij.execution.Location; //导入方法依赖的package包/类
/** The single selected {@link PsiElement}. Returns null if multiple elements are selected. */
@Nullable
private static PsiElement selectedPsiElement(ConfigurationContext context) {
  PsiElement[] psi = LangDataKeys.PSI_ELEMENT_ARRAY.getData(context.getDataContext());
  if (psi != null && psi.length > 1) {
    return null; // multiple elements selected.
  }
  Location<?> location = context.getLocation();
  return location != null ? location.getPsiElement() : null;
}
 
开发者ID:bazelbuild,项目名称:intellij,代码行数:11,代码来源:BlazeCidrTestConfigurationProducer.java

示例14: setupConfigurationFromContext

import com.intellij.execution.Location; //导入方法依赖的package包/类
@Override
protected boolean setupConfigurationFromContext(AbstractPythonTestRunConfiguration configuration,
                                                ConfigurationContext context,
                                                Ref<PsiElement> sourceElement) {
  if (context == null) return false;
  final Location location = context.getLocation();
  if (location == null || !isAvailable(location)) return false;
  PsiElement element = location.getPsiElement();
  if (element instanceof PsiWhiteSpace) {
    element = PyUtil.findNonWhitespaceAtOffset(element.getContainingFile(), element.getTextOffset());
  }

  if (PythonUnitTestRunnableScriptFilter.isIfNameMain(location)) return false;
  final Module module = location.getModule();
  if (!isPythonModule(module)) return false;

  if (element instanceof PsiDirectory) {
    return setupConfigurationFromFolder((PsiDirectory)element, configuration);
  }

  final PyFunction pyFunction = PsiTreeUtil.getParentOfType(element, PyFunction.class, false);
  if (pyFunction != null && isTestFunction(pyFunction, configuration)) {
    return setupConfigurationFromFunction(pyFunction, configuration);
  }
  final PyClass pyClass = PsiTreeUtil.getParentOfType(element, PyClass.class, false);
  if (pyClass != null && isTestClass(pyClass, configuration)) {
    return setupConfigurationFromClass(pyClass, configuration);
  }
  if (element == null) return false;
  final PsiFile file = element.getContainingFile();
  if (file instanceof PyFile && isTestFile((PyFile)file)) {
    return setupConfigurationFromFile((PyFile)file, configuration);
  }

  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:37,代码来源:PythonTestConfigurationProducer.java

示例15: isConfigurationFromContext

import com.intellij.execution.Location; //导入方法依赖的package包/类
@Override
public boolean isConfigurationFromContext(AbstractPythonTestRunConfiguration configuration, ConfigurationContext context) {
  final Location location = context.getLocation();
  if (location == null) return false;
  if (!(configuration instanceof PyTestRunConfiguration)) return false;
  final PsiElement element = location.getPsiElement();

  final PsiFileSystemItem file = element instanceof PsiDirectory ? (PsiDirectory)element : element.getContainingFile();
  if (file == null) return false;
  final VirtualFile virtualFile = file.getVirtualFile();
  if (virtualFile == null) return false;

  if (file instanceof PyFile || file instanceof PsiDirectory) {
    final List<PyStatement> testCases = PyTestUtil.getPyTestCasesFromFile(file);
    if (testCases.isEmpty()) return false;
  } else return false;

  final Sdk sdk = PythonSdkType.findPythonSdk(context.getModule());
  if (sdk == null) return false;
  final String keywords = getKeywords(element, sdk);
  final String scriptName = ((PyTestRunConfiguration)configuration).getTestToRun();
  final String workingDirectory = configuration.getWorkingDirectory();
  final String path = virtualFile.getPath();
  final boolean isTestFileEquals = scriptName.equals(path) ||
                                   path.equals(new File(workingDirectory, scriptName).getAbsolutePath());

  final String configurationKeywords = ((PyTestRunConfiguration)configuration).getKeywords();
  return isTestFileEquals && (configurationKeywords.equals(keywords) ||
                              StringUtil.isEmptyOrSpaces(((PyTestRunConfiguration)configuration).getKeywords()) && keywords == null);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:31,代码来源:PyTestConfigurationProducer.java


注:本文中的com.intellij.execution.Location.getPsiElement方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。