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

Java PyFile类代码示例

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

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



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

示例1: getTarget

import com.jetbrains.python.psi.PyFile; //导入依赖的package包/类
@Nullable
@Override
public PsiElement getTarget(@NotNull DataContext dataContext) {
  Project project = CommonDataKeys.PROJECT.getData(dataContext);
  if (project == null) return null;

  PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(dataContext);
  if (element == null) {
    Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
    if (editor != null) {
      PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
      if (file == null) return null;

      element = TargetElementUtil.findTargetElement(editor, TargetElementUtil.ELEMENT_NAME_ACCEPTED |
                                                            TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED |
                                                            TargetElementUtil.LOOKUP_ITEM_ACCEPTED);
      if (element instanceof PyFunction || element instanceof PyClass || element instanceof PyFile) {
        return element;
      }

      element = file.findElementAt(editor.getCaretModel().getOffset());
    }
  }
  return PsiTreeUtil.getNonStrictParentOfType(element, PyFunction.class, PyClass.class, PyFile.class);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:PyCallHierarchyProvider.java


示例2: getMembersByQName

import com.jetbrains.python.psi.PyFile; //导入依赖的package包/类
@Override
protected Collection<PyCustomMember> getMembersByQName(PyFile module, String qName) {
 final PyFile moduleSkeleton = PyUserSkeletonsUtil.getUserSkeletonForModuleQName(qName, module);
  if (moduleSkeleton != null) {
    final List<PyCustomMember> results = new ArrayList<PyCustomMember>();
    for (PyElement element : moduleSkeleton.iterateNames()) {
      if (element instanceof PsiFileSystemItem) {
        continue;
      }
      final String name = element.getName();
      if (name != null) {
        results.add(new PyCustomMember(name, element));
      }
    }
    return results;
  }
  return Collections.emptyList();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:PyUserSkeletonsModuleMembersProvider.java


示例3: getMembers

import com.jetbrains.python.psi.PyFile; //导入依赖的package包/类
@NotNull
@Override
public Collection<PyCustomMember> getMembers(PyClassType classType, PsiElement location) {
  PyClass clazz = classType.getPyClass();
  final String qualifiedName = clazz.getQualifiedName();
  if ("socket._socketobject".equals(qualifiedName)) {
    final PyFile socketFile = (PyFile)clazz.getContainingFile();
    List<PyCustomMember> socketMembers = socketFile.getUserData(mySocketMembersKey);
    if (socketMembers == null) {
      socketMembers = calcSocketMembers(socketFile);
      socketFile.putUserData(mySocketMembersKey, socketMembers);
    }
    return socketMembers;
  }
  return Collections.emptyList();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:PyStdlibClassMembersProvider.java


示例4: fun

import com.jetbrains.python.psi.PyFile; //导入依赖的package包/类
public DFAMap<ScopeVariable> fun(final DFAMap<ScopeVariable> map, final Instruction instruction) {
  final PsiElement element = instruction.getElement();
  if (element == null || !((PyFile) element.getContainingFile()).getLanguageLevel().isPy3K()){
    return processReducedMap(map, instruction, element);
  }
  // Scope reduction
  final DFAMap<ScopeVariable> reducedMap = new DFAMap<ScopeVariable>();
  for (Map.Entry<String, ScopeVariable> entry : map.entrySet()) {
    final ScopeVariable value = entry.getValue();
    // Support PEP-3110. (PY-1408)
    if (value.isParameter()){
      final PsiElement declaration = value.getDeclarations().iterator().next();
      final PyExceptPart exceptPart = PyExceptPartNavigator.getPyExceptPartByTarget(declaration);
      if (exceptPart != null){
        if (!PsiTreeUtil.isAncestor(exceptPart, element, false)){
          continue;
        }
      }
    } 
    reducedMap.put(entry.getKey(), value);
  }

  return processReducedMap(reducedMap, instruction, element);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:PyReachingDefsDfaInstance.java


示例5: isAvailable

import com.jetbrains.python.psi.PyFile; //导入依赖的package包/类
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
  if (!(file instanceof PyFile)) {
    return false;
  }

  PsiElement element = file.findElementAt(editor.getCaretModel().getOffset());
  PyBinaryExpression binaryExpression = PsiTreeUtil.getParentOfType(element, PyBinaryExpression.class, false);
  while (binaryExpression != null) {
    PyElementType operator = binaryExpression.getOperator();
    if (FLIPPED_OPERATORS.containsKey(operator)) {
      String operatorText = binaryExpression.getPsiOperator().getText();
      String flippedOperatorText = FLIPPED_OPERATORS.get(operator);
      if (flippedOperatorText.equals(operatorText)) {
        setText(PyBundle.message("INTN.flip.$0", operatorText));
      }
      else {
        setText(PyBundle.message("INTN.flip.$0.to.$1", operatorText, flippedOperatorText));
      }
      return true;
    }
    binaryExpression = PsiTreeUtil.getParentOfType(binaryExpression, PyBinaryExpression.class);
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:PyFlipComparisonIntention.java


示例6: addNavigationElements

import com.jetbrains.python.psi.PyFile; //导入依赖的package包/类
private static void addNavigationElements(final ArrayList<PsiElement> array, final PsiElement psiElement) {
  if (psiElement instanceof PyFile) {
    for (PyClass pyClass : ((PyFile)psiElement).getTopLevelClasses()) {
      addNavigationElements(array, pyClass);
    }
    for (PyFunction pyFunction : ((PyFile)psiElement).getTopLevelFunctions()) {
      addNavigationElements(array, pyFunction);
    }
  }
  else if (psiElement instanceof PyFunction){
    array.add(psiElement);
  }
  else if (psiElement instanceof PyClass) {
    Collections.addAll(array, ((PyClass)psiElement).getMethods(false));
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:PyMethodNavigationOffsetProvider.java


示例7: getFormatFromDocformatAttribute

import com.jetbrains.python.psi.PyFile; //导入依赖的package包/类
@Nullable
public static DocStringFormat getFormatFromDocformatAttribute(@NotNull PsiFile file) {
  if (file instanceof PyFile) {
    final PyTargetExpression expr = ((PyFile)file).findTopLevelAttribute(PyNames.DOCFORMAT);
    if (expr != null) {
      final String docformat = PyPsiUtils.strValue(expr.findAssignedValue());
      if (docformat != null) {
        final List<String> words = StringUtil.split(docformat, " ");
        if (words.size() > 0) {
          final DocStringFormat fileFormat = DocStringFormat.fromName(words.get(0));
          if (fileFormat != null) {
            return fileFormat;
          }
        }
      }
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:PyDocumentationSettings.java


示例8: isSupported

import com.jetbrains.python.psi.PyFile; //导入依赖的package包/类
@Override
public boolean isSupported(@NotNull final Class visitorClass, @NotNull final PsiFile file) {
  //inspections
  if (visitorClass == PyArgumentListInspection.class) {
    return false;
  }
  if (visitorClass == PyIncorrectDocstringInspection.class || visitorClass == PyMissingOrEmptyDocstringInspection.class ||
      visitorClass == PyUnboundLocalVariableInspection.class || visitorClass == PyUnnecessaryBackslashInspection.class ||
      visitorClass == PyByteLiteralInspection.class || visitorClass == PyNonAsciiCharInspection.class ||
      visitorClass == PyPackageRequirementsInspection.class || visitorClass == PyMandatoryEncodingInspection.class ||
      visitorClass == PyInterpreterInspection.class || visitorClass == PyDocstringTypesInspection.class ||
      visitorClass == PySingleQuotedDocstringInspection.class || visitorClass == PyClassHasNoInitInspection.class || 
      visitorClass == PyStatementEffectInspection.class) {
    return false;
  }
  //annotators
  if (visitorClass == DocStringAnnotator.class || visitorClass == ParameterListAnnotator.class || visitorClass == ReturnAnnotator.class || visitorClass == HighlightingAnnotator.class)
    return false;
  // doctest in separate file
  final PsiFile topLevelFile = InjectedLanguageManager.getInstance(file.getProject()).getTopLevelFile(file);
  if (visitorClass == PyUnresolvedReferencesInspection.class && !(topLevelFile instanceof PyFile)) {
    return false;
  }
  return true;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:PyDocstringVisitorFilter.java


示例9: isInsideCodeBlock

import com.jetbrains.python.psi.PyFile; //导入依赖的package包/类
private static boolean isInsideCodeBlock(PsiElement element) {
  if (element instanceof PsiFileSystemItem) {
    return false;
  }

  if (element == null || element.getParent() == null) return true;

  while(true) {
    if (element instanceof PyFile) {
      return false;
    }
    if (element instanceof PsiFile || element instanceof PsiDirectory || element == null) {
      return true;
    }
    PsiElement pparent = element.getParent();
    if (pparent instanceof PyFunction) {
      final PyFunction pyFunction = (PyFunction)pparent;
      return !(element == pyFunction.getParameterList() || element == pyFunction.getNameIdentifier());
    }
    element = pparent;
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:PythonPsiManager.java


示例10: appendDescriptors

import com.jetbrains.python.psi.PyFile; //导入依赖的package包/类
private static void appendDescriptors(ASTNode node, List<FoldingDescriptor> descriptors) {
  if (node.getElementType() instanceof PyFileElementType) {
    final List<PyImportStatementBase> imports = ((PyFile)node.getPsi()).getImportBlock();
    if (imports.size() > 1) {
      final PyImportStatementBase firstImport = imports.get(0);
      final PyImportStatementBase lastImport = imports.get(imports.size()-1);
      descriptors.add(new FoldingDescriptor(firstImport, new TextRange(firstImport.getTextRange().getStartOffset(),
                                                                       lastImport.getTextRange().getEndOffset())));
    }
  }
  else if (node.getElementType() == PyElementTypes.STATEMENT_LIST) {
    foldStatementList(node, descriptors);
  }
  else if (node.getElementType() == PyElementTypes.STRING_LITERAL_EXPRESSION) {
    foldDocString(node, descriptors);
  }

  ASTNode child = node.getFirstChildNode();
  while (child != null) {
    appendDescriptors(child, descriptors);
    child = child.getTreeNext();
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:PythonFoldingBuilder.java


示例11: findReferencesToHighlight

import com.jetbrains.python.psi.PyFile; //导入依赖的package包/类
@NotNull
@Override
public Collection<PsiReference> findReferencesToHighlight(@NotNull PsiElement target, @NotNull SearchScope searchScope) {
  if (target instanceof PyImportedModule) {
    target = ((PyImportedModule) target).resolve();
  }
  if (target instanceof PyFile && PyNames.INIT_DOT_PY.equals(((PyFile)target).getName())) {
    List<PsiReference> result = new ArrayList<PsiReference>();
    result.addAll(super.findReferencesToHighlight(target, searchScope));
    PsiElement targetDir = PyUtil.turnInitIntoDir(target);
    if (targetDir != null) {
      result.addAll(ReferencesSearch.search(targetDir, searchScope, false).findAll());
    }
    return result;
  }
  return super.findReferencesToHighlight(target, searchScope);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:PyModuleFindUsagesHandler.java


示例12: visitPyFile

import com.jetbrains.python.psi.PyFile; //导入依赖的package包/类
@Override
public void visitPyFile(PyFile node) {
  super.visitPyFile(node);
  if (PlatformUtils.isPyCharm()) {
    final Module module = ModuleUtilCore.findModuleForPsiElement(node);
    if (module != null) {
      final Sdk sdk = PythonSdkType.findPythonSdk(module);
      if (sdk == null) {
        registerProblem(node, "No Python interpreter configured for the project", new ConfigureInterpreterFix());
      }
      else if (PythonSdkType.isInvalid(sdk)) {
        registerProblem(node, "Invalid Python interpreter selected for the project", new ConfigureInterpreterFix());
      }
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:PyInterpreterInspection.java


示例13: getTopLevelElement

import com.jetbrains.python.psi.PyFile; //导入依赖的package包/类
@Override
public PsiElement getTopLevelElement(PsiElement element) {
  final PsiFile containingFile = element.getContainingFile();
  if (!(containingFile instanceof PyFile)) {
    return null;
  }
  List<PsiElement> parents = new ArrayList<PsiElement>();
  PyDocStringOwner container = PsiTreeUtil.getParentOfType(element, PyDocStringOwner.class);
  while (container != null) {
    if (container instanceof PyFile) {
      break;
    }
    parents.add(0, container);
    container = PsiTreeUtil.getParentOfType(container, PyDocStringOwner.class);
  }
  for (PsiElement parent : parents) {
    if (parent instanceof PyFunction) {
      return parent;     // we don't display any nodes under functions
    }
  }
  if (parents.size() > 0) {
    return parents.get(parents.size() - 1);
  }
  return element.getContainingFile();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:PyTreeStructureProvider.java


示例14: resolveTopLevelMember

import com.jetbrains.python.psi.PyFile; //导入依赖的package包/类
@Nullable
@Override
public <T extends PsiNamedElement> T resolveTopLevelMember(@NotNull final Class<T> aClass) {
  Preconditions.checkState(getModule() != null, "Module is not set");
  final String memberName = myQualifiedName.getLastComponent();
  if (memberName == null) {
    return null;
  }
  final PyFile file =
    new QualifiedNameResolverImpl(myQualifiedName.removeLastComponent()).fromModule(getModule()).firstResultOfType(PyFile.class);
  if (file == null) {
    return null;
  }
  for (final T element : PsiTreeUtil.getChildrenOfTypeAsList(file, aClass)) {
    if (memberName.equals(element.getName())) {
      return element;
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:QualifiedNameResolverImpl.java


示例15: resolveName

import com.jetbrains.python.psi.PyFile; //导入依赖的package包/类
@NotNull
@Override
public List<RatedResolveResult> resolveName(@NotNull PyQualifiedExpression element,
                                            @NotNull List<PsiElement> definers) {
  final List<RatedResolveResult> result = new ArrayList<RatedResolveResult>();
  final PsiElement realContext = PyPsiUtils.getRealContext(element);
  final String referencedName = element.getReferencedName();
  final PyBuiltinCache builtinCache = PyBuiltinCache.getInstance(realContext);
  // ...as a builtin symbol
  final PyFile bfile = builtinCache.getBuiltinsFile();
  if (bfile != null && !PyUtil.isClassPrivateName(referencedName)) {
    PsiElement resultElement = bfile.getElementNamed(referencedName);
    if (resultElement == null && "__builtins__".equals(referencedName)) {
      resultElement = bfile; // resolve __builtins__ reference
    }
    if (resultElement != null)
      result.add(new ImportedResolveResult(resultElement, PyReferenceImpl.getRate(resultElement), definers));
  }
  return result;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:PythonBuiltinReferenceResolveProvider.java


示例16: find

import com.jetbrains.python.psi.PyFile; //导入依赖的package包/类
@NotNull
public static List<PyFile> find(@NotNull String name, @NotNull Project project, boolean includeNonProjectItems) {
  final List<PyFile> results = new ArrayList<PyFile>();
  final GlobalSearchScope scope = includeNonProjectItems
                                  ? PyProjectScopeBuilder.excludeSdkTestsScope(project)
                                  : GlobalSearchScope.projectScope(project);
  final Collection<VirtualFile> files = FileBasedIndex.getInstance().getContainingFiles(NAME, name, scope);
  for (VirtualFile virtualFile : files) {
    final PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile);
    if (psiFile instanceof PyFile) {
      if (!PyUserSkeletonsUtil.isUnderUserSkeletonsDirectory(psiFile)) {
        results.add((PyFile)psiFile);
      }
    }
  }
  return results;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:PyModuleNameIndex.java


示例17: preprocessEnter

import com.jetbrains.python.psi.PyFile; //导入依赖的package包/类
@Override
public Result preprocessEnter(@NotNull PsiFile file,
                              @NotNull Editor editor,
                              @NotNull Ref<Integer> caretOffset,
                              @NotNull Ref<Integer> caretAdvance,
                              @NotNull DataContext dataContext,
                              EditorActionHandler originalHandler) {
  int offset = caretOffset.get();
  if (editor instanceof EditorWindow) {
    file = InjectedLanguageManager.getInstance(file.getProject()).getTopLevelFile(file);
    editor = InjectedLanguageUtil.getTopLevelEditor(editor);
    offset = editor.getCaretModel().getOffset();
  }
  if (!(file instanceof PyFile)) {
    return Result.Continue;
  }

  // honor dedent (PY-3009)
  if (BackspaceHandler.isWhitespaceBeforeCaret(editor)) {
    return Result.DefaultSkipIndent;
  }
  return Result.Continue;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:PyEnterAtIndentHandler.java


示例18: createPackageFromModule

import com.jetbrains.python.psi.PyFile; //导入依赖的package包/类
@VisibleForTesting
public void createPackageFromModule(@NotNull final PyFile file) {
  final VirtualFile vFile = file.getVirtualFile();
  final VirtualFile parentDir = vFile.getParent();
  final String newPackageName = vFile.getNameWithoutExtension();
  final VirtualFile existing = parentDir.findChild(newPackageName);
  if (existing != null) {
    showFileExistsErrorMessage(existing, ID, file.getProject());
    return;
  }
  WriteCommandAction.runWriteCommandAction(file.getProject(), new Runnable() {
    public void run() {
      try {
        final VirtualFile packageDir = parentDir.createChildDirectory(PyConvertModuleToPackageAction.this, newPackageName);
        vFile.move(PyConvertModuleToPackageAction.this, packageDir);
        vFile.rename(PyConvertModuleToPackageAction.this, PyNames.INIT_DOT_PY);
      }
      catch (IOException e) {
        LOG.error(e);
      }
    }
  });
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:PyConvertModuleToPackageAction.java


示例19: testImportBuiltInSystem

import com.jetbrains.python.psi.PyFile; //导入依赖的package包/类
/**
 * Tests skeletons for built-in classes. We can't compare files (CLR class may be changed from version to version),
 * but we are sure there should be class System.Web.AspNetHostingPermissionLevel which is part of public API
 */
public void testImportBuiltInSystem() throws Exception {
  final SkeletonTestTask task = new SkeletonTestTask(
    null,
    "System.Web",
    "import_system.py",
    null
  );
  runPythonTest(task);
  final PyFile skeleton = task.getGeneratedSkeleton();
  new ReadAction() {
    @Override
    protected void run(@NotNull Result result) throws Throwable {
      Assert.assertNotNull("System.Web does not contain class AspNetHostingPermissionLevel. Error generating stub? It has classes  " +
                           skeleton.getTopLevelClasses(),
                           skeleton.findTopLevelClass("AspNetHostingPermissionLevel"));
    }
  }.execute();

}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:PyIronPythonTest.java


示例20: doIsConfigFromContext

import com.jetbrains.python.psi.PyFile; //导入依赖的package包/类
@Override
protected boolean doIsConfigFromContext(
    BlazeCommandRunConfiguration configuration, ConfigurationContext context) {

  BlazeCommandRunConfigurationCommonState handlerState =
      configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
  if (handlerState == null
      || !BlazeCommandName.RUN.equals(handlerState.getCommandState().getCommand())) {
    return false;
  }

  Location<?> location = context.getLocation();
  if (location == null) {
    return false;
  }
  PsiElement element = location.getPsiElement();
  PsiFile file = element.getContainingFile();
  if (!(file instanceof PyFile)) {
    return false;
  }
  TargetInfo binaryTarget = getTargetLabel(file);
  if (binaryTarget == null) {
    return false;
  }
  return binaryTarget.label.equals(configuration.getTarget());
}
 
开发者ID:bazelbuild,项目名称:intellij,代码行数:27,代码来源:BlazePyBinaryConfigurationProducer.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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