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


Java GroovyFile.getPackageDefinition方法代码示例

本文整理汇总了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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:GrPackageInspection.java

示例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);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:MoveGroovyClassHandler.java

示例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;
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:12,代码来源:GrFileStub.java

示例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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:32,代码来源:GroovyCompletionData.java

示例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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:45,代码来源:GroovyCodeStyleManagerImpl.java

示例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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:44,代码来源:MoveGroovyClassHandler.java


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