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


Java GroovyFile类代码示例

本文整理汇总了Java中org.jetbrains.plugins.groovy.lang.psi.GroovyFile的典型用法代码示例。如果您正苦于以下问题:Java GroovyFile类的具体用法?Java GroovyFile怎么用?Java GroovyFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


GroovyFile类属于org.jetbrains.plugins.groovy.lang.psi包,在下文中一共展示了GroovyFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getText

import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; //导入依赖的package包/类
@NotNull
@Override
public String getText() {
  String id = getLintId(myId);
  final PsiFile file = PsiTreeUtil.getParentOfType(myElement, PsiFile.class);
  if (file == null) {
    return "";
  } else if (file instanceof XmlFile) {
    return AndroidBundle.message("android.lint.fix.suppress.lint.api.attr", id);
  } else if (file instanceof PsiJavaFile) {
    return AndroidBundle.message("android.lint.fix.suppress.lint.api.annotation", id);
  } else if (file instanceof GroovyFile) {
    return "Suppress: Add //noinspection " + id;
  } else {
    return "";
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:SuppressLintIntentionAction.java

示例2: findExistingByElement

import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; //导入依赖的package包/类
@Override
protected RunnerAndConfigurationSettings findExistingByElement(Location location,
                                                               @NotNull List<RunnerAndConfigurationSettings> existingConfigurations,
                                                               ConfigurationContext context) {
  for (RunnerAndConfigurationSettings existingConfiguration : existingConfigurations) {
    final RunConfiguration configuration = existingConfiguration.getConfiguration();
    final GroovyScriptRunConfiguration existing = (GroovyScriptRunConfiguration)configuration;
    final String path = existing.getScriptPath();
    if (path != null) {
      final PsiFile file = location.getPsiElement().getContainingFile();
      if (file instanceof GroovyFile) {
        final VirtualFile vfile = file.getVirtualFile();
        if (vfile != null && FileUtil.toSystemIndependentName(path).equals(ScriptFileUtil.getScriptFilePath(vfile))) {
          if (!((GroovyFile)file).isScript() ||
              GroovyScriptUtil.getScriptType((GroovyFile)file).isConfigurationByLocation(existing, location)) {
            return existingConfiguration;
          }
        }
      }
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:GroovyScriptRunConfigurationProducer.java

示例3: buildVisitor

import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; //导入依赖的package包/类
@NotNull
@Override
protected BaseInspectionVisitor buildVisitor() {
  return new BaseInspectionVisitor() {
    @Override
    public void visitFile(GroovyFileBase file) {
      if (!(file instanceof GroovyFile)) return;

      if (!myCheckScripts && file.isScript()) return;

      String expectedPackage = ResolveUtil.inferExpectedPackageName(file);
      String actual = file.getPackageName();
      if (!expectedPackage.equals(actual)) {

        PsiElement toHighlight = getElementToHighlight((GroovyFile)file);
        if (toHighlight == null) return;

        registerError(toHighlight, "Package name mismatch. Actual: '" + actual + "', expected: '" + expectedPackage+"'",
                      new LocalQuickFix[]{new ChangePackageQuickFix(expectedPackage), GroovyQuickFixFactory.getInstance().createGrMoveToDirFix(actual)},
                      ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
      }
    }
  };
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:GrPackageInspection.java

示例4: generateClassInfo

import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; //导入依赖的package包/类
private static String generateClassInfo(PsiClass aClass) {
  StringBuilder buffer = new StringBuilder();
  GroovyFile file = (GroovyFile)aClass.getContainingFile();

  String packageName = file.getPackageName();
  if (!packageName.isEmpty()) {
    buffer.append(packageName).append("\n");
  }

  final String classString =
    aClass.isInterface() ? "interface" : aClass instanceof PsiTypeParameter ? "type parameter" : aClass.isEnum() ? "enum" : "class";
  buffer.append(classString).append(" ").append(aClass.getName());

  JavaDocumentationProvider.generateTypeParameters(aClass, buffer);

  JavaDocumentationProvider.writeExtends(aClass, buffer, aClass.getExtendsListTypes());
  JavaDocumentationProvider.writeImplements(aClass, buffer, aClass.getImplementsListTypes());

  return buffer.toString();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:GroovyDocumentationProvider.java

示例5: isSemiColonUnnecessaryInCodeBlock

import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; //导入依赖的package包/类
private static boolean isSemiColonUnnecessaryInCodeBlock(PsiElement semicolon, String text, Project project) {
  final GrStatement prev = getPreviousStatement(semicolon, GrStatement.class);
  final GrStatement next = getNextStatement(semicolon, GrStatement.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 statementWithoutSemicolon = text.substring(startOffset, offset) + text.substring(offset + 1, endOffset);
  final GroovyFile file = GroovyPsiElementFactory.getInstance(project).createGroovyFile(statementWithoutSemicolon, false, null);
  final GrStatement[] statements = file.getStatements();
  if (statements.length != 2) return false;

  return checkStatementsAreEqual(prev, statements[0]) &&
         checkStatementsAreEqual(next, statements[1]);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:RemoveUnnecessarySemicolonsIntention.java

示例6: visitNewExpression

import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; //导入依赖的package包/类
@Override
public void visitNewExpression(GrNewExpression newExpression) {
  super.visitNewExpression(newExpression);
  final GrCodeReferenceElement refElement = newExpression.getReferenceElement();
  if (refElement == null) return;      //new expression is not correct so we shouldn't check it
  
  final PsiElement parent = newExpression.getParent();

  if (parent instanceof GrCodeBlock || parent instanceof GroovyFile) {
    if (parent instanceof GrOpenBlock || parent instanceof GrClosableBlock) {
      if (ControlFlowUtils.openBlockCompletesWithStatement(((GrCodeBlock)parent), newExpression)) {
        return;
      }
    }
    registerError(refElement, newExpression.getArrayCount());
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:GroovyResultOfObjectAllocationIgnoredInspection.java

示例7: checkApplicability

import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; //导入依赖的package包/类
@Override
public boolean checkApplicability(@NotNull AnnotationHolder holder, @NotNull GrAnnotation annotation) {
  if (GroovyCommonClassNames.GROOVY_TRANSFORM_BASE_SCRIPT.equals(annotation.getQualifiedName())) {
    PsiFile file = annotation.getContainingFile();
    if (file instanceof GroovyFile && !(((GroovyFile)file).isScript())) {
      holder.createErrorAnnotation(annotation, GroovyBundle.message("base.script.annotation.is.allowed.only.inside.scripts"));
      return true;
    }

    PsiElement pparent = annotation.getParent().getParent();
    if (pparent instanceof GrVariableDeclaration) {
      GrTypeElement typeElement = ((GrVariableDeclaration)pparent).getTypeElementGroovy();
      PsiType type = typeElement != null ? typeElement.getType() : null;

      if (!InheritanceUtil.isInheritor(type, GroovyCommonClassNames.GROOVY_LANG_SCRIPT)) {
        String typeText = type != null ? type.getCanonicalText() : CommonClassNames.JAVA_LANG_OBJECT;
        holder.createErrorAnnotation(annotation, GroovyBundle.message("declared.type.0.have.to.extend.script", typeText));
        return true;
      }
    }
  }

  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:BaseScriptAnnotationChecker.java

示例8: suggestImport

import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; //导入依赖的package包/类
private static boolean suggestImport(PsiElement context) {
  if (context.getParent() != null &&
      !(context.getParent() instanceof PsiErrorElement) &&
      GroovyCompletionUtil.isNewStatement(context, false) &&
      context.getParent().getParent() instanceof GroovyFile) {
    return true;
  }
  final PsiElement leaf = GroovyCompletionUtil.getLeafByOffset(context.getTextRange().getStartOffset() - 1, context);
  if (leaf != null) {
    PsiElement parent = leaf.getParent();
    if (parent instanceof GroovyFile) {
      return GroovyCompletionUtil.isNewStatement(context, false);
    }
  }
  return context.getTextRange().getStartOffset() == 0 && !(context instanceof OuterLanguageElement);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:GroovyCompletionData.java

示例9: getPresentation

import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; //导入依赖的package包/类
@Override
public ItemPresentation getPresentation(@NotNull final GroovyFile file) {
  return new ItemPresentation() {
    @Override
    public String getPresentableText() {
      return GroovyBundle.message("groovy.file.0", file.getName());
    }

    @Override
    public String getLocationString() {
      PsiDirectory directory = file.getContainingDirectory();
      return ItemPresentationProviders.getItemPresentation(directory).getPresentableText();
    }

    @Override
    public Icon getIcon(boolean unused) {
      return file.getIcon(Iconable.ICON_FLAG_VISIBILITY | Iconable.ICON_FLAG_READ_STATUS);
    }
  };
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:GrFileItemPresentationProvider.java

示例10: checkLocalScope

import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; //导入依赖的package包/类
@Nullable
@Override
protected PsiElement checkLocalScope() {
  final GrVariable variable = getVariable();
  if (variable instanceof PsiField) {
    return ((PsiField)getVariable()).getContainingClass();
  }
  else {
    final PsiFile file = variable.getContainingFile();
    if (file instanceof GroovyFile) {
      return ((GroovyFile)file).getScriptClass();
    }
    else {
      return null;
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:GrInplaceFieldIntroducer.java

示例11: findConfiguration

import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; //导入依赖的package包/类
@Nullable
private GroovyScriptRunner findConfiguration() {
  final VirtualFile scriptFile = getScriptFile();
  if (scriptFile == null) {
    return null;
  }

  final PsiFile psiFile = PsiManager.getInstance(getProject()).findFile(scriptFile);
  if (!(psiFile instanceof GroovyFile)) {
    return null;
  }
  if (!((GroovyFile)psiFile).isScript()) {
    return new DefaultGroovyScriptRunner();
  }

  return GroovyScriptUtil.getScriptType((GroovyFile)psiFile).getRunner();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:GroovyScriptRunConfiguration.java

示例12: 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

示例13: processIntention

import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; //导入依赖的package包/类
@Override
protected void processIntention(@NotNull PsiElement element, Project project, Editor editor) throws IncorrectOperationException {
  if (!(element instanceof GrReferenceElement)) return;
  final GrReferenceElement ref = (GrReferenceElement)element;
  final PsiElement resolved = ref.resolve();
  if (!(resolved instanceof PsiClass)) return;

  final String qname = ((PsiClass)resolved).getQualifiedName();

  final GrImportStatement importStatement =
    GroovyPsiElementFactory.getInstance(project).createImportStatementFromText(qname, true, true, null);

  final PsiFile containingFile = element.getContainingFile();
  if (!(containingFile instanceof GroovyFile)) return;
  ((GroovyFile)containingFile).addImport(importStatement);

  for (PsiReference reference : ReferencesSearch.search(resolved, new LocalSearchScope(containingFile))) {
    final PsiElement refElement = reference.getElement();
    if (refElement == null) continue;
    final PsiElement parent = refElement.getParent();
    if (parent instanceof GrQualifiedReference<?>) {
      org.jetbrains.plugins.groovy.codeStyle.GrReferenceAdjuster.shortenReference((GrQualifiedReference<?>)parent);
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:ImportOnDemandIntention.java

示例14: getAntTasks

import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; //导入依赖的package包/类
public static Set<LightMethodBuilder> getAntTasks(PsiElement place) {
  final PsiFile file = place.getContainingFile();
  if (!(file instanceof GroovyFile)) {
    return Collections.emptySet();
  }

  return CachedValuesManager.getManager(file.getProject()).getCachedValue(file, GANT_METHODS, new CachedValueProvider<Set<LightMethodBuilder>>() {
    @Override
    public Result<Set<LightMethodBuilder>> compute() {
      Map<String, Class> antObjects = getAntObjects((GroovyFile)file);

      final Set<LightMethodBuilder> methods = new HashSet<LightMethodBuilder>();

      final Project project = file.getProject();
      final PsiType closureType = TypesUtil.createType(GroovyCommonClassNames.GROOVY_LANG_CLOSURE, file);
      final PsiClassType stringType = TypesUtil.createType(CommonClassNames.JAVA_LANG_STRING, file);

      for (String name : antObjects.keySet()) {
        methods.add(new AntBuilderMethod(file, name, closureType, antObjects.get(name), stringType));
      }
      return Result.create(methods, PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT, ProjectRootManager.getInstance(project));
    }
  }, false);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:AntTasksProvider.java

示例15: getRunningClass

import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; //导入依赖的package包/类
@Nullable
public static PsiClass getRunningClass(@Nullable PsiElement element) {
  if (element == null) return null;

  final PsiFile file = element.getContainingFile();
  if (!(file instanceof GroovyFile)) return null;

  for (PsiClass clazz = PsiTreeUtil.getParentOfType(element, PsiClass.class);
       clazz != null;
       clazz = PsiTreeUtil.getParentOfType(clazz, PsiClass.class)) {
    if (canBeRunByGroovy(clazz)) return clazz;
  }

  if (((GroovyFile)file).isScript()) return ((GroovyFile)file).getScriptClass();

  final PsiClass[] classes = ((GroovyFile)file).getClasses();
  if (classes.length > 0) {
    return classes[0];
  }

  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:GroovyRunnerPsiUtil.java


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