### Eclipse Workspace Patch 1.0 #P org.eclipse.jpt.common.core Index: src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryMethod.java =================================================================== RCS file: /cvsroot/webtools/org.eclipse.jpa/components/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryMethod.java,v retrieving revision 1.3 diff -u -r1.3 BinaryMethod.java --- src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryMethod.java 19 Sep 2011 20:24:30 -0000 1.3 +++ src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryMethod.java 18 Apr 2012 01:24:18 -0000 @@ -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.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 @@ 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(); Index: src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceAbstractType.java =================================================================== RCS file: /cvsroot/webtools/org.eclipse.jpa/components/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceAbstractType.java,v retrieving revision 1.3 diff -u -r1.3 SourceAbstractType.java --- src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceAbstractType.java 1 Mar 2012 16:58:08 -0000 1.3 +++ src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceAbstractType.java 18 Apr 2012 01:24:18 -0000 @@ -14,6 +14,7 @@ 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 @@ } @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)); + public 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)); } Index: src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceAnnotatedElement.java =================================================================== RCS file: /cvsroot/webtools/org.eclipse.jpa/components/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceAnnotatedElement.java,v retrieving revision 1.12 diff -u -r1.12 SourceAnnotatedElement.java --- src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceAnnotatedElement.java 17 Apr 2012 14:33:04 -0000 1.12 +++ src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceAnnotatedElement.java 18 Apr 2012 01:24:18 -0000 @@ -21,6 +21,7 @@ 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 @@ } /** + * 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 @@ } } + /** + * @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 @@ } 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) { Index: src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceAttribute.java =================================================================== RCS file: /cvsroot/webtools/org.eclipse.jpa/components/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceAttribute.java,v retrieving revision 1.4 diff -u -r1.4 SourceAttribute.java --- src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceAttribute.java 24 Feb 2012 17:26:12 -0000 1.4 +++ src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceAttribute.java 18 Apr 2012 01:24:18 -0000 @@ -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,49 +59,61 @@ } @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)); + } // ******** overrides ******** @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)); + public void synchronizeWith(IBinding binding) { + super.synchronizeWith(binding); + this.syncModifiers(this.buildModifiers(binding)); } @Override @@ -138,7 +150,7 @@ 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 +169,7 @@ /** * 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(); } Index: src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceField.java =================================================================== RCS file: /cvsroot/webtools/org.eclipse.jpa/components/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceField.java,v retrieving revision 1.2 diff -u -r1.2 SourceField.java --- src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceField.java 1 Aug 2011 15:10:14 -0000 1.2 +++ src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceField.java 18 Apr 2012 01:24:18 -0000 @@ -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 @@ 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()); + } + } Index: src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceMember.java =================================================================== RCS file: /cvsroot/webtools/org.eclipse.jpa/components/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceMember.java,v retrieving revision 1.6 diff -u -r1.6 SourceMember.java --- src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceMember.java 1 Mar 2012 19:52:51 -0000 1.6 +++ src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceMember.java 18 Apr 2012 01:24:18 -0000 @@ -11,6 +11,7 @@ import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jdt.core.dom.IBinding; +import org.eclipse.jdt.core.dom.ITypeBinding; import org.eclipse.jdt.core.dom.Modifier; import org.eclipse.jpt.common.core.resource.java.Annotation; import org.eclipse.jpt.common.core.resource.java.JavaResourceMember; @@ -41,9 +42,8 @@ } @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 +52,8 @@ } @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)); Index: src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceMethod.java =================================================================== RCS file: /cvsroot/webtools/org.eclipse.jpa/components/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceMethod.java,v retrieving revision 1.3 diff -u -r1.3 SourceMethod.java --- src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceMethod.java 19 Sep 2011 20:24:30 -0000 1.3 +++ src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceMethod.java 18 Apr 2012 01:24:18 -0000 @@ -14,8 +14,10 @@ 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 @@ MethodSignature signature, int occurrence, JavaResourceCompilationUnit javaResourceCompilationUnit, - CompilationUnit astRoot) { + MethodDeclaration methodDeclaration) { MethodAttribute method = JDTMethodAttribute.newInstance( declaringType, @@ -57,7 +59,7 @@ javaResourceCompilationUnit.getModifySharedDocumentCommandExecutor(), javaResourceCompilationUnit.getAnnotationEditFormatter()); JavaResourceMethod jrm = new SourceMethod(parent, method); - jrm.initialize(astRoot); + jrm.initialize(methodDeclaration); return jrm; } @@ -65,14 +67,28 @@ 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 @@ 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()); Index: src/org/eclipse/jpt/common/core/internal/resource/java/source/SourcePackage.java =================================================================== RCS file: /cvsroot/webtools/org.eclipse.jpa/components/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourcePackage.java,v retrieving revision 1.2 diff -u -r1.2 SourcePackage.java --- src/org/eclipse/jpt/common/core/internal/resource/java/source/SourcePackage.java 1 Aug 2011 15:10:14 -0000 1.2 +++ src/org/eclipse/jpt/common/core/internal/resource/java/source/SourcePackage.java 18 Apr 2012 01:24:18 -0000 @@ -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 @@ @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 @@ } } - 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 @@ // ********** 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 Index: src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceType.java =================================================================== RCS file: /cvsroot/webtools/org.eclipse.jpa/components/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceType.java,v retrieving revision 1.6 diff -u -r1.6 SourceType.java --- src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceType.java 1 Mar 2012 16:59:13 -0000 1.6 +++ src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceType.java 18 Apr 2012 01:24:18 -0000 @@ -17,6 +17,7 @@ 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 @@ @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 + public 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 @@ } 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 @@ 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 @@ 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); } Index: src/org/eclipse/jpt/common/core/internal/utility/jdt/ASTTools.java =================================================================== RCS file: /cvsroot/webtools/org.eclipse.jpa/components/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/ASTTools.java,v retrieving revision 1.7 diff -u -r1.7 ASTTools.java --- src/org/eclipse/jpt/common/core/internal/utility/jdt/ASTTools.java 1 Mar 2012 19:52:51 -0000 1.7 +++ src/org/eclipse/jpt/common/core/internal/utility/jdt/ASTTools.java 18 Apr 2012 01:24:18 -0000 @@ -149,7 +149,7 @@ 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; } Index: src/org/eclipse/jpt/common/core/resource/java/JavaResourceMethod.java =================================================================== RCS file: /cvsroot/webtools/org.eclipse.jpa/components/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/java/JavaResourceMethod.java,v retrieving revision 1.2 diff -u -r1.2 JavaResourceMethod.java --- src/org/eclipse/jpt/common/core/resource/java/JavaResourceMethod.java 19 Sep 2011 20:24:30 -0000 1.2 +++ src/org/eclipse/jpt/common/core/resource/java/JavaResourceMethod.java 18 Apr 2012 01:24:18 -0000 @@ -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 @@ * 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 @@ * 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); } #P org.eclipse.jpt.common.utility Index: src/org/eclipse/jpt/common/utility/internal/SimpleJavaType.java =================================================================== RCS file: /cvsroot/webtools/org.eclipse.jpa/components/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SimpleJavaType.java,v retrieving revision 1.1 diff -u -r1.1 SimpleJavaType.java --- src/org/eclipse/jpt/common/utility/internal/SimpleJavaType.java 5 Feb 2011 16:21:59 -0000 1.1 +++ src/org/eclipse/jpt/common/utility/internal/SimpleJavaType.java 18 Apr 2012 01:24:19 -0000 @@ -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 @@ import java.io.PrintWriter; import java.io.Serializable; +import java.util.HashMap; import org.eclipse.jpt.common.utility.JavaType; @@ -35,10 +36,36 @@ 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 stardardJavaTypesCache = new HashMap(); // ********** 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) { #P org.eclipse.jpt.jpa.core Index: src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentAttribute.java =================================================================== RCS file: /cvsroot/webtools/org.eclipse.jpa/components/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentAttribute.java,v retrieving revision 1.17 diff -u -r1.17 AbstractJavaPersistentAttribute.java --- src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentAttribute.java 11 Apr 2012 18:49:56 -0000 1.17 +++ src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentAttribute.java 18 Apr 2012 01:24:20 -0000 @@ -379,9 +379,11 @@ * source code. */ protected JavaAttributeMappingDefinition getSpecifiedMappingDefinition() { - for (JavaAttributeMappingDefinition definition : this.getSpecifiedMappingDefinitions()) { - if (definition.isSpecified(this)) { - return definition; + if (this.accessor.getResourceAttribute().isAnnotated()) { //short-circuit for performance + for (JavaAttributeMappingDefinition definition : this.getSpecifiedMappingDefinitions()) { + if (definition.isSpecified(this)) { + return definition; + } } } return null; Index: src/org/eclipse/jpt/jpa/core/internal/context/java/PropertyAccessor.java =================================================================== RCS file: /cvsroot/webtools/org.eclipse.jpa/components/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/PropertyAccessor.java,v retrieving revision 1.3 diff -u -r1.3 PropertyAccessor.java --- src/org/eclipse/jpt/jpa/core/internal/context/java/PropertyAccessor.java 6 Oct 2011 13:32:21 -0000 1.3 +++ src/org/eclipse/jpt/jpa/core/internal/context/java/PropertyAccessor.java 18 Apr 2012 01:24:20 -0000 @@ -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 boolean isFor(MethodSignature methodSignature, int occurrence) { return this.member.isFor(methodSignature, occurrence); } + + public void synchronizeWith(MethodDeclaration methodDeclaration) { + // NOP + } + + public void initialize(MethodDeclaration methodDeclaration) { + // NOP + } } }