• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java QualifiedName类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.intellij.psi.util.QualifiedName的典型用法代码示例。如果您正苦于以下问题:Java QualifiedName类的具体用法?Java QualifiedName怎么用?Java QualifiedName使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



QualifiedName类属于com.intellij.psi.util包,在下文中一共展示了QualifiedName类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: resolveImportReference

import com.intellij.psi.util.QualifiedName; //导入依赖的package包/类
@Nullable
public PsiElement resolveImportReference(QualifiedName name, PyQualifiedNameResolveContext context, boolean withRoots) {
  if (StudyTaskManager.getInstance(context.getProject()).getCourse() == null) {
    return null;
  }
  final String nameString = name.toString();
  PsiFile containingFile = context.getFootholdFile();
  if (containingFile == null) return null;

  final PsiDirectory directory = containingFile.getContainingDirectory();
  if (directory == null) return null;
  final PsiFile file = directory.findFile(nameString + ".py");
  if (file != null) {
    return file;
  }

  return null;
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:19,代码来源:PyStudyImportResolver.java


示例2: resolveImportReference

import com.intellij.psi.util.QualifiedName; //导入依赖的package包/类
@Nullable
public PsiElement resolveImportReference(QualifiedName name, QualifiedNameResolveContext context, boolean withRoots) {
  if (StudyTaskManager.getInstance(context.getProject()).getCourse() == null) {
    return null;
  }
  final String nameString = name.toString();
  PsiFile containingFile = context.getFootholdFile();
  if (containingFile == null) return null;

  final PsiDirectory directory = containingFile.getContainingDirectory();
  if (directory == null) return null;
  final PsiFile file = directory.findFile(nameString + ".py");
  if (file != null) {
    return file;
  }

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


示例3: resolveImportReference

import com.intellij.psi.util.QualifiedName; //导入依赖的package包/类
@Nullable
public PsiElement resolveImportReference(QualifiedName name, QualifiedNameResolveContext context, boolean withRoots) {
  String fqn = name.toString();
  final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(context.getProject());
  final PsiPackage aPackage = psiFacade.findPackage(fqn);
  if (aPackage != null) {
    return aPackage;
  }

  Module module = context.getModule();
  if (module != null) {
    final PsiClass aClass = psiFacade.findClass(fqn, module.getModuleWithDependenciesAndLibrariesScope(false));
    if (aClass != null) return aClass;
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:PyJavaImportResolver.java


示例4: getCallableType

import com.intellij.psi.util.QualifiedName; //导入依赖的package包/类
@Nullable
@Override
public PyType getCallableType(@NotNull PyCallable callable, @NotNull TypeEvalContext context) {
  if (callable instanceof PyFunction) {
    final String qualifiedName = callable.getQualifiedName();
    if (qualifiedName != null && qualifiedName.startsWith("PyQt")){
      final QualifiedName name = QualifiedName.fromDottedString(qualifiedName);
      final String qtVersion = name.getComponents().get(0);
      final String docstring = ((PyFunction)callable).getDocStringValue();
      if (docstring != null && docstring.contains("[signal]")) {
        final PyClass aClass = PyClassNameIndex.findClass(qtVersion + "." + ourQtBoundSignal, callable.getProject());
        if (aClass != null)
          return new PyClassTypeImpl(aClass, false);
      }
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:PyQtTypeProvider.java


示例5: addImportCandidates

import com.intellij.psi.util.QualifiedName; //导入依赖的package包/类
@Override
public final void addImportCandidates(
    PsiReference reference, String name, AutoImportQuickFix quickFix) {
  Project project = reference.getElement().getProject();
  PySourcesIndex index = getSourcesIndex(project);
  if (index == null) {
    return;
  }
  PsiManager psiManager = PsiManager.getInstance(project);
  for (QualifiedName candidate : index.shortNames.get(name)) {
    PsiElementProvider resolver = index.sourceMap.get(candidate);
    if (resolver == null) {
      continue;
    }
    PsiElement psi = resolver.get(psiManager);
    if (psi == null) {
      continue;
    }
    PsiFile file = psi.getContainingFile();
    if (file != null) {
      quickFix.addImport(psi, file, candidate.removeLastComponent());
    }
  }
}
 
开发者ID:bazelbuild,项目名称:intellij,代码行数:25,代码来源:AbstractPyImportResolverStrategy.java


示例6: createStub

import com.intellij.psi.util.QualifiedName; //导入依赖的package包/类
public PyClassStub createStub(@NotNull final PyClass psi, final StubElement parentStub) {
  final PyExpression[] exprs = psi.getSuperClassExpressions();
  List<QualifiedName> superClasses = new ArrayList<QualifiedName>();
  for (PyExpression expression : exprs) {
    if (expression instanceof PyKeywordArgument) {
      continue;
    }
    expression = PyClassImpl.unfoldClass(expression);
    superClasses.add(PyPsiUtils.asQualifiedName(expression));
  }
  final PyStringLiteralExpression docStringExpression = psi.getDocStringExpression();
  return new PyClassStubImpl(psi.getName(), parentStub,
                             superClasses.toArray(new QualifiedName[superClasses.size()]),
                             PyPsiUtils.asQualifiedName(psi.getMetaClassExpression()),
                             psi.getOwnSlots(),
                             PyPsiUtils.strValue(docStringExpression),
                             getStubElementType());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:PyClassElementType.java


示例7: getQualifiedName

import com.intellij.psi.util.QualifiedName; //导入依赖的package包/类
/**
 * Helper method that builds an import path, handling all these "import foo", "import foo as bar", "from bar import foo", etc.
 * Either importPath or importSource must be not null.
 *
 * @param name       what is ultimately imported.
 * @param importPath known path to import the name.
 * @param source     known ImportElement to import the name; its 'as' clause is used if present.
 * @return a properly qualified name.
 */
@NotNull
public static String getQualifiedName(@NotNull String name, @Nullable QualifiedName importPath, @Nullable PyImportElement source) {
  final StringBuilder sb = new StringBuilder();
  if (source != null) {
    final PsiElement parent = source.getParent();
    if (parent instanceof PyFromImportStatement) {
      sb.append(name);
    }
    else {
      sb.append(source.getVisibleName()).append(".").append(name);
    }
  }
  else {
    if (importPath != null && importPath.getComponentCount() > 0) {
      sb.append(importPath).append(".");
    }
    sb.append(name);
  }
  return sb.toString();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:30,代码来源:ImportCandidateHolder.java


示例8: findImportableName

import com.intellij.psi.util.QualifiedName; //导入依赖的package包/类
@Nullable
private static QualifiedName findImportableName(@NotNull PyFile file) {
  final VirtualFile moduleVirtualFile = file.getVirtualFile();
  if (moduleVirtualFile != null) {
    String moduleName = QualifiedNameFinder.findShortestImportableName(file, moduleVirtualFile);
    if (moduleName != null) {
      final QualifiedName qName = QualifiedName.fromDottedString(moduleName);
      for (PyCanonicalPathProvider provider : Extensions.getExtensions(PyCanonicalPathProvider.EP_NAME)) {
        final QualifiedName restored = provider.getCanonicalPath(qName, null);
        if (restored != null) {
          return restored;
        }
      }
      return qName;
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:PyiUtil.java


示例9: bindToElement

import com.intellij.psi.util.QualifiedName; //导入依赖的package包/类
@Nullable
@Override
public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException {
  if (element.equals(resolve())) {
    return element;
  }
  if (myElement instanceof PyStringLiteralExpression && element instanceof PyClass) {
    final PyStringLiteralExpression e = (PyStringLiteralExpression)myElement;
    final PyClass cls = (PyClass)element;
    QualifiedName qname = QualifiedNameFinder.findCanonicalImportPath(cls, element);
    if (qname != null) {
      qname = qname.append(cls.getName());
      ElementManipulator<PyStringLiteralExpression> manipulator = ElementManipulators.getManipulator(e);
      myType = new PyClassTypeImpl(cls, false);
      return manipulator.handleContentChange(e, myFullRange, qname.toString());
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:DocStringTypeReference.java


示例10: promptToConfigureDocumentation

import com.intellij.psi.util.QualifiedName; //导入依赖的package包/类
@Override
public void promptToConfigureDocumentation(@NotNull PsiElement element) {
  final Project project = element.getProject();
  final QualifiedName qName = QualifiedNameFinder.findCanonicalImportPath(element, element);
  if (qName != null && qName.getComponentCount() > 0) {
    ApplicationManager.getApplication().invokeLater(new Runnable() {
      @Override
      public void run() {
        final int rc = Messages.showOkCancelDialog(project,
                                                   "No external documentation URL configured for module " + qName.getComponents().get(0) +
                                                   ".\nWould you like to configure it now?",
                                                   "Python External Documentation",
                                                   Messages.getQuestionIcon());
        if (rc == Messages.OK) {
          ShowSettingsUtilImpl.showSettingsDialog(project, PythonDocumentationConfigurable.ID, "");
        }
      }
    }, ModalityState.NON_MODAL);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:PythonDocumentationProvider.java


示例11: collectAssignedAttributes

import com.intellij.psi.util.QualifiedName; //导入依赖的package包/类
private static Collection<PyExpression> collectAssignedAttributes(PyQualifiedExpression qualifier) {
  final Set<String> names = new HashSet<String>();
  final QualifiedName qualifierQName = qualifier.asQualifiedName();
  if (qualifierQName != null) {
    final List<PyExpression> results = new ArrayList<PyExpression>();
    for (ScopeOwner owner = ScopeUtil.getScopeOwner(qualifier); owner != null; owner = ScopeUtil.getScopeOwner(owner)) {
      final Scope scope = ControlFlowCache.getScope(owner);
      for (PyTargetExpression target : scope.getTargetExpressions()) {
        final QualifiedName targetQName = target.asQualifiedName();
        if (targetQName != null) {
          if (targetQName.getComponentCount() == qualifierQName.getComponentCount() + 1 && targetQName.matchesPrefix(qualifierQName)) {
            final String name = target.getName();
            if (!names.contains(name)) {
              names.add(name);
              results.add(target);
            }
          }
        }
      }
    }
    return results;
  }
  return Collections.emptyList();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:PyQualifiedReference.java


示例12: visitPyImportElement

import com.intellij.psi.util.QualifiedName; //导入依赖的package包/类
@Override
public void visitPyImportElement(PyImportElement node) {
  final String asName = node.getAsName();
  final QualifiedName importedQName = node.getImportedQName();
  if (importedQName == null) return;
  final String name = importedQName.getLastComponent();

  if (asName == null || name == null) return;
  if (UPPERCASE_REGEX.matcher(name).matches()) {
    if (!UPPERCASE_REGEX.matcher(asName).matches()) {
      registerAndAddRenameQuickFix(node.getAsNameElement(), "Constant variable imported as non constant");
    }
  }
  else if (LOWERCASE_REGEX.matcher(name).matches()) {
    if (!LOWERCASE_REGEX.matcher(asName).matches()) {
      registerAndAddRenameQuickFix(node.getAsNameElement(), "Lowercase variable imported as non lowercase");
    }
  }
  else if (LOWERCASE_REGEX.matcher(asName).matches()) {
    registerAndAddRenameQuickFix(node.getAsNameElement(), "CamelCase variable imported as lowercase");
  }
  else if (UPPERCASE_REGEX.matcher(asName).matches()) {
    registerAndAddRenameQuickFix(node.getAsNameElement(), "CamelCase variable imported as constant");
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:PyPep8NamingInspection.java


示例13: resolveModuleAt

import com.intellij.psi.util.QualifiedName; //导入依赖的package包/类
@Nullable
private static PsiElement resolveModuleAt(
    @Nullable PsiDirectory directory,
    QualifiedName qualifiedName,
    PyQualifiedNameResolveContext context) {
  if (directory == null || !directory.isValid()) {
    return null;
  }
  PsiElement seeker = directory;
  for (String name : qualifiedName.getComponents()) {
    if (name == null) {
      return null;
    }
    seeker =
        ResolveImportUtil.resolveChild(
            seeker, name, context.getFootholdFile(), false, true, false);
  }
  return seeker;
}
 
开发者ID:bazelbuild,项目名称:intellij,代码行数:20,代码来源:BlazePyOutsideModuleImportResolver.java


示例14: visitRoot

import com.intellij.psi.util.QualifiedName; //导入依赖的package包/类
public boolean visitRoot(final VirtualFile root, @Nullable Module module, @Nullable Sdk sdk, boolean isModuleSource) {
  if (!root.isValid()) {
    return true;
  }
  if (root.equals(PyUserSkeletonsUtil.getUserSkeletonsDirectory())) {
    return true;
  }
  PsiElement resolveResult = resolveInRoot(root);
  if (resolveResult != null) {
    addRoot(resolveResult, isModuleSource);
  }

  if (isAcceptRootAsTopLevelPackage() && myQualifiedName.matchesPrefix(QualifiedName.fromDottedString(root.getName()))) {
    resolveResult = resolveInRoot(root.getParent());
    if (resolveResult != null) {
      addRoot(resolveResult, isModuleSource);
    }
  }

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


示例15: addRelativeImportResultsFromSkeletons

import com.intellij.psi.util.QualifiedName; //导入依赖的package包/类
/**
 * Resolve relative imports from sdk root to the skeleton dir
 */
private void addRelativeImportResultsFromSkeletons(@NotNull final PsiFile foothold) {
  final boolean inSource = FileIndexFacade.getInstance(foothold.getProject()).isInContent(foothold.getVirtualFile());
  if (inSource) return;
  PsiDirectory containingDirectory = foothold.getContainingDirectory();
  if (myRelativeLevel > 0) {
    containingDirectory = ResolveImportUtil.stepBackFrom(foothold, myRelativeLevel);
  }
  if (containingDirectory != null) {
    final QualifiedName containingQName = QualifiedNameFinder.findCanonicalImportPath(containingDirectory, null);
    if (containingQName != null && containingQName.getComponentCount() > 0) {
      final QualifiedName absoluteQName = containingQName.append(myQualifiedName.toString());
      final QualifiedNameResolverImpl absoluteVisitor =
        (QualifiedNameResolverImpl)new QualifiedNameResolverImpl(absoluteQName).fromElement(foothold);

      final Sdk sdk = PythonSdkType.getSdk(foothold);
      if (sdk == null) return;
      final VirtualFile skeletonsDir = PySdkUtil.findSkeletonsDir(sdk);
      if (skeletonsDir == null) return;
      final PsiDirectory directory = myContext.getPsiManager().findDirectory(skeletonsDir);
      final PsiElement psiElement = absoluteVisitor.resolveModuleAt(directory);
      if (psiElement != null)
        myLibResults.add(psiElement);
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:29,代码来源:QualifiedNameResolverImpl.java


示例16: resolveNameInFromImport

import com.intellij.psi.util.QualifiedName; //导入依赖的package包/类
public static List<RatedResolveResult> resolveNameInFromImport(PyFromImportStatement importStatement, @NotNull QualifiedName qName) {
  PsiFile file = importStatement.getContainingFile().getOriginalFile();
  String name = qName.getComponents().get(0);

  final List<PsiElement> candidates = importStatement.resolveImportSourceCandidates();
  List<PsiElement> resultList = new ArrayList<PsiElement>();
  for (PsiElement candidate : candidates) {
    if (!candidate.isValid()) {
      throw new PsiInvalidElementAccessException(candidate, "Got an invalid candidate from resolveImportSourceCandidates(): " + candidate.getClass());
    }
    if (candidate instanceof PsiDirectory) {
      candidate = PyUtil.getPackageElement((PsiDirectory)candidate, importStatement);
    }
    PsiElement result = resolveChild(candidate, name, file, false, true);
    if (result != null) {
      if (!result.isValid()) {
        throw new PsiInvalidElementAccessException(result, "Got an invalid candidate from resolveChild(): " + result.getClass());
      }
      resultList.add(result);
    }
  }
  if (!resultList.isEmpty()) {
    return rateResults(resultList);
  }
  return Collections.emptyList();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:ResolveImportUtil.java


示例17: getImplicitResultRate

import com.intellij.psi.util.QualifiedName; //导入依赖的package包/类
private int getImplicitResultRate(PyElement target, List<QualifiedName> imports) {
  int rate = RatedResolveResult.RATE_LOW;
  if (target.getContainingFile() == myElement.getContainingFile()) {
    rate += 200;
  }
  else {
    final VirtualFile vFile = target.getContainingFile().getVirtualFile();
    if (vFile != null) {
      if (ProjectScope.getProjectScope(myElement.getProject()).contains(vFile)) {
        rate += 80;
      }
      final QualifiedName qName = QualifiedNameFinder.findShortestImportableQName(myElement, vFile);
      if (qName != null && imports.contains(qName)) {
        rate += 70;
      }
    }
  }
  if (myElement.getParent() instanceof PyCallExpression) {
    if (target instanceof PyFunction) rate += 50;
  }
  else {
    if (!(target instanceof PyFunction)) rate += 50;
  }
  return rate;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:PyQualifiedReference.java


示例18: testImportStatement

import com.intellij.psi.util.QualifiedName; //导入依赖的package包/类
public void testImportStatement() {
  final PyFileImpl file = (PyFileImpl) getTestFile();

  final List<PyFromImportStatement> fromImports = file.getFromImports();
  assertEquals(1, fromImports.size());
  final PyFromImportStatement fromImport = fromImports.get(0);
  final PyImportElement[] importElements = fromImport.getImportElements();
  assertEquals(1, importElements.length);
  assertEquals("argv", importElements [0].getVisibleName());
  assertFalse(fromImport.isStarImport());
  assertEquals(0, fromImport.getRelativeLevel());
  final QualifiedName qName = fromImport.getImportSourceQName();
  assertSameElements(qName.getComponents(), "sys");

  final List<PyImportElement> importTargets = file.getImportTargets();
  assertEquals(1, importTargets.size());
  final PyImportElement importElement = importTargets.get(0);
  final QualifiedName importQName = importElement.getImportedQName();
  assertSameElements(importQName.getComponents(), "os", "path");

  assertNotParsed(file);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:PyStubsTest.java


示例19: visitRoot

import com.intellij.psi.util.QualifiedName; //导入依赖的package包/类
public boolean visitRoot(VirtualFile root, Module module, Sdk sdk, boolean isModuleSource) {
  if (myVFile != null) {
    final String relativePath = VfsUtilCore.getRelativePath(myVFile, root, '/');
    if (relativePath != null && !relativePath.isEmpty()) {
      List<String> result = StringUtil.split(relativePath, "/");
      if (result.size() > 0) {
        result.set(result.size() - 1, FileUtil.getNameWithoutExtension(result.get(result.size() - 1)));
      }
      for (String component : result) {
        if (!PyNames.isIdentifier(component)) {
          return true;
        }
      }
      myResults.add(QualifiedName.fromComponents(result));
    }
  }
  return true;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:QualifiedNameFinder.java


示例20: getImportSourceQName

import com.intellij.psi.util.QualifiedName; //导入依赖的package包/类
public QualifiedName getImportSourceQName() {
  final PyFromImportStatementStub stub = getStub();
  if (stub != null) {
    final QualifiedName qName = stub.getImportSourceQName();
    if (qName != null && qName.getComponentCount() == 0) {  // relative import only: from .. import the_name
      return null;
    }
    return qName;
  }

  final PyReferenceExpression importSource = getImportSource();
  if (importSource == null) {
    return null;
  }
  return importSource.asQualifiedName();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:PyFromImportStatementImpl.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ChildProcessService类代码示例发布时间:2022-05-22
下一篇:
Java ClassReader类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap