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


Java JavaDirectoryServiceImpl类代码示例

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


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

示例1: isMoveRedundant

import com.intellij.psi.impl.file.JavaDirectoryServiceImpl; //导入依赖的package包/类
@Override
public boolean isMoveRedundant(PsiElement source, PsiElement target) {
  if (target instanceof PsiDirectory && source instanceof PsiClass) {
    try {
      JavaDirectoryServiceImpl.checkCreateClassOrInterface((PsiDirectory)target, ((PsiClass)source).getName());
    }
    catch (IncorrectOperationException e) {
      return true;
    }
  }
  if (target instanceof PsiPackage && source instanceof PsiClass) {
    final GlobalSearchScope globalSearchScope = GlobalSearchScope.projectScope(source.getProject());
    return ((PsiPackage)target).findClassByShortName(((PsiClass)source).getName(), globalSearchScope).length > 0;
  }
  if (target instanceof PsiDirectory && source instanceof PsiDirectory) {
    final PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage((PsiDirectory)source);
    if (aPackage != null && !MoveClassesOrPackagesImpl.checkNesting(target.getProject(), aPackage, target, false)) return true;
  }
  return super.isMoveRedundant(source, target);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:JavaMoveClassesOrPackagesHandler.java

示例2: isMoveRedundant

import com.intellij.psi.impl.file.JavaDirectoryServiceImpl; //导入依赖的package包/类
@Override
public boolean isMoveRedundant(PsiElement source, PsiElement target) {
  if (target instanceof PsiDirectory && source instanceof PsiClass) {
    try {
      JavaDirectoryServiceImpl.checkCreateClassOrInterface((PsiDirectory)target, ((PsiClass)source).getName());
    }
    catch (IncorrectOperationException e) {
      return true;
    }
  }
  if (target instanceof PsiDirectory && source instanceof PsiDirectory) {
    final PsiPackage aPackage = JavaDirectoryServiceImpl.getInstance().getPackage((PsiDirectory)source);
    if (aPackage != null && !MoveClassesOrPackagesImpl.checkNesting(target.getProject(), aPackage, target, false)) return true;
  }
  return super.isMoveRedundant(source, target);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:17,代码来源:JavaMoveClassesOrPackagesHandler.java

示例3: isMoveRedundant

import com.intellij.psi.impl.file.JavaDirectoryServiceImpl; //导入依赖的package包/类
@Override
public boolean isMoveRedundant(PsiElement source, PsiElement target)
{
	if(target instanceof PsiDirectory && source instanceof PsiClass)
	{
		try
		{
			JavaDirectoryServiceImpl.checkCreateClassOrInterface((PsiDirectory) target, ((PsiClass) source).getName());
		}
		catch(IncorrectOperationException e)
		{
			return true;
		}
	}
	if(target instanceof PsiDirectory && source instanceof PsiDirectory)
	{
		final PsiJavaPackage aPackage = JavaDirectoryServiceImpl.getInstance().getPackage((PsiDirectory) source);
		if(aPackage != null && !MoveClassesOrPackagesImpl.checkNesting(target.getProject(), aPackage, target, false))
		{
			return true;
		}
	}
	return super.isMoveRedundant(source, target);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:25,代码来源:JavaMoveClassesOrPackagesHandler.java

示例4: isAvailable

import com.intellij.psi.impl.file.JavaDirectoryServiceImpl; //导入依赖的package包/类
@Override
public boolean isAvailable(@NotNull Project project, @Nullable Editor editor, @NotNull PsiFile file) {
  if  (!myClass.isValid() || !myClass.getManager().isInProject(myClass)) return false;
  PsiDirectory dir = file.getContainingDirectory();
  if (dir == null) return false;
  try {
    JavaDirectoryServiceImpl.checkCreateClassOrInterface(dir, myClass.getName());
  }
  catch (IncorrectOperationException e) {
    return false;
  }

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

示例5: obtainContainingFile

import com.intellij.psi.impl.file.JavaDirectoryServiceImpl; //导入依赖的package包/类
@Nullable
private static PsiFile obtainContainingFile(@NotNull PsiElement element, PsiElement[] elements) {
  final PsiFile containingFile = element.getContainingFile();
  final PsiClass[] classes = ((PsiClassOwner)containingFile).getClasses();
  final Set<PsiClass> nonMovedClasses = new HashSet<PsiClass>();
  for (PsiClass aClass : classes) {
    if (ArrayUtilRt.find(elements, aClass) < 0) {
      nonMovedClasses.add(aClass);
    }
  }
  if (nonMovedClasses.isEmpty()) {
    return containingFile;
  }
  else {
    final PsiDirectory containingDirectory = containingFile.getContainingDirectory();
    if (containingDirectory != null) {
      try {
        JavaDirectoryServiceImpl.checkCreateClassOrInterface(containingDirectory, ((PsiClass)element).getName());
        final PsiElement createdClass = containingDirectory.add(element);
        element.delete();
        return createdClass.getContainingFile();
      }
      catch (IncorrectOperationException e) {
        final Iterator<PsiClass> iterator = nonMovedClasses.iterator();
        final PsiClass nonMovedClass = iterator.next();
        final PsiElement createdFile = containingDirectory.add(nonMovedClass).getContainingFile();
        nonMovedClass.delete();
        while (iterator.hasNext()) {
          final PsiClass currentClass = iterator.next();
          createdFile.add(currentClass);
          currentClass.delete();
        }
        return containingFile;
      }
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:39,代码来源:JavaMoveFilesOrDirectoriesHandler.java

示例6: obtainContainingFile

import com.intellij.psi.impl.file.JavaDirectoryServiceImpl; //导入依赖的package包/类
@Nullable
private static PsiFile obtainContainingFile(@NotNull PsiElement element, PsiElement[] elements) {
  final PsiClass[] classes = ((PsiClassOwner)element.getParent()).getClasses();
  final Set<PsiClass> nonMovedClasses = new HashSet<PsiClass>();
  for (PsiClass aClass : classes) {
    if (ArrayUtilRt.find(elements, aClass) < 0) {
      nonMovedClasses.add(aClass);
    }
  }
  final PsiFile containingFile = element.getContainingFile();
  if (nonMovedClasses.isEmpty()) {
    return containingFile;
  }
  else {
    final PsiDirectory containingDirectory = containingFile.getContainingDirectory();
    if (containingDirectory != null) {
      try {
        JavaDirectoryServiceImpl.checkCreateClassOrInterface(containingDirectory, ((PsiClass)element).getName());
        final PsiElement createdClass = containingDirectory.add(element);
        element.delete();
        return createdClass.getContainingFile();
      }
      catch (IncorrectOperationException e) {
        final Iterator<PsiClass> iterator = nonMovedClasses.iterator();
        final PsiClass nonMovedClass = iterator.next();
        final PsiElement createdFile = containingDirectory.add(nonMovedClass).getContainingFile();
        nonMovedClass.delete();
        while (iterator.hasNext()) {
          final PsiClass currentClass = iterator.next();
          createdFile.add(currentClass);
          currentClass.delete();
        }
        return containingFile;
      }
    }
  }
  return null;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:39,代码来源:JavaMoveFilesOrDirectoriesHandler.java

示例7: obtainContainingFile

import com.intellij.psi.impl.file.JavaDirectoryServiceImpl; //导入依赖的package包/类
@Nullable
private static PsiFile obtainContainingFile(PsiElement element, PsiElement[] elements) {
  final PsiClass[] classes = ((PsiClassOwner)element.getParent()).getClasses();
  final Set<PsiClass> nonMovedClasses = new HashSet<PsiClass>();
  for (PsiClass aClass : classes) {
    if (ArrayUtil.find(elements, aClass) < 0) {
      nonMovedClasses.add(aClass);
    }
  }
  final PsiFile containingFile = element.getContainingFile();
  if (nonMovedClasses.isEmpty()) {
    return containingFile;
  }
  else {
    final PsiDirectory containingDirectory = containingFile.getContainingDirectory();
    if (containingDirectory != null) {
      try {
        JavaDirectoryServiceImpl.checkCreateClassOrInterface(containingDirectory, ((PsiClass)element).getName());
        final PsiElement createdClass = containingDirectory.add(element);
        element.delete();
        return createdClass.getContainingFile();
      }
      catch (IncorrectOperationException e) {
        final Iterator<PsiClass> iterator = nonMovedClasses.iterator();
        final PsiClass nonMovedClass = iterator.next();
        final PsiElement createdFile = containingDirectory.add(nonMovedClass).getContainingFile();
        nonMovedClass.delete();
        while (iterator.hasNext()) {
          final PsiClass currentClass = iterator.next();
          createdFile.add(currentClass);
          currentClass.delete();
        }
        return containingFile;
      }
    }
  }
  return null;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:39,代码来源:JavaMoveFilesOrDirectoriesHandler.java

示例8: createClassOrInterface

import com.intellij.psi.impl.file.JavaDirectoryServiceImpl; //导入依赖的package包/类
public static PsiClass createClassOrInterface(Project project,
                                              PsiDirectory directory,
                                              String content,
                                              boolean reformat,
                                              String extension) throws IncorrectOperationException {
  if (extension == null) extension = StdFileTypes.JAVA.getDefaultExtension();
  final String name = "myClass" + "." + extension;
  final PsiFile psiFile = PsiFileFactory.getInstance(project).createFileFromText(name, StdFileTypes.JAVA, content);
  if (!(psiFile instanceof PsiJavaFile)){
    throw new IncorrectOperationException("This template did not produce a Java class or an interface\n"+psiFile.getText());
  }
  PsiJavaFile psiJavaFile = (PsiJavaFile)psiFile;
  final PsiClass[] classes = psiJavaFile.getClasses();
  if (classes.length == 0) {
    throw new IncorrectOperationException("This template did not produce a Java class or an interface\n"+psiFile.getText());
  }
  PsiClass createdClass = classes[0];
  if(reformat){
    CodeStyleManager.getInstance(project).reformat(psiJavaFile);
  }
  String className = createdClass.getName();
  JavaDirectoryServiceImpl.checkCreateClassOrInterface(directory, className);

  final LanguageLevel ll = JavaDirectoryService.getInstance().getLanguageLevel(directory);
  if (ll.compareTo(LanguageLevel.JDK_1_5) < 0) {
    if (createdClass.isAnnotationType()) {
      throw new IncorrectOperationException("Annotations only supported at language level 1.5 and higher");
    }

    if (createdClass.isEnum()) {
      throw new IncorrectOperationException("Enums only supported at language level 1.5 and higher");
    }
  }

  psiJavaFile = (PsiJavaFile)psiJavaFile.setName(className + "." + extension);
  PsiElement addedElement = directory.add(psiJavaFile);
  if (addedElement instanceof PsiJavaFile) {
    psiJavaFile = (PsiJavaFile)addedElement;

    return psiJavaFile.getClasses()[0];
  }
  else {
    PsiFile containingFile = addedElement.getContainingFile();
    throw new IncorrectOperationException("Selected class file name '" +
                                          containingFile.getName() +  "' mapped to not java file type '"+
                                          containingFile.getFileType().getDescription() + "'");
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:49,代码来源:JavaCreateFromTemplateHandler.java

示例9: createClassOrInterface

import com.intellij.psi.impl.file.JavaDirectoryServiceImpl; //导入依赖的package包/类
public static PsiClass createClassOrInterface(Project project,
                                              PsiDirectory directory,
                                              String content,
                                              boolean reformat,
                                              String extension) throws IncorrectOperationException {
  if (extension == null) extension = StdFileTypes.JAVA.getDefaultExtension();
  final String name = "myClass" + "." + extension;
  final FileType type = FileTypeRegistry.getInstance().getFileTypeByFileName(name);
  final PsiFile psiFile = PsiFileFactory.getInstance(project).createFileFromText(name, type, content);
  if (!(psiFile instanceof PsiJavaFile)){
    throw new IncorrectOperationException("This template did not produce a Java class or an interface\n"+psiFile.getText());
  }
  PsiJavaFile psiJavaFile = (PsiJavaFile)psiFile;
  final PsiClass[] classes = psiJavaFile.getClasses();
  if (classes.length == 0) {
    throw new IncorrectOperationException("This template did not produce a Java class or an interface\n"+psiFile.getText());
  }
  PsiClass createdClass = classes[0];
  if(reformat){
    CodeStyleManager.getInstance(project).reformat(psiJavaFile);
  }
  String className = createdClass.getName();
  JavaDirectoryServiceImpl.checkCreateClassOrInterface(directory, className);

  final LanguageLevel ll = JavaDirectoryService.getInstance().getLanguageLevel(directory);
  if (ll.compareTo(LanguageLevel.JDK_1_5) < 0) {
    if (createdClass.isAnnotationType()) {
      throw new IncorrectOperationException("Annotations only supported at language level 1.5 and higher");
    }

    if (createdClass.isEnum()) {
      throw new IncorrectOperationException("Enums only supported at language level 1.5 and higher");
    }
  }

  psiJavaFile = (PsiJavaFile)psiJavaFile.setName(className + "." + extension);
  PsiElement addedElement = directory.add(psiJavaFile);
  if (addedElement instanceof PsiJavaFile) {
    psiJavaFile = (PsiJavaFile)addedElement;

    return psiJavaFile.getClasses()[0];
  }
  else {
    PsiFile containingFile = addedElement.getContainingFile();
    throw new IncorrectOperationException("Selected class file name '" +
                                          containingFile.getName() +  "' mapped to not java file type '"+
                                          containingFile.getFileType().getDescription() + "'");
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:50,代码来源:JavaCreateFromTemplateHandler.java


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