Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE #3437] @JpaAssociationSync annotation for bidirectional entity associations #3692

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Roel Spilker <[email protected]>
Roland Praml <[email protected]>
Rostislav Krasny <[email protected]>
Samuel Pereira <[email protected]>
Sergey Rukin <[email protected]>
Sasha Koning <[email protected]>
Szymon Pacanowski <[email protected]>
Taiki Sugawara <[email protected]>
Expand Down
7 changes: 7 additions & 0 deletions src/core/lombok/ConfigurationKeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -743,4 +743,11 @@ private ConfigurationKeys() {}
* If set, <em>any</em> usage of {@code @StandardException} results in a warning / error.
*/
public static final ConfigurationKey<FlagUsageType> STANDARD_EXCEPTION_FLAG_USAGE = new ConfigurationKey<FlagUsageType>("lombok.standardException.flagUsage", "Emit a warning or error if @StandardException is used.") {};

/**
* lombok configuration: {@code lombok.jpaAssociationSync.flagUsage} = {@code WARNING} | {@code ERROR}.
*
* If set, <em>any</em> usage of {@code @JpaAssociationSync} results in a warning / error.
*/
public static final ConfigurationKey<FlagUsageType> JPA_ASSOCIATION_SYNC_FLAG_USAGE = new ConfigurationKey<FlagUsageType>("lombok.jpaAssociationSync.flagUsage", "Emit a warning or error if @JpaAssociationSync is used.") {};
}
4 changes: 4 additions & 0 deletions src/core/lombok/core/AnnotationValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -571,4 +571,8 @@ public boolean isMarking() {
for (AnnotationValue v : values.values()) if (v.isExplicit) return false;
return true;
}

public Class<A> getType() {
return this.type;
}
}
25 changes: 22 additions & 3 deletions src/core/lombok/core/configuration/CapitalizationStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,47 @@
public enum CapitalizationStrategy {
BASIC {
@Override public String capitalize(String in) {
if (in.length() == 0) return in;
if (in.isEmpty()) return in;
char first = in.charAt(0);
if (!Character.isLowerCase(first)) return in;
boolean useUpperCase = in.length() > 2 &&
(Character.isTitleCase(in.charAt(1)) || Character.isUpperCase(in.charAt(1)));
return (useUpperCase ? Character.toUpperCase(first) : Character.toTitleCase(first)) + in.substring(1);
}

@Override public String uncapitalize(String in) {
if (in.isEmpty()) return in;
char first = in.charAt(0);
if (!Character.isUpperCase(first)) return in;
boolean useLowerCase = in.length() > 2 &&
(Character.isTitleCase(in.charAt(1)) || Character.isLowerCase(in.charAt(1)));
return (useLowerCase ? Character.toLowerCase(first) : Character.toTitleCase(first)) + in.substring(1);
}
},
BEANSPEC {
@Override public String capitalize(String in) {
if (in.length() == 0) return in;
if (in.isEmpty()) return in;
char first = in.charAt(0);
if (!Character.isLowerCase(first) || (in.length() > 1 && Character.isUpperCase(in.charAt(1)))) return in;
boolean useUpperCase = in.length() > 2 && Character.isTitleCase(in.charAt(1));
return (useUpperCase ? Character.toUpperCase(first) : Character.toTitleCase(first)) + in.substring(1);
}

@Override public String uncapitalize(String in) {
if (in.isEmpty()) return in;
char first = in.charAt(0);
if (!Character.isUpperCase(first) || (in.length() > 1 && Character.isLowerCase(in.charAt(1)))) return in;
boolean useLowerCase = in.length() > 2 && Character.isTitleCase(in.charAt(1));
return (useLowerCase ? Character.isLowerCase(first) : Character.toTitleCase(first)) + in.substring(1);
}
},
;

public static CapitalizationStrategy defaultValue() {
return BASIC;
}

public abstract String capitalize(String in);

public abstract String uncapitalize(String in);
}
42 changes: 41 additions & 1 deletion src/core/lombok/core/handlers/HandlerUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,47 @@ public static String camelCaseToConstant(String fieldName) {
}
return b.toString();
}


/**
* @param node Any node (used to fetch config of capitalization strategy).
* @param str any string.
* @return string with uppercased first char.
*/
public static String capitalize(LombokNode<?, ?, ?> node, String str) {
CapitalizationStrategy capitalizationStrategy = node.getAst().readConfigurationOr(ConfigurationKeys.ACCESSORS_JAVA_BEANS_SPEC_CAPITALIZATION, CapitalizationStrategy.defaultValue());
return capitalize(str, capitalizationStrategy);
}

/**
* @param str any string.
* @return string with uppercased first char.
*/
public static String capitalize(String str, CapitalizationStrategy capitalizationStrategy) {
if (str == null || str.isEmpty()) return str;

return capitalizationStrategy.capitalize(str);
}

/**
* @param node Any node (used to fetch config of capitalization strategy).
* @param str any string.
* @return string with lowercased first char.
*/
public static String uncapitalize(LombokNode<?, ?, ?> node, String str) {
CapitalizationStrategy capitalizationStrategy = node.getAst().readConfigurationOr(ConfigurationKeys.ACCESSORS_JAVA_BEANS_SPEC_CAPITALIZATION, CapitalizationStrategy.defaultValue());
return uncapitalize(str, capitalizationStrategy);
}

/**
* @param str any string.
* @return string with lowercased first char.
*/
public static String uncapitalize(String str, CapitalizationStrategy capitalizationStrategy) {
if (str == null || str.isEmpty()) return str;

return capitalizationStrategy.uncapitalize(str);
}

/** Matches any of the 8 primitive wrapper names, such as {@code Boolean}. */
private static final Pattern PRIMITIVE_WRAPPER_TYPE_NAME_PATTERN = Pattern.compile("^(?:java\\.lang\\.)?(?:Boolean|Byte|Short|Integer|Long|Float|Double|Character)$");

Expand Down
132 changes: 132 additions & 0 deletions src/core/lombok/eclipse/EclipseASTVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -465,5 +465,137 @@ public boolean isDeferUntilPostDiet() {
}
}

/**
* A default implementation of the {@link EclipseASTVisitor} interface.
* This class provides empty method implementations for all the methods in the {@link EclipseASTVisitor} interface.
* Subclasses can override the methods they are interested in.
*/
public static abstract class Default implements EclipseASTVisitor {
@Override
public void visitCompilationUnit(EclipseNode top, CompilationUnitDeclaration unit) {

}

@Override
public void endVisitCompilationUnit(EclipseNode top, CompilationUnitDeclaration unit) {

}

@Override
public void visitType(EclipseNode typeNode, TypeDeclaration type) {

}

@Override
public void visitAnnotationOnType(TypeDeclaration type, EclipseNode annotationNode, Annotation annotation) {

}

@Override
public void endVisitType(EclipseNode typeNode, TypeDeclaration type) {

}

@Override
public void visitField(EclipseNode fieldNode, FieldDeclaration field) {

}

@Override
public void visitAnnotationOnField(FieldDeclaration field, EclipseNode annotationNode, Annotation annotation) {

}

@Override
public void endVisitField(EclipseNode fieldNode, FieldDeclaration field) {

}

@Override
public void visitInitializer(EclipseNode initializerNode, Initializer initializer) {

}

@Override
public void endVisitInitializer(EclipseNode initializerNode, Initializer initializer) {

}

@Override
public void visitMethod(EclipseNode methodNode, AbstractMethodDeclaration method) {

}

@Override
public void visitAnnotationOnMethod(AbstractMethodDeclaration method, EclipseNode annotationNode, Annotation annotation) {

}

@Override
public void endVisitMethod(EclipseNode methodNode, AbstractMethodDeclaration method) {

}

@Override
public void visitMethodArgument(EclipseNode argNode, Argument arg, AbstractMethodDeclaration method) {

}

@Override
public void visitAnnotationOnMethodArgument(Argument arg, AbstractMethodDeclaration method, EclipseNode annotationNode, Annotation annotation) {

}

@Override
public void endVisitMethodArgument(EclipseNode argNode, Argument arg, AbstractMethodDeclaration method) {

}

@Override
public void visitLocal(EclipseNode localNode, LocalDeclaration local) {

}

@Override
public void visitAnnotationOnLocal(LocalDeclaration local, EclipseNode annotationNode, Annotation annotation) {

}

@Override
public void endVisitLocal(EclipseNode localNode, LocalDeclaration local) {

}

@Override
public void visitTypeUse(EclipseNode typeUseNode, TypeReference typeUse) {

}

@Override
public void visitAnnotationOnTypeUse(TypeReference typeUse, EclipseNode annotationNode, Annotation annotation) {

}

@Override
public void endVisitTypeUse(EclipseNode typeUseNode, TypeReference typeUse) {

}

@Override
public void visitStatement(EclipseNode statementNode, Statement statement) {

}

@Override
public void endVisitStatement(EclipseNode statementNode, Statement statement) {

}

@Override
public boolean isDeferUntilPostDiet() {
return false;
}
}

boolean isDeferUntilPostDiet();
}
14 changes: 14 additions & 0 deletions src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -2992,4 +2992,18 @@ public static boolean hasParsedBody(EclipseNode method) {
}
return false;
}

public static List<TypeReference> getGenericTypes(TypeReference fieldType) {
List<TypeReference> result = new ArrayList<TypeReference>();

TypeReference[][] typeArguments = fieldType.getTypeArguments();
if (typeArguments != null) {
for (TypeReference[] arg : typeArguments) {
if (arg == null) continue;
result.addAll(Arrays.asList(arg));
}
}

return result;
}
}
Loading