diff --git a/plugins/org.springframework.ide.eclipse.core/src/org/springframework/ide/eclipse/core/java/classreading/CachingJdtMetadataReaderFactory.java b/plugins/org.springframework.ide.eclipse.core/src/org/springframework/ide/eclipse/core/java/classreading/CachingJdtMetadataReaderFactory.java new file mode 100644 index 0000000000..65589803c0 --- /dev/null +++ b/plugins/org.springframework.ide.eclipse.core/src/org/springframework/ide/eclipse/core/java/classreading/CachingJdtMetadataReaderFactory.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2012 Spring IDE Developers + * 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 + * + * Contributors: + * Spring IDE Developers - initial API and implementation + *******************************************************************************/ +package org.springframework.ide.eclipse.core.java.classreading; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.jdt.core.IJavaProject; +import org.springframework.core.io.Resource; +import org.springframework.core.type.classreading.MetadataReader; +import org.springframework.core.type.classreading.MetadataReaderFactory; + +/** + * @author Martin Lippert + * @since 3.2.0 + */ +public class CachingJdtMetadataReaderFactory implements MetadataReaderFactory { + + private final JdtMetadataReaderFactory factory; + private final Map cache = new HashMap(); + + public CachingJdtMetadataReaderFactory(IJavaProject project) { + this.factory = new JdtMetadataReaderFactory(project); + } + + public MetadataReader getMetadataReader(String className) throws IOException { + synchronized(cache) { + if (!cache.containsKey(className)) { + cache.put(className, factory.getMetadataReader(className)); + } + } + + return cache.get(className); + } + + public MetadataReader getMetadataReader(Resource resource) throws IOException { + throw new JdtMetadataReaderException("'getMetadataReader' is not supported"); + } + +} diff --git a/plugins/org.springframework.ide.eclipse.core/src/org/springframework/ide/eclipse/core/java/classreading/JdtMetadataReader.java b/plugins/org.springframework.ide.eclipse.core/src/org/springframework/ide/eclipse/core/java/classreading/JdtMetadataReader.java index 986581959a..3453992a5b 100644 --- a/plugins/org.springframework.ide.eclipse.core/src/org/springframework/ide/eclipse/core/java/classreading/JdtMetadataReader.java +++ b/plugins/org.springframework.ide.eclipse.core/src/org/springframework/ide/eclipse/core/java/classreading/JdtMetadataReader.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 Spring IDE Developers + * Copyright (c) 2009, 2012 Spring IDE Developers * 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 @@ -21,22 +21,33 @@ /** * @author Christian Dupuis + * @author Martin Lippert * @since 2.2.5 */ public class JdtMetadataReader implements MetadataReader { private final IType type; + private AnnotationMetadata annotationMetadata; + private ClassMetadata classMetadata; public JdtMetadataReader(IType type) { + System.out.println("JdtMetadataReader created for: " + type.getFullyQualifiedName()); this.type = type; } public AnnotationMetadata getAnnotationMetadata() { - return new JdtAnnotationMetadata(type); + if (this.annotationMetadata == null) { + System.out.println("getAnnotationMetadata for: " + type.getFullyQualifiedName()); + this.annotationMetadata = new JdtAnnotationMetadata(type); + } + return this.annotationMetadata; } public ClassMetadata getClassMetadata() { - return new JdtClassMetadata(type); + if (this.classMetadata == null) { + this.classMetadata = new JdtClassMetadata(type); + } + return this.classMetadata; } public Resource getResource() { diff --git a/plugins/org.springframework.ide.eclipse.metadata/src/org/springframework/ide/eclipse/metadata/process/JdtConfigurationClassPostProcessor.java b/plugins/org.springframework.ide.eclipse.metadata/src/org/springframework/ide/eclipse/metadata/process/JdtConfigurationClassPostProcessor.java index c2426e3792..efac802f0d 100644 --- a/plugins/org.springframework.ide.eclipse.metadata/src/org/springframework/ide/eclipse/metadata/process/JdtConfigurationClassPostProcessor.java +++ b/plugins/org.springframework.ide.eclipse.metadata/src/org/springframework/ide/eclipse/metadata/process/JdtConfigurationClassPostProcessor.java @@ -39,8 +39,8 @@ import org.springframework.ide.eclipse.beans.core.model.process.IBeansConfigPostProcessor; import org.springframework.ide.eclipse.beans.core.model.process.IBeansConfigRegistrationSupport; import org.springframework.ide.eclipse.core.java.JdtUtils; +import org.springframework.ide.eclipse.core.java.classreading.CachingJdtMetadataReaderFactory; import org.springframework.ide.eclipse.core.java.classreading.JdtAnnotationMetadata; -import org.springframework.ide.eclipse.core.java.classreading.JdtMetadataReaderFactory; import org.springframework.ide.eclipse.core.java.classreading.JdtMethodMetadata; import org.springframework.ide.eclipse.core.model.java.JavaModelSourceLocation; import org.springframework.ide.eclipse.core.model.validation.ValidationProblem; @@ -65,7 +65,7 @@ public void postProcess(final IBeansConfigPostProcessingContext postProcessingCo ConfigurationClassPostProcessor processor = new ConfigurationClassPostProcessor(); processor.setSourceExtractor(new DelegatingSourceExtractor(project.getProject())); - processor.setMetadataReaderFactory(new JdtMetadataReaderFactory(project)); + processor.setMetadataReaderFactory(new CachingJdtMetadataReaderFactory(project)); processor.setProblemReporter(new JdtAnnotationMetadataProblemReporter(postProcessingContext)); processor.processConfigBeanDefinitions(new ReaderEventListenerForwardingBeanDefinitionRegistry(