當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。