summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaren Butzke2013-01-16 15:48:21 (EST)
committerKaren Butzke2013-01-16 15:48:21 (EST)
commit0ce44c3d5d0cdbb794aa8bc4ce7b653c5d90d473 (patch)
tree434d8767a8e0786f6d4200c34e62f60dc68faa55
parent4ede27fb73b68afc01037c116baa4aa8af87354e (diff)
downloadwebtools.dali-0ce44c3d5d0cdbb794aa8bc4ce7b653c5d90d473.zip
webtools.dali-0ce44c3d5d0cdbb794aa8bc4ce7b653c5d90d473.tar.gz
webtools.dali-0ce44c3d5d0cdbb794aa8bc4ce7b653c5d90d473.tar.bz2
performance improvements related to when we build an astRootv201301170344
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceCompilationUnit.java19
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/java/JavaResourceCompilationUnit.java17
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentType.java4
3 files changed, 36 insertions, 4 deletions
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceCompilationUnit.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceCompilationUnit.java
index e5dac76..bcc172e 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceCompilationUnit.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceCompilationUnit.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2012 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2013 Oracle. 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 http://www.eclipse.org/legal/epl-v10.html.
@@ -15,6 +15,7 @@ import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jpt.common.core.AnnotationProvider;
import org.eclipse.jpt.common.core.JptResourceModelListener;
+import org.eclipse.jpt.common.core.internal.plugin.JptCommonCorePlugin;
import org.eclipse.jpt.common.core.internal.utility.jdt.ASTTools;
import org.eclipse.jpt.common.core.resource.java.JavaResourceCompilationUnit;
import org.eclipse.jpt.common.core.utility.TextRange;
@@ -152,6 +153,22 @@ public abstract class SourceCompilationUnit
this.synchronizeWith(this.buildASTRoot());
}
+ public void synchronizeWithJavaSource(CompilationUnit astRoot) {
+ this.synchronizeWith(astRoot);
+ }
+
+ public void synchronizeWithJavaSourceIfNecessary() {
+ try {
+ if (this.compilationUnit.isConsistent()) {
+ return;
+ }
+ }
+ catch (JavaModelException e) {
+ JptCommonCorePlugin.instance().logError(e);
+ }
+ this.synchronizeWithJavaSource();
+ }
+
protected abstract void synchronizeWith(CompilationUnit astRoot);
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/java/JavaResourceCompilationUnit.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/java/JavaResourceCompilationUnit.java
index 99339e7..34ff630 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/java/JavaResourceCompilationUnit.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/java/JavaResourceCompilationUnit.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2012 Oracle. All rights reserved.
+ * Copyright (c) 2010, 2013 Oracle. 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 http://www.eclipse.org/legal/epl-v10.html.
@@ -71,6 +71,21 @@ public interface JavaResourceCompilationUnit
void synchronizeWithJavaSource();
/**
+ * Call this method over {@link #synchronizeWithJavaSource()} if possible
+ * It is more performant to pass an already build astRoot than to build
+ * a new one. The passed in CompilationUnit must have resolved bindings.
+ */
+ void synchronizeWithJavaSource(CompilationUnit astRoot);
+
+ /**
+ * Checks {@link ICompilationUnit#isConsistent()} and if
+ * true, does nothing. If false, calls synchronizeWithJavaSource()
+ * which calls buildASTRoot(). Trying to avoid building astRoots
+ * since that is expensive.
+ */
+ void synchronizeWithJavaSourceIfNecessary();
+
+ /**
* Build an AST for the compilation unit with its bindings resolved.
*/
CompilationUnit buildASTRoot();
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentType.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentType.java
index 143844a..aba6253 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentType.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentType.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2012 Oracle. All rights reserved.
+ * Copyright (c) 2006, 2013 Oracle. 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 http://www.eclipse.org/legal/epl-v10.html.
@@ -952,7 +952,7 @@ public abstract class AbstractJavaPersistentType
* the textRange gets updated after the java delay which is after we are notified of a selection change.
*/
public JpaStructureNode getStructureNode(int offset) {
- this.resourceType.getJavaResourceCompilationUnit().synchronizeWithJavaSource();
+ this.resourceType.getJavaResourceCompilationUnit().synchronizeWithJavaSourceIfNecessary(); //TODO this new API? or just check isConsistent() right here?
if (this.contains(offset)) {
for (JavaPersistentAttribute persistentAttribute : this.getAttributes()) {
if (persistentAttribute.contains(offset)) {