Java 类com.intellij.psi.PsiClassInitializer 实例源码

项目:intellij-reference-diagram    文件:ReferenceDiagramDataModel.java   
public void collectNodes(PsiClass psiClass) {
    for (PsiMethod psiMethod : psiClass.getMethods()) {
        elementsAddedByUser.put(getFqn(psiMethod), spManager.createSmartPsiElementPointer((PsiElement) psiMethod));
    }

    for (PsiField psiField : psiClass.getFields()) {
        elementsAddedByUser.put(getFqn(psiField), spManager.createSmartPsiElementPointer((PsiElement) psiField));
    }

    for (PsiClassInitializer psiClassInitializer : psiClass.getInitializers()) {
        elementsAddedByUser.put(getFqn(psiClassInitializer), spManager.createSmartPsiElementPointer((PsiElement) psiClassInitializer));
    }

    for (PsiClass innerClass : psiClass.getInnerClasses()) {
        elementsAddedByUser.put(getFqn(innerClass), spManager.createSmartPsiElementPointer((PsiElement) innerClass));
    }
}
项目:intellij-reference-diagram    文件:PsiElementDispatcher.java   
public T dispatch(PsiElement psiElement) {
    if (psiElement instanceof PsiClass) {
        if (((PsiClass) psiElement).getContainingClass() == null) {
            return processClass((PsiClass) psiElement);
        } else {
            if (((PsiClass) psiElement).isEnum()) {
                return processEnum((PsiClass) psiElement);
            } else {
                if (((PsiClass) psiElement).hasModifierProperty("static")) {
                    return processStaticInnerClass((PsiClass) psiElement);
                } else {
                    return processInnerClass((PsiClass) psiElement);
                }
            }
        }
    } else if (psiElement instanceof PsiMethod) {
        return processMethod((PsiMethod) psiElement);
    } else if (psiElement instanceof PsiField) {
        return processField((PsiField) psiElement);
    } else if (psiElement instanceof PsiClassInitializer) {
        return processClassInitializer((PsiClassInitializer) psiElement);
    }
    throw new IllegalArgumentException("Type of PsiElement not supported: " + psiElement);
}
项目:consulo-java    文件:DataFlowRunner.java   
private void registerNestedClosures(@NotNull DfaInstructionState instructionState, @NotNull PsiClass nestedClass)
{
    DfaMemoryState state = instructionState.getMemoryState();
    for(PsiMethod method : nestedClass.getMethods())
    {
        PsiCodeBlock body = method.getBody();
        if(body != null)
        {
            createClosureState(body, state);
        }
    }
    for(PsiClassInitializer initializer : nestedClass.getInitializers())
    {
        createClosureState(initializer.getBody(), state);
    }
    for(PsiField field : nestedClass.getFields())
    {
        createClosureState(field, state);
    }
}
项目:consulo-java    文件:InstanceVariableUninitializedUseInspection.java   
private boolean isInitializedInInitializer(@NotNull PsiField field, UninitializedReadCollector uninitializedReadsCollector) {
  final PsiClass aClass = field.getContainingClass();
  if (aClass == null) {
    return false;
  }
  final PsiClassInitializer[] initializers = aClass.getInitializers();
  for (final PsiClassInitializer initializer : initializers) {
    if (!initializer.hasModifierProperty(PsiModifier.STATIC)) {
      final PsiCodeBlock body = initializer.getBody();
      if (uninitializedReadsCollector.blockAssignsVariable(body, field)) {
        return true;
      }
    }
  }
  return false;
}
项目:intellij-ce-playground    文件:ClassInitializerDeclarationRangeHandler.java   
@Override
@NotNull
public TextRange getDeclarationRange(@NotNull final PsiElement container) {
  PsiClassInitializer initializer = (PsiClassInitializer)container;
  int startOffset = initializer.getModifierList().getTextRange().getStartOffset();
  int endOffset = initializer.getBody().getTextRange().getStartOffset();
  return new TextRange(startOffset, endOffset);
}
项目:intellij-ce-playground    文件:MethodNameMacro.java   
@Override
public Result calculateResult(@NotNull Expression[] params, final ExpressionContext context) {
  PsiElement place = context.getPsiElementAtStartOffset();
  while(place != null){
    if (place instanceof PsiMethod){
      return new TextResult(((PsiMethod)place).getName());
    } else if (place instanceof PsiClassInitializer) {
      return ((PsiClassInitializer) place).hasModifierProperty(PsiModifier.STATIC) ?
             new TextResult(LangBundle.message("java.terms.static.initializer")) :
             new TextResult(LangBundle.message("java.terms.instance.initializer"));
    }
    place = place.getParent();
  }
  return null;
}
项目:intellij-ce-playground    文件:TestCaseWithConstructorInspection.java   
@Override
public void visitClassInitializer(PsiClassInitializer initializer) {
  if (initializer.hasModifierProperty(PsiModifier.STATIC)) {
    return;
  }
  final PsiClass aClass = initializer.getContainingClass();
  if (!TestUtils.isJUnitTestClass(aClass) && !TestUtils.isJUnit4TestClass(aClass, true)) {
    return;
  }
  if (MethodUtils.isTrivial(initializer)) {
    return;
  }
  registerClassInitializerError(initializer, Boolean.TRUE);
}
项目:intellij-ce-playground    文件:EmptyInitializerInspection.java   
@Override
public void visitClassInitializer(
  @NotNull PsiClassInitializer initializer) {
  super.visitClassInitializer(initializer);
  final PsiCodeBlock body = initializer.getBody();
  if (!codeBlockIsEmpty(body)) {
    return;
  }
  registerClassInitializerError(initializer);
}
项目:intellij-ce-playground    文件:ClassComplexityInspection.java   
private int calculateInitializerComplexity(PsiClass aClass) {
  final CyclomaticComplexityVisitor visitor = new CyclomaticComplexityVisitor();
  int complexity = 0;
  final PsiClassInitializer[] initializers = aClass.getInitializers();
  for (final PsiClassInitializer initializer : initializers) {
    visitor.reset();
    initializer.accept(visitor);
    complexity += visitor.getComplexity();
  }
  return complexity;
}
项目:intellij-reference-diagram    文件:PsiUtils.java   
private static PsiElement getRootPsiElementWithStack(PsiClass psiClass, PsiElement psiElement, List<PsiElement> stack) {
    stack.add(psiElement);
    PsiElement parent = psiElement.getParent();
    if (parent == null) {
        return null;
    }
    try {
        if (parent instanceof PsiMethod) {
            if (PsiUtils.classHasMethod(psiClass, (PsiMethod) parent)) {
                return parent;
            }
        } else if (parent instanceof PsiClassInitializer) {
            if (PsiUtils.classHasClassInitializer(psiClass, (PsiClassInitializer) parent)) {
                return parent;
            }
        } else if (parent instanceof PsiField) {
            if (PsiUtils.classHasField(psiClass, (PsiField) parent)) {
                return parent;
            }
        } else if (parent instanceof PsiClass) {
            if (psiClass.equals(((PsiClass) parent).getContainingClass())) {
                return parent;
            }
        } else if (parent instanceof PsiAnonymousClass) {
            if (((PsiAnonymousClass) parent).getContainingClass().equals(psiClass)) {
                return parent;
            }
        }
    } catch (Exception ex) {
        stack.add(parent);
        String preparedStack = prepareStack(stack);
        throw new IllegalStateException("Cannot get root element. Stack: " + preparedStack);
    }

    return getRootPsiElementWithStack(psiClass, parent, stack);
}
项目:intellij-reference-diagram    文件:PsiUtils.java   
private static boolean classHasClassInitializer(PsiClass psiClass, PsiClassInitializer other) {
    for (PsiClassInitializer classInitializer : psiClass.getInitializers()) {
        if (classInitializer.equals(other)) {
            return true;
        }
    }
    return false;
}
项目:intellij-reference-diagram    文件:PsiUtils.java   
public static String getName(PsiClassInitializer psiClassInitializer) {
    if (psiClassInitializer.getModifierList().hasModifierProperty("static")) {
        return "[static init]";
    } else {
        return "[init]";
    }
}
项目:tools-idea    文件:ClassInitializerDeclarationRangeHandler.java   
@Override
@NotNull
public TextRange getDeclarationRange(@NotNull final PsiElement container) {
  PsiClassInitializer initializer = (PsiClassInitializer)container;
  int startOffset = initializer.getModifierList().getTextRange().getStartOffset();
  int endOffset = initializer.getBody().getTextRange().getStartOffset();
  return new TextRange(startOffset, endOffset);
}
项目:tools-idea    文件:MethodNameMacro.java   
@Override
public Result calculateResult(@NotNull Expression[] params, final ExpressionContext context) {
  PsiElement place = context.getPsiElementAtStartOffset();
  while(place != null){
    if (place instanceof PsiMethod){
      return new TextResult(((PsiMethod)place).getName());
    } else if (place instanceof PsiClassInitializer) {
      return ((PsiClassInitializer) place).hasModifierProperty(PsiModifier.STATIC) ?
             new TextResult(LangBundle.message("java.terms.static.initializer")) :
             new TextResult(LangBundle.message("java.terms.instance.initializer"));
    }
    place = place.getParent();
  }
  return null;
}
项目:tools-idea    文件:ClassInitializerInspection.java   
@Override
public void visitClassInitializer(PsiClassInitializer initializer) {
  super.visitClassInitializer(initializer);
  if (initializer.hasModifierProperty(PsiModifier.STATIC)) {
    return;
  }
  registerClassInitializerError(initializer);
}
项目:tools-idea    文件:EmptyInitializerInspection.java   
@Override
public void visitClassInitializer(
  @NotNull PsiClassInitializer initializer) {
  super.visitClassInitializer(initializer);
  final PsiCodeBlock body = initializer.getBody();
  if (!codeBlockIsEmpty(body)) {
    return;
  }
  registerClassInitializerError(initializer);
}
项目:tools-idea    文件:ClassComplexityInspection.java   
private int calculateInitializerComplexity(PsiClass aClass) {
  final ComplexityVisitor visitor = new ComplexityVisitor();
  int complexity = 0;
  final PsiClassInitializer[] initializers = aClass.getInitializers();
  for (final PsiClassInitializer initializer : initializers) {
    visitor.reset();
    initializer.accept(visitor);
    complexity += visitor.getComplexity();
  }
  return complexity;
}
项目:consulo-java    文件:ClassInitializerDeclarationRangeHandler.java   
@Override
@NotNull
public TextRange getDeclarationRange(@NotNull final PsiElement container) {
  PsiClassInitializer initializer = (PsiClassInitializer)container;
  int startOffset = initializer.getModifierList().getTextRange().getStartOffset();
  int endOffset = initializer.getBody().getTextRange().getStartOffset();
  return new TextRange(startOffset, endOffset);
}
项目:consulo-java    文件:MethodNameMacro.java   
@Override
public Result calculateResult(@NotNull Expression[] params, final ExpressionContext context) {
  PsiElement place = context.getPsiElementAtStartOffset();
  while(place != null){
    if (place instanceof PsiMethod){
      return new TextResult(((PsiMethod)place).getName());
    } else if (place instanceof PsiClassInitializer) {
      return ((PsiClassInitializer) place).hasModifierProperty(PsiModifier.STATIC) ?
             new TextResult(LangBundle.message("java.terms.static.initializer")) :
             new TextResult(LangBundle.message("java.terms.instance.initializer"));
    }
    place = place.getParent();
  }
  return null;
}
项目:consulo-java    文件:ClassInitializerInspection.java   
@Override
public void visitClassInitializer(PsiClassInitializer initializer) {
  super.visitClassInitializer(initializer);
  if (initializer.hasModifierProperty(PsiModifier.STATIC)) {
    return;
  }
  registerClassInitializerError(initializer);
}
项目:consulo-java    文件:ClassInitializerMayBeStaticInspection.java   
@Override
public void visitClassInitializer(PsiClassInitializer initializer)
{
    if(initializer.hasModifierProperty(PsiModifier.STATIC))
    {
        return;
    }

    final PsiClass containingClass = ClassUtils.getContainingClass(initializer);
    if(containingClass == null)
    {
        return;
    }
    for(Condition<PsiElement> addin : JavaExtensionPoints.CANT_BE_STATIC_EP_NAME.getExtensions())
    {
        if(addin.value(initializer))
        {
            return;
        }
    }
    final PsiElement scope = containingClass.getScope();
    if(!(scope instanceof PsiJavaFile) && !containingClass.hasModifierProperty(PsiModifier.STATIC))
    {
        return;
    }

    final MethodReferenceVisitor visitor = new MethodReferenceVisitor(initializer);
    initializer.accept(visitor);
    if(!visitor.areReferencesStaticallyAccessible())
    {
        return;
    }

    registerClassInitializerError(initializer);
}
项目:consulo-java    文件:EmptyInitializerInspection.java   
@Override
public void visitClassInitializer(
  @NotNull PsiClassInitializer initializer) {
  super.visitClassInitializer(initializer);
  final PsiCodeBlock body = initializer.getBody();
  if (!codeBlockIsEmpty(body)) {
    return;
  }
  registerClassInitializerError(initializer);
}
项目:consulo-java    文件:ClassComplexityInspection.java   
private int calculateInitializerComplexity(PsiClass aClass) {
  final ComplexityVisitor visitor = new ComplexityVisitor();
  int complexity = 0;
  final PsiClassInitializer[] initializers = aClass.getInitializers();
  for (final PsiClassInitializer initializer : initializers) {
    visitor.reset();
    initializer.accept(visitor);
    complexity += visitor.getComplexity();
  }
  return complexity;
}
项目:Android_Lint_SRP_Practice_Example    文件:PsiClassStructureDetector.java   
@Override
public void visitClassInitializer(PsiClassInitializer initializer) {
    mVisitor.report("PsiClassInitializer", initializer.getText(), initializer);
    super.visitElement(initializer);
}
项目:cuppa-intellij-plugin    文件:CuppaCantBeStaticExtension.java   
@Override
public boolean value(PsiElement psiElement) {
    return psiElement instanceof PsiClassInitializer && CuppaUtils.isCuppaClass(psiElement);
}
项目:Rearranger    文件:MethodAttributes.java   
public final boolean isMatch(RangeEntry entry)
{
    final boolean result = (entry.getEnd() instanceof PsiMethod           ||
                            entry.getEnd() instanceof PsiClassInitializer   ) &&
                           super.isMatch           (entry               )     &&
                           abstractAttr.isMatch    (entry.getModifiers())     &&
                           overriddenAttr.isMatch  (entry.getModifiers())     &&
                           overridingAttr.isMatch  (entry.getModifiers())     &&
                           implementedAttr.isMatch (entry.getModifiers())     &&
                           implementingAttr.isMatch(entry.getModifiers())     &&
                           staticInitAttr.isMatch  (entry.getModifiers())     &&
                           nativeAttr.isMatch      (entry.getModifiers())     &&
                           syncAttr.isMatch        (entry.getModifiers())     &&
                           returnTypeAttr.isMatch  (entry.getType     ())     &&
                           minParamsAttr.isMatch   (entry.getEnd      ())     &&
                           maxParamsAttr.isMatch   (entry.getEnd      ());
    if (result == false)
        return false;
    boolean typeResult = false;
    if (isConstructorMethodType()) {
        typeResult |= (entry.getModifiers() & ModifierConstants.CONSTRUCTOR) == ModifierConstants.CONSTRUCTOR;
    }
    if (isGetterSetterMethodType() &&
            entry.getEnd() instanceof PsiMethod)
    {
        /**
         * determine if the method is a getter or setter according to this rule's specific
         * definition.
         */
        boolean isGetter = MethodUtil.isGetter((PsiMethod) entry.getEnd(),
                getterSetterDefinition           );
        boolean isSetter = MethodUtil.isSetter((PsiMethod) entry.getEnd(),
                getterSetterDefinition           );
        typeResult |= isGetter | isSetter;
    }
    if (isCanonicalMethodType()) {
        typeResult |= (entry.getModifiers() & ModifierConstants.CANONICAL) == ModifierConstants.CANONICAL;
    }
    if (isOtherMethodType()) {
        typeResult |= (entry.getModifiers() & ModifierConstants.OTHER_METHOD) == ModifierConstants.OTHER_METHOD;
    }
    typeResult ^= invertMethodType;
    if (!constructorMethodType  &&
        !getterSetterMethodType &&
        !canonicalMethodType    &&
        !otherMethodType          )
    {
        typeResult = true; // true if no method type options are selected.
    }
    return result && typeResult;
}
项目:intellij-ce-playground    文件:JavaClassInitializerElementType.java   
@Override
public PsiClassInitializer createPsi(@NotNull final PsiClassInitializerStub stub) {
  return getPsiFactory(stub).createClassInitializer(stub);
}
项目:intellij-ce-playground    文件:JavaClassInitializerElementType.java   
@Override
public PsiClassInitializer createPsi(@NotNull final ASTNode node) {
  return new PsiClassInitializerImpl(node);
}
项目:intellij-ce-playground    文件:JavaDocMatchingStrategy.java   
@Override public void visitClassInitializer(final PsiClassInitializer clazzInit) {
  result = true;
}
项目:intellij-reference-diagram    文件:LCOMConverter.java   
public LCOMNode.Type resolveType(DiagramNode<PsiElement> referenceNode) {
    PsiElementDispatcher<LCOMNode.Type> elementDispatcher = new PsiElementDispatcher<LCOMNode.Type>() {

        @Override
        public LCOMNode.Type processClass(PsiClass psiClass) {
            return LCOMNode.Type.Class;
        }

        @Override
        public LCOMNode.Type processMethod(PsiMethod psiMethod) {
            if (psiMethod.isConstructor()) {
                return LCOMNode.Type.Constructur;
            } else {
                return LCOMNode.Type.Method;
            }
        }

        @Override
        public LCOMNode.Type processField(PsiField psiField) {
            if (psiField.hasModifierProperty("static")) {
                return LCOMNode.Type.Constant;
            } else {
                return LCOMNode.Type.Field;
            }
        }

        @Override
        public LCOMNode.Type processClassInitializer(PsiClassInitializer psiClassInitializer) {
            return LCOMNode.Type.ClassInitializer;
        }

        @Override
        public LCOMNode.Type processInnerClass(PsiClass innerClass) {
            return LCOMNode.Type.InnerClass;
        }

        @Override
        public LCOMNode.Type processStaticInnerClass(PsiClass staticInnerClass) {
            return LCOMNode.Type.StaticInnerClass;
        }

        @Override
        public LCOMNode.Type processEnum(PsiClass anEnum) {
            return LCOMNode.Type.Enum;
        }
    };
    return elementDispatcher.dispatch(referenceNode.getIdentifyingElement());
}
项目:intellij-reference-diagram    文件:PsiUtils.java   
public static String getPresentableName(PsiElement psiElement) {
    PsiElementDispatcher<String> psiElementDispatcher = new PsiElementDispatcher<String>() {

        @Override
        public String processClass(PsiClass psiClass) {
            return psiClass.getName();
        }

        @Override
        public String processMethod(PsiMethod psiMethod) {
            List<String> parameterArray = MethodFQN.getParameterArray(psiMethod);
            String parameterRepresentation = MethodFQN.createParameterRepresentation(parameterArray);
            return psiMethod.getName() + "(" + parameterRepresentation + ")";
        }

        @Override
        public String processField(PsiField psiField) {
            return psiField.getName();
        }

        @Override
        public String processClassInitializer(PsiClassInitializer psiClassInitializer) {
            return getName(psiClassInitializer);
        }

        @Override
        public String processInnerClass(PsiClass innerClass) {
            return innerClass.getName();
        }

        @Override
        public String processStaticInnerClass(PsiClass staticInnerClass) {
            return staticInnerClass.getName();
        }

        @Override
        public String processEnum(PsiClass anEnum) {
            return anEnum.getName();
        }
    };

    return psiElementDispatcher.dispatch(psiElement);
}
项目:intellij-reference-diagram    文件:PsiUtils.java   
public static String getFqn(PsiElement psiElement) {
    PsiElementDispatcher<String> psiElementDispatcher = new PsiElementDispatcher<String>() {

        @Override
        public String processClass(PsiClass psiClass) {
            return ClassFQN.create(psiClass).getFQN();
        }

        @Override
        public String processMethod(PsiMethod psiMethod) {
            return MethodFQN.create(psiMethod).getFQN();
        }

        @Override
        public String processField(PsiField psiField) {
            return FieldFQN.create(psiField).getFQN();
        }

        @Override
        public String processClassInitializer(PsiClassInitializer psiClassInitializer) {
            return getName(psiClassInitializer);
        }

        @Override
        public String processInnerClass(PsiClass innerClass) {
            return ClassFQN.create(innerClass).getFQN();
        }

        @Override
        public String processStaticInnerClass(PsiClass staticInnerClass) {
            return ClassFQN.create(staticInnerClass).getFQN();
        }

        @Override
        public String processEnum(PsiClass anEnum) {
            return ClassFQN.create(anEnum).getFQN();
        }
    };

    return psiElementDispatcher.dispatch(psiElement);
}
项目:tools-idea    文件:JavaClassInitializerElementType.java   
@Override
public PsiClassInitializer createPsi(@NotNull final PsiClassInitializerStub stub) {
  return getPsiFactory(stub).createClassInitializer(stub);
}
项目:tools-idea    文件:JavaClassInitializerElementType.java   
@Override
public PsiClassInitializer createPsi(@NotNull final ASTNode node) {
  return new PsiClassInitializerImpl(node);
}
项目:consulo-java    文件:JavaClassInitializerElementType.java   
@Override
public PsiClassInitializer createPsi(@NotNull final PsiClassInitializerStub stub) {
  return getPsiFactory(stub).createClassInitializer(stub);
}
项目:consulo-java    文件:JavaClassInitializerElementType.java   
@Override
public PsiClassInitializer createPsi(@NotNull final ASTNode node) {
  return new PsiClassInitializerImpl(node);
}
项目:intellij-reference-diagram    文件:PsiElementDispatcher.java   
public abstract T processClassInitializer(PsiClassInitializer psiClassInitializer);