本文整理匯總了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);
}
示例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();
}
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
}
示例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);
}
示例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)};
}
示例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)};
}