From 18c4c109fd6ab622c46b360bf208257a9bd7b1e0 Mon Sep 17 00:00:00 2001 From: aboyko Date: Wed, 15 Feb 2023 13:55:34 -0500 Subject: [PATCH] Integrate partial java parser reset. Rewrite parser logging --- .../vscode/commons/rewrite/java/ORAstUtils.java | 6 +++++- .../java/rewrite/RewriteCompilationUnitCache.java | 14 ++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/headless-services/commons/commons-rewrite/src/main/java/org/springframework/ide/vscode/commons/rewrite/java/ORAstUtils.java b/headless-services/commons/commons-rewrite/src/main/java/org/springframework/ide/vscode/commons/rewrite/java/ORAstUtils.java index 9bf94a973..a8ee09413 100644 --- a/headless-services/commons/commons-rewrite/src/main/java/org/springframework/ide/vscode/commons/rewrite/java/ORAstUtils.java +++ b/headless-services/commons/commons-rewrite/src/main/java/org/springframework/ide/vscode/commons/rewrite/java/ORAstUtils.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2022 VMware, Inc. + * Copyright (c) 2022, 2023 VMware, Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -295,10 +295,13 @@ public class ORAstUtils { InMemoryExecutionContext ctx = new InMemoryExecutionContext(ORAstUtils::logExceptionWhileParsing); ctx.putMessage(JavaParser.SKIP_SOURCE_SET_TYPE_GENERATION, true); List cus = Collections.emptyList(); + long start = System.currentTimeMillis(); synchronized (parser) { cus = parser.parseInputs(inputs, null, ctx); } + log.info("Rewrite parser: " + (System.currentTimeMillis() - start)); List finalCus = new ArrayList<>(cus.size()); + start = System.currentTimeMillis(); for (CompilationUnit cu : cus) { J.CompilationUnit newCu = (J.CompilationUnit) new UpdateSourcePositions().getVisitor().visit(cu, ctx); if (newCu == null) { @@ -307,6 +310,7 @@ public class ORAstUtils { finalCus.add(newCu); } } + log.info("Positions Update: " + (System.currentTimeMillis() - start)); return finalCus; } diff --git a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/rewrite/RewriteCompilationUnitCache.java b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/rewrite/RewriteCompilationUnitCache.java index ccee28031..1723a7ae5 100644 --- a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/rewrite/RewriteCompilationUnitCache.java +++ b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/rewrite/RewriteCompilationUnitCache.java @@ -14,6 +14,7 @@ import java.io.ByteArrayInputStream; import java.net.URI; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Optional; @@ -89,8 +90,8 @@ public class RewriteCompilationUnitCache implements DocumentContentProvider, Dis JavaParser parser = javaParsers.getIfPresent(project.get().getLocationUri()); if (parser != null) { -// parser.reset(List.of(uri)); - parser.reset(); + parser.reset(List.of(uri)); +// parser.reset(); } } } @@ -222,9 +223,10 @@ public class RewriteCompilationUnitCache implements DocumentContentProvider, Dis private CompilationUnit doParse(IJavaProject project, URI uri) throws Exception { boolean newParser = javaParsers.getIfPresent(project) == null; + JavaParser javaParser = null;; try { logger.debug("Parsing CU {}", uri); - JavaParser javaParser = loadJavaParser(project); + javaParser = loadJavaParser(project); Path sourcePath = Paths.get(uri); javaParser.setSourceSet(ORAstUtils.getSourceSetName(project, sourcePath)); @@ -250,7 +252,11 @@ public class RewriteCompilationUnitCache implements DocumentContentProvider, Dis javaParsers.invalidate(project); } throw e; - } + } finally { + if (javaParser != null) { + javaParser.reset(Collections.emptyList()); + } + } } /**