com.intellij.psi.PsiField Java Examples

The following examples show how to use com.intellij.psi.PsiField. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JavaParamsObjectBuilder.java    From OkHttpParamsGet with Apache License 2.0 6 votes vote down vote up
@Override
protected void buildMethodBody(PsiClass psiClass, PsiField[] fields, boolean needAll, StringBuilder sb) {
    for (PsiField field : fields) {
        PsiElement older = null;
        if (field instanceof KtLightField) {
            older = ((KtLightField) field).getKotlinOrigin();
        }
        if (!findIgnore(older == null ? field : older)) {
            String defaultName  = getParamName(older == null ? field : older);
            if (isNullable(field)) {
                addNullableValue(field, sb, defaultName);
            } else {
                sb.append(mFieldName).append(".put(");
                if (defaultName == null ) {
                    sb.append('"').append(field.getName()).append('"');
                } else {
                    sb.append(defaultName);
                }
                sb.append(", ").append(toString(field)).append(");");
            }

        }
    }
}
 
Example #2
Source File: KotlinParamsFileBodyBuilder.java    From OkHttpParamsGet with Apache License 2.0 6 votes vote down vote up
@Override
protected void addNullableValue(PsiField field, StringBuilder sb, String defaultName) {
    boolean add = PropertiesComponent.getInstance().getBoolean(Constant.VALUE_NULL, false);
    if (!add) {
        sb.append(field.getName()).append("?.also{\n");
        sb.append(mFieldName).append(".addFormDataPart(");
        if (defaultName == null) {
            sb.append('"').append(field.getName()).append('"');
        } else {
            sb.append(defaultName);
        }
        sb.append(", ").append(toString(field, false, "it")).append(")\n}\n");
    } else {
        sb.append(mFieldName).append(".addFormDataPart(");
        if (defaultName == null) {
            sb.append('"').append(field.getName()).append('"');
        } else {
            sb.append(defaultName);
        }
        sb.append(", ").append(toString(field, true, null)).append(" ?: \"\" )\n");
    }
}
 
Example #3
Source File: LazyGetterHandler.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static boolean isInitializedInConstructors(@NotNull PsiElement element) {
  if (!(element instanceof PsiIdentifier)) {
    return false;
  }
  PsiElement parent = element.getParent();
  if (!(parent instanceof PsiReferenceExpression)) {
    return false;
  }
  PsiElement qualifier = ((PsiReferenceExpression) parent).getQualifier();
  if (qualifier == null) {
    return false;
  }
  PsiReference reference = qualifier.getReference();
  if (reference == null) {
    return false;
  }
  PsiElement field = reference.resolve();
  if (!(field instanceof PsiField)) {
    return false;
  }
  PsiClass containingClass = ((PsiField) field).getContainingClass();
  if (containingClass == null) {
    return false;
  }
  return isInitializedInConstructors((PsiField) field, containingClass);
}
 
Example #4
Source File: PsiJavaElementVisitor.java    From KodeBeagle with Apache License 2.0 6 votes vote down vote up
private void visitPsiFields(final PsiField psiField) {
    if (!ClassUtils.isPrimitive(psiField.getType())) {
        String type = removeSpecialSymbols(psiField.getType().getCanonicalText());
        if (psiField.getInitializer() != null) {
            PsiExpression psiExpression = psiField.getInitializer();
            if (psiExpression != null) {
                PsiType psiType = psiExpression.getType();
                if (psiType != null && !ClassUtils.isPrimitive(psiType)) {
                    String psiFieldInitializer =
                            removeSpecialSymbols(psiType.getCanonicalText());
                    addInMap(psiFieldInitializer, emptySet);
                }
            }
        }
        addInMap(type, emptySet);
    }
}
 
Example #5
Source File: GetterFieldProcessor.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private boolean validateExistingMethods(@NotNull PsiField psiField, @NotNull ProblemBuilder builder) {
  boolean result = true;
  final PsiClass psiClass = psiField.getContainingClass();
  if (null != psiClass) {
    final boolean isBoolean = PsiType.BOOLEAN.equals(psiField.getType());
    final AccessorsInfo accessorsInfo = AccessorsInfo.build(psiField);
    final Collection<String> methodNames = LombokUtils.toAllGetterNames(accessorsInfo, psiField.getName(), isBoolean);
    final Collection<PsiMethod> classMethods = PsiClassUtil.collectClassMethodsIntern(psiClass);
    filterToleratedElements(classMethods);

    for (String methodName : methodNames) {
      if (PsiMethodUtil.hasSimilarMethod(classMethods, methodName, 0)) {
        final String setterMethodName = LombokUtils.getGetterName(psiField);

        builder.addWarning("Not generated '%s'(): A method with similar name '%s' already exists", setterMethodName, methodName);
        result = false;
      }
    }
  }
  return result;
}
 
Example #6
Source File: ConfigElementsUtils.java    From aircon with MIT License 6 votes vote down vote up
public static String getConfigFieldType(final PsiField configField) {
	final PsiAnnotation configAnnotation = extractConfigAnnotation(configField);

	if (configAnnotation == null) {
		return null;
	}

	if (isJsonConfigAnnotation(configAnnotation)) {
		final PsiImmediateClassType jsonType = getAttributeValue(configAnnotation, ATTRIBUTE_TYPE);
		return jsonType.resolve()
		               .getQualifiedName();
	}
	else if (isEnumConfigAnnotation(configAnnotation)) {
		return getEnumConfigImplClass(configAnnotation);
	}
	else if (isColorConfigAnnotation(configAnnotation)) {
		return getColorIntClass();
	}
	else if (isConfigGroupAnnotation(configAnnotation)) {
		return getConfigGroupImplClass(configField);
	}
	else {
		final PsiClass annotationClass = ElementUtils.getAnnotationDeclarationClass(configAnnotation);
		return annotationClass != null ? ElementUtils.getQualifiedName(getDefaultValueMethod(annotationClass).getReturnType()) : null;
	}
}
 
Example #7
Source File: Decider.java    From dagger-intellij-plugin with Apache License 2.0 6 votes vote down vote up
@Override public boolean shouldShow(UsageTarget target, Usage usage) {
  PsiElement element = ((UsageInfo2UsageAdapter) usage).getElement();

  PsiField field = PsiConsultantImpl.findField(element);
  if (field != null //
      && PsiConsultantImpl.hasAnnotation(field, CLASS_INJECT) //
      && PsiConsultantImpl.hasQuailifierAnnotations(field, qualifierAnnotations)
      && PsiConsultantImpl.hasTypeParameters(field, typeParameters)) {
    return true;
  }

  PsiMethod method = PsiConsultantImpl.findMethod(element);
  if (method != null && (PsiConsultantImpl.hasAnnotation(method, CLASS_INJECT)
          || PsiConsultantImpl.hasAnnotation(method, CLASS_PROVIDES))) {
    for (PsiParameter parameter : method.getParameterList().getParameters()) {
      PsiClass parameterClass = PsiConsultantImpl.checkForLazyOrProvider(parameter);
      if (parameterClass.equals(returnType) && PsiConsultantImpl.hasQuailifierAnnotations(
          parameter, qualifierAnnotations)
          && PsiConsultantImpl.hasTypeParameters(parameter, typeParameters)) {
        return true;
      }
    }
  }

  return false;
}
 
Example #8
Source File: GetterFieldProcessor.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@NotNull
public PsiMethod createGetterMethod(@NotNull PsiField psiField, @NotNull PsiClass psiClass, @NotNull String methodModifier) {
  final String methodName = LombokUtils.getGetterName(psiField);

  LombokLightMethodBuilder methodBuilder = new LombokLightMethodBuilder(psiField.getManager(), methodName)
    .withMethodReturnType(psiField.getType())
    .withContainingClass(psiClass)
    .withNavigationElement(psiField);
  if (StringUtil.isNotEmpty(methodModifier)) {
    methodBuilder.withModifier(methodModifier);
  }
  boolean isStatic = psiField.hasModifierProperty(PsiModifier.STATIC);
  if (isStatic) {
    methodBuilder.withModifier(PsiModifier.STATIC);
  }

  final String blockText = String.format("return %s.%s;", isStatic ? psiClass.getName() : "this", psiField.getName());
  methodBuilder.withBody(PsiMethodUtil.createCodeBlockFromText(blockText, methodBuilder));

  PsiModifierList modifierList = methodBuilder.getModifierList();
  copyAnnotations(psiField, modifierList,
    LombokUtils.NON_NULL_PATTERN, LombokUtils.NULLABLE_PATTERN, LombokUtils.DEPRECATED_PATTERN);
  addOnXAnnotations(PsiAnnotationSearchUtil.findAnnotation(psiField, Getter.class), modifierList, "onMethod");
  return methodBuilder;
}
 
Example #9
Source File: PsiJavaElementVisitor.java    From KodeBeagle with Apache License 2.0 6 votes vote down vote up
@Override
public final void visitElement(final PsiElement element) {
    super.visitElement(element);
    if (startOffset <= element.getTextOffset() && element.getTextOffset() <= endOffset) {
        if (element.getNode().getElementType().equals(JavaElementType.FIELD)) {
            visitPsiFields((PsiField) element);
        } else if (element.getNode().getElementType().
                equals(JavaElementType.DECLARATION_STATEMENT)) {
            visitPsiDeclarationStatement((PsiDeclarationStatement) element);
        } else if (element.getNode().getElementType().equals(JavaElementType.CATCH_SECTION)) {
            visitPsiCatchSection((PsiCatchSection) element);
        } else if (element.getNode().getElementType().
                equals(JavaElementType.RETURN_STATEMENT)) {
            visitPsiReturnStatement((PsiReturnStatement) element);
        } else {
            visitExpression(element);
        }
    }
}
 
Example #10
Source File: SetterFieldProcessor.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private boolean validateExistingMethods(@NotNull PsiField psiField, @NotNull ProblemBuilder builder) {
  boolean result = true;
  final PsiClass psiClass = psiField.getContainingClass();
  if (null != psiClass) {
    final Collection<PsiMethod> classMethods = PsiClassUtil.collectClassMethodsIntern(psiClass);
    filterToleratedElements(classMethods);

    final boolean isBoolean = PsiType.BOOLEAN.equals(psiField.getType());
    final Collection<String> methodNames = getAllSetterNames(psiField, isBoolean);

    for (String methodName : methodNames) {
      if (PsiMethodUtil.hasSimilarMethod(classMethods, methodName, 1)) {
        final String setterMethodName = getSetterName(psiField, isBoolean);

        builder.addWarning("Not generated '%s'(): A method with similar name '%s' already exists", setterMethodName, methodName);
        result = false;
      }
    }
  }
  return result;
}
 
Example #11
Source File: KotlinParamsFilePartBuilder.java    From OkHttpParamsGet with Apache License 2.0 6 votes vote down vote up
@Override
protected void addNullableValue(PsiField field, StringBuilder sb, String defaultName) {
    boolean add = PropertiesComponent.getInstance().getBoolean(Constant.VALUE_NULL, false);
    if (!add) {
        sb.append(field.getName()).append("?.also{\n");
        sb.append(mFieldName).append(".add(").append(getValueType()).append(".createFormData(");
        if (defaultName == null) {
            sb.append('"').append(field.getName()).append('"');
        } else {
            sb.append(defaultName);
        }
        sb.append(", ").append(toString(field, false, "it")).append("))\n}\n");
    } else {
        sb.append(mFieldName).append(".add(").append(getValueType()).append(".createFormData(");
        if (defaultName == null) {
            sb.append('"').append(field.getName()).append('"');
        } else {
            sb.append(defaultName);
        }
        sb.append(", ").append(toString(field, true, null)).append(" ?: \"\"))\n");
    }
}
 
Example #12
Source File: EqualsAndHashCodeToStringHandler.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private String buildAttributeNameString(boolean doNotUseGetters, @NotNull PsiField classField, @NotNull PsiClass psiClass) {
  final String fieldName = classField.getName();
  if (doNotUseGetters) {
    return fieldName;
  } else {
    final String getterName = LombokUtils.getGetterName(classField);

    final boolean hasGetter;
    @SuppressWarnings("unchecked") final boolean annotatedWith = PsiAnnotationSearchUtil.isAnnotatedWith(psiClass, Data.class, Value.class, Getter.class);
    if (annotatedWith) {
      final PsiAnnotation getterLombokAnnotation = PsiAnnotationSearchUtil.findAnnotation(psiClass, Getter.class);
      hasGetter = null == getterLombokAnnotation || null != LombokProcessorUtil.getMethodModifier(getterLombokAnnotation);
    } else {
      hasGetter = PsiMethodUtil.hasMethodByName(PsiClassUtil.collectClassMethodsIntern(psiClass), getterName);
    }

    return hasGetter ? getterName + "()" : fieldName;
  }
}
 
Example #13
Source File: KotlinParamsStringBuilder.java    From OkHttpParamsGet with Apache License 2.0 6 votes vote down vote up
@Override
protected void addNullableValue(PsiField field, StringBuilder sb, String defaultName) {
    boolean add = PropertiesComponent.getInstance().getBoolean(Constant.VALUE_NULL, false);
    if (!add) {
        sb.append(field.getName()).append("?.also{\n");
        sb.append(mFieldName).append("[");
        if (defaultName == null) {
            sb.append('"').append(field.getName()).append('"');
        } else {
            sb.append(defaultName);
        }
        sb.append("] = ").append(toString(field, false, "it")).append("\n}\n");
    } else {
        sb.append(mFieldName).append("[");
        if (defaultName == null) {
            sb.append('"').append(field.getName()).append('"');
        } else {
            sb.append(defaultName);
        }
        sb.append("] = ").append(toString(field, true, null)).append("?: \"\"\n");
    }
}
 
Example #14
Source File: LombokUtils.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static String getGetterName(final @NotNull PsiField psiField) {
  final AccessorsInfo accessorsInfo = AccessorsInfo.build(psiField);

  final String psiFieldName = psiField.getName();
  final boolean isBoolean = PsiType.BOOLEAN.equals(psiField.getType());

  return LombokUtils.toGetterName(accessorsInfo, psiFieldName, isBoolean);
}
 
Example #15
Source File: LombokFieldFindUsagesHandlerFactory.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public boolean canFindUsages(@NotNull PsiElement element) {
  if (element instanceof PsiField && !DumbService.isDumb(element.getProject())) {
    final PsiField psiField = (PsiField) element;
    final PsiClass containingClass = psiField.getContainingClass();
    if (containingClass != null) {
      return Arrays.stream(containingClass.getMethods()).anyMatch(LombokLightMethodBuilder.class::isInstance) ||
        Arrays.stream(containingClass.getInnerClasses()).anyMatch(LombokLightClassBuilder.class::isInstance);
    }
  }
  return false;
}
 
Example #16
Source File: SetterFieldProcessor.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private boolean validateFinalModifier(@NotNull PsiAnnotation psiAnnotation, @NotNull PsiField psiField, @NotNull ProblemBuilder builder) {
  boolean result = true;
  if (psiField.hasModifierProperty(PsiModifier.FINAL) && null != LombokProcessorUtil.getMethodModifier(psiAnnotation)) {
    builder.addWarning("Not generating setter for this field: Setters cannot be generated for final fields.",
      PsiQuickFixFactory.createModifierListFix(psiField, PsiModifier.FINAL, false, false));
    result = false;
  }
  return result;
}
 
Example #17
Source File: PsiPropDefaultsExtractor.java    From litho with Apache License 2.0 5 votes vote down vote up
/** Get the prop defaults from the given {@link PsiClass}. */
public static ImmutableList<PropDefaultModel> getPropDefaults(PsiClass psiClass) {
  final List<PropDefaultModel> propDefaults = new ArrayList<>();

  for (PsiField psiField : psiClass.getFields()) {
    propDefaults.addAll(extractFromField(psiField));
  }

  return ImmutableList.copyOf(propDefaults);
}
 
Example #18
Source File: GetterFieldProcessor.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected void generatePsiElements(@NotNull PsiField psiField, @NotNull PsiAnnotation psiAnnotation, @NotNull List<? super PsiElement> target) {
  final String methodVisibility = LombokProcessorUtil.getMethodModifier(psiAnnotation);
  final PsiClass psiClass = psiField.getContainingClass();
  if (null != methodVisibility && null != psiClass) {
    target.add(createGetterMethod(psiField, psiClass, methodVisibility));
  }
}
 
Example #19
Source File: AbstractFieldNameConstantsProcessor.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@NotNull
Collection<PsiField> filterFields(@NotNull PsiClass psiClass, PsiAnnotation psiAnnotation) {
  final Collection<PsiField> psiFields = new ArrayList<>();

  final boolean onlyExplicitlyIncluded = PsiAnnotationUtil.getBooleanAnnotationValue(psiAnnotation, "onlyExplicitlyIncluded", false);

  for (PsiField psiField : PsiClassUtil.collectClassFieldsIntern(psiClass)) {
    boolean useField = true;
    PsiModifierList modifierList = psiField.getModifierList();
    if (null != modifierList) {

      //Skip static fields.
      useField = !modifierList.hasModifierProperty(PsiModifier.STATIC);
      //Skip transient fields
      useField &= !modifierList.hasModifierProperty(PsiModifier.TRANSIENT);
    }
    //Skip fields that start with $
    useField &= !psiField.getName().startsWith(LombokUtils.LOMBOK_INTERN_FIELD_MARKER);
    //Skip fields annotated with @FieldNameConstants.Exclude
    useField &= !PsiAnnotationSearchUtil.isAnnotatedWith(psiField, FIELD_NAME_CONSTANTS_EXCLUDE);

    if (onlyExplicitlyIncluded) {
      //Only use fields annotated with @FieldNameConstants.Include, Include annotation overrides other rules
      useField = PsiAnnotationSearchUtil.isAnnotatedWith(psiField, FIELD_NAME_CONSTANTS_INCLUDE);
    }

    if (useField) {
      psiFields.add(psiField);
    }
  }
  return psiFields;
}
 
Example #20
Source File: PsiElementDispatcher.java    From intellij-reference-diagram with Apache License 2.0 5 votes vote down vote up
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);
                }
            }
        }
    }
    if (psiElement instanceof PsiMethod) {
        return processMethod((PsiMethod) psiElement);
    }
    if (psiElement instanceof PsiField) {
        return processField((PsiField) psiElement);
    }
    if (psiElement instanceof PsiClassInitializer) {
        return processClassInitializer((PsiClassInitializer) psiElement);
    }
    if (psiElement instanceof PsiJavaDirectoryImpl) {
        return processPackage((PsiJavaDirectoryImpl) psiElement);
    }
    if (psiElement instanceof PsiJavaFile) {
        return processFile((PsiJavaFile) psiElement);
    }
    throw new IllegalArgumentException("Type of PsiElement not supported: " + psiElement);
}
 
Example #21
Source File: SynchronizedProcessor.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@NotNull
@Override
public Collection<LombokProblem> verifyAnnotation(@NotNull PsiAnnotation psiAnnotation) {
  final ProblemNewBuilder problemNewBuilder = new ProblemNewBuilder(2);

  PsiMethod psiMethod = PsiTreeUtil.getParentOfType(psiAnnotation, PsiMethod.class);
  if (null != psiMethod) {
    if (psiMethod.hasModifierProperty(PsiModifier.ABSTRACT)) {
      problemNewBuilder.addError("'@Synchronized' is legal only on concrete methods.",
        PsiQuickFixFactory.createModifierListFix(psiMethod, PsiModifier.ABSTRACT, false, false)
      );
    }

    final String lockFieldName = PsiAnnotationUtil.getStringAnnotationValue(psiAnnotation, "value");
    if (StringUtil.isNotEmpty(lockFieldName)) {
      final PsiClass containingClass = psiMethod.getContainingClass();

      if (null != containingClass) {
        final PsiField lockField = containingClass.findFieldByName(lockFieldName, true);
        if (null != lockField) {
          if (!lockField.hasModifierProperty(PsiModifier.FINAL)) {
            problemNewBuilder.addWarning(String.format("Synchronization on a non-final field %s.", lockFieldName),
              PsiQuickFixFactory.createModifierListFix(lockField, PsiModifier.FINAL, true, false));
          }
        } else {
          final PsiClassType javaLangObjectType = PsiType.getJavaLangObject(containingClass.getManager(), containingClass.getResolveScope());

          problemNewBuilder.addError(String.format("The field %s does not exist.", lockFieldName),
            PsiQuickFixFactory.createNewFieldFix(containingClass, lockFieldName, javaLangObjectType, "new Object()", PsiModifier.PRIVATE, PsiModifier.FINAL));
        }
      }
    }
  } else {
    problemNewBuilder.addError("'@Synchronized' is legal only on methods.");
  }

  return problemNewBuilder.getProblems();
}
 
Example #22
Source File: EnumClassMetadata.java    From intellij-spring-assistant with MIT License 5 votes vote down vote up
@Override
protected Collection<? extends SuggestionDocumentationHelper> doFindDirectChildrenForQueryPrefix(
    Module module, String querySegmentPrefix, @Nullable Set<String> siblingsToExclude) {
  if (childrenTrie != null && childLookup != null) {
    SortedMap<String, PsiField> prefixMap = childrenTrie.prefixMap(querySegmentPrefix);
    if (!isEmpty(prefixMap)) {
      return getMatchStreamAfterExclusions(childLookup, prefixMap.values(), siblingsToExclude)
          .map(EnumKeySuggestionDocumentationHelper::new).collect(toList());
    }
  }
  return null;
}
 
Example #23
Source File: LombokReferenceSearcher.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void processQuery(@NotNull ReferencesSearch.SearchParameters queryParameters, @NotNull Processor consumer) {
  PsiElement refElement = queryParameters.getElementToSearch();

  if (refElement instanceof PsiField) {
    DumbService.getInstance(queryParameters.getProject()).runReadActionInSmartMode(() ->
      processPsiField((PsiField) refElement, queryParameters.getOptimizer()));
  }
}
 
Example #24
Source File: ExtractClassCandidateRefactoring.java    From IntelliJDeodorant with MIT License 5 votes vote down vote up
public Set<PsiField> getExtractedFieldFragments() {
    Map<Integer, PsiField> extractedFieldFragmentMap = new TreeMap<>();
    for (Entity entity : extractedEntities) {
        if (entity instanceof MyAttribute) {
            MyAttribute attribute = (MyAttribute) entity;
            int index = sourceClass.getAttributeList().indexOf(attribute);
            extractedFieldFragmentMap.put(index, attribute.getFieldObject().getVariableDeclaration());
        }
    }
    return new LinkedHashSet<>(extractedFieldFragmentMap.values());
}
 
Example #25
Source File: BuilderHandler.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static boolean isDefaultBuilderValue(@NotNull PsiElement highlightedElement) {
  PsiField field = PsiTreeUtil.getParentOfType(highlightedElement, PsiField.class);
  if (field == null) {
    return false;
  }

  return PsiAnnotationSearchUtil.isAnnotatedWith(field, Builder.Default.class.getCanonicalName());
}
 
Example #26
Source File: JavaClassUtils.java    From camel-idea-plugin with Apache License 2.0 5 votes vote down vote up
public PsiClass resolveClassReference(@NotNull PsiReference reference) {
    final PsiElement resolveElement = reference.resolve();

    if (resolveElement instanceof PsiClass) {
        return (PsiClass) resolveElement;
    } else if (resolveElement instanceof PsiField) {
        final PsiType psiType = PsiUtil.getTypeByPsiElement(resolveElement);
        if (psiType != null) {
            return ((PsiClassReferenceType) psiType).resolve();
        }
    }

    return null;
}
 
Example #27
Source File: ConfigElementsUtils.java    From aircon with MIT License 5 votes vote down vote up
public static boolean isConfigFieldReference(final PsiElement element) {
	if (!ElementUtils.isFieldReference(element)) {
		return false;
	}

	final PsiField configField = ElementUtils.getReferencedField(element);
	if (!isConfigField(configField)) {
		return false;
	}
	return true;
}
 
Example #28
Source File: AbstractClassProcessor.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@NotNull
@Override
public Collection<LombokProblem> verifyAnnotation(@NotNull PsiAnnotation psiAnnotation) {
  Collection<LombokProblem> result = Collections.emptyList();
  // check first for fields, methods and filter it out, because PsiClass is parent of all annotations and will match other parents too
  @SuppressWarnings("unchecked")
  PsiElement psiElement = PsiTreeUtil.getParentOfType(psiAnnotation, PsiField.class, PsiMethod.class, PsiClass.class);
  if (psiElement instanceof PsiClass) {
    ProblemNewBuilder problemNewBuilder = new ProblemNewBuilder();
    validate(psiAnnotation, (PsiClass) psiElement, problemNewBuilder);
    result = problemNewBuilder.getProblems();
  }

  return result;
}
 
Example #29
Source File: SetterFieldProcessor.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private PsiType getReturnType(@NotNull PsiField psiField) {
  PsiType result = PsiType.VOID;
  if (!psiField.hasModifierProperty(PsiModifier.STATIC) && AccessorsInfo.build(psiField).isChain()) {
    final PsiClass fieldClass = psiField.getContainingClass();
    if (null != fieldClass) {
      result = PsiClassUtil.getTypeWithGenerics(fieldClass);
    }
  }
  return result;
}
 
Example #30
Source File: FieldDefaultsModifierTest.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@NotNull
private PsiModifierList getFieldModifierListAtCaret() {
  PsiFile file = loadToPsiFile(getTestName(false) + ".java");
  PsiField field = PsiTreeUtil.getParentOfType(file.findElementAt(myFixture.getCaretOffset()), PsiField.class);

  assertNotNull(field);

  PsiModifierList modifierList = field.getModifierList();
  assertNotNull(modifierList);

  return modifierList;
}