本文整理汇总了Java中org.jetbrains.plugins.groovy.lang.psi.GroovyFile.getTypeDefinitions方法的典型用法代码示例。如果您正苦于以下问题:Java GroovyFile.getTypeDefinitions方法的具体用法?Java GroovyFile.getTypeDefinitions怎么用?Java GroovyFile.getTypeDefinitions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jetbrains.plugins.groovy.lang.psi.GroovyFile
的用法示例。
在下文中一共展示了GroovyFile.getTypeDefinitions方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getIcon
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; //导入方法依赖的package包/类
@Nullable
@Override
public Icon getIcon(@NotNull VirtualFile virtualFile, @Iconable.IconFlags int flags, @Nullable Project project) {
if (project == null || virtualFile.getFileType() != GroovyFileType.GROOVY_FILE_TYPE) return null;
final PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile);
if (!(psiFile instanceof GroovyFile)) return null;
final GroovyFile file = (GroovyFile)psiFile;
final Icon icon;
if (file.isScript()) {
icon = GroovyScriptTypeDetector.getIcon(file);
}
else if (GrFileIndexUtil.isGroovySourceFile(file)) {
final GrTypeDefinition[] typeDefinitions = file.getTypeDefinitions();
icon = typeDefinitions.length > 0
? typeDefinitions[0].getIcon(flags)
: JetgroovyIcons.Groovy.Groovy_16x16;
}
else {
icon = JetgroovyIcons.Groovy.Groovy_outsideSources;
}
return ElementBase.createLayeredIcon(psiFile, icon, ElementBase.transformFlags(psiFile, flags));
}
示例2: isSemiColonUnnecessaryInClassBody
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; //导入方法依赖的package包/类
private static boolean isSemiColonUnnecessaryInClassBody(PsiElement semicolon, String text, Project project) {
final GrMembersDeclaration prev = getPreviousStatement(semicolon, GrMembersDeclaration.class);
final GrMembersDeclaration next = getNextStatement(semicolon, GrMembersDeclaration.class);
if (prev == null || next == null) return true;
final int startOffset = prev.getTextRange().getStartOffset();
final int endOffset = next.getTextRange().getEndOffset();
final int offset = semicolon.getTextRange().getStartOffset();
final String declarationsWithoutSemicolon = text.substring(startOffset, offset) + text.substring(offset + 1, endOffset);
PsiElement parent = semicolon.getParent().getParent();
String prefix = parent instanceof GrClassDefinition ? "class":
parent instanceof GrEnumTypeDefinition ? "enum":
parent instanceof GrInterfaceDefinition ? "interface":
parent instanceof GrAnnotationTypeDefinition ? "@interface":
parent instanceof GrAnonymousClassDefinition ? "class":
"class";
final GroovyFile file = GroovyPsiElementFactory.getInstance(project).createGroovyFile(prefix + " Name {\n" + declarationsWithoutSemicolon + "\n}", false, null);
GrTypeDefinition[] typeDefs = file.getTypeDefinitions();
if (typeDefs.length != 1) return false;
GrTypeDefinition clazz = typeDefs[0];
GrMembersDeclaration[] declarations = clazz.getMemberDeclarations();
if (declarations.length != 2) return false;
return checkStatementsAreEqual(prev, declarations[0]) &&
checkStatementsAreEqual(next, declarations[1]);
}
示例3: processIntention
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; //导入方法依赖的package包/类
@Override
protected void processIntention(@NotNull PsiElement element, Project project, Editor editor) throws IncorrectOperationException {
final GrTypeDefinition psiClass = (GrTypeDefinition)element.getParent();
final String name = psiClass.getName();
final PsiFile file = psiClass.getContainingFile();
final String fileExtension = FileUtilRt.getExtension(file.getName());
final String newFileName = name + "." + fileExtension;
final PsiDirectory dir = file.getParent();
if (dir != null) {
if (dir.findFile(newFileName) != null) {
if (!ApplicationManager.getApplication().isUnitTestMode()) {
final String message = GroovyIntentionsBundle.message("file.exists", newFileName, dir.getName());
CommonRefactoringUtil.showErrorHint(project, editor, message, getFamilyName(), null);
}
return;
}
}
final GroovyFile newFile = (GroovyFile)GroovyTemplatesFactory.createFromTemplate(dir, name, newFileName, GroovyTemplates.GROOVY_CLASS,
true);
final GrTypeDefinition template = newFile.getTypeDefinitions()[0];
final PsiElement newClass = template.replace(psiClass);
final GrDocComment docComment = psiClass.getDocComment();
if (newClass instanceof GrTypeDefinition && docComment != null) {
final GrDocComment newDoc = ((GrTypeDefinition)newClass).getDocComment();
if (newDoc != null) {
newDoc.replace(docComment);
}
else {
final PsiElement parent = newClass.getParent();
parent.addBefore(docComment, psiClass);
parent.getNode().addLeaf(GroovyTokenTypes.mNLS, "\n", psiClass.getNode());
}
docComment.delete();
}
psiClass.delete();
IntentionUtils.positionCursor(project, newClass.getContainingFile(), newClass.getNavigationElement());
}
示例4: getTargetClass
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; //导入方法依赖的package包/类
@Nullable
private static PsiClass getTargetClass(String qualifiedName, PsiDirectory baseDirectory, Project project, Module module) {
GlobalSearchScope scope = GlobalSearchScope.projectScope(project);
PsiClass targetClass = JavaPsiFacade.getInstance(project).findClass(qualifiedName, scope);
if (targetClass != null) return targetClass;
final String packageName = StringUtil.getPackageName(qualifiedName);
PsiPackage psiPackage = JavaPsiFacade.getInstance(project).findPackage(packageName);
final PsiDirectory psiDirectory;
if (psiPackage != null) {
final PsiDirectory[] directories = psiPackage.getDirectories(GlobalSearchScope.allScope(project));
psiDirectory = directories.length > 1 ? DirectoryChooserUtil
.chooseDirectory(directories, null, project, new HashMap<PsiDirectory, String>()) : directories[0];
}
else {
psiDirectory = PackageUtil.findOrCreateDirectoryForPackage(module, packageName, baseDirectory, false);
}
if (psiDirectory == null) return null;
final String shortName = StringUtil.getShortName(qualifiedName);
final String fileName = shortName + NewGroovyActionBase.GROOVY_EXTENSION;
final AccessToken lock = ApplicationManager.getApplication().acquireWriteActionLock(GrIntroduceConstantDialog.class);
try {
final GroovyFile file =
(GroovyFile)GroovyTemplatesFactory.createFromTemplate(psiDirectory, shortName, fileName, GroovyTemplates.GROOVY_CLASS, true);
return file.getTypeDefinitions()[0];
}
finally {
lock.finish();
}
}