本文整理汇总了Java中org.jetbrains.plugins.groovy.lang.psi.GroovyFile.getPackageDefinition方法的典型用法代码示例。如果您正苦于以下问题:Java GroovyFile.getPackageDefinition方法的具体用法?Java GroovyFile.getPackageDefinition怎么用?Java GroovyFile.getPackageDefinition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jetbrains.plugins.groovy.lang.psi.GroovyFile
的用法示例。
在下文中一共展示了GroovyFile.getPackageDefinition方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getElementToHighlight
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; //导入方法依赖的package包/类
@Nullable
private static PsiElement getElementToHighlight(GroovyFile file) {
GrPackageDefinition packageDefinition = file.getPackageDefinition();
if (packageDefinition != null) return packageDefinition;
PsiClass[] classes = file.getClasses();
for (PsiClass aClass : classes) {
if (!(aClass instanceof SyntheticElement) && aClass instanceof GrTypeDefinition) {
return ((GrTypeDefinition)aClass).getNameIdentifierGroovy();
}
}
GrTopStatement[] statements = file.getTopStatements();
if (statements.length > 0) {
GrTopStatement first = statements[0];
if (first instanceof GrNamedElement) return ((GrNamedElement)first).getNameIdentifierGroovy();
return first;
}
return null;
}
示例2: setPackageDefinition
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; //导入方法依赖的package包/类
private static void setPackageDefinition(GroovyFile file, GroovyFile newFile, String newPackageName) {
String modifiersText = null;
final GrPackageDefinition packageDefinition = file.getPackageDefinition();
if (packageDefinition != null) {
final PsiModifierList modifierList = packageDefinition.getModifierList();
if (modifierList != null) {
modifiersText = modifierList.getText().trim();
}
}
if (modifiersText != null && !modifiersText.isEmpty()) {
final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(file.getProject());
final GrPackageDefinition newPackageDefinition = (GrPackageDefinition)factory.createTopElementFromText(modifiersText + " package " + newPackageName);
newFile.setPackage(newPackageDefinition);
}
else {
newFile.setPackageName(newPackageName);
}
}
示例3: GrFileStub
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; //导入方法依赖的package包/类
public GrFileStub(GroovyFile file) {
super(file);
myName = StringRef.fromString(file.getViewProvider().getVirtualFile().getNameWithoutExtension());
isScript = file.isScript();
final GrPackageDefinition definition = file.getPackageDefinition();
if (definition != null) {
myAnnotations = GrStubUtils.getAnnotationNames(definition);
} else {
myAnnotations = ArrayUtil.EMPTY_STRING_ARRAY;
}
}
示例4: suggestPackage
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; //导入方法依赖的package包/类
private static boolean suggestPackage(PsiElement context) {
if (context.getParent() != null &&
!(context.getParent() instanceof PsiErrorElement) &&
context.getParent().getParent() instanceof GroovyFile &&
((GroovyFile) context.getParent().getParent()).getPackageDefinition() == null) {
if (context.getParent() instanceof GrReferenceExpression) {
return true;
}
if (context.getParent() instanceof GrApplicationStatement &&
((GrApplicationStatement) context.getParent()).getExpressionArguments()[0] instanceof GrReferenceExpression) {
return true;
}
return false;
}
if (context.getTextRange().getStartOffset() == 0 && !(context instanceof OuterLanguageElement)) {
return true;
}
final PsiElement leaf = GroovyCompletionUtil.getLeafByOffset(context.getTextRange().getStartOffset() - 1, context);
if (leaf != null) {
PsiElement parent = leaf.getParent();
if (parent instanceof GroovyFile) {
GroovyFile groovyFile = (GroovyFile) parent;
if (groovyFile.getPackageDefinition() == null) {
return GroovyCompletionUtil.isNewStatement(context, false);
}
}
}
return false;
}
示例5: getAnchorToInsertImportAfter
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; //导入方法依赖的package包/类
@Nullable
private PsiElement getAnchorToInsertImportAfter(@NotNull GroovyFile psiFile, @NotNull GrImportStatement statement) {
final GroovyCodeStyleSettings settings = CodeStyleSettingsManager.getInstance(psiFile.getProject()).getCurrentSettings().getCustomSettings(
GroovyCodeStyleSettings.class);
final PackageEntryTable layoutTable = settings.IMPORT_LAYOUT_TABLE;
final PackageEntry[] entries = layoutTable.getEntries();
GrImportStatement[] importStatements = psiFile.getImportStatements();
if (importStatements.length == 0) {
final GrPackageDefinition definition = psiFile.getPackageDefinition();
if (definition != null) {
return definition;
}
return getShellComment(psiFile);
}
final Comparator<GrImportStatement> comparator = GroovyImportOptimizer.getComparator(settings);
final int idx = getPackageEntryIdx(entries, statement);
PsiElement anchor = null;
for (GrImportStatement importStatement : importStatements) {
final int i = getPackageEntryIdx(entries, importStatement);
if (i < idx) {
anchor = importStatement;
}
else if (i > idx) {
break;
}
else if (comparator.compare(statement, importStatement) > 0) {
anchor = importStatement;
}
else {
break;
}
}
if (anchor == null) anchor = psiFile.getPackageDefinition();
if (anchor == null) anchor = getShellComment(psiFile);
if (anchor == null && importStatements.length > 0) anchor = importStatements[0].getPrevSibling();
return anchor;
}
示例6: generateNewScript
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; //导入方法依赖的package包/类
private static GroovyFile generateNewScript(GroovyFile file, PsiPackage newPackage) {
for (GrImportStatement importStatement : file.getImportStatements()) {
importStatement.delete();
}
final GroovyFile newFile = GroovyPsiElementFactory.getInstance(file.getProject()).createGroovyFile("", true, null);
newFile.addRange(file.getFirstChild(), file.getLastChild());
final PsiClass[] newFileClasses = newFile.getClasses();
for (PsiClass psiClass : newFileClasses) {
if (psiClass instanceof GroovyScriptClass) continue;
final GrDocComment docComment = GrDocCommentUtil.findDocComment((GrDocCommentOwner)psiClass);
if (docComment != null) docComment.delete();
psiClass.delete();
}
final GrPackageDefinition packageDefinition = newFile.getPackageDefinition();
if (packageDefinition != null) packageDefinition.delete();
PsiElement cur = newFile.getFirstChild();
while (cur != null && PsiImplUtil.isWhiteSpaceOrNls(cur)) {
cur = cur.getNextSibling();
}
if (cur != null && cur != newFile.getFirstChild()) {
cur = cur.getPrevSibling();
newFile.deleteChildRange(newFile.getFirstChild(), cur);
}
cur = newFile.getLastChild();
while (cur != null && PsiImplUtil.isWhiteSpaceOrNls(cur)) {
cur = cur.getPrevSibling();
}
if (cur != null && cur != newFile.getLastChild()) {
cur = cur.getNextSibling();
newFile.deleteChildRange(cur, newFile.getLastChild());
}
newFile.setName(file.getName());
setPackageDefinition(file, newFile, newPackage.getQualifiedName());
GroovyChangeContextUtil.decodeContextInfo(newFile, null, null);
return newFile;
}