Java 类com.intellij.psi.PsiFileSystemItem 实例源码

项目:hybris-integration-intellij-idea-plugin    文件:ImpexFoldingLinesFilter.java   
/**
 * Optimized method.
 *
 * @param element
 *
 * @return
 */
@Contract(pure = true)
private boolean isSupportedType(final @Nullable PsiElement element) {
    return !(element instanceof PsiFileSystemItem) &&
           !(element instanceof ImpexAnyAttributeName) &&
           !(element instanceof ImpexAnyAttributeValue) &&
           !(element instanceof ImpexAnyHeaderParameterName) &&
           !(element instanceof ImpexAttribute) &&
           !(element instanceof ImpexFullHeaderType) &&
           !(element instanceof ImpexFullHeaderParameter) &&
           !(element instanceof ImpexHeaderTypeName) &&
           !(element instanceof ImpexParameter) &&
           !(element instanceof ImpexParameters) &&
           !(element instanceof ImpexAnyHeaderMode) &&
           !(element instanceof ImpexModifier) &&
           !(element instanceof ImpexModifiers) &&
           PsiTreeUtil.getParentOfType(element, ImpexHeaderLine.class) == null &&
           (element instanceof ImpexValueLine || element instanceof ImpexHeaderLine || aroundIsValueLine(element));
}
项目:manifold-ij    文件:MoveTypeManifoldFileProcessor.java   
@Nullable
private PsiClass findPsiClass( PsiFileSystemItem element )
{
  Module mod = ModuleUtilCore.findModuleForPsiElement( element );
  if( mod == null )
  {
    return null;
  }

  ManModule module = ManProject.getModule( mod );
  String[] fqns = module.getTypesForFile( FileUtil.toIFile( module.getProject(), element.getVirtualFile() ) );
  PsiClass psiClass = null;
  for( String fqn: fqns )
  {
    psiClass = ManifoldPsiClassCache.instance().getPsiClass( GlobalSearchScope.moduleWithDependenciesAndLibrariesScope( module.getIjModule() ), module, fqn );
    if( psiClass != null )
    {
      break;
    }
  }
  return psiClass;
}
项目:intellij-ce-playground    文件:AntDomTargetReference.java   
@Nullable
private TargetResolver.Result doResolve(@Nullable final String referenceText) {
  final AntDomElement hostingElement = getHostingAntDomElement();
  if (hostingElement == null) {
    return null;
  }
  AntDomProject projectToSearchFrom;
  AntDomTarget contextTarget;
  if (hostingElement instanceof AntDomAnt) {
    final PsiFileSystemItem antFile = ((AntDomAnt)hostingElement).getAntFilePath().getValue();
    projectToSearchFrom = antFile instanceof PsiFile ? AntSupport.getAntDomProjectForceAntFile((PsiFile)antFile) : null;
    contextTarget = null;
  }
  else {
    projectToSearchFrom = hostingElement.getContextAntProject();
    contextTarget = hostingElement.getParentOfType(AntDomTarget.class, false);
  }
  if (projectToSearchFrom == null) {
    return null;
  }
  return TargetResolver.resolve(projectToSearchFrom, contextTarget, referenceText == null? Collections.<String>emptyList() : Collections.singletonList(referenceText));
}
项目:intellij-ce-playground    文件:ProjectViewNode.java   
@NotNull
@Override
public Collection<VirtualFile> getRoots() {
  Value value = getValue();

  if (value instanceof RootsProvider) {
    return ((RootsProvider)value).getRoots();
  } else if (value instanceof PsiFile) {
    PsiFile vFile = ((PsiFile)value).getContainingFile();
    if (vFile != null && vFile.getVirtualFile() != null) {
      return Collections.singleton(vFile.getVirtualFile());
    }
  } else if (value instanceof VirtualFile) {
    return Collections.singleton(((VirtualFile)value));
  } else if (value instanceof PsiFileSystemItem) {
    return Collections.singleton(((PsiFileSystemItem)value).getVirtualFile());
  }

  return EMPTY_ROOTS;
}
项目:intellij-ce-playground    文件:PsiFileSystemItemUtil.java   
@Nullable
public static String getRelativePath(PsiFileSystemItem src, PsiFileSystemItem dst) {
  final PsiFileSystemItem commonAncestor = getCommonAncestor(src, dst);

  if (commonAncestor != null) {
    StringBuilder buffer = new StringBuilder();
    if (!src.equals(commonAncestor)) {
      while (!commonAncestor.equals(src.getParent())) {
        buffer.append("..").append('/');
        src = src.getParent();
        assert src != null;
      }
    }
    buffer.append(getRelativePathFromAncestor(dst, commonAncestor));
    return buffer.toString();
  }

  return null;
}
项目:intellij-ce-playground    文件:FileIncludeManagerImpl.java   
@Override
protected VirtualFile[] computeFiles(final PsiFile file, final boolean compileTimeOnly) {
  final Set<VirtualFile> files = new THashSet<VirtualFile>();
  processIncludes(file, new Processor<FileIncludeInfo>() {
    @Override
    public boolean process(FileIncludeInfo info) {
      if (compileTimeOnly != info.runtimeOnly) {
        PsiFileSystemItem item = resolveFileInclude(info, file);
        if (item != null) {
          ContainerUtil.addIfNotNull(files, item.getVirtualFile());
        }
      }
      return true;
    }

  });
  return VfsUtilCore.toVirtualFileArray(files);
}
项目:intellij-ce-playground    文件:PsiFileReferenceHelper.java   
static Collection<PsiFileSystemItem> getContextsForModule(@NotNull Module module, @NotNull String packageName, @Nullable GlobalSearchScope scope) {
  List<PsiFileSystemItem> result = null;
  Query<VirtualFile> query = DirectoryIndex.getInstance(module.getProject()).getDirectoriesByPackageName(packageName, false);
  PsiManager manager = null;

  for(VirtualFile file:query) {
    if (scope != null && !scope.contains(file)) continue;
    if (result == null) {
      result = new ArrayList<PsiFileSystemItem>();
      manager = PsiManager.getInstance(module.getProject());
    }
    PsiDirectory psiDirectory = manager.findDirectory(file);
    if (psiDirectory != null) result.add(psiDirectory);
  }

  return result != null ? result:Collections.<PsiFileSystemItem>emptyList();
}
项目:intellij    文件:BlazeCoverageAnnotator.java   
private boolean showCoverage(PsiFileSystemItem psiFile) {
  if (coverageFilePaths.isEmpty()) {
    return false;
  }
  VirtualFile vf = psiFile.getVirtualFile();
  if (vf == null) {
    return false;
  }
  String filePath = normalizeFilePath(vf.getPath());
  for (String path : coverageFilePaths) {
    if (filePath.startsWith(path)) {
      return true;
    }
  }
  return false;
}
项目:intellij-ce-playground    文件:FileTreeModelBuilder.java   
@Nullable
public PackageDependenciesNode findNode(PsiFileSystemItem file, final PsiElement psiElement) {
  if (file instanceof PsiDirectory) {
    return getModuleDirNode(file.getVirtualFile(), myFileIndex.getModuleForFile(file.getVirtualFile()), null);
  }
  PackageDependenciesNode parent = getFileParentNode(file.getVirtualFile());
  PackageDependenciesNode[] nodes = findNodeForPsiElement(parent, file);
  if (nodes == null || nodes.length == 0) {
    return null;
  }
  else {
    for (PackageDependenciesNode node : nodes) {
      if (node.getPsiElement() == psiElement) return node;
    }
    return nodes[0];
  }
}
项目:intellij-ce-playground    文件:AntDomProject.java   
@Nullable
public final PsiFileSystemItem getProjectBasedir() {
  final PsiFileSystemItem basedir = getBasedir().getValue();
  if (basedir != null) {
    return basedir;
  }
  final XmlTag tag = getXmlTag();
  final VirtualFile containingFile = tag.getContainingFile().getOriginalFile().getVirtualFile();
  if (containingFile == null) {
    return null;
  }
  final VirtualFile parent = containingFile.getParent();
  if (parent == null) {
    return null;
  }
  return tag.getManager().findDirectory(parent);
}
项目:intellij-ce-playground    文件:NewElementToolbarAction.java   
@Override
public void actionPerformed(AnActionEvent e) {
  if (e.getData(LangDataKeys.IDE_VIEW) == null) {
    final Project project = e.getData(CommonDataKeys.PROJECT);
    final PsiFileSystemItem psiFile = e.getData(CommonDataKeys.PSI_FILE).getParent();
    ProjectViewImpl.getInstance(project).selectCB(psiFile, psiFile.getVirtualFile(), true).doWhenDone(new Runnable() {
      @Override
      public void run() {
        showPopup(DataManager.getInstance().getDataContext());
      }
    });
  }
  else {
    super.actionPerformed(e);
  }
}
项目:intellij-ce-playground    文件:GotoFileItemProvider.java   
@Override
public boolean filterElements(@NotNull ChooseByNameBase base,
                              @NotNull String pattern,
                              boolean everywhere,
                              @NotNull ProgressIndicator indicator,
                              @NotNull Processor<Object> consumer) {
  if (pattern.contains("/") || pattern.contains("\\")) {
    String path = FileUtil.toSystemIndependentName(ChooseByNamePopup.getTransformedPattern(pattern, myModel));
    VirtualFile vFile = LocalFileSystem.getInstance().findFileByPathIfCached(path);
    if (vFile != null) {
      ProjectFileIndex index = ProjectFileIndex.SERVICE.getInstance(myProject);
      if (index.isInContent(vFile) || index.isInLibraryClasses(vFile) || index.isInLibrarySource(vFile)) {
        PsiFileSystemItem fileOrDir = vFile.isDirectory() ?
                                      PsiManager.getInstance(myProject).findDirectory(vFile) :
                                      PsiManager.getInstance(myProject).findFile(vFile);
        if (fileOrDir != null && !consumer.process(fileOrDir)) {
          return false;
        }
      }
    }
  }

  return super.filterElements(base, pattern, everywhere, indicator, consumer);
}
项目:intellij-ce-playground    文件:SearchEverywherePsiRenderer.java   
@Override
protected String getContainerText(PsiElement element, String name) {
  if (element instanceof PsiFileSystemItem) {
    PsiFileSystemItem parent = ((PsiFileSystemItem)element).getParent();
    final PsiDirectory psiDirectory = parent instanceof PsiDirectory ? (PsiDirectory)parent : null;
    VirtualFile virtualFile = psiDirectory == null ? null : psiDirectory.getVirtualFile();
    if (virtualFile == null) return null;
    final String relativePath = getRelativePath(virtualFile, element.getProject());
    if (relativePath == null) return "( " + File.separator + " )";
    int width = myList.getWidth();
    if (width == 0) width += 800;
    String path = FilePathSplittingPolicy.SPLIT_BY_SEPARATOR.getOptimalTextForComponent(name, new File(relativePath), this, width - myRightComponentWidth - 16 - 10);
    return "(" + path + ")";
  }
  return getSymbolContainerText(name, element);
}
项目:intellij-ce-playground    文件:ScratchProjectViewPane.java   
@Nullable
@Override
protected Collection<AbstractTreeNode> getChildrenImpl() {
  if (isAlwaysLeaf()) return Collections.emptyList();
  return ApplicationManager.getApplication().runReadAction(new Computable<Collection<AbstractTreeNode>>() {
    @Override
    public Collection<AbstractTreeNode> compute() {
      final PsiFileSystemItem value = getValue();
      if (value == null || !value.isValid()) return Collections.emptyList();
      final List<AbstractTreeNode> list = ContainerUtil.newArrayList();
      value.processChildren(new PsiElementProcessor<PsiFileSystemItem>() {
        @Override
        public boolean execute(@NotNull PsiFileSystemItem element) {
          if (!myRootType.isIgnored(value.getProject(), element.getVirtualFile())) {
            list.add(new MyPsiNode(value.getProject(), myRootType, element));
          }
          return true;
        }
      });
      return list;
    }
  });
}
项目:intellij-ce-playground    文件:AntDomDirname.java   
@Nullable
protected final String calcPropertyValue(String propertyName) {
  final PsiFileSystemItem fsItem = getFile().getValue();
  if (fsItem != null) {
    final PsiFileSystemItem parent = fsItem.getParent();
    if (parent != null) {
      final VirtualFile vFile = parent.getVirtualFile();
      if (vFile != null) {
        return FileUtil.toSystemDependentName(vFile.getPath());
      }
    }
  }
  // according to the doc, defaulting to project's current dir
  final String projectBasedirPath = getContextAntProject().getProjectBasedirPath();
  if (projectBasedirPath == null) {
    return null;
  }
  return FileUtil.toSystemDependentName(projectBasedirPath);
}
项目:intellij-ce-playground    文件:PyTemplateFileReferenceSet.java   
@NotNull
@Override
public Collection<PsiFileSystemItem> computeDefaultContexts() {
  List<PsiFileSystemItem> contexts = ContainerUtil.newArrayList();
  if (getPathString().startsWith("/") || getPathString().startsWith("\\")) {
    return contexts;
  }
  Module module = ModuleUtilCore.findModuleForPsiElement(getElement());
  if (module != null) {
    List<VirtualFile> templatesFolders = getRoots(module);
    for (VirtualFile folder : templatesFolders) {
      final PsiDirectory directory = PsiManager.getInstance(module.getProject()).findDirectory(folder);
      if (directory != null) {
        contexts.add(directory);
      }
    }
  }
  return contexts;
}
项目:intellij-ce-playground    文件:TemplateFileReferenceSet.java   
@NotNull
@Override
public Collection<PsiFileSystemItem> computeDefaultContexts() {
  List<PsiFileSystemItem> contexts = ContainerUtil.newArrayList();
  if (getPathString().startsWith("/") || getPathString().startsWith("\\")) {
    return contexts;
  }
  Module module = ModuleUtilCore.findModuleForPsiElement(getElement());
  if (module != null) {
    List<VirtualFile> templatesFolders = getRoots(module);
    for (VirtualFile folder : templatesFolders) {
      final PsiFileSystemItem directory = getPsiDirectory(module, folder);
      if (directory != null) {
        contexts.add(directory);
      }
    }
  }
  return contexts;
}
项目:intellij-ce-playground    文件:PyUserSkeletonsModuleMembersProvider.java   
@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();
}
项目:intellij-ce-playground    文件:PythonPsiManager.java   
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;
  }
}
项目:intellij    文件:GlobReferenceSearcher.java   
@Override
public void processQuery(SearchParameters queryParameters, Processor<PsiReference> consumer) {
  PsiFileSystemItem file =
      ResolveUtil.asFileSystemItemSearch(queryParameters.getElementToSearch());
  if (file == null) {
    return;
  }
  BlazePackage containingPackage = BlazePackage.getContainingPackage(file);
  if (containingPackage == null || !inScope(queryParameters, containingPackage.buildFile)) {
    return;
  }
  String relativePath = containingPackage.getRelativePathToChild(file.getVirtualFile());
  if (relativePath == null) {
    return;
  }

  List<GlobExpression> globs =
      PsiUtils.findAllChildrenOfClassRecursive(containingPackage.buildFile, GlobExpression.class);
  for (GlobExpression glob : globs) {
    if (glob.matches(relativePath, file.isDirectory())) {
      consumer.process(globReference(glob, file));
    }
  }
}
项目:manifold-ij    文件:RenameTypeManifoldFileProcessor.java   
private void storeTypeManifoldReferences( @NotNull PsiElement element )
{
  Module mod = ModuleUtilCore.findModuleForPsiElement( element );
  if( mod == null )
  {
    return;
  }

  ManModule module = ManProject.getModule( mod );

  PsiClass psiClass = findPsiClass( (PsiFileSystemItem)element, module );
  if( psiClass == null )
  {
    return;
  }

  Query<PsiReference> search = ReferencesSearch.search( psiClass, GlobalSearchScope.projectScope( mod.getProject() ) );
  List<UsageInfo> usages = new ArrayList<>();
  for( PsiReference ref: search.findAll() )
  {
    usages.add( new MoveRenameUsageInfo( ref.getElement(), ref, ref.getRangeInElement().getStartOffset(),
      ref.getRangeInElement().getEndOffset(), element,
      ref.resolve() == null && !(ref instanceof PsiPolyVariantReference && ((PsiPolyVariantReference)ref).multiResolve( true ).length > 0) ) );
  }
  _usages = usages;

  if( psiClass instanceof ManifoldPsiClass )
  {
    PsiElement fakeElement = ManGotoDeclarationHandler.find( psiClass, (ManifoldPsiClass)psiClass );
    if( fakeElement instanceof PsiNamedElement && isTopLevelClassDeclaration( fakeElement ) )
    {
      _classDeclElement = (PsiNamedElement)fakeElement;
    }
  }
}
项目:manifold-ij    文件:RenameTypeManifoldFileProcessor.java   
@Nullable
private PsiClass findPsiClass( @NotNull PsiFileSystemItem element, ManModule module )
{
  String[] fqns = module.getTypesForFile( FileUtil.toIFile( module.getProject(), element.getVirtualFile() ) );
  PsiClass psiClass = null;
  for( String fqn: fqns )
  {
    psiClass = ManifoldPsiClassCache.instance().getPsiClass( GlobalSearchScope.moduleWithDependenciesAndLibrariesScope( module.getIjModule() ), module, fqn );
    if( psiClass != null )
    {
      break;
    }
  }
  return psiClass;
}
项目:manifold-ij    文件:RenameTypeManifoldFileProcessor.java   
private void renameManifoldTypeRefs( PsiElement element, RefactoringElementListener elementListener )
{
  ApplicationManager.getApplication().invokeLater( () ->
    WriteCommandAction.runWriteCommandAction( element.getProject(), () ->
    {
      Module ijModule = ModuleUtilCore.findModuleForPsiElement( element );
      if( ijModule == null )
      {
        return;
      }

      ManModule module = ManProject.getModule( ijModule );
      PsiClass psiClass = findPsiClass( (PsiFileSystemItem)element, module );
      if( psiClass == null )
      {
        return;
      }

      RenameUtil.doRename( psiClass, psiClass.getName(), _usages.toArray( new UsageInfo[_usages.size()] ), element.getProject(), elementListener );

      // for plain text files, also rename a class name declaration if such a thing exists e.g., javascript class declaration
      if( _classDeclElement != null )
      {
        _classDeclElement.setName( psiClass.getName() == null ? "" : psiClass.getName() );
      }
    } ) );
}
项目:manifold-ij    文件:ResourceToManifoldUtil.java   
/**
 * Find the Manifold PisClass corresponding with a resource file.
 *
 * @param fileElem a psiFile, normally this should be a resource file
 *
 * @return The corresponding Manifold PsiClass or null
 */
public static PsiClass findPsiClass( PsiFileSystemItem fileElem )
{
  Project project = fileElem.getProject();
  ManProject manProject = ManProject.manProjectFrom( project );
  VirtualFile virtualFile = fileElem.getVirtualFile();
  if( virtualFile == null )
  {
    return null;
  }
  for( ManModule module : manProject.getModules() )
  {
    IjFile file = FileUtil.toIFile( manProject, virtualFile );
    Set<ITypeManifold> set = module.findTypeManifoldsFor( file );
    if( set != null )
    {
      for( ITypeManifold tf : set )
      {
        if( tf.getProducerKind() == ITypeManifold.ProducerKind.Primary )
        {
          String[] fqns = tf.getTypesForFile( file );
          for( String fqn : fqns )
          {
            PsiClass psiClass = ManifoldPsiClassCache.instance().getPsiClass( GlobalSearchScope.moduleWithDependenciesAndLibrariesScope( module.getIjModule() ), module, fqn );
            if( psiClass != null )
            {
              return psiClass;
            }
          }
        }
      }
    }
  }
  return null;
}
项目:intellij-ce-playground    文件:FilePathResolveTest.java   
public void testResolveFileReference() throws Exception {
  configureByFile(BASE_PATH + "C.java", BASE_PATH);
  FileIncludeManager fileIncludeManager = FileIncludeManager.getManager(getProject());
  PsiFileSystemItem item = fileIncludeManager.resolveFileInclude(new FileIncludeInfo("x/MyFile.txt"), getFile());
  assertNotNull(item);
  assertEquals("MyFile.txt", item.getName());
}
项目:intellij    文件:BuildEnterHandler.java   
private static PsiElement getBlockEndingParent(PsiElement element) {
  while (element != null && !(element instanceof PsiFileSystemItem)) {
    if (endsBlock(element)) {
      return element;
    }
    element = element.getParent();
  }
  return null;
}
项目:intellij-ce-playground    文件:MavenParentRelativePathConverter.java   
@NotNull
public PsiReference[] createReferences(final GenericDomValue genericDomValue, final PsiElement element, final ConvertContext context) {
  return new MavenPathReferenceConverter(new Condition<PsiFileSystemItem>() {
    @Override
    public boolean value(PsiFileSystemItem item) {
      return item.isDirectory() || item.getName().equals("pom.xml");
    }
  }).createReferences(genericDomValue, element, context);
}
项目:intellij-ce-playground    文件:AntDomProperty.java   
public PsiElement getNavigationElement(final String propertyName) {
  DomTarget domTarget = DomTarget.getTarget(this);
  if (domTarget == null) {
    final GenericAttributeValue<String> environment = getEnvironment();
    if (environment.getRawText() != null) {
      domTarget = DomTarget.getTarget(this, environment);
    }
    if (domTarget == null) {
      final GenericAttributeValue<String> resource = getResource();
      if (resource.getRawText() != null) {
        domTarget = DomTarget.getTarget(this, resource);
      }
    }
  }

  if (domTarget != null) {
    final PsiElement psi = PomService.convertToPsi(domTarget);
    if (psi != null) {
      return psi;
    }
  }

  final PsiFileSystemItem psiFile = getFile().getValue();
  if (psiFile != null) {
    final String prefix = getPropertyPrefixValue();
    String _propertyName = propertyName;
    if (prefix != null) {
      if (!propertyName.startsWith(prefix)) {
        return null;
      }
      _propertyName = propertyName.substring(prefix.length());
    }
    final PropertiesFile pf = toPropertiesFile(psiFile);
    if (pf != null) {
      final IProperty property = pf.findPropertyByKey(_propertyName);
      return property != null? property.getPsiElement() : null;
    }
  }
  return null;
}
项目:intellij-ce-playground    文件:FileReferenceHelperRegistrar.java   
public static <T extends PsiFileSystemItem> List<FileReferenceHelper> getHelpers(@NotNull final T psiFileSystemItem) {
  final VirtualFile file = psiFileSystemItem.getVirtualFile();
  if (file == null) return null;
  final Project project = psiFileSystemItem.getProject();
  return ContainerUtil.findAll(getHelpers(), new Condition<FileReferenceHelper>() {
    @Override
    public boolean value(final FileReferenceHelper fileReferenceHelper) {
      return fileReferenceHelper.isMine(project, file);
    }
  });
}
项目:intellij-ce-playground    文件:AntDomExtender.java   
@Nullable
private static PomTarget doFindDeclaration(DomElement parent, XmlName xmlName) {
  if (!(parent instanceof AntDomElement)) {
    return null;
  }
  final AntDomElement parentElement = (AntDomElement)parent;
  final AntDomProject antDomProject = parentElement.getAntProject();
  if (antDomProject == null) {
    return null;
  }
  final CustomAntElementsRegistry registry = CustomAntElementsRegistry.getInstance(antDomProject);
  final AntDomElement declaringElement = registry.findDeclaringElement(parentElement, xmlName);
  if (declaringElement == null) {
    return null;
  }
  DomTarget target = DomTarget.getTarget(declaringElement);
  if (target == null && declaringElement instanceof AntDomTypeDef) {
    final AntDomTypeDef typedef = (AntDomTypeDef)declaringElement;
    final GenericAttributeValue<PsiFileSystemItem> resource = typedef.getResource();
    if (resource != null) {
      target = DomTarget.getTarget(declaringElement, resource);
    }
    if (target == null) {
      final GenericAttributeValue<PsiFileSystemItem> file = typedef.getFile();
      if (file != null) {
        target = DomTarget.getTarget(declaringElement, file);
      }
    }
  }
  return target;
}
项目:intellij-ce-playground    文件:NullFileReferenceHelper.java   
@Override
@NotNull
public Collection<PsiFileSystemItem> getRoots(@NotNull final Module module) {
  return ContainerUtil.mapNotNull(ModuleRootManager.getInstance(module).getContentRoots(), new Function<VirtualFile, PsiFileSystemItem>() {
    @Override
    public PsiFileSystemItem fun(VirtualFile virtualFile) {
      return PsiManager.getInstance(module.getProject()).findDirectory(virtualFile);
    }
  });
}
项目:intellij-ce-playground    文件:NullFileReferenceHelper.java   
@Override
@NotNull
public Collection<PsiFileSystemItem> getContexts(final Project project, @NotNull final VirtualFile file) {
  final PsiFileSystemItem item = getPsiFileSystemItem(project, file);
  if (item != null) {
    final PsiFileSystemItem parent = item.getParent();
    if (parent != null) {
      return Collections.singleton(parent);
    }
  }
  return Collections.emptyList();
}
项目:intellij-ce-playground    文件:FilenameIndex.java   
public static boolean processFilesByName(@NotNull final String name,
                                         boolean includeDirs,
                                         @NotNull Processor<? super PsiFileSystemItem> processor,
                                         @NotNull GlobalSearchScope scope,
                                         @NotNull Project project,
                                         @Nullable IdFilter idFilter) {
  return processFilesByName(name, includeDirs, true, processor, scope, project, idFilter);
}
项目:intellij-ce-playground    文件:PsiFileSystemItemUtil.java   
@Nullable
public static String getRelativePathFromAncestor(PsiFileSystemItem file, PsiFileSystemItem ancestor) {
  int length = 0;
  PsiFileSystemItem parent = file;

  while (true) {
    if (parent == null) return null;
    if (parent.equals(ancestor)) break;
    if (length > 0) {
      length++;
    }
    length += parent.getName().length();
    parent = parent.getParent();
  }

  char[] chars = new char[length];
  int index = chars.length;
  parent = file;

  while (true) {
    if (parent.equals(ancestor)) break;
    if (index < length) {
      chars[--index] = '/';
    }
    String name = parent.getName();
    for (int i = name.length() - 1; i >= 0; i--) {
      chars[--index] = name.charAt(i);
    }
    parent = parent.getParent();
  }
  return StringFactory.createShared(chars);
}
项目:intellij    文件:ResolveUtil.java   
/**
 * Checks if the element we're searching for is represented by a file or directory.<br>
 * e.g. a java class PSI element, or an actual PsiFile element.
 */
@Nullable
public static PsiFileSystemItem asFileSystemItemSearch(PsiElement elementToSearch) {
  if (elementToSearch instanceof PsiFileSystemItem) {
    return (PsiFileSystemItem) elementToSearch;
  }
  return asFileSearch(elementToSearch);
}
项目:intellij-ce-playground    文件:FilePathCompletionContributor.java   
@Nullable
private String getRelativePath() {
  final VirtualFile virtualFile = myFile.getVirtualFile();
  LOG.assertTrue(virtualFile != null);
  for (FileReferenceHelper helper : myHelpers) {
    final PsiFileSystemItem root = helper.findRoot(myFile.getProject(), virtualFile);
    String path = PsiFileSystemItemUtil.getRelativePath(root, helper.getPsiFileSystemItem(myFile.getProject(), virtualFile));
    if (path != null) return path;
  }
  return null;
}
项目:intellij    文件:BuildEnterHandler.java   
private static boolean skipElement(PsiElement element, int offset) {
  PsiElement parent = element.getParent();
  if (parent == null || parent.getNode() == null || parent instanceof PsiFileSystemItem) {
    return false;
  }
  TextRange childRange = element.getNode().getTextRange();
  return childRange.equals(parent.getNode().getTextRange())
      || childRange.getStartOffset() == offset
          && (parent instanceof Argument || parent instanceof Parameter);
}
项目:intellij-ce-playground    文件:ImagePreviewComponent.java   
public static JComponent getPreviewComponent(@Nullable final PsiElement parent) {
  if (parent == null) {
    return null;
  }
  final PsiReference[] references = parent.getReferences();
  for (final PsiReference reference : references) {
    final PsiElement fileItem = reference.resolve();
    if (fileItem instanceof PsiFileSystemItem) {
      final PsiFileSystemItem item = (PsiFileSystemItem)fileItem;
      if (!item.isDirectory()) {
        final VirtualFile file = item.getVirtualFile();
        if (file != null && supportedExtensions.contains(file.getExtension())) {
          try {
            refresh(file);
            SoftReference<BufferedImage> imageRef = file.getUserData(BUFFERED_IMAGE_REF_KEY);
            final BufferedImage image = SoftReference.dereference(imageRef);
            if (image != null) {
              return new ImagePreviewComponent(image, file.getLength());
            }
          }
          catch (IOException ignored) {
            // nothing
          }
        }
      }
    }
  }

  return null;
}
项目:intellij    文件:BlazeCoverageEngine.java   
@Nullable
private static PsiFileSystemItem resolveFile(Project project, @Nullable File file) {
  if (file == null) {
    return null;
  }
  PsiManager manager = PsiManager.getInstance(project);
  VirtualFile vf =
      VirtualFileSystemProvider.getInstance().getSystem().findFileByPath(file.getPath());
  if (vf == null) {
    return null;
  }
  return vf.isDirectory() ? manager.findDirectory(vf) : manager.findFile(vf);
}
项目:intellij    文件:GlobReference.java   
@Override
protected ResolveResult[] resolveInner(boolean incompleteCode, PsiFile containingFile) {
  File containingDirectory = ((BuildFile) containingFile).getFile().getParentFile();
  if (containingDirectory == null) {
    return ResolveResult.EMPTY_ARRAY;
  }
  List<String> includes = resolveListContents(element.getIncludes());
  List<String> excludes = resolveListContents(element.getExcludes());
  boolean directoriesExcluded = element.areDirectoriesExcluded();
  if (includes.isEmpty()) {
    return ResolveResult.EMPTY_ARRAY;
  }
  Project project = element.getProject();
  try {
    List<File> files =
        UnixGlob.forPath(containingDirectory)
            .addPatterns(includes)
            .addExcludes(excludes)
            .setExcludeDirectories(directoriesExcluded)
            .setDirectoryFilter(directoryFilter(project, containingDirectory.getPath()))
            .glob();

    List<ResolveResult> results = Lists.newArrayListWithCapacity(files.size());
    for (File file : files) {
      PsiFileSystemItem psiFile = BuildReferenceManager.getInstance(project).resolveFile(file);
      if (psiFile != null) {
        results.add(new PsiElementResolveResult(psiFile));
      }
    }
    return results.toArray(ResolveResult.EMPTY_ARRAY);

  } catch (Exception e) {
    return ResolveResult.EMPTY_ARRAY;
  }
}