Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkmoore2012-04-18 22:02:13 +0000
committerkmoore2012-04-18 22:02:13 +0000
commit85d055463bdfa0d5256bc83b08f1cd872dc8cbf9 (patch)
tree42f60ed1a06b2bb828124e35c878dc82b1b5a7f1
parenteb77b57934e882281ab0f847ddc1415c5918aa55 (diff)
downloadwebtools.dali-85d055463bdfa0d5256bc83b08f1cd872dc8cbf9.tar.gz
webtools.dali-85d055463bdfa0d5256bc83b08f1cd872dc8cbf9.tar.xz
webtools.dali-85d055463bdfa0d5256bc83b08f1cd872dc8cbf9.zip
bug 377039 - Performance - enhancements for synching methods in the Java resource model
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryMethod.java13
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceAbstractType.java31
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceAnnotatedElement.java57
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceAttribute.java76
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceField.java17
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceMember.java10
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceMethod.java58
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourcePackage.java21
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceType.java44
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/ASTTools.java2
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/java/JavaResourceMethod.java17
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SimpleJavaType.java29
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/PropertyAccessor.java11
13 files changed, 277 insertions, 109 deletions
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryMethod.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryMethod.java
index ef034a159c..6570371ae7 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryMethod.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryMethod.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 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.
@@ -17,6 +17,7 @@ import org.eclipse.jdt.core.ILocalVariable;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.ITypeParameter;
import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jpt.common.core.JptCommonCorePlugin;
import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement;
import org.eclipse.jpt.common.core.resource.java.JavaResourceMethod;
@@ -58,7 +59,15 @@ final class BinaryMethod
this.setParameterTypeNames(this.buildParameterTypeNames());
}
-
+
+ public void initialize(MethodDeclaration methodDeclaration) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void synchronizeWith(MethodDeclaration methodDeclaration) {
+ throw new UnsupportedOperationException();
+ }
+
@Override
IMethod getMember() {
return (IMethod) super.getMember();
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceAbstractType.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceAbstractType.java
index 49f6b04abd..16a42f37d3 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceAbstractType.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceAbstractType.java
@@ -14,6 +14,7 @@ import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.IBinding;
import org.eclipse.jdt.core.dom.ITypeBinding;
import org.eclipse.jpt.common.core.resource.java.JavaResourceAbstractType;
import org.eclipse.jpt.common.core.resource.java.JavaResourceCompilationUnit;
@@ -46,28 +47,26 @@ abstract class SourceAbstractType<A extends AbstractType>
}
@Override
- public void initialize(CompilationUnit astRoot) {
- super.initialize(astRoot);
- ITypeBinding binding = this.annotatedElement.getBinding(astRoot);
- this.name = this.buildName(binding);
- this.qualifiedName = this.buildQualifiedName(binding);
- this.packageName = this.buildPackageName(binding);
- this.declaringTypeName = this.buildDeclaringTypeName(binding);
- this.memberType = this.buildMemberType(binding);
+ protected void initialize(IBinding binding) {
+ super.initialize(binding);
+ this.name = this.buildName((ITypeBinding) binding);
+ this.qualifiedName = this.buildQualifiedName((ITypeBinding) binding);
+ this.packageName = this.buildPackageName((ITypeBinding) binding);
+ this.declaringTypeName = this.buildDeclaringTypeName((ITypeBinding) binding);
+ this.memberType = this.buildMemberType((ITypeBinding) binding);
}
// ********** update **********
@Override
- public void synchronizeWith(CompilationUnit astRoot) {
- super.synchronizeWith(astRoot);
- ITypeBinding binding = this.annotatedElement.getBinding(astRoot);
- this.syncName(this.buildName(binding));
- this.syncQualifiedName(this.buildQualifiedName(binding));
- this.syncPackageName(this.buildPackageName(binding));
- this.syncDeclaringTypeName(this.buildDeclaringTypeName(binding));
- this.syncMemberType(this.buildMemberType(binding));
+ protected void synchronizeWith(IBinding binding) {
+ super.synchronizeWith(binding);
+ this.syncName(this.buildName((ITypeBinding) binding));
+ this.syncQualifiedName(this.buildQualifiedName((ITypeBinding) binding));
+ this.syncPackageName(this.buildPackageName((ITypeBinding) binding));
+ this.syncDeclaringTypeName(this.buildDeclaringTypeName((ITypeBinding) binding));
+ this.syncMemberType(this.buildMemberType((ITypeBinding) binding));
}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceAnnotatedElement.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceAnnotatedElement.java
index d8affcc882..cc93e73e27 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceAnnotatedElement.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceAnnotatedElement.java
@@ -21,6 +21,7 @@ import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.ASTVisitor;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.IAnnotationBinding;
+import org.eclipse.jdt.core.dom.IBinding;
import org.eclipse.jdt.core.dom.ITypeBinding;
import org.eclipse.jdt.core.dom.MarkerAnnotation;
import org.eclipse.jdt.core.dom.NormalAnnotation;
@@ -80,11 +81,35 @@ abstract class SourceAnnotatedElement<E extends AnnotatedElement>
}
/**
+ * There are 2 initialize calls, 1 for ASTNode and one for IBinding.
+ * This is a performance enhancement because finding a MethodDeclaration
+ * for a SourceMethod is very non-performant. SourceMethod actually overrides
+ * this as unsupported and instead uses initialize(MethodDeclaration).
+ * TODO continue the pattern in SourceMethod with the other classes in this hierarchy
+ * trying not to change much API in 3.2M7
+ *
+ * This is also to handle multiple fields declared in a single statement:
+ * private int foo, bar;
+ * JDTFieldAttribute.getBodyDeclaration(CompilationUnit) returns the FieldDeclaration
+ * in the call to getBodyDeclaration, this is the ASTNode for a field and
+ * has the annotations on it.
+ * JDTFieldAttribute.getBinding(CompiltationUnit) returns the IVariableBinding of the
+ * VariableDeclarationFragment which is the ASTNode for the particular field.
+ */
+ public void initialize(CompilationUnit astRoot) {
+ this.initialize(this.annotatedElement.getBodyDeclaration(astRoot));
+ this.initialize(this.annotatedElement.getBinding(astRoot));
+ }
+
+ protected void initialize(IBinding binding) {
+ //do nothing
+ }
+
+ /**
* Gather up all the significant AST annotations
* and build the corresponding Dali annotations.
*/
- public void initialize(CompilationUnit astRoot) {
- ASTNode node = this.annotatedElement.getBodyDeclaration(astRoot);
+ protected void initialize(ASTNode node) {
AnnotationVisitor visitor = new AnnotationVisitor(node);
node.accept(visitor);
this.initializeAnnotations(visitor.astAnnotations);
@@ -129,8 +154,20 @@ abstract class SourceAnnotatedElement<E extends AnnotatedElement>
}
}
+ /**
+ * @see #initialize(CompilationUnit)
+ */
public void synchronizeWith(CompilationUnit astRoot) {
- this.syncAnnotations(this.annotatedElement.getBodyDeclaration(astRoot));
+ this.synchronizeWith(this.annotatedElement.getBodyDeclaration(astRoot));
+ this.synchronizeWith(this.annotatedElement.getBinding(astRoot));
+ }
+
+ protected void synchronizeWith(ASTNode bodyDeclaration) {
+ this.syncAnnotations(bodyDeclaration);
+ }
+
+ protected void synchronizeWith(IBinding binding) {
+ //do nothing
}
@@ -155,10 +192,22 @@ abstract class SourceAnnotatedElement<E extends AnnotatedElement>
}
public Annotation getNonNullAnnotation(String annotationName) {
- Annotation annotation = this.getAnnotation(annotationName);
+ Annotation annotation = this.performantGetAnnotation(annotationName);
return (annotation != null) ? annotation : this.getNullAnnotation(annotationName);
}
+ /**
+ * TODO performance - hack for performance so we don't have to break API in M7.
+ * Our calls to getNonNullAnnotation are never used for container annotations, so
+ * I can use this method to avoid the expensive {@link #annotationIsValidContainer(String)} check
+ * in {@link #getAnnotation(String)}. In the next release I think we need
+ * to change the genAnnotation api to not check for container annotations and instead have
+ * separate API.
+ */
+ protected Annotation performantGetAnnotation(String annotationName) {
+ return this.annotations.get(annotationName);
+ }
+
private Annotation getNullAnnotation(String annotationName) {
Annotation annotation = this.nullAnnotationCache.get(annotationName);
if (annotation == null) {
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceAttribute.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceAttribute.java
index d2e3fbd194..4802d09239 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceAttribute.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceAttribute.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 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.
@@ -59,19 +59,24 @@ abstract class SourceAttribute<A extends Attribute>
}
@Override
- public void initialize(CompilationUnit astRoot) {
- super.initialize(astRoot);
- ITypeBinding typeBinding = this.getTypeBinding(astRoot); //build once, minor performance tweak for major benefit
- this.modifiers = this.buildModifiers(astRoot);
- this.typeName = this.buildTypeName(typeBinding);
- this.typeIsInterface = this.buildTypeIsInterface(typeBinding);
- this.typeIsEnum = this.buildTypeIsEnum(typeBinding);
- this.typeIsArray = this.buildTypeIsArray(typeBinding);
- this.typeArrayDimensionality = buildTypeArrayDimensionality(typeBinding);
- this.typeArrayComponentTypeName = buildTypeArrayComponentTypeName(typeBinding);
- this.typeSuperclassNames.addAll(this.buildTypeSuperclassNames(typeBinding));
- this.typeInterfaceNames.addAll(this.buildTypeInterfaceNames(typeBinding));
- this.typeTypeArgumentNames.addAll(this.buildTypeTypeArgumentNames(typeBinding));
+ protected void initialize(IBinding binding) {
+ super.initialize(binding);
+ this.modifiers = this.buildModifiers(binding);
+ }
+
+ /**
+ * subclasses need to call this method
+ */
+ protected void initialize(ITypeBinding attributeTypeBinding) {
+ this.typeName = this.buildTypeName(attributeTypeBinding);
+ this.typeIsInterface = this.buildTypeIsInterface(attributeTypeBinding);
+ this.typeIsEnum = this.buildTypeIsEnum(attributeTypeBinding);
+ this.typeIsArray = this.buildTypeIsArray(attributeTypeBinding);
+ this.typeArrayDimensionality = buildTypeArrayDimensionality(attributeTypeBinding);
+ this.typeArrayComponentTypeName = buildTypeArrayComponentTypeName(attributeTypeBinding);
+ this.typeSuperclassNames.addAll(this.buildTypeSuperclassNames(attributeTypeBinding));
+ this.typeInterfaceNames.addAll(this.buildTypeInterfaceNames(attributeTypeBinding));
+ this.typeTypeArgumentNames.addAll(this.buildTypeTypeArgumentNames(attributeTypeBinding));
}
@@ -80,28 +85,36 @@ abstract class SourceAttribute<A extends Attribute>
@Override
public void resolveTypes(CompilationUnit astRoot) {
super.resolveTypes(astRoot);
- ITypeBinding typeBinding = this.getTypeBinding(astRoot);//build once, minor performance tweak for major benefit
+ this.resolveTypes(this.getTypeBinding(astRoot));//build once, minor performance tweak for major benefit
+ }
+
+ protected void resolveTypes(ITypeBinding typeBinding) {
this.syncTypeName(this.buildTypeName(typeBinding));
- syncTypeArrayComponentTypeName(buildTypeArrayComponentTypeName(typeBinding));
+ this.syncTypeArrayComponentTypeName(this.buildTypeArrayComponentTypeName(typeBinding));
this.syncTypeSuperclassNames(this.buildTypeSuperclassNames(typeBinding));
this.syncTypeInterfaceNames(this.buildTypeInterfaceNames(typeBinding));
this.syncTypeTypeArgumentNames(this.buildTypeTypeArgumentNames(typeBinding));
}
+ /**
+ * subclasses need to call this method
+ */
+ protected void synchronizeWith(ITypeBinding attributeTypeBinding) {
+ this.syncTypeName(this.buildTypeName(attributeTypeBinding));
+ this.syncTypeIsInterface(this.buildTypeIsInterface(attributeTypeBinding));
+ this.syncTypeIsEnum(this.buildTypeIsEnum(attributeTypeBinding));
+ this.syncTypeIsArray(this.buildTypeIsArray(attributeTypeBinding));
+ this.syncTypeArrayDimensionality(this.buildTypeArrayDimensionality(attributeTypeBinding));
+ this.syncTypeArrayComponentTypeName(this.buildTypeArrayComponentTypeName(attributeTypeBinding));
+ this.syncTypeSuperclassNames(this.buildTypeSuperclassNames(attributeTypeBinding));
+ this.syncTypeInterfaceNames(this.buildTypeInterfaceNames(attributeTypeBinding));
+ this.syncTypeTypeArgumentNames(this.buildTypeTypeArgumentNames(attributeTypeBinding));
+ }
+
@Override
- public void synchronizeWith(CompilationUnit astRoot) {
- super.synchronizeWith(astRoot);
- ITypeBinding typeBinding = this.getTypeBinding(astRoot);//build once, minor performance tweak for major benefit
- this.syncModifiers(this.buildModifiers(astRoot));
- this.syncTypeName(this.buildTypeName(typeBinding));
- this.syncTypeIsInterface(this.buildTypeIsInterface(typeBinding));
- this.syncTypeIsEnum(this.buildTypeIsEnum(typeBinding));
- this.syncTypeIsArray(this.buildTypeIsArray(typeBinding));
- syncTypeArrayDimensionality(buildTypeArrayDimensionality(typeBinding));
- syncTypeArrayComponentTypeName(buildTypeArrayComponentTypeName(typeBinding));
- this.syncTypeSuperclassNames(this.buildTypeSuperclassNames(typeBinding));
- this.syncTypeInterfaceNames(this.buildTypeInterfaceNames(typeBinding));
- this.syncTypeTypeArgumentNames(this.buildTypeTypeArgumentNames(typeBinding));
+ protected void synchronizeWith(IBinding binding) {
+ super.synchronizeWith(binding);
+ this.syncModifiers(this.buildModifiers(binding));
}
@Override
@@ -138,7 +151,7 @@ abstract class SourceAttribute<A extends Attribute>
return (this.typeName != null) && ClassName.isVariablePrimitive(this.typeName);
}
- private ITypeBinding getTypeBinding(CompilationUnit astRoot) {
+ protected ITypeBinding getTypeBinding(CompilationUnit astRoot) {
return this.annotatedElement.getTypeBinding(astRoot);
}
@@ -157,8 +170,7 @@ abstract class SourceAttribute<A extends Attribute>
/**
* zero seems like a reasonable default...
*/
- private int buildModifiers(CompilationUnit astRoot) {
- IBinding binding = this.annotatedElement.getBinding(astRoot);
+ private int buildModifiers(IBinding binding) {
return (binding == null) ? 0 : binding.getModifiers();
}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceField.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceField.java
index 936231cc6a..fc4e4ab95f 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceField.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceField.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 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.
@@ -9,7 +9,9 @@
******************************************************************************/
package org.eclipse.jpt.common.core.internal.resource.java.source;
+import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.FieldDeclaration;
import org.eclipse.jpt.common.core.internal.utility.jdt.JDTFieldAttribute;
import org.eclipse.jpt.common.core.resource.java.JavaResourceCompilationUnit;
import org.eclipse.jpt.common.core.resource.java.JavaResourceField;
@@ -58,4 +60,17 @@ final class SourceField
public Kind getKind() {
return Kind.FIELD;
}
+
+ @Override
+ protected void initialize(ASTNode node) {
+ super.initialize(node);
+ this.initialize(((FieldDeclaration) node).getType().resolveBinding());
+ }
+
+ @Override
+ public void synchronizeWith(ASTNode node) {
+ super.synchronizeWith(node);
+ this.synchronizeWith(((FieldDeclaration) node).getType().resolveBinding());
+ }
+
}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceMember.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceMember.java
index f872eac69c..380f175fcf 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceMember.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceMember.java
@@ -41,9 +41,8 @@ abstract class SourceMember<M extends Member>
}
@Override
- public void initialize(CompilationUnit astRoot) {
- super.initialize(astRoot);
- IBinding binding = this.annotatedElement.getBinding(astRoot);
+ protected void initialize(IBinding binding) {
+ super.initialize(binding);
this.final_ = this.buildFinal(binding);
this.transient_ = this.buildTransient(binding);
this.public_ = this.buildPublic(binding);
@@ -52,9 +51,8 @@ abstract class SourceMember<M extends Member>
}
@Override
- public void synchronizeWith(CompilationUnit astRoot) {
- super.synchronizeWith(astRoot);
- IBinding binding = this.annotatedElement.getBinding(astRoot);
+ protected void synchronizeWith(IBinding binding) {
+ super.synchronizeWith(binding);
this.syncFinal(this.buildFinal(binding));
this.syncTransient(this.buildTransient(binding));
this.syncPublic(this.buildPublic(binding));
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceMethod.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceMethod.java
index 99cda60bc4..d92d2d7dcb 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceMethod.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceMethod.java
@@ -14,8 +14,10 @@ import java.util.Collections;
import java.util.List;
import java.util.Vector;
import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.IBinding;
import org.eclipse.jdt.core.dom.IMethodBinding;
import org.eclipse.jdt.core.dom.ITypeBinding;
+import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jpt.common.core.internal.utility.jdt.JDTMethodAttribute;
import org.eclipse.jpt.common.core.resource.java.JavaResourceCompilationUnit;
import org.eclipse.jpt.common.core.resource.java.JavaResourceMethod;
@@ -47,7 +49,7 @@ final class SourceMethod
MethodSignature signature,
int occurrence,
JavaResourceCompilationUnit javaResourceCompilationUnit,
- CompilationUnit astRoot) {
+ MethodDeclaration methodDeclaration) {
MethodAttribute method = JDTMethodAttribute.newInstance(
declaringType,
@@ -57,7 +59,7 @@ final class SourceMethod
javaResourceCompilationUnit.getModifySharedDocumentCommandExecutor(),
javaResourceCompilationUnit.getAnnotationEditFormatter());
JavaResourceMethod jrm = new SourceMethod(parent, method);
- jrm.initialize(astRoot);
+ jrm.initialize(methodDeclaration);
return jrm;
}
@@ -65,14 +67,28 @@ final class SourceMethod
private SourceMethod(JavaResourceType parent, MethodAttribute method){
super(parent, method);
}
-
-
+
+ //call initialize(MethodDeclaration) now for performance
+ //trying to minimize API changes, this should be removed from the interface
+ //TODO other members of this hierarchy should have similar initialize methods
@Override
public void initialize(CompilationUnit astRoot) {
- super.initialize(astRoot);
- IMethodBinding binding = this.annotatedElement.getBinding(astRoot);
- this.constructor = this.buildConstructor(binding);
- this.parameterTypeNames.addAll(this.buildParameterTypeNames(binding));
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ protected void initialize(IBinding binding) {
+ super.initialize(binding);
+ this.constructor = this.buildConstructor((IMethodBinding) binding);
+ this.parameterTypeNames.addAll(this.buildParameterTypeNames((IMethodBinding) binding));
+ }
+
+ public void initialize(MethodDeclaration methodDeclaration) {
+ super.initialize(methodDeclaration);
+ IMethodBinding binding = methodDeclaration.resolveBinding();
+ this.initialize(binding.getReturnType());
+ this.initialize(binding);
+
}
@@ -89,15 +105,29 @@ final class SourceMethod
public void resolveTypes(CompilationUnit astRoot) {
super.resolveTypes(astRoot);
}
-
+
+ //call synchronizeWith(MethodDeclaration) now for performance
+ //trying to minimize API changes, this should be removed from the interface
+ //TODO other members of this hierarchy should have similar synchronizeWith methods
@Override
public void synchronizeWith(CompilationUnit astRoot) {
- super.synchronizeWith(astRoot);
- IMethodBinding binding = this.annotatedElement.getBinding(astRoot);
- this.syncConstructor(this.buildConstructor(binding));
- this.syncParameterTypeNames(this.buildParameterTypeNames(binding));
+ throw new UnsupportedOperationException();
}
-
+
+ public void synchronizeWith(MethodDeclaration methodDeclaration) {
+ super.synchronizeWith(methodDeclaration);
+ IMethodBinding binding = methodDeclaration.resolveBinding();
+ this.synchronizeWith(binding.getReturnType());
+ this.synchronizeWith(binding);
+ }
+
+ @Override
+ public void synchronizeWith(IBinding binding) {
+ super.synchronizeWith(binding);
+ this.syncConstructor(this.buildConstructor((IMethodBinding) binding));
+ this.syncParameterTypeNames(this.buildParameterTypeNames((IMethodBinding) binding));
+ }
+
@Override
public void toString(StringBuilder sb) {
sb.append(this.getMethodName());
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourcePackage.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourcePackage.java
index 7c3d504d1d..b2fbc06fff 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourcePackage.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourcePackage.java
@@ -1,16 +1,18 @@
/*******************************************************************************
- * Copyright (c) 2010 Red Hat, Inc.
+ * Copyright (c) 2010, 2012 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is 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
*
- * Contributor:
+ * Contributors:
* Red Hat, Inc. - initial API and implementation
+ * Oracle
******************************************************************************/
package org.eclipse.jpt.common.core.internal.resource.java.source;
import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.IBinding;
import org.eclipse.jdt.core.dom.IPackageBinding;
import org.eclipse.jdt.core.dom.PackageDeclaration;
import org.eclipse.jpt.common.core.internal.utility.jdt.JDTPackage;
@@ -55,9 +57,9 @@ public final class SourcePackage
@Override
- public void initialize(CompilationUnit astRoot) {
- super.initialize(astRoot);
- this.name = this.buildName(astRoot);
+ protected void initialize(IBinding binding) {
+ super.initialize(binding);
+ this.name = this.buildName((IPackageBinding) binding);
}
// ******** JavaResourceAnnotatedElement implementation ********
@@ -82,8 +84,7 @@ public final class SourcePackage
}
}
- private String buildName(CompilationUnit astRoot) {
- IPackageBinding binding = this.annotatedElement.getBinding(astRoot);
+ private String buildName(IPackageBinding binding) {
return (binding == null) ? null : binding.getName();
}
@@ -91,9 +92,9 @@ public final class SourcePackage
// ********** Java changes **********
@Override
- public void synchronizeWith(CompilationUnit astRoot) {
- super.synchronizeWith(astRoot);
- this.syncName(this.buildName(astRoot));
+ protected void synchronizeWith(IBinding binding) {
+ super.synchronizeWith(binding);
+ this.syncName(this.buildName((IPackageBinding) binding));
}
@Override
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceType.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceType.java
index 24cdd48820..38cab3727d 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceType.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceType.java
@@ -17,6 +17,7 @@ import java.util.Vector;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.EnumDeclaration;
import org.eclipse.jdt.core.dom.FieldDeclaration;
+import org.eclipse.jdt.core.dom.IBinding;
import org.eclipse.jdt.core.dom.IMethodBinding;
import org.eclipse.jdt.core.dom.ITypeBinding;
import org.eclipse.jdt.core.dom.MethodDeclaration;
@@ -114,34 +115,42 @@ final class SourceType
@Override
public void initialize(CompilationUnit astRoot) {
super.initialize(astRoot);
- ITypeBinding binding = this.annotatedElement.getBinding(astRoot);
- this.superclassQualifiedName = this.buildSuperclassQualifiedName(binding);
- this.abstract_ = this.buildAbstract(binding);
- this.hasNoArgConstructor = this.buildHasNoArgConstructor(binding);
- this.hasPrivateNoArgConstructor = this.buildHasPrivateNoArgConstructor(binding);
this.initializeTypes(astRoot);
this.initializeEnums(astRoot);
this.initializeFields(astRoot);
this.initializeMethods(astRoot);
}
+ @Override
+ protected void initialize(IBinding binding) {
+ super.initialize(binding);
+ this.superclassQualifiedName = this.buildSuperclassQualifiedName((ITypeBinding) binding);
+ this.abstract_ = this.buildAbstract((ITypeBinding) binding);
+ this.hasNoArgConstructor = this.buildHasNoArgConstructor((ITypeBinding) binding);
+ this.hasPrivateNoArgConstructor = this.buildHasPrivateNoArgConstructor((ITypeBinding) binding);
+ }
+
// ********** update **********
@Override
public void synchronizeWith(CompilationUnit astRoot) {
super.synchronizeWith(astRoot);
- ITypeBinding binding = this.annotatedElement.getBinding(astRoot);
- this.syncSuperclassQualifiedName(this.buildSuperclassQualifiedName(binding));
- this.syncAbstract(this.buildAbstract(binding));
- this.syncHasNoArgConstructor(this.buildHasNoArgConstructor(binding));
- this.syncHasPrivateNoArgConstructor(this.buildHasPrivateNoArgConstructor(binding));
this.syncTypes(astRoot);
this.syncEnums(astRoot);
this.syncFields(astRoot);
this.syncMethods(astRoot);
}
+ @Override
+ protected void synchronizeWith(IBinding binding) {
+ super.synchronizeWith(binding);
+ this.syncSuperclassQualifiedName(this.buildSuperclassQualifiedName((ITypeBinding) binding));
+ this.syncAbstract(this.buildAbstract((ITypeBinding) binding));
+ this.syncHasNoArgConstructor(this.buildHasNoArgConstructor((ITypeBinding) binding));
+ this.syncHasPrivateNoArgConstructor(this.buildHasPrivateNoArgConstructor((ITypeBinding) binding));
+ }
+
// ********** SourceAnnotatedElement implementation **********
@@ -191,10 +200,7 @@ final class SourceType
}
private String buildSuperclassQualifiedName(ITypeBinding binding) {
- if (binding == null) {
- return null;
- }
- ITypeBinding superclass = binding.getSuperclass();
+ ITypeBinding superclass = binding == null ? null : binding.getSuperclass();
return (superclass == null) ? null : superclass.getTypeDeclaration().getQualifiedName();
}
@@ -526,7 +532,7 @@ final class SourceType
for (MethodDeclaration methodDeclaration : methodDeclarations) {
MethodSignature signature = ASTTools.buildMethodSignature(methodDeclaration);
int occurrence = counters.increment(signature);
- this.methods.add(this.buildMethod(signature, occurrence, astRoot));
+ this.methods.add(this.buildMethod(signature, occurrence, methodDeclaration));
}
}
@@ -540,17 +546,17 @@ final class SourceType
JavaResourceMethod method = this.getMethod(signature, occurrence);
if (method == null) {
- this.addMethod(this.buildMethod(signature, occurrence, astRoot));
+ this.addMethod(this.buildMethod(signature, occurrence, methodDeclaration));
} else {
methodsToRemove.remove(method);
- method.synchronizeWith(astRoot);
+ method.synchronizeWith(methodDeclaration);
}
}
this.removeMethods(methodsToRemove);
}
- private JavaResourceMethod buildMethod(MethodSignature signature, int occurrence, CompilationUnit astRoot) {
- return SourceMethod.newInstance(this, this.annotatedElement, signature, occurrence, this.getJavaResourceCompilationUnit(), astRoot);
+ private JavaResourceMethod buildMethod(MethodSignature signature, int occurrence, MethodDeclaration methodDeclaration) {
+ return SourceMethod.newInstance(this, this.annotatedElement, signature, occurrence, this.getJavaResourceCompilationUnit(), methodDeclaration);
}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/ASTTools.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/ASTTools.java
index 3be76642bd..cafdf479a8 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/ASTTools.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/ASTTools.java
@@ -149,7 +149,7 @@ public class ASTTools {
JavaType[] parameterTypes = new JavaType[len];
for (int i = 0; i < len; i++) {
ITypeBinding type = parameters.get(i).getType().resolveBinding();
- parameterTypes[i] = new SimpleJavaType(type.getQualifiedName(), type.getDimensions());
+ parameterTypes[i] = SimpleJavaType.buildSimpleJavaType(type.getQualifiedName(), type.getDimensions());
}
return parameterTypes;
}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/java/JavaResourceMethod.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/java/JavaResourceMethod.java
index 8e5ff93244..491a5c3ca6 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/java/JavaResourceMethod.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/java/JavaResourceMethod.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2010, 2012 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.
@@ -9,6 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.common.core.resource.java;
+import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jpt.common.utility.MethodSignature;
import org.eclipse.jpt.common.utility.internal.iterables.ListIterable;
@@ -21,7 +22,7 @@ import org.eclipse.jpt.common.utility.internal.iterables.ListIterable;
* pioneering adopters on the understanding that any code that uses this API
* will almost certainly be broken (repeatedly) as the API evolves.
*
- * @version 3.0
+ * @version 3.2
* @since 3.0
*/
public interface JavaResourceMethod
@@ -60,4 +61,16 @@ public interface JavaResourceMethod
* method.
*/
boolean isFor(MethodSignature methodSignature, int occurrence);
+
+ /**
+ * Call this instead of initialize(CompilationUnit)
+ * TODO remove initialize(CompilationUnit) from the hierarchy
+ */
+ void initialize(MethodDeclaration methodDeclaration);
+
+ /**
+ * Call this instead of synchronizeWith(CompilationUnit)
+ * TODO remove synchronizeWith(CompilationUnit) from the hierarchy
+ */
+ void synchronizeWith(MethodDeclaration methodDeclaration);
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SimpleJavaType.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SimpleJavaType.java
index ef47ba3097..ab9890e013 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SimpleJavaType.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SimpleJavaType.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2012 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.
@@ -11,6 +11,7 @@ package org.eclipse.jpt.common.utility.internal;
import java.io.PrintWriter;
import java.io.Serializable;
+import java.util.HashMap;
import org.eclipse.jpt.common.utility.JavaType;
@@ -35,10 +36,36 @@ public final class SimpleJavaType
private static final String BRACKETS = "[]"; //$NON-NLS-1$
private static final long serialVersionUID = 1L;
+ /**
+ * Cache the "standard" java types for performance
+ * Defining this as java.lang*, java.util*, java.sql.* for array dimensionality of 0
+ * Make this a HashMap for performance, duplicate creation shouldn't be an issue.
+ */
+ private static final HashMap<String, JavaType> stardardJavaTypesCache = new HashMap<String, JavaType>();
// ********** constructors **********
/**
+ * Use this factory method for performance. Standard java types will be cached.
+ */
+ public static JavaType buildSimpleJavaType(String elementTypeName, int arrayDepth) {
+ if (arrayDepth == 0) {
+ JavaType javaType = stardardJavaTypesCache.get(elementTypeName);
+ if (javaType != null) {
+ return javaType;
+ }
+ if (elementTypeName.startsWith("java.lang.") || //$NON-NLS-1$
+ elementTypeName.startsWith("java.util.") || //$NON-NLS-1$
+ elementTypeName.startsWith("java.sql.")) { //$NON-NLS-1$
+ javaType = new SimpleJavaType(elementTypeName, arrayDepth);
+ stardardJavaTypesCache.put(elementTypeName, javaType);
+ return javaType;
+ }
+ }
+ return new SimpleJavaType(elementTypeName, arrayDepth);
+ }
+
+ /**
* Construct a Java type with the specified element type and array depth.
*/
public SimpleJavaType(String elementTypeName, int arrayDepth) {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/PropertyAccessor.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/PropertyAccessor.java
index 183148c29c..9c6fe74fa3 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/PropertyAccessor.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/PropertyAccessor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 Oracle. All rights reserved.
+ * Copyright (c) 2011, 2012 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
@@ -10,6 +10,7 @@
package org.eclipse.jpt.jpa.core.internal.context.java;
import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jpt.common.core.resource.java.JavaResourceAttribute;
import org.eclipse.jpt.common.core.resource.java.JavaResourceField;
import org.eclipse.jpt.common.core.resource.java.JavaResourceMethod;
@@ -139,6 +140,14 @@ public class PropertyAccessor
public boolean isFor(MethodSignature methodSignature, int occurrence) {
return this.member.isFor(methodSignature, occurrence);
}
+
+ public void synchronizeWith(MethodDeclaration methodDeclaration) {
+ // NOP
+ }
+
+ public void initialize(MethodDeclaration methodDeclaration) {
+ // NOP
+ }
}
}

Back to the top