本文整理汇总了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);
}
示例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);
}
示例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);
}