diff options
author | Karen Butzke | 2013-01-16 20:48:21 +0000 |
---|---|---|
committer | Karen Butzke | 2013-01-16 20:48:21 +0000 |
commit | 0ce44c3d5d0cdbb794aa8bc4ce7b653c5d90d473 (patch) | |
tree | 434d8767a8e0786f6d4200c34e62f60dc68faa55 | |
parent | 4ede27fb73b68afc01037c116baa4aa8af87354e (diff) | |
download | webtools.dali-0ce44c3d5d0cdbb794aa8bc4ce7b653c5d90d473.tar.gz webtools.dali-0ce44c3d5d0cdbb794aa8bc4ce7b653c5d90d473.tar.xz webtools.dali-0ce44c3d5d0cdbb794aa8bc4ce7b653c5d90d473.zip |
performance improvements related to when we build an astRootv201301170344
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 e5dac765ff..bcc172e226 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 99339e7b82..34ff630dd8 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 143844abcc..aba62530a7 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)) { |