本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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() + "'");
}
}
示例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() + "'");
}
}