Unnamed: 0
int64
0
305k
body
stringlengths
7
52.9k
name
stringlengths
1
185
13,500
boolean (@NotNull PsiAnnotation psiAnnotation, @NotNull PsiClass psiClass, @NotNull ProblemSink builder) { boolean result = true; if (psiClass.isInterface() || psiClass.isAnnotationType()) { builder.addErrorMessage("inspection.message.s.legal.only.on.classes.enums", getSupportedAnnotationClasses()[0]); result = false; } if (result) { final String loggerName = getLoggerName(psiClass); if (hasFieldByName(psiClass, loggerName)) { builder.addErrorMessage("inspection.message.not.generating.field.s.field.with.same.name.already.exists", loggerName); result = false; } } return result; }
validate
13,501
void (@NotNull PsiClass psiClass, @NotNull PsiAnnotation psiAnnotation, @NotNull List<? super PsiElement> target, @Nullable String nameHint) { target.add(createLoggerField(psiClass, psiAnnotation)); }
generatePsiElements
13,502
LombokLightFieldBuilder (@NotNull PsiClass psiClass, @NotNull PsiAnnotation psiAnnotation) { // called only after validation succeeded final Project project = psiClass.getProject(); final PsiManager manager = psiClass.getContainingFile().getManager(); final PsiElementFactory psiElementFactory = JavaPsiFacade.getElementFactory(project); String loggerType = getLoggerType(psiClass); if (loggerType == null) { throw new IllegalStateException("Invalid custom log declaration."); // validated } final PsiType psiLoggerType = psiElementFactory.createTypeFromText(loggerType, psiClass); LombokLightFieldBuilder loggerField = new LombokLightFieldBuilder(manager, getLoggerName(psiClass), psiLoggerType) .withContainingClass(psiClass) .withModifier(PsiModifier.FINAL) .withModifier(PsiModifier.PRIVATE) .withNavigationElement(psiAnnotation); if (isLoggerStatic(psiClass)) { loggerField.withModifier(PsiModifier.STATIC); } final String loggerInitializerParameters = createLoggerInitializeParameters(psiClass, psiAnnotation); final String initializerText = String.format(getLoggerInitializer(psiClass), loggerInitializerParameters); final PsiExpression initializer = psiElementFactory.createExpressionFromText(initializerText, psiClass); loggerField.setInitializer(initializer); return loggerField; }
createLoggerField
13,503
String (@NotNull PsiClass psiClass, @NotNull PsiAnnotation psiAnnotation) { final StringBuilder parametersBuilder = new StringBuilder(); final String topic = PsiAnnotationUtil.getStringAnnotationValue(psiAnnotation, "topic", ""); final boolean topicPresent = !StringUtil.isEmptyOrSpaces(topic); final List<LoggerInitializerParameter> loggerInitializerParameters = getLoggerInitializerParameters(psiClass, topicPresent); for (LoggerInitializerParameter loggerInitializerParameter : loggerInitializerParameters) { if (parametersBuilder.length() > 0) { parametersBuilder.append(", "); } switch (loggerInitializerParameter) { case TYPE -> parametersBuilder.append(psiClass.getName()).append(".class"); case NAME -> parametersBuilder.append(psiClass.getName()).append(".class.getName()"); case TOPIC -> { if (!topicPresent) { // sanity check; either implementation of CustomLogParser or predefined loggers is wrong throw new IllegalStateException("Topic can never be a parameter when topic was not set."); } parametersBuilder.append('"').append(StringUtil.escapeStringCharacters(topic)).append('"'); } case NULL -> parametersBuilder.append("null"); default -> // sanity check; either implementation of CustomLogParser or predefined loggers is wrong throw new IllegalStateException("Unexpected logger initializer parameter " + loggerInitializerParameter); } } return parametersBuilder.toString(); }
createLoggerInitializeParameters
13,504
boolean (@NotNull PsiClass psiClass, @NotNull String fieldName) { final Collection<PsiField> psiFields = PsiClassUtil.collectClassFieldsIntern(psiClass); for (PsiField psiField : psiFields) { if (fieldName.equals(psiField.getName())) { return true; } } return false; }
hasFieldByName
13,505
String (@NotNull PsiClass psiClass) { return ConfigDiscovery.getInstance().getStringLombokConfigProperty(ConfigKey.LOG_CUSTOM_DECLARATION, psiClass); }
getCustomDeclaration
13,506
String (@NotNull PsiClass psiClass) { return CustomLogParser.parseLoggerType(getCustomDeclaration(psiClass)); }
getLoggerType
13,507
boolean ( @NotNull PsiAnnotation psiAnnotation, @NotNull PsiClass psiClass, @NotNull ProblemSink builder ) { if (!super.validate(psiAnnotation, psiClass, builder)) { return false; } final LoggerInitializerDeclaration declaration = CustomLogParser.parseInitializerParameters(getCustomDeclaration(psiClass)); if (declaration == null) { builder.addErrorMessage("inspection.message.custom.log.not.configured.correctly"); return false; } final String topic = PsiAnnotationUtil.getStringAnnotationValue(psiAnnotation, "topic", ""); final boolean topicPresent = !StringUtil.isEmptyOrSpaces(topic); if (topicPresent) { if (!declaration.hasWithTopic()) { builder.addErrorMessage("inspection.message.custom.log.does.not.allow.topic"); return false; } } else { if (!declaration.hasWithoutTopic()) { builder.addErrorMessage("inspection.message.custom.log.requires.topic"); return false; } } return true; }
validate
13,508
String (@NotNull PsiClass psiClass) { return loggerType; }
getLoggerType
13,509
String (@NotNull PsiClass psiClass) { return loggerInitializer; }
getLoggerInitializer
13,510
List<LoggerInitializerParameter> (@NotNull PsiClass psiClass, boolean topicPresent) { return Collections.singletonList(topicPresent ? LoggerInitializerParameter.TOPIC : defaultParameter); }
getLoggerInitializerParameters
13,511
boolean (Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } LoggerInitializerDeclaration that = (LoggerInitializerDeclaration) o; return Objects.equals(withTopic, that.withTopic) && Objects.equals(withoutTopic, that.withoutTopic); }
equals
13,512
int () { return Objects.hash(withTopic, withoutTopic); }
hashCode
13,513
String (@NotNull String customDeclaration) { final Matcher declarationMatcher = DECLARATION_PATTERN.matcher(customDeclaration); if (!declarationMatcher.matches()) { return null; } String loggerType = declarationMatcher.group(1); if (loggerType == null) { loggerType = declarationMatcher.group(2); } return loggerType; }
parseLoggerType
13,514
String (@NotNull String customDeclaration) { final Matcher declarationMatcher = DECLARATION_PATTERN.matcher(customDeclaration); if (!declarationMatcher.matches()) { return null; } return declarationMatcher.group(2) + "." + declarationMatcher.group(3) + "(%s)"; }
parseLoggerInitializer
13,515
LoggerInitializerDeclaration (@NotNull String customDeclaration) { final Matcher declarationMatcher = DECLARATION_PATTERN.matcher(customDeclaration); if (!declarationMatcher.matches()) { return null; } List<LoggerInitializerParameter> withTopic = null; List<LoggerInitializerParameter> withoutTopic = null; final Matcher allParametersMatcher = PARAMETERS_PATTERN.matcher(declarationMatcher.group(4)); while (allParametersMatcher.find()) { final List<LoggerInitializerParameter> splitParameters = splitParameters(allParametersMatcher.group(1)); if (splitParameters.contains(LoggerInitializerParameter.UNKNOWN)) { return null; } if (splitParameters.contains(LoggerInitializerParameter.TOPIC)) { if (withTopic != null) { return null; } withTopic = splitParameters; } else { if (withoutTopic != null) { return null; } withoutTopic = splitParameters; } } return new LoggerInitializerDeclaration(withTopic, withoutTopic); }
parseInitializerParameters
13,516
List<LoggerInitializerParameter> (@NotNull String parameters) { if (parameters.isEmpty()) { return Collections.emptyList(); } return Arrays.stream(parameters.split(",")).map(LoggerInitializerParameter::find).collect(Collectors.toList()); }
splitParameters
13,517
ConfigDiscovery () { return ConfigDiscovery.getInstance(); }
getConfigDiscovery
13,518
boolean (@NotNull PsiModifierList modifierList) { // FieldDefaults only change modifiers of class fields // but not for enum constants or lombok generated fields final PsiElement psiElement = modifierList.getParent(); if (!(psiElement instanceof PsiField) || psiElement instanceof PsiEnumConstant || psiElement instanceof LombokLightFieldBuilder) { return false; } final PsiClass searchableClass = PsiTreeUtil.getParentOfType(modifierList, PsiClass.class, true); return null != searchableClass && canBeAffected(searchableClass); }
isSupported
13,519
void (@NotNull PsiModifierList modifierList, @NotNull final Set<String> modifiers) { if (modifiers.contains(PsiModifier.STATIC) || UtilityClassModifierProcessor.isModifierListSupported(modifierList)) { return; // skip static fields } final PsiClass searchableClass = PsiTreeUtil.getParentOfType(modifierList, PsiClass.class, true); if (searchableClass == null) { return; // Should not get here, but safer to check } @Nullable final PsiAnnotation fieldDefaultsAnnotation = PsiAnnotationSearchUtil.findAnnotation(searchableClass, LombokClassNames.FIELD_DEFAULTS); final boolean isConfigDefaultFinal = isConfigDefaultFinal(searchableClass); final boolean isConfigDefaultPrivate = isConfigDefaultPrivate(searchableClass); final PsiField parentField = (PsiField) modifierList.getParent(); // FINAL if (shouldMakeFinal(parentField, fieldDefaultsAnnotation, isConfigDefaultFinal)) { modifiers.add(PsiModifier.FINAL); } // VISIBILITY if (canChangeVisibility(parentField, modifierList)) { final String defaultAccessLevel = detectDefaultAccessLevel(fieldDefaultsAnnotation, isConfigDefaultPrivate); if (PsiModifier.PRIVATE.equals(defaultAccessLevel)) { modifiers.add(PsiModifier.PRIVATE); modifiers.remove(PsiModifier.PACKAGE_LOCAL); } else if (PsiModifier.PROTECTED.equals(defaultAccessLevel)) { modifiers.add(PsiModifier.PROTECTED); modifiers.remove(PsiModifier.PACKAGE_LOCAL); } else if (PsiModifier.PUBLIC.equals(defaultAccessLevel)) { modifiers.add(PsiModifier.PUBLIC); modifiers.remove(PsiModifier.PACKAGE_LOCAL); } } }
transformModifiers
13,520
boolean (PsiClass searchableClass) { return PsiAnnotationSearchUtil.isAnnotatedWith(searchableClass, LombokClassNames.FIELD_DEFAULTS) || isConfigDefaultFinal(searchableClass) || isConfigDefaultPrivate(searchableClass); }
canBeAffected
13,521
boolean (PsiClass searchableClass) { return getConfigDiscovery().getBooleanLombokConfigProperty(ConfigKey.FIELDDEFAULTS_FINAL, searchableClass); }
isConfigDefaultFinal
13,522
boolean (PsiClass searchableClass) { return getConfigDiscovery().getBooleanLombokConfigProperty(ConfigKey.FIELDDEFAULTS_PRIVATE, searchableClass); }
isConfigDefaultPrivate
13,523
boolean (@NotNull PsiField parentField, @Nullable PsiAnnotation fieldDefaultsAnnotation, boolean isConfigDefaultFinal) { return shouldMakeFinalByDefault(fieldDefaultsAnnotation, isConfigDefaultFinal) && !PsiAnnotationSearchUtil.isAnnotatedWith(parentField, LombokClassNames.NON_FINAL); }
shouldMakeFinal
13,524
boolean (@Nullable PsiAnnotation fieldDefaultsAnnotation, boolean isConfigDefaultFinal) { if (fieldDefaultsAnnotation != null) { // Is @FieldDefaults(makeFinal = true)? return PsiAnnotationUtil.getBooleanAnnotationValue(fieldDefaultsAnnotation, "makeFinal", false); } return isConfigDefaultFinal; }
shouldMakeFinalByDefault
13,525
boolean (@NotNull PsiField parentField, @NotNull PsiModifierList modifierList) { return !hasExplicitAccessModifier(modifierList) && !PsiAnnotationSearchUtil.isAnnotatedWith(parentField, LombokClassNames.PACKAGE_PRIVATE); }
canChangeVisibility
13,526
String (@Nullable PsiAnnotation fieldDefaultsAnnotation, boolean isConfigDefaultPrivate) { final String accessLevelFromAnnotation = fieldDefaultsAnnotation != null ? LombokProcessorUtil.getAccessLevel(fieldDefaultsAnnotation, "level") : null; if (accessLevelFromAnnotation == null && isConfigDefaultPrivate) { return PsiModifier.PRIVATE; } return accessLevelFromAnnotation; }
detectDefaultAccessLevel
13,527
boolean (@NotNull PsiModifierList modifierList) { return modifierList.hasExplicitModifier(PsiModifier.PUBLIC) || modifierList.hasExplicitModifier(PsiModifier.PRIVATE) || modifierList.hasExplicitModifier(PsiModifier.PROTECTED); }
hasExplicitAccessModifier
13,528
boolean (@NotNull PsiModifierList modifierList) { final PsiElement parent = modifierList.getParent(); return (parent instanceof PsiLocalVariable && ValProcessor.isVal((PsiLocalVariable) parent)); }
isSupported
13,529
void (@NotNull PsiModifierList modifierList, @NotNull final Set<String> modifiers) { modifiers.add(PsiModifier.FINAL); }
transformModifiers
13,530
boolean (@NotNull PsiModifierList modifierList) { PsiElement modifierListParent = modifierList.getParent(); if (modifierListParent instanceof PsiClass parentClass) { if (PsiAnnotationSearchUtil.isAnnotatedWith(parentClass, LombokClassNames.UTILITY_CLASS)) { return UtilityClassProcessor.validateOnRightType(parentClass, new ProblemValidationSink()); } } if (!isElementFieldOrMethodOrInnerClass(modifierListParent)) { return false; } PsiClass searchableClass = PsiTreeUtil.getParentOfType(modifierListParent, PsiClass.class, true); return null != searchableClass && PsiAnnotationSearchUtil.isAnnotatedWith(searchableClass, LombokClassNames.UTILITY_CLASS) && UtilityClassProcessor.validateOnRightType(searchableClass, new ProblemValidationSink()); }
isModifierListSupported
13,531
boolean (@NotNull PsiModifierList modifierList) { return isModifierListSupported(modifierList); }
isSupported
13,532
void (@NotNull PsiModifierList modifierList, @NotNull final Set<String> modifiers) { final PsiElement parent = modifierList.getParent(); // FINAL if (parent instanceof PsiClass psiClass) { if (PsiAnnotationSearchUtil.isAnnotatedWith(psiClass, LombokClassNames.UTILITY_CLASS)) { modifiers.add(PsiModifier.FINAL); } } // STATIC if (isElementFieldOrMethodOrInnerClass(parent)) { modifiers.add(PsiModifier.STATIC); } }
transformModifiers
13,533
boolean (PsiElement element) { return element instanceof PsiField || element instanceof PsiMethod || (element instanceof PsiClass && element.getParent() instanceof PsiClass && !((PsiClass) element.getParent()).isInterface()); }
isElementFieldOrMethodOrInnerClass
13,534
boolean (@NotNull PsiModifierList modifierList) { final PsiElement modifierListParent = modifierList.getParent(); if (!(modifierListParent instanceof PsiField || modifierListParent instanceof PsiClass)) { return false; } PsiClass searchableClass = PsiTreeUtil.getParentOfType(modifierList, PsiClass.class, true); return null != searchableClass && PsiAnnotationSearchUtil.isAnnotatedWith(searchableClass, LombokClassNames.VALUE); }
isSupported
13,535
void (@NotNull PsiModifierList modifierList, @NotNull final Set<String> modifiers) { if (modifiers.contains(PsiModifier.STATIC) && modifierList.getParent() instanceof PsiField) { return; // skip static fields } final PsiModifierListOwner parentElement = PsiTreeUtil.getParentOfType(modifierList, PsiModifierListOwner.class, false); if (null != parentElement) { // FINAL if (!PsiAnnotationSearchUtil.isAnnotatedWith(parentElement, LombokClassNames.NON_FINAL)) { modifiers.add(PsiModifier.FINAL); } // PRIVATE if (modifierList.getParent() instanceof PsiField && // Visibility is only changed for package private fields hasPackagePrivateModifier(modifierList) && // except they are annotated with @PackagePrivate !PsiAnnotationSearchUtil.isAnnotatedWith(parentElement, LombokClassNames.PACKAGE_PRIVATE)) { modifiers.add(PsiModifier.PRIVATE); // IDEA _right now_ checks if other modifiers are set, and ignores PACKAGE_LOCAL but may as well clean it up modifiers.remove(PsiModifier.PACKAGE_LOCAL); } } }
transformModifiers
13,536
boolean (@NotNull PsiModifierList modifierList) { return !(modifierList.hasExplicitModifier(PsiModifier.PUBLIC) || modifierList.hasExplicitModifier(PsiModifier.PRIVATE) || modifierList.hasExplicitModifier(PsiModifier.PROTECTED)); }
hasPackagePrivateModifier
13,537
boolean (@NotNull PsiAnnotation psiAnnotation, @NotNull PsiMethod psiMethod, @NotNull ProblemSink problemSink) { boolean result = true; if (psiMethod.hasParameters()) { problemSink.addErrorMessage("inspection.message.delegate.legal.only.on.no.argument.methods"); result = false; } final PsiType returnType = psiMethod.getReturnType(); result &= null != returnType && DelegateHandler.validate(psiMethod, returnType, psiAnnotation, problemSink); return result; }
validate
13,538
void (@NotNull PsiMethod psiMethod, @NotNull PsiAnnotation psiAnnotation, @NotNull List<? super PsiElement> target) { final PsiType returnType = psiMethod.getReturnType(); if (null != returnType) { DelegateHandler.generateElements(psiMethod, returnType, psiAnnotation, target); } }
processIntern
13,539
boolean (@NotNull PsiClass psiClass, @NotNull PsiAnnotation psiAnnotation, @NotNull PsiMethod psiMethod) { return BuilderHandler.checkAnnotationFQN(psiClass, psiAnnotation, psiMethod); }
checkAnnotationFQN
13,540
boolean (@Nullable String nameHint, @NotNull PsiClass psiClass, @NotNull PsiAnnotation psiAnnotation, @NotNull PsiMethod psiMethod) { if (null == nameHint) { return true; } final String innerBuilderClassName = BuilderHandler.getBuilderClassName(psiClass, psiAnnotation, psiMethod); return Objects.equals(nameHint, innerBuilderClassName); }
possibleToGenerateElementNamed
13,541
boolean (@NotNull PsiAnnotation psiAnnotation, @NotNull PsiMethod psiMethod, @NotNull ProblemSink problemSink) { return getHandler().validate(psiMethod, psiAnnotation, problemSink); }
validate
13,542
void (@NotNull PsiMethod psiMethod, @NotNull PsiAnnotation psiAnnotation, @NotNull List<? super PsiElement> target) { final PsiClass psiClass = psiMethod.getContainingClass(); if (null != psiClass) { final BuilderHandler builderHandler = getHandler(); builderHandler.createBuilderClassIfNotExist(psiClass, psiMethod, psiAnnotation).ifPresent(target::add); } }
processIntern
13,543
BuilderHandler () { return new BuilderHandler(); }
getHandler
13,544
List<PsiExtensionMethod> (final @NotNull PsiClass targetClass, final @NotNull String nameHint, final @NotNull PsiElement place) { if (!(place instanceof PsiMethodCallExpression)) { return Collections.emptyList(); } PsiReferenceExpression methodExpression = ((PsiMethodCallExpression)place).getMethodExpression(); PsiExpression qualifierExpression = methodExpression.getQualifierExpression(); if (qualifierExpression == null || !nameHint.equals(methodExpression.getReferenceName()) || qualifierExpression instanceof PsiReferenceExpression && ((PsiReferenceExpression)qualifierExpression).resolve() instanceof PsiClass) { return Collections.emptyList(); } List<PsiExtensionMethod> result = new SmartList<>(); @Nullable PsiClass context = PsiTreeUtil.getContextOfType(place, PsiClass.class); while (context != null) { final @Nullable PsiAnnotation annotation = context.getAnnotation(LombokClassNames.EXTENSION_METHOD); if (annotation != null) { final Set<PsiClass> providers = PsiAnnotationUtil.getAnnotationValues(annotation, PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME, PsiType.class).stream() .filter(PsiClassType.class::isInstance) .map(PsiClassType.class::cast) .map(PsiClassType::resolve) .filter(Objects::nonNull) .collect(Collectors.toSet()); if (!providers.isEmpty()) { List<PsiExtensionMethod> extensionMethods = collectExtensionMethods(providers, ((PsiMethodCallExpression)place), targetClass); extensionMethods .stream() .map(method -> MethodSignatureBackedByPsiMethod.create(method, PsiSubstitutor.EMPTY)) .distinct() .filter(methodSignature -> !targetClass.getVisibleSignatures().contains(methodSignature)) .forEach(methodSignature -> result.add((PsiExtensionMethod)methodSignature.getMethod())); } } context = PsiTreeUtil.getContextOfType(context, PsiClass.class); } return result; }
getExtensionMethods
13,545
List<PsiExtensionMethod> (final Set<PsiClass> providers, final PsiMethodCallExpression callExpression, final PsiClass targetClass) { List<PsiExtensionMethod> psiMethods = new ArrayList<>(); providers.forEach(providerClass -> providerData(providerClass).forEach(function -> ContainerUtil.addIfNotNull(psiMethods, function.apply(targetClass, callExpression)))); return psiMethods; }
collectExtensionMethods
13,546
PsiExtensionMethod (PsiMethod staticMethod, PsiClass targetClass, PsiMethodCallExpression callExpression) { if (!staticMethod.getName().equals(callExpression.getMethodExpression().getReferenceName())) return null; PsiClass providerClass = Objects.requireNonNull(staticMethod.getContainingClass()); PsiMethodCallExpression staticMethodCall; try { StringBuilder args = new StringBuilder(Objects.requireNonNull(callExpression.getMethodExpression().getQualifierExpression()).getText()); PsiExpression[] expressions = callExpression.getArgumentList().getExpressions(); if (expressions.length > 0) { args.append(", "); } args.append(StringUtil.join(expressions, expression -> expression.getText(), ",")); staticMethodCall = (PsiMethodCallExpression)JavaPsiFacade.getElementFactory(staticMethod.getProject()) .createExpressionFromText(providerClass.getQualifiedName() + "." + staticMethod.getName() + "(" + args + ")", callExpression); } catch (ProcessCanceledException e) { throw e; } catch (Throwable e) { LOG.error(e); return null; } JavaResolveResult result = staticMethodCall.resolveMethodGenerics(); if (!(result instanceof MethodCandidateInfo)) return null; PsiMethod method = ((MethodCandidateInfo)result).getElement(); if (!method.equals(staticMethod) || !((MethodCandidateInfo)result).isApplicable()) return null; PsiSubstitutor substitutor = result.getSubstitutor(); final LombokExtensionMethod lightMethod = new LombokExtensionMethod(staticMethod); lightMethod .addModifiers(PsiModifier.PUBLIC); PsiParameter @NotNull [] parameters = staticMethod.getParameterList().getParameters(); if (targetClass.isInterface()) { lightMethod.addModifier(PsiModifier.DEFAULT); } lightMethod.setMethodReturnType(substitutor.substitute(staticMethod.getReturnType())); for (int i = 1, length = parameters.length; i < length; i++) { PsiParameter parameter = parameters[i]; lightMethod.addParameter(new LombokLightParameter(parameter.getName(), substitutor.substitute(parameter.getType()), lightMethod, JavaLanguage.INSTANCE)); } PsiClassType[] thrownTypes = staticMethod.getThrowsList().getReferencedTypes(); for (PsiClassType thrownType : thrownTypes) { lightMethod.addException((PsiClassType)substitutor.substitute(thrownType)); } PsiTypeParameter[] staticMethodTypeParameters = staticMethod.getTypeParameters(); HashSet<PsiTypeParameter> initialTypeParameters = ContainerUtil.newHashSet(staticMethodTypeParameters); Arrays.stream(staticMethodTypeParameters) .filter(typeParameter -> PsiTypesUtil.mentionsTypeParameters(substitutor.substitute(typeParameter), initialTypeParameters)) .forEach(lightMethod::addTypeParameter); lightMethod.setNavigationElement(staticMethod); lightMethod.setContainingClass(targetClass); return lightMethod; }
createLightMethodBySignature
13,547
boolean (final PsiElement another) { return myStaticMethod.isEquivalentTo(another); }
isEquivalentTo
13,548
PsiMethod () { return myStaticMethod; }
getTargetMethod
13,549
boolean (@NotNull PsiClass psiClass, @NotNull PsiAnnotation psiAnnotation, @NotNull PsiMethod psiMethod) { return PsiAnnotationSearchUtil.checkAnnotationHasOneOfFQNs(psiAnnotation, getSupportedAnnotationClasses()); }
checkAnnotationFQN
13,550
boolean (@Nullable String nameHint, @NotNull PsiClass psiClass, @NotNull PsiAnnotation psiAnnotation, @NotNull PsiMethod psiMethod) { return true; }
possibleToGenerateElementNamed
13,551
Collection<PsiAnnotation> (@NotNull PsiClass psiClass) { List<PsiAnnotation> result = new ArrayList<>(); for (PsiMethod psiMethod : PsiClassUtil.collectClassMethodsIntern(psiClass)) { PsiAnnotation psiAnnotation = PsiAnnotationSearchUtil.findAnnotation(psiMethod, getSupportedAnnotationClasses()); if (null != psiAnnotation) { result.add(psiAnnotation); } } return result; }
collectProcessedAnnotations
13,552
Collection<LombokProblem> (@NotNull PsiAnnotation psiAnnotation) { Collection<LombokProblem> result = Collections.emptyList(); PsiMethod psiMethod = PsiTreeUtil.getParentOfType(psiAnnotation, PsiMethod.class); if (null != psiMethod) { ProblemValidationSink problemNewBuilder = new ProblemValidationSink(); validate(psiAnnotation, psiMethod, problemNewBuilder); result = problemNewBuilder.getProblems(); } return result; }
verifyAnnotation
13,553
boolean (@NotNull PsiAnnotation psiAnnotation, @NotNull PsiMethod psiMethod, @NotNull ProblemSink problemSink) { // we skip validation here, because it will be validated by other BuilderClassProcessor return true;//builderHandler.validate(psiMethod, psiAnnotation, builder); }
validate
13,554
boolean (@NotNull PsiClass psiClass, @NotNull PsiAnnotation psiAnnotation, @NotNull PsiMethod psiMethod) { return BuilderHandler.checkAnnotationFQN(psiClass, psiAnnotation, psiMethod); }
checkAnnotationFQN
13,555
void (@NotNull PsiMethod psiMethod, @NotNull PsiAnnotation psiAnnotation, @NotNull List<? super PsiElement> target) { final PsiClass psiClass = psiMethod.getContainingClass(); final BuilderHandler builderHandler = getHandler(); if (null != psiClass) { PsiClass builderClass = builderHandler.getExistInnerBuilderClass(psiClass, psiMethod, psiAnnotation).orElse(null); if (null == builderClass) { // have to create full class (with all methods) here, or auto-completion doesn't work builderClass = builderHandler.createBuilderClass(psiClass, psiMethod, psiAnnotation); } target.addAll( builderHandler.createBuilderDefaultProviderMethodsIfNecessary(psiClass, null, builderClass, psiAnnotation)); builderHandler.createBuilderMethodIfNecessary(psiClass, psiMethod, builderClass, psiAnnotation) .ifPresent(target::add); builderHandler.createToBuilderMethodIfNecessary(psiClass, psiMethod, builderClass, psiAnnotation) .ifPresent(target::add); } }
processIntern
13,556
BuilderHandler () { return new BuilderHandler(); }
getHandler
13,557
void (@NotNull ActionContext context, @NotNull PsiElement element, @NotNull ModPsiUpdater updater) { PsiElement parent = PsiTreeUtil.getParentOfType(element, PsiVariable.class, PsiClass.class, PsiMethod.class); if (parent instanceof PsiField) { handleField((PsiField)parent); } else if (parent instanceof PsiMethod) { handleMethod((PsiMethod)parent); } }
invoke
13,558
void (@NotNull PsiMethod psiMethod) { findAnchorFieldForGetter(psiMethod) .map(PsiField::getModifierList) .ifPresent(modifierList -> replaceWithAnnotation(modifierList, psiMethod, LombokClassNames.GETTER)); findAnchorFieldForSetter(psiMethod) .map(PsiField::getModifierList) .ifPresent(modifierList -> replaceWithAnnotation(modifierList, psiMethod, LombokClassNames.SETTER)); }
handleMethod
13,559
Optional<PsiMethod> (@NotNull PsiField psiField) { final PsiMethod getterForField = PropertyUtilBase.findGetterForField(psiField); if (null != getterForField && !(getterForField instanceof LombokLightMethodBuilder)) { if (findAnchorFieldForGetter(getterForField).filter(psiField::equals).isPresent()) { return Optional.of(getterForField); } } return Optional.empty(); }
findGetterMethodToReplace
13,560
Optional<PsiMethod> (@NotNull PsiField psiField) { final PsiMethod setterForField = PropertyUtilBase.findSetterForField(psiField); if (null != setterForField && !(setterForField instanceof LombokLightMethodBuilder)) { if (findAnchorFieldForSetter(setterForField).filter(psiField::equals).isPresent()) { return Optional.of(setterForField); } } return Optional.empty(); }
findSetterMethodToReplace
13,561
void (@NotNull PsiField psiField) { PsiModifierList psiFieldModifierList = psiField.getModifierList(); if (null == psiFieldModifierList) { return; } // replace getter if it matches the requirements findGetterMethodToReplace(psiField).ifPresent( psiMethod -> replaceWithAnnotation(psiFieldModifierList, psiMethod, LombokClassNames.GETTER) ); // replace setter if it matches the requirements findSetterMethodToReplace(psiField).ifPresent( psiMethod -> replaceWithAnnotation(psiFieldModifierList, psiMethod, LombokClassNames.SETTER) ); }
handleField
13,562
Optional<PsiField> (@NotNull PsiMethod method) { // it seems wrong to replace abstract possible getters // abstract methods maybe the part of interface so let them live if (!PropertyUtilBase.isSimplePropertySetter(method) || method.hasModifierProperty(PsiModifier.ABSTRACT)) { return Optional.empty(); } // check the parameter list // it should have 1 parameter with the same type if (Optional.of(method.getParameterList()) .filter(paramList -> paramList.getParametersCount() == 1) .map(paramList -> paramList.getParameter(0)) .map(PsiParameter::getType) .filter(expectedType -> Optional.ofNullable(method.getContainingClass()) .map(PsiClassUtil::collectClassFieldsIntern) .orElse(Collections.emptyList()) .stream() .filter(field -> method.getName().equals(LombokUtils.getSetterName(field))) .noneMatch(field -> expectedType.equals(field.getType())) ).isPresent()) { return Optional.empty(); } PsiCodeBlock body = method.getBody(); if (body == null) { return Optional.ofNullable(method.getContainingClass()) .map(PsiClassUtil::collectClassFieldsIntern) .orElse(Collections.emptyList()) .stream() .filter(field -> method.getName().equals(LombokUtils.getSetterName(field))) .findAny(); } else if (body.getStatementCount() == 1) { // validate that the method body doesn't contain anything additional // and also contain proper assign statement Optional<PsiAssignmentExpression> assignmentExpression = Optional.of(body.getStatements()[0]) .filter(PsiExpressionStatement.class::isInstance) .map(PsiExpressionStatement.class::cast) .map(PsiExpressionStatement::getExpression) .filter(PsiAssignmentExpression.class::isInstance) .map(PsiAssignmentExpression.class::cast); if (assignmentExpression.map(PsiAssignmentExpression::getRExpression) .filter(PsiReferenceExpression.class::isInstance).map(PsiReferenceExpression.class::cast) .map(PsiReferenceExpression::resolve).filter(PsiParameter.class::isInstance).isPresent()) { return assignmentExpression.map(PsiAssignmentExpression::getLExpression) .filter(PsiReferenceExpression.class::isInstance).map(PsiReferenceExpression.class::cast) .map(PsiReferenceExpression::resolve).filter(PsiField.class::isInstance) .map(PsiField.class::cast); } } return Optional.empty(); }
findAnchorFieldForSetter
13,563
Optional<PsiField> (@NotNull PsiMethod method) { // it seems wrong to replace abstract possible getters // abstract methods maybe the part of interface so let them live if (!PropertyUtilBase.isSimplePropertyGetter(method) || method.hasModifierProperty(PsiModifier.ABSTRACT)) { return Optional.empty(); } PsiCodeBlock body = method.getBody(); if (body == null) { return Optional.ofNullable(method.getContainingClass()) .map(PsiClassUtil::collectClassFieldsIntern) .orElse(Collections.emptyList()) .stream() .filter(field -> method.getName().equals(LombokUtils.getGetterName(field))) .findAny(); } else if (body.getStatementCount() == 1) { return Optional.of(body.getStatements()[0]) .filter(PsiReturnStatement.class::isInstance) .map(PsiReturnStatement.class::cast) .map(PsiReturnStatement::getReturnValue) .map(PsiUtil::deparenthesizeExpression) .filter(PsiReferenceExpression.class::isInstance) .map(PsiReferenceExpression.class::cast) .map(PsiReferenceExpression::resolve) .filter(PsiField.class::isInstance) .map(PsiField.class::cast); } return Optional.empty(); }
findAnchorFieldForGetter
13,564
void (@NotNull PsiModifierList modifierList, @NotNull PsiMethod method, @NotNull String annotationName) { final Optional<String> accessLevelFQN = LombokProcessorUtil.convertModifierToLombokAccessLevel(method); method.delete(); PsiAnnotation addedAnnotation = modifierList.addAnnotation(annotationName); if (accessLevelFQN.isPresent()) { PsiExpression accessLevelExpression = PsiElementFactory.getInstance(modifierList.getProject()) .createExpressionFromText(accessLevelFQN.get(), null); addedAnnotation.setDeclaredAttributeValue(PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME, accessLevelExpression); } }
replaceWithAnnotation
13,565
String () { return LombokBundle.message("replace.with.annotations.lombok"); }
getFamilyName
13,566
void (@NotNull ActionContext context, @NotNull PsiElement element, @NotNull ModPsiUpdater updater) { final PsiDeclarationStatement declarationStatement = PsiTreeUtil.getParentOfType(element, PsiDeclarationStatement.class); if (declarationStatement != null) { invokeOnDeclarationStatement(declarationStatement); return; } final PsiParameter parameter = PsiTreeUtil.getParentOfType(element, PsiParameter.class); if (parameter != null) { invokeOnVariable(parameter); } }
invoke
13,567
String () { return LombokBundle.message("replace.explicit.type.with.0.lombok", StringUtil.getShortName(variableClassName)); }
getFamilyName
13,568
boolean (PsiDeclarationStatement context) { if (PsiUtil.isLanguageLevel10OrHigher(context)) { return false; } PsiElement[] declaredElements = context.getDeclaredElements(); if (declaredElements.length != 1) { return false; } PsiElement declaredElement = declaredElements[0]; if (!(declaredElement instanceof PsiLocalVariable localVariable)) { return false; } if (!localVariable.hasInitializer()) { return false; } PsiExpression initializer = localVariable.getInitializer(); if (initializer instanceof PsiArrayInitializerExpression || initializer instanceof PsiLambdaExpression) { return false; } if (localVariable.getTypeElement().isInferredType()) { return false; } return isAvailableOnDeclarationCustom(context, localVariable); }
isAvailableOnDeclarationStatement
13,569
void (PsiDeclarationStatement declarationStatement) { if (declarationStatement.getDeclaredElements().length == 1) { PsiLocalVariable localVariable = (PsiLocalVariable) declarationStatement.getDeclaredElements()[0]; invokeOnVariable(localVariable); } }
invokeOnDeclarationStatement
13,570
void (PsiVariable psiVariable) { Project project = psiVariable.getProject(); psiVariable.normalizeDeclaration(); PsiTypeElement typeElement = psiVariable.getTypeElement(); if (typeElement == null || typeElement.isInferredType()) { return; } PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(project); PsiClass variablePsiClass = JavaPsiFacade.getInstance(project).findClass(variableClassName, psiVariable.getResolveScope()); if (variablePsiClass == null) { return; } PsiJavaCodeReferenceElement referenceElementByFQClassName = elementFactory.createReferenceElementByFQClassName(variableClassName, psiVariable.getResolveScope()); typeElement = (PsiTypeElement) IntroduceVariableUtil.expandDiamondsAndReplaceExplicitTypeWithVar(typeElement, typeElement); typeElement.deleteChildRange(typeElement.getFirstChild(), typeElement.getLastChild()); typeElement.add(referenceElementByFQClassName); RemoveRedundantTypeArgumentsUtil.removeRedundantTypeArguments(psiVariable); executeAfterReplacing(psiVariable); CodeStyleManager.getInstance(project).reformat(psiVariable); }
invokeOnVariable
13,571
boolean (@NotNull PsiDeclarationStatement declarationStatement, @NotNull PsiLocalVariable localVariable) { return !(declarationStatement.getParent() instanceof PsiForStatement); }
isAvailableOnDeclarationCustom
13,572
void (PsiVariable psiVariable) { PsiModifierList modifierList = psiVariable.getModifierList(); if (modifierList != null) { modifierList.setModifierProperty(FINAL, false); } }
executeAfterReplacing
13,573
boolean (PsiVariable psiVariable) { if (!(psiVariable instanceof PsiParameter parameter)) { return false; } if (!(parameter.getDeclarationScope() instanceof PsiForeachStatement)) { return false; } PsiTypeElement typeElement = parameter.getTypeElement(); return typeElement == null || !typeElement.isInferredType(); }
isAvailableOnVariable
13,574
boolean (@NotNull PsiDeclarationStatement declarationStatement, @NotNull PsiLocalVariable localVariable) { return isNotFinal(localVariable); }
isAvailableOnDeclarationCustom
13,575
void (PsiVariable psiVariable) { }
executeAfterReplacing
13,576
boolean (@NotNull PsiVariable psiVariable) { if (!(psiVariable instanceof PsiParameter psiParameter)) { return false; } PsiElement declarationScope = psiParameter.getDeclarationScope(); if (!(declarationScope instanceof PsiForStatement) && !(declarationScope instanceof PsiForeachStatement)) { return false; } PsiTypeElement typeElement = psiParameter.getTypeElement(); return typeElement != null && !typeElement.isInferredType() && isNotFinal(psiParameter); }
isAvailableOnVariable
13,577
boolean (@NotNull PsiVariable variable) { PsiModifierList modifierList = variable.getModifierList(); return modifierList == null || !modifierList.hasExplicitModifier(FINAL); }
isNotFinal
13,578
void (PsiVariable psiVariable) { }
executeAfterReplacing
13,579
String () { return LombokBundle.message("replace.0.with.explicit.type.lombok", StringUtil.getShortName(variableClassName)); }
getFamilyName
13,580
boolean (PsiVariable psiVariable) { if (LombokClassNames.VAL.equals(variableClassName)) { return ValProcessor.isVal(psiVariable); } if (LombokClassNames.VAR.equals(variableClassName)) { return ValProcessor.isVar(psiVariable); } return false; }
isAvailableOnVariable
13,581
boolean (PsiDeclarationStatement context) { if (context.getDeclaredElements().length <= 0) { return false; } PsiElement declaredElement = context.getDeclaredElements()[0]; if (!(declaredElement instanceof PsiLocalVariable)) { return false; } return isAvailableOnVariable((PsiLocalVariable) declaredElement); }
isAvailableOnDeclarationStatement
13,582
void (PsiDeclarationStatement declarationStatement) { if (declarationStatement.getDeclaredElements().length > 0) { PsiElement declaredElement = declarationStatement.getDeclaredElements()[0]; if (declaredElement instanceof PsiLocalVariable) { invokeOnVariable((PsiLocalVariable) declaredElement); } } }
invokeOnDeclarationStatement
13,583
void (PsiVariable psiVariable) { PsiTypeElement psiTypeElement = psiVariable.getTypeElement(); if (psiTypeElement == null) { return; } PsiTypesUtil.replaceWithExplicitType(psiTypeElement); RemoveRedundantTypeArgumentsUtil.removeRedundantTypeArguments(psiVariable); executeAfterReplacing(psiVariable); CodeStyleManager.getInstance(psiVariable.getProject()).reformat(psiVariable); }
invokeOnVariable
13,584
void (PsiVariable psiVariable) { PsiModifierList psiModifierList = psiVariable.getModifierList(); if (psiModifierList != null) { psiModifierList.setModifierProperty(PsiModifier.FINAL, true); } }
executeAfterReplacing
13,585
ExternalClassResolveResult (@NotNull String shortClassName, @NotNull ThreeState isAnnotation, @NotNull Module contextModule) { if (isAnnotation == ThreeState.YES && simpleNameToFQNameMap.containsKey(shortClassName)) { return new ExternalClassResolveResult(simpleNameToFQNameMap.get(shortClassName), LOMBOK_DESCRIPTOR); } return null; }
resolveClass
13,586
ExternalLibraryDescriptor (@NotNull String packageName) { if (allLombokPackages.contains(packageName)) { return LOMBOK_DESCRIPTOR; } return null; }
resolvePackage
13,587
String (final @NotNull PsiField psiField) { final AccessorsInfo accessorsInfo = AccessorsInfo.buildFor(psiField); return getGetterName(psiField, accessorsInfo); }
getGetterName
13,588
String (@NotNull PsiField psiField, @NotNull AccessorsInfo accessorsInfo) { final String psiFieldName = psiField.getName(); final boolean isBoolean = PsiTypes.booleanType().equals(psiField.getType()); return toGetterName(accessorsInfo, psiFieldName, isBoolean); }
getGetterName
13,589
String (@NotNull PsiField psiField) { final AccessorsInfo accessorsInfo = AccessorsInfo.buildFor(psiField); return getSetterName(psiField, accessorsInfo); }
getSetterName
13,590
String (@NotNull PsiField psiField, @NotNull AccessorsInfo accessorsInfo) { return toSetterName(accessorsInfo, psiField.getName(), PsiTypes.booleanType().equals(psiField.getType())); }
getSetterName
13,591
String (@NotNull PsiVariable psiVariable, @NotNull AccessorsInfo accessorsInfo) { return toWitherName(accessorsInfo.withFluent(false), psiVariable.getName(), PsiTypes.booleanType().equals(psiVariable.getType())); }
getWitherName
13,592
String (@NotNull AccessorsInfo accessors, String fieldName, boolean isBoolean) { return toAccessorName(accessors, fieldName, isBoolean, "is", "get"); }
toGetterName
13,593
String (@NotNull AccessorsInfo accessors, String fieldName, boolean isBoolean) { return toAccessorName(accessors, fieldName, isBoolean, "set", "set"); }
toSetterName
13,594
String (@NotNull AccessorsInfo accessors, String fieldName, boolean isBoolean) { if (accessors.isFluent()) { throw new IllegalArgumentException("@Wither does not support @Accessors(fluent=true)"); } return toAccessorName(accessors, fieldName, isBoolean, "with", "with"); }
toWitherName
13,595
String (@NotNull AccessorsInfo accessorsInfo, String fieldName, boolean isBoolean, String booleanPrefix, String normalPrefix) { final String result; fieldName = accessorsInfo.removePrefix(fieldName); if (accessorsInfo.isFluent()) { return fieldName; } final boolean useBooleanPrefix = isBoolean && !accessorsInfo.isDoNotUseIsPrefix(); if (useBooleanPrefix) { if (fieldName.startsWith("is") && fieldName.length() > 2 && !Character.isLowerCase(fieldName.charAt(2))) { final String baseName = fieldName.substring(2); result = buildName(booleanPrefix, baseName, accessorsInfo.getCapitalizationStrategy()); } else { result = buildName(booleanPrefix, fieldName, accessorsInfo.getCapitalizationStrategy()); } } else { result = buildName(normalPrefix, fieldName, accessorsInfo.getCapitalizationStrategy()); } return result; }
toAccessorName
13,596
Collection<String> (@NotNull AccessorsInfo accessorsInfo, String fieldName, boolean isBoolean) { return toAllAccessorNames(accessorsInfo, fieldName, isBoolean, "is", "get"); }
toAllGetterNames
13,597
Collection<String> (@NotNull AccessorsInfo accessorsInfo, String fieldName, boolean isBoolean) { return toAllAccessorNames(accessorsInfo, fieldName, isBoolean, "set", "set"); }
toAllSetterNames
13,598
Collection<String> (@NotNull AccessorsInfo accessorsInfo, String fieldName, boolean isBoolean) { if (accessorsInfo.isFluent()) { throw new IllegalArgumentException("@Wither does not support @Accessors(fluent=true)"); } return toAllAccessorNames(accessorsInfo, fieldName, isBoolean, "with", "with"); }
toAllWitherNames
13,599
Collection<String> (@NotNull AccessorsInfo accessorsInfo, String fieldName, boolean isBoolean, String booleanPrefix, String normalPrefix) { Collection<String> result = new HashSet<>(); fieldName = accessorsInfo.removePrefix(fieldName); if (accessorsInfo.isFluent()) { result.add(StringUtil.decapitalize(fieldName)); return result; } final CapitalizationStrategy capitalizationStrategy = accessorsInfo.getCapitalizationStrategy(); if (isBoolean) { result.add(buildName(normalPrefix, fieldName, capitalizationStrategy)); result.add(buildName(booleanPrefix, fieldName, capitalizationStrategy)); if (fieldName.startsWith("is") && fieldName.length() > 2 && !Character.isLowerCase(fieldName.charAt(2))) { final String baseName = fieldName.substring(2); result.add(buildName(normalPrefix, baseName, capitalizationStrategy)); result.add(buildName(booleanPrefix, baseName, capitalizationStrategy)); } } else { result.add(buildName(normalPrefix, fieldName, capitalizationStrategy)); } return result; }
toAllAccessorNames