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


Java CreateConstructorMatchingSuperFix类代码示例

本文整理汇总了Java中com.intellij.codeInsight.daemon.impl.quickfix.CreateConstructorMatchingSuperFix的典型用法代码示例。如果您正苦于以下问题:Java CreateConstructorMatchingSuperFix类的具体用法?Java CreateConstructorMatchingSuperFix怎么用?Java CreateConstructorMatchingSuperFix使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CreateConstructorMatchingSuperFix类属于com.intellij.codeInsight.daemon.impl.quickfix包,在下文中一共展示了CreateConstructorMatchingSuperFix类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: chooseAndImplement

import com.intellij.codeInsight.daemon.impl.quickfix.CreateConstructorMatchingSuperFix; //导入依赖的package包/类
protected static void chooseAndImplement(PsiClass psiClass, Project project, @NotNull PsiClass targetClass, Editor editor) {
  boolean hasNonTrivialConstructor = false;
  final PsiMethod[] constructors = psiClass.getConstructors();
  for (PsiMethod constructor : constructors) {
    if (constructor.getParameterList().getParametersCount() > 0) {
      hasNonTrivialConstructor = true;
      break;
    }
  }
  if (hasNonTrivialConstructor) {
    final PsiSubstitutor substitutor = TypeConversionUtil.getSuperClassSubstitutor(psiClass, targetClass, PsiSubstitutor.EMPTY);
    final List<PsiMethodMember> baseConstructors = new ArrayList<PsiMethodMember>();
    for (PsiMethod baseConstr : constructors) {
      if (PsiUtil.isAccessible(project, baseConstr, targetClass, targetClass)) {
        baseConstructors.add(new PsiMethodMember(baseConstr, substitutor));
      }
    }
    final int offset = editor.getCaretModel().getOffset();
    CreateConstructorMatchingSuperFix.chooseConstructor2Delegate(project, editor,
                                                                 substitutor,
                                                                 baseConstructors, constructors, targetClass);
    editor.getCaretModel().moveToOffset(offset);
  }

  OverrideImplementUtil.chooseAndImplementMethods(project, editor, targetClass);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:CreateSubclassAction.java

示例2: chooseAndImplement

import com.intellij.codeInsight.daemon.impl.quickfix.CreateConstructorMatchingSuperFix; //导入依赖的package包/类
protected static void chooseAndImplement(PsiClass psiClass, Project project, @NotNull PsiClass targetClass, Editor editor) {
  boolean hasNonTrivialConstructor = false;
  final PsiMethod[] constructors = psiClass.getConstructors();
  for (PsiMethod constructor : constructors) {
    if (constructor.getParameterList().getParametersCount() > 0) {
      hasNonTrivialConstructor = true;
      break;
    }
  }
  if (hasNonTrivialConstructor) {
    final PsiSubstitutor substitutor = TypeConversionUtil.getSuperClassSubstitutor(psiClass, targetClass, PsiSubstitutor.EMPTY);
    final List<PsiMethodMember> baseConstructors = new ArrayList<PsiMethodMember>();
    for (PsiMethod baseConstr : constructors) {
      if (PsiUtil.isAccessible(baseConstr, targetClass, targetClass)) {
        baseConstructors.add(new PsiMethodMember(baseConstr, substitutor));
      }
    }
    final int offset = editor.getCaretModel().getOffset();
    CreateConstructorMatchingSuperFix.chooseConstructor2Delegate(project, editor,
                                                                 substitutor,
                                                                 baseConstructors, constructors, targetClass);
    editor.getCaretModel().moveToOffset(offset);
  }

  OverrideImplementUtil.chooseAndImplementMethods(project, editor, targetClass);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:27,代码来源:CreateSubclassAction.java

示例3: checkConstructors

import com.intellij.codeInsight.daemon.impl.quickfix.CreateConstructorMatchingSuperFix; //导入依赖的package包/类
private static void checkConstructors(AnnotationHolder holder, GrTypeDefinition typeDefinition) {
  if (typeDefinition.isEnum() || typeDefinition.isInterface() || typeDefinition.isAnonymous() || typeDefinition instanceof GrTypeParameter) return;
  final PsiClass superClass = typeDefinition.getSuperClass();
  if (superClass == null) return;

  if (GrInheritConstructorContributor.hasInheritConstructorsAnnotation(typeDefinition)) return;

  PsiMethod defConstructor = getDefaultConstructor(superClass);
  boolean hasImplicitDefConstructor = superClass.getConstructors().length == 0;

  final PsiMethod[] constructors = typeDefinition.getCodeConstructors();
  final String qName = superClass.getQualifiedName();
  if (constructors.length == 0) {
    if (!hasImplicitDefConstructor && (defConstructor == null || !PsiUtil.isAccessible(typeDefinition, defConstructor))) {
      final TextRange range = GrHighlightUtil.getClassHeaderTextRange(typeDefinition);
      holder.createErrorAnnotation(range, GroovyBundle.message("there.is.no.default.constructor.available.in.class.0", qName))
        .registerFix(new CreateConstructorMatchingSuperFix(typeDefinition));
    }
    return;
  }
  for (PsiMethod method : constructors) {
    if (method instanceof GrMethod) {
      final GrOpenBlock block = ((GrMethod)method).getBlock();
      if (block == null) continue;
      final GrStatement[] statements = block.getStatements();
      if (statements.length > 0) {
        if (statements[0] instanceof GrConstructorInvocation) continue;
      }

      if (!hasImplicitDefConstructor && (defConstructor == null || !PsiUtil.isAccessible(typeDefinition, defConstructor))) {
        holder.createErrorAnnotation(GrHighlightUtil.getMethodHeaderTextRange(method),
                                     GroovyBundle.message("there.is.no.default.constructor.available.in.class.0", qName));
      }
    }
  }

  checkRecursiveConstructors(holder, constructors);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:39,代码来源:GroovyAnnotator.java


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