Bug 560254 - [performance] Import of 23 breakpoints takes 12 seconds 

Change-Id: I30dcc265bf17e9fda90a2eee5b0ec90a21aba7a7
Signed-off-by: Vikas Chandra <Vikas.Chandra@in.ibm.com>
diff --git a/org.eclipse.jdt.debug/META-INF/MANIFEST.MF b/org.eclipse.jdt.debug/META-INF/MANIFEST.MF
index 04a9cea..65ac95b 100644
--- a/org.eclipse.jdt.debug/META-INF/MANIFEST.MF
+++ b/org.eclipse.jdt.debug/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@
 Bundle-ManifestVersion: 2
 Bundle-Name: %pluginName
 Bundle-SymbolicName: org.eclipse.jdt.debug; singleton:=true
-Bundle-Version: 3.16.0.qualifier
+Bundle-Version: 3.16.100.qualifier
 Bundle-ClassPath: jdimodel.jar,
  tools.jar
 Bundle-Activator: org.eclipse.jdt.internal.debug.core.JDIDebugPlugin
diff --git a/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/breakpoints/JavaBreakpointImportParticipant.java b/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/breakpoints/JavaBreakpointImportParticipant.java
index 940966f..ad27a1c 100644
--- a/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/breakpoints/JavaBreakpointImportParticipant.java
+++ b/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/breakpoints/JavaBreakpointImportParticipant.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2008, 2016 IBM Corporation and others.
+ * Copyright (c) 2008, 2020 IBM Corporation and others.
  *
  * This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License 2.0
@@ -58,6 +58,11 @@
 public class JavaBreakpointImportParticipant implements
 		IBreakpointImportParticipant {
 
+	// keep the last resource/timestamp with CU for optimization
+	IResource lastResourceVerified = null;
+	long lastResourceVerifiedTimeStamp = -1;
+	CompilationUnit lastCompilationUnit = null;
+
 	class BreakpointVerifier extends ASTVisitor {
 		final int TYPE = 0;
 		final int METHOD = 1;
@@ -537,17 +542,25 @@
 		IResource resource = breakpoint.getMarker().getResource();
 		CompilationUnit unit = null;
 		if (resource != null && resource.getType() == IResource.FILE) {
-			ICompilationUnit cunit = JavaCore
-					.createCompilationUnitFrom((IFile) resource);
-			if (cunit != null) {
-				ASTParser parser = ASTParser.newParser(AST.JLS4);
-				parser.setSource(cunit);
-				parser.setResolveBindings(true);
-				unit = (CompilationUnit) parser
-						.createAST(new NullProgressMonitor());
+			if (resource.equals(lastResourceVerified)) {
+				if (resource.getModificationStamp() == lastResourceVerifiedTimeStamp) {
+					unit = lastCompilationUnit;
+				}
+			}
+			if (unit == null) {
+				ICompilationUnit cunit = JavaCore.createCompilationUnitFrom((IFile) resource);
+				if (cunit != null) {
+					ASTParser parser = ASTParser.newParser(AST.JLS4);
+					parser.setSource(cunit);
+					parser.setResolveBindings(true);
+					unit = (CompilationUnit) parser.createAST(new NullProgressMonitor());
+				}
 			}
 		}
 		if (unit != null) {
+			lastResourceVerified = resource;
+			lastCompilationUnit = unit;
+			lastResourceVerifiedTimeStamp = lastResourceVerified.getModificationStamp();
 			if (breakpoint instanceof JavaClassPrepareBreakpoint
 					|| breakpoint instanceof JavaWatchpoint
 					|| breakpoint instanceof JavaMethodEntryBreakpoint
diff --git a/org.eclipse.jdt.debug/pom.xml b/org.eclipse.jdt.debug/pom.xml
index d159823..19974f3 100644
--- a/org.eclipse.jdt.debug/pom.xml
+++ b/org.eclipse.jdt.debug/pom.xml
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!--
-  Copyright (c) 2012, 200 Eclipse Foundation and others.
+  Copyright (c) 2012, 2020 Eclipse Foundation and others.
   All rights reserved. This program and the accompanying materials
   are made available under the terms of the Eclipse Distribution License v1.0
   which accompanies this distribution, and is available at
@@ -18,6 +18,6 @@
   </parent>
   <groupId>org.eclipse.jdt</groupId>
   <artifactId>org.eclipse.jdt.debug</artifactId>
-  <version>3.16.0-SNAPSHOT</version>
+  <version>3.16.100-SNAPSHOT</version>
   <packaging>eclipse-plugin</packaging>
 </project>