Skip to content

Commit

Permalink
code reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
DineshSolanki committed Feb 4, 2023
1 parent b27eecb commit d569a1b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ public void actionPerformed(AnActionEvent e) {
}

/**
Determines if the action should be enabled based on the given project and selected file.
also sets the selectedClass and psiJavaFile fields
@param project the current project
@param selectedFile the currently selected file
@return true if the action should be enabled, false otherwise
* Determines if the action should be enabled based on the given project and selected file.
* also sets the selectedClass and psiJavaFile fields
*
* @param project the current project
* @param selectedFile the currently selected file
* @return true if the action should be enabled, false otherwise
*/
private boolean shouldEnableAction(Project project, VirtualFile selectedFile) {
boolean isEnable = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public class DatabaseConnection {
private String connectionString;
private DatabaseType databaseType;

public DatabaseConnection(String connectionString, DatabaseType databaseName) {
this.connectionString = connectionString;
this.databaseType = databaseName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class AnnotationHelper {
private static final String NULLABLE_IMPORT = "org.springframework.lang.Nullable";
private static final String NON_NULL_IMPORT = "org.springframework.lang.NonNull";
private Project project;

public void processAnnotations(Project project, PsiJavaFile psiJavaFile, PsiClass selectedClass) {
this.project = project;
Optional<DatabaseConnection> connectionProperties = DatabaseHelper.getConnectionProperties(project);
Expand All @@ -66,7 +67,7 @@ public void run(@NotNull ProgressIndicator indicator) {
indicator.setFraction(0);
indicator.setText("Scanning class");

String entityClassName = ReadAction.compute(()->getNameFromAnnotation(selectedClass.getAnnotation(TABLE_ANNOTATION)));
String entityClassName = ReadAction.compute(() -> getNameFromAnnotation(selectedClass.getAnnotation(TABLE_ANNOTATION)));
PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(project);
//establish a connection to the database and retrieve the schema
try {
Expand All @@ -75,7 +76,7 @@ public void run(@NotNull ProgressIndicator indicator) {
Optional<Connection> connectionOptional = DatabaseHelper.getDatabaseDriver(project, databaseConnection);
indicator.checkCanceled();
if (connectionOptional.isEmpty()) {
ApplicationManager.getApplication().invokeAndWait(() ->
ApplicationManager.getApplication().invokeAndWait(() ->
Messages.showErrorDialog(project,
"Could not create connection",
"Connection Error"));
Expand All @@ -84,7 +85,7 @@ public void run(@NotNull ProgressIndicator indicator) {
try (Connection connection = connectionOptional.get()) {
DatabaseMetaData metaData = connection.getMetaData();
indicator.setFraction(0.4);
indicator.setText(String.format("Processing class %s (%s)", selectedClass.getName(),entityClassName));
indicator.setText(String.format("Processing class %s (%s)", selectedClass.getName(), entityClassName));
processTable(selectedClass, entityClassName, elementFactory, metaData);
indicator.setFraction(0.6);
indicator.setText("Importing annotations");
Expand Down Expand Up @@ -129,7 +130,7 @@ private void saveDocument(PsiJavaFile psiJavaFile) {
*/
private void processTable(PsiClass selectedClass, String tableName,
PsiElementFactory elementFactory, @NotNull DatabaseMetaData metaData) throws SQLException {

try (ResultSet resultSet = metaData.getColumns(null, null, tableName, null)) {
Map<String, String> columnInfo = new HashMap<>();
while (resultSet.next()) {
Expand All @@ -139,7 +140,7 @@ private void processTable(PsiClass selectedClass, String tableName,
}
ReadAction.run(() -> {
List<PsiField> columnFields = Arrays.stream(selectedClass.getFields())
.filter(psiField ->
.filter(psiField ->
psiField.hasAnnotation(COLUMN_ANNOTATION) || psiField.hasAnnotation(JOIN_COLUMN_ANNOTATION))
.collect(Collectors.toList());
for (PsiField field : columnFields) {
Expand All @@ -158,6 +159,7 @@ private void processTable(PsiClass selectedClass, String tableName,

/**
* gets the name of the field from the annotation
*
* @param field the field to get the name from
* @return the name of the field
*/
Expand Down Expand Up @@ -188,14 +190,15 @@ private void addAnnotation(@NotNull PsiField field, PsiAnnotation annotation) {
if (qualifiedName != null) {
boolean existingAnnotation = modifierList.hasAnnotation(qualifiedName);
if (!existingAnnotation) {
ApplicationManager.getApplication().invokeLater(() -> WriteCommandAction.runWriteCommandAction(project, (Computable<PsiElement>) ()->modifierList.addAfter(annotation, null)));
ApplicationManager.getApplication().invokeLater(() -> WriteCommandAction.runWriteCommandAction(project, (Computable<PsiElement>) () -> modifierList.addAfter(annotation, null)));
}
}
}
}

/**
* Extracts the name attribute from the annotation
*
* @param annotation the annotation to extract the name from
* @return the name attribute value
*/
Expand Down Expand Up @@ -230,8 +233,9 @@ else if (nameValuePair instanceof PsiReferenceExpression) {
*/
private void importAnnotations(@NotNull PsiJavaFile psiJavaFile) {
PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(project);
PsiImportStatement nullableImport = ReadAction.compute(()-> elementFactory.createImportStatement(findClass(NULLABLE_IMPORT)));
PsiImportStatement nonNullImport = ReadAction.compute(()-> elementFactory.createImportStatement(findClass(NON_NULL_IMPORT)));
PsiImportStatement nullableImport = ReadAction.compute(() ->
elementFactory.createImportStatement(findClass(NULLABLE_IMPORT)));
PsiImportStatement nonNullImport = ReadAction.compute(() -> elementFactory.createImportStatement(findClass(NON_NULL_IMPORT)));
PsiImportList importList = ReadAction.compute(psiJavaFile::getImportList);
if (importList != null) {
PsiElement lastImport = ReadAction.compute(importList::getLastChild);
Expand Down

0 comments on commit d569a1b

Please sign in to comment.