Skip to content

Commit

Permalink
STS-3056: improved performance for annotation processing by caching m…
Browse files Browse the repository at this point in the history
…etadata reading results
  • Loading branch information
martinlippert committed Nov 28, 2012
1 parent 9a0f264 commit 46deebf
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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<String, MetadataReader> cache = new HashMap<String, MetadataReader>();

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");
}

}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(
Expand Down

0 comments on commit 46deebf

Please sign in to comment.