當前位置: 首頁>>代碼示例>>Java>>正文


Java PsiField.getContainingClass方法代碼示例

本文整理匯總了Java中com.intellij.psi.PsiField.getContainingClass方法的典型用法代碼示例。如果您正苦於以下問題:Java PsiField.getContainingClass方法的具體用法?Java PsiField.getContainingClass怎麽用?Java PsiField.getContainingClass使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.intellij.psi.PsiField的用法示例。


在下文中一共展示了PsiField.getContainingClass方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: visitField

import com.intellij.psi.PsiField; //導入方法依賴的package包/類
@Override
public void visitField(@NotNull PsiField field) {
  //no call to super, so we don't drill into anonymous classes
  if (!field.hasModifierProperty(PsiModifier.STATIC) ||
      !field.hasModifierProperty(PsiModifier.PUBLIC) ||
      !field.hasModifierProperty(PsiModifier.FINAL)) {
    return;
  }
  final PsiClass containingClass = field.getContainingClass();
  if (containingClass == null) {
    return;
  }
  if (containingClass.isInterface() ||
      containingClass.isAnnotationType() ||
      containingClass.isEnum()) {
    return;
  }
  if (!containingClass.hasModifierProperty(PsiModifier.ABSTRACT)) {
    return;
  }
  registerFieldError(field);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:23,代碼來源:ConstantDeclaredInAbstractClassInspection.java

示例2: visitClass

import com.intellij.psi.PsiField; //導入方法依賴的package包/類
@Override
public void visitClass(@NotNull PsiClass aClass) {
  if (!containsSynchronization(aClass)) {
    return;
  }
  final VariableAccessVisitor visitor = new VariableAccessVisitor(aClass, countGettersAndSetters);
  aClass.accept(visitor);
  final Set<PsiField> fields = visitor.getInappropriatelyAccessedFields();
  for (final PsiField field : fields) {
    if (field.hasModifierProperty(PsiModifier.FINAL) ||
        field.hasModifierProperty(PsiModifier.VOLATILE)) {
      continue;
    }
    final PsiClass containingClass = field.getContainingClass();
    if (aClass.equals(containingClass)) {
      registerFieldError(field, field);
    }
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:20,代碼來源:FieldAccessedSynchronizedAndUnsynchronizedInspection.java

示例3: visitReferenceExpression

import com.intellij.psi.PsiField; //導入方法依賴的package包/類
@Override
public void visitReferenceExpression(@NotNull PsiReferenceExpression expression) {
  super.visitReferenceExpression(expression);
  final String name = expression.getReferenceName();
  if (!HardcodedMethodConstants.OUT.equals(name) &&
      !HardcodedMethodConstants.ERR.equals(name)) {
    return;
  }
  final PsiElement referent = expression.resolve();
  if (!(referent instanceof PsiField)) {
    return;
  }
  final PsiField field = (PsiField)referent;
  final PsiClass containingClass = field.getContainingClass();
  if (containingClass == null) {
    return;
  }
  final String className = containingClass.getQualifiedName();
  if (!"java.lang.System".equals(className)) {
    return;
  }
  registerError(expression, expression);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:24,代碼來源:SystemOutErrInspectionBase.java

示例4: visitField

import com.intellij.psi.PsiField; //導入方法依賴的package包/類
@Override
public void visitField(PsiField field) {
  super.visitField(field);
  if (field.hasModifierProperty(PsiModifier.FINAL)) {
    return;
  }
  final PsiClass containingClass = field.getContainingClass();
  if (containingClass == null) {
    return;
  }
  if (!InheritanceUtil.isInheritor(containingClass,
                                   CommonClassNames.JAVA_LANG_EXCEPTION)) {
    return;
  }
  registerFieldError(field, field);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:17,代碼來源:NonFinalFieldOfExceptionInspection.java

示例5: getTitle

import com.intellij.psi.PsiField; //導入方法依賴的package包/類
@Override
public String getTitle() {
  final PsiField field = getValue();
  if (field != null) {
    PsiClass aClass = field.getContainingClass();
    if (aClass != null) {
      return aClass.getQualifiedName();
    }
    else {
      return field.toString();
    }
  }
  return super.getTitle();
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:15,代碼來源:PsiFieldNode.java

示例6: visitField

import com.intellij.psi.PsiField; //導入方法依賴的package包/類
@Override
public void visitField(@NotNull PsiField field) {
  if (field.hasModifierProperty(PsiModifier.TRANSIENT) || field.hasModifierProperty(PsiModifier.STATIC)) {
    return;
  }
  final PsiClass aClass = field.getContainingClass();
  if (aClass == null) {
    return;
  }
  if (ignoreAnonymousInnerClasses && aClass instanceof PsiAnonymousClass) {
    return;
  }
  if (!SerializationUtils.isSerializable(aClass)) {
    return;
  }
  if (SerializationUtils.isProbablySerializable(field.getType())) {
    return;
  }
  final boolean hasWriteObject = SerializationUtils.hasWriteObject(aClass);
  if (hasWriteObject) {
    return;
  }
  if (isIgnoredSubclass(aClass)) {
    return;
  }
  if (AnnotationUtil.isAnnotated(field, ignorableAnnotations)) {
    return;
  }
  registerFieldError(field, field);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:31,代碼來源:NonSerializableFieldInSerializableClassInspectionBase.java

示例7: visitField

import com.intellij.psi.PsiField; //導入方法依賴的package包/類
@Override
public void visitField(@NotNull PsiField field) {
  if (!field.hasModifierProperty(PsiModifier.TRANSIENT)) {
    return;
  }
  final PsiClass aClass = field.getContainingClass();
  if (SerializationUtils.isSerializable(aClass)) {
    return;
  }
  registerModifierError(PsiModifier.TRANSIENT, field, field);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:12,代碼來源:TransientFieldInNonSerializableClassInspection.java

示例8: visitField

import com.intellij.psi.PsiField; //導入方法依賴的package包/類
@Override
public void visitField(@NotNull PsiField field) {
  //no call to super, so we don't drill into anonymous classes
  final PsiClass containingClass = field.getContainingClass();
  if (containingClass == null) {
    return;
  }
  if (!containingClass.isInterface() &&
      !containingClass.isAnnotationType()) {
    return;
  }
  registerFieldError(field);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:14,代碼來源:ConstantDeclaredInInterfaceInspection.java

示例9: visitField

import com.intellij.psi.PsiField; //導入方法依賴的package包/類
@Override
public void visitField(PsiField field) {
  super.visitField(field);
  final PsiClass containingClass = field.getContainingClass();
  if (containingClass == null || !containingClass.isEnum()) {
    return;
  }
  if (field.hasModifierProperty(PsiModifier.FINAL)) {
    return;
  }
  registerFieldError(field, containingClass, field);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:13,代碼來源:NonFinalFieldInEnumInspection.java

示例10: visitField

import com.intellij.psi.PsiField; //導入方法依賴的package包/類
@Override
public void visitField(@NotNull PsiField field) {
  if (!field.hasModifierProperty(PsiModifier.PROTECTED)) {
    return;
  }
  final PsiClass containingClass = field.getContainingClass();
  if (containingClass == null || !containingClass.hasModifierProperty(PsiModifier.FINAL)) {
    return;
  }
  registerModifierError(PsiModifier.PROTECTED, field, PsiModifier.PROTECTED);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:12,代碼來源:ProtectedMemberInFinalClassInspectionBase.java

示例11: visitField

import com.intellij.psi.PsiField; //導入方法依賴的package包/類
@Override
public void visitField(@NotNull PsiField field) {
  final PsiClass aClass = field.getContainingClass();
  if (aClass == null) {
    return;
  }
  final String fieldName = field.getName();
  if (HardcodedMethodConstants.SERIAL_VERSION_UID.equals(fieldName)) {
    return;    //special case
  }
  PsiClass ancestorClass = aClass.getSuperClass();
  final Set<PsiClass> visitedClasses = new HashSet<PsiClass>();
  while (ancestorClass != null) {
    if (!visitedClasses.add(ancestorClass)) {
      return;
    }
    final PsiField ancestorField = ancestorClass.findFieldByName(fieldName, false);
    ancestorClass = ancestorClass.getSuperClass();
    if (ancestorField == null) {
      continue;
    }
    if (m_ignoreInvisibleFields && !ClassUtils.isFieldVisible(ancestorField, aClass)) {
      continue;
    }
    if (ignoreStaticFields && field.hasModifierProperty(PsiModifier.STATIC) &&
        ancestorField.hasModifierProperty(PsiModifier.STATIC)) {
      continue;
    }
    registerFieldError(field);
    return;
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:33,代碼來源:FieldHidesSuperclassFieldInspectionBase.java

示例12: visitField

import com.intellij.psi.PsiField; //導入方法依賴的package包/類
@Override
public void visitField(@NotNull PsiField field) {
  final PsiClass aClass = field.getContainingClass();
  if (aClass == null) {
    return;
  }
  final String fieldName = field.getName();
  if (HardcodedMethodConstants.SERIAL_VERSION_UID.equals(fieldName)) {
    return;    //special case
  }
  boolean reportStaticsOnly = false;
  if (aClass.hasModifierProperty(PsiModifier.STATIC)) {
    reportStaticsOnly = true;
  }
  PsiClass ancestorClass =
    ClassUtils.getContainingClass(aClass);
  while (ancestorClass != null) {
    final PsiField ancestorField =
      ancestorClass.findFieldByName(fieldName, false);
    if (ancestorField != null) {
      if (!m_ignoreInvisibleFields ||
          !reportStaticsOnly ||
          field.hasModifierProperty(PsiModifier.STATIC)) {
        registerFieldError(field);
      }
    }
    ancestorClass = ClassUtils.getContainingClass(ancestorClass);
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:30,代碼來源:InnerClassVariableHidesOuterClassVariableInspectionBase.java

示例13: visitField

import com.intellij.psi.PsiField; //導入方法依賴的package包/類
@Override
public void visitField(@NotNull PsiField field) {
  final String propertyName = PropertyUtil.suggestPropertyName(field);
  final boolean isStatic = field.hasModifierProperty(PsiModifier.STATIC);
  final PsiClass containingClass = field.getContainingClass();
  final PsiMethod setter = PropertyUtil.findPropertySetter(containingClass, propertyName, isStatic, false);
  if (setter == null) {
    return;
  }
  final PsiMethod getter = PropertyUtil.findPropertyGetter(containingClass, propertyName, isStatic, false);
  if (getter != null) {
    return;
  }
  registerFieldError(field);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:16,代碼來源:FieldHasSetterButNoGetterInspection.java


注:本文中的com.intellij.psi.PsiField.getContainingClass方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。