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


Java PsiField.getType方法代碼示例

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


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

示例1: visitField

import com.intellij.psi.PsiField; //導入方法依賴的package包/類
@Override
public void visitField(@NotNull PsiField field) {
  super.visitField(field);
  if (field instanceof PsiEnumConstant) {
    return;
  }
  if (!field.hasModifierProperty(PsiModifier.STATIC) || !field.hasModifierProperty(PsiModifier.FINAL)) {
    return;
  }
  final String name = field.getName();
  if (name == null) {
    return;
  }
  final PsiType type = field.getType();
  if (onlyCheckImmutables && !ClassUtils.isImmutable(type)) {
    return;
  }
  if (isValid(name)) {
    return;
  }
  registerFieldError(field, name);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:23,代碼來源:ConstantNamingConventionInspectionBase.java

示例2: resolveFieldConfigType

import com.intellij.psi.PsiField; //導入方法依賴的package包/類
Optional<PsiClass> resolveFieldConfigType(PsiField psiField) {
    PsiType fieldType = psiField.getType();
    if (fieldType instanceof PsiClassType) {
        PsiClassType fieldClassType = ((PsiClassType) fieldType);
        if (collectionType != null && collectionType.isAssignableFrom(fieldType) && fieldClassType.getParameterCount() == 1) {
            return toPsiClass(fieldClassType.getParameters()[0]);
        } else if (mapType != null && mapType.isAssignableFrom(fieldType) && fieldClassType.getParameterCount() == 2) {
            return toPsiClass(fieldClassType.getParameters()[1]);
        } else {
            return toPsiClass(fieldType);
        }
    } else if (fieldType instanceof PsiArrayType) {
        return toPsiClass(((PsiArrayType) fieldType).getComponentType());
    } else {
        return Optional.empty();
    }
}
 
開發者ID:seedstack,項目名稱:intellij-plugin,代碼行數:18,代碼來源:CoffigResolver.java

示例3: visitField

import com.intellij.psi.PsiField; //導入方法依賴的package包/類
@Override
public void visitField(@NotNull PsiField field) {
  super.visitField(field);
  if (!field.hasModifierProperty(PsiModifier.PUBLIC)) {
    return;
  }
  if (!field.hasModifierProperty(PsiModifier.STATIC)) {
    return;
  }
  final PsiType type = field.getType();
  if (!(type instanceof PsiArrayType)) {
    return;
  }
  if (CollectionUtils.isConstantEmptyArray(field)) {
    return;
  }
  registerFieldError(field);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:19,代碼來源:PublicStaticArrayFieldInspection.java

示例4: visitField

import com.intellij.psi.PsiField; //導入方法依賴的package包/類
@Override
public void visitField(@NotNull PsiField field) {
  if (!field.hasModifierProperty(PsiModifier.STATIC)) {
    return;
  }
  if (field.hasModifierProperty(PsiModifier.FINAL)) {
    if (!checkMutableFinals) {
      return;
    }
    else {
      final PsiType type = field.getType();
      if (ClassUtils.isImmutable(type)) {
        return;
      }
    }
  }
  final String name = field.getName();
  if (name == null) {
    return;
  }
  if (isValid(name)) {
    return;
  }
  registerFieldError(field, name);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:26,代碼來源:StaticVariableNamingConventionInspectionBase.java

示例5: visitClass

import com.intellij.psi.PsiField; //導入方法依賴的package包/類
@Override
public void visitClass(@NotNull PsiClass aClass) {
  // no call to super, so it doesn't drill down
  if (aClass.isInterface() || aClass.isAnnotationType()) {
    return;
  }
  PsiField badSerialPersistentFields = null;
  final PsiField[] fields = aClass.getFields();
  for (final PsiField field : fields) {
    if (isSerialPersistentFields(field)) {
      if (!field.hasModifierProperty(PsiModifier.PRIVATE) ||
          !field.hasModifierProperty(PsiModifier.STATIC) ||
          !field.hasModifierProperty(PsiModifier.FINAL)) {
        badSerialPersistentFields = field;
        break;
      }
      else {
        final PsiType type = field.getType();
        if (!type.equalsToText("java.io.ObjectStreamField" +
                               "[]")) {
          badSerialPersistentFields = field;
          break;
        }
      }
    }
  }
  if (badSerialPersistentFields == null) {
    return;
  }
  if (!SerializationUtils.isSerializable(aClass)) {
    return;
  }
  registerFieldError(badSerialPersistentFields);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:35,代碼來源:SerialPersistentFieldsWithWrongSignatureInspection.java

示例6: visitField

import com.intellij.psi.PsiField; //導入方法依賴的package包/類
@Override
public void visitField(@NotNull PsiField field) {
  super.visitField(field);
  if (!field.hasModifierProperty(PsiModifier.PUBLIC)) {
    return;
  }
  if (!field.hasModifierProperty(PsiModifier.STATIC)) {
    return;
  }
  final PsiType type = field.getType();
  if (!CollectionUtils.isCollectionClassOrInterface(type)) {
    return;
  }
  registerFieldError(field);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:16,代碼來源:PublicStaticCollectionFieldInspection.java

示例7: visitField

import com.intellij.psi.PsiField; //導入方法依賴的package包/類
@Override
public void visitField(@NotNull PsiField field) {
  super.visitField(field);
  final PsiType type = field.getType();
  if (!type.equalsToText(CommonClassNames.JAVA_LANG_STRING_BUFFER) &&
      !type.equalsToText(CommonClassNames.JAVA_LANG_STRING_BUILDER)) {
    return;
  }
  registerFieldError(field, type);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:11,代碼來源:StringBufferFieldInspection.java

示例8: visitField

import com.intellij.psi.PsiField; //導入方法依賴的package包/類
@Override
public void visitField(@NotNull PsiField field) {
  if (!field.hasModifierProperty(PsiModifier.STATIC)) {
    return;
  }
  final PsiType type = field.getType();
  if (!CollectionUtils.isCollectionClassOrInterface(type)) {
    return;
  }
  if (!m_ignoreWeakCollections ||
      CollectionUtils.isWeakCollectionClass(type)) {
    return;
  }
  registerFieldError(field);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:16,代碼來源:StaticCollectionInspection.java

示例9: visitField

import com.intellij.psi.PsiField; //導入方法依賴的package包/類
@Override
public void visitField(@NotNull PsiField field) {
  super.visitField(field);
  if (!field.hasModifierProperty(PsiModifier.VOLATILE)) {
    return;
  }
  final PsiType type = field.getType();
  if (PsiType.LONG.equals(type) || PsiType.DOUBLE.equals(type)) {
    registerFieldError(field, type);
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:12,代碼來源:VolatileLongOrDoubleFieldInspection.java

示例10: visitField

import com.intellij.psi.PsiField; //導入方法依賴的package包/類
@Override
public void visitField(@NotNull PsiField field) {
  super.visitField(field);
  if (!field.hasModifierProperty(PsiModifier.VOLATILE)) {
    return;
  }
  final PsiType type = field.getType();
  if (type.getArrayDimensions() == 0) {
    return;
  }
  registerFieldError(field, type);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:13,代碼來源:VolatileArrayFieldInspection.java

示例11: checkElement

import com.intellij.psi.PsiField; //導入方法依賴的package包/類
@Override
@Nullable
public CommonProblemDescriptor[] checkElement(
  @NotNull RefEntity refEntity, @NotNull AnalysisScope analysisScope,
  @NotNull InspectionManager inspectionManager,
  @NotNull GlobalInspectionContext globalInspectionContext) {
  if (!(refEntity instanceof RefField)) {
    return null;
  }
  final RefField refField = (RefField)refEntity;
  final PsiField field = refField.getElement();
  if (field == null) {
    return null;
  }
  final PsiType type = field.getType();
  if (!type.equals(PsiType.BOOLEAN)) {
    return null;
  }

  final RefClass fieldClass = refField.getOwnerClass();
  final Collection<RefElement> inReferences = refField.getInReferences();
  final RefJavaUtil refUtil = RefJavaUtil.getInstance();
  final Set<RefClass> classesUsed = new HashSet<RefClass>();
  for (RefElement inReference : inReferences) {
    final RefClass referringClass = refUtil.getOwnerClass(inReference);
    if (referringClass == null) {
      return null;
    }
    if (referringClass.equals(fieldClass)) {
      return null;
    }
    classesUsed.add(referringClass);
    if (classesUsed.size() > 1) {
      return null;
    }
  }
  if (classesUsed.size() != 1) {
    return null;
  }
  final RefClass referencingClass = classesUsed.iterator().next();
  //TODO: check that referencing class is a subclass of the field class
  final String errorString = "Field " + refEntity.getName() + " is only accessed in subclass " + referencingClass.getName();
  return new CommonProblemDescriptor[]{inspectionManager.createProblemDescriptor(errorString)};
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:45,代碼來源:FieldCanBeMovedToSubclassInspection.java

示例12: checkElement

import com.intellij.psi.PsiField; //導入方法依賴的package包/類
@Override
@Nullable
public CommonProblemDescriptor[] checkElement(
  @NotNull RefEntity refEntity, @NotNull AnalysisScope analysisScope,
  @NotNull InspectionManager inspectionManager,
  @NotNull GlobalInspectionContext globalInspectionContext) {
  if (!(refEntity instanceof RefField)) {
    return null;
  }
  final RefField refField = (RefField)refEntity;
  final PsiField field = refField.getElement();
  if (field == null) {
    return null;
  }
  final PsiType type = field.getType();
  if (!type.equals(PsiType.BOOLEAN)) {
    return null;
  }

  final RefClass fieldClass = refField.getOwnerClass();
  final Collection<RefElement> inReferences = refField.getInReferences();
  final RefJavaUtil refUtil = RefJavaUtil.getInstance();
  final Set<RefClass> classesUsed = new HashSet<RefClass>();
  for (RefElement inReference : inReferences) {
    final RefClass referringClass = refUtil.getOwnerClass(inReference);
    if (referringClass == null) {
      return null;
    }
    if (referringClass.equals(fieldClass)) {
      return null;
    }
    classesUsed.add(referringClass);
    if (classesUsed.size() > 1) {
      return null;
    }
  }
  if (classesUsed.size() != 1) {
    return null;
  }
  final RefClass referencingClass = classesUsed.iterator().next();
  final String errorString = "Static field " + refEntity.getName() + " is only accessed in subclass " + referencingClass.getName();
  return new CommonProblemDescriptor[]{inspectionManager.createProblemDescriptor(errorString)};
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:44,代碼來源:StaticFieldCanBeMovedToUseInspection.java


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