Java Code Examples for com.intellij.psi.PsiDirectory#equals()

The following examples show how to use com.intellij.psi.PsiDirectory#equals() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NeosUtil.java    From intellij-neos with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Collect all parent directories until a directory named "Fusion" is found.
 * If none is found, return an empty array.
 */
public static ArrayList<PsiDirectory> getParentFusionDirectories(PsiDirectory currentDirectory) {
    if (currentDirectory == null) {
        return null;
    }

    PsiFile composerManifest = ComposerUtil.getComposerManifest(currentDirectory);
    PsiDirectory packageDirectory = null;
    if (composerManifest != null) {
        packageDirectory = composerManifest.getContainingDirectory();
    }

    ArrayList<PsiDirectory> parentDirectories = new ArrayList<>();
    boolean fusionDirectoryExists = false;

    do {
        parentDirectories.add(currentDirectory);
        currentDirectory = currentDirectory.getParentDirectory();

        if (currentDirectory != null && currentDirectory.getName().equals("Fusion")) {
            fusionDirectoryExists = true;
        }
    } while (currentDirectory != null
            && !currentDirectory.getName().equals("Fusion")
            && !currentDirectory.equals(packageDirectory)
            && !currentDirectory.equals(guessProjectDir(currentDirectory.getProject())));

    if (!fusionDirectoryExists) {
        return new ArrayList<>();
    }

    return parentDirectories;
}
 
Example 2
Source File: ComposerUtil.java    From intellij-neos with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
public static JsonFile getComposerManifest(PsiDirectory currentDirectory) {
    if (currentDirectory == null) {
        return null;
    }

    JsonFile composerFile;
    do {
        composerFile = getComposerManifestInDirectory(currentDirectory);
        currentDirectory = currentDirectory.getParentDirectory();
    } while (composerFile == null && currentDirectory != null && !currentDirectory.equals(guessProjectDir(currentDirectory.getProject())));

    return composerFile;
}
 
Example 3
Source File: SameDirectoryWeigher.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Comparable weigh(@Nonnull final PsiElement element, @Nonnull final ProximityLocation location) {
  if (location.getPosition() == null){
    return null;
  }
  final PsiDirectory placeDirectory = PLACE_DIRECTORY.getValue(location);
  if (placeDirectory == null) {
    return false;
  }

  return placeDirectory.equals(PsiTreeUtil.getParentOfType(element, PsiDirectory.class, false));
}
 
Example 4
Source File: DirectoryChooser.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static boolean isParent(PsiDirectory directory, PsiDirectory parentCandidate) {
  while (directory != null) {
    if (directory.equals(parentCandidate)) return true;
    directory = directory.getParentDirectory();
  }
  return false;
}
 
Example 5
Source File: MoveDirectoryWithClassesProcessor.java    From consulo with Apache License 2.0 5 votes vote down vote up
public MoveDirectoryWithClassesProcessor(Project project,
                                         PsiDirectory[] directories,
                                         PsiDirectory targetDirectory,
                                         boolean searchInComments,
                                         boolean searchInNonJavaFiles,
                                         boolean includeSelf,
                                         MoveCallback moveCallback) {
  super(project);
  if (targetDirectory != null) {
    final List<PsiDirectory> dirs = new ArrayList<PsiDirectory>(Arrays.asList(directories));
    for (Iterator<PsiDirectory> iterator = dirs.iterator(); iterator.hasNext(); ) {
      final PsiDirectory directory = iterator.next();
      if (targetDirectory.equals(directory.getParentDirectory()) || targetDirectory.equals(directory)) {
        iterator.remove();
      }
    }
    directories = dirs.toArray(new PsiDirectory[dirs.size()]);
  }
  myDirectories = directories;
  myTargetDirectory = targetDirectory;
  mySearchInComments = searchInComments;
  mySearchInNonJavaFiles = searchInNonJavaFiles;
  myMoveCallback = moveCallback;
  myFilesToMove = new HashMap<PsiFile, TargetDirectoryWrapper>();
  for (PsiDirectory dir : directories) {
    collectFiles2Move(myFilesToMove, dir, includeSelf ? dir.getParentDirectory() : dir, getTargetDirectory(dir));
  }
}