Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorthanson2006-02-03 23:12:41 +0000
committerthanson2006-02-03 23:12:41 +0000
commit9a8affe2fe13cdaff4ce03fabb5092a18b8fcbaa (patch)
tree6ad21ee2f5b92f95ccdff1d25b516c2a1015d6fc
parente2c8b8023f769df30a2baf6b7a009e9cef4c3a51 (diff)
downloadeclipse.jdt.core-9a8affe2fe13cdaff4ce03fabb5092a18b8fcbaa.tar.gz
eclipse.jdt.core-9a8affe2fe13cdaff4ce03fabb5092a18b8fcbaa.tar.xz
eclipse.jdt.core-9a8affe2fe13cdaff4ce03fabb5092a18b8fcbaa.zip
Fix OutOfMemoryError by caching type requests.
-rw-r--r--org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/APTDispatchRunnable.java20
-rw-r--r--org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/BaseProcessorEnv.java36
2 files changed, 23 insertions, 33 deletions
diff --git a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/APTDispatchRunnable.java b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/APTDispatchRunnable.java
index ba0c179856..ce3e14405c 100644
--- a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/APTDispatchRunnable.java
+++ b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/APTDispatchRunnable.java
@@ -470,7 +470,9 @@ import com.sun.mirror.declaration.AnnotationTypeDeclaration;
final List<IFile> filesWithMissingType = new ArrayList<IFile>();
final List<ICompilationUnit> unitsForFiles = new ArrayList<ICompilationUnit>();
final APTResult result = runAPT(factories, processorEnv, filesWithMissingType, unitsForFiles, 0);
-
+
+
+ /* Comment out internal rounding
if( processorEnv.getPhase() == Phase.BUILD )
{
boolean generatedTypes = result.hasGeneratedTypes();
@@ -507,25 +509,11 @@ import com.sun.mirror.declaration.AnnotationTypeDeclaration;
newEnv.close();
}
}
+ */
return result;
}
- /**
- * Diff the sets of files -- if the new result has
- * files that the old one does not, we have new files.
- */
- private boolean hasNewFiles(APTResult oldResult, APTResult newResult) {
- Set<IFile> oldFiles = oldResult.getNewFiles();
- Set<IFile> newFiles = newResult.getNewFiles();
- for (IFile file : newFiles) {
- if (!oldFiles.contains(file)) {
- return true;
- }
- }
- return false;
- }
-
private APTResult runAPT(
final Map<AnnotationProcessorFactory, FactoryPath.Attributes> factories,
final ProcessorEnvImpl processorEnv,
diff --git a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/BaseProcessorEnv.java b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/BaseProcessorEnv.java
index 687007c4fa..0cbc193c64 100644
--- a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/BaseProcessorEnv.java
+++ b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/BaseProcessorEnv.java
@@ -118,6 +118,7 @@ public class BaseProcessorEnv implements AnnotationProcessorEnvironment
// is outside of the workspace.
private VoidTypeImpl _voidType;
private PrimitiveTypeImpl[] _primitives;
+ private final Map<String,TypeDeclaration>_typeCache = new HashMap<String,TypeDeclaration>();
public BaseProcessorEnv(CompilationUnit astCompilationUnit,
IFile file,
@@ -340,12 +341,15 @@ public class BaseProcessorEnv implements AnnotationProcessorEnvironment
public Map<String, String> getOptions(){ return Collections.emptyMap(); }
// does not generate dependencies
- public TypeDeclaration getTypeDeclaration(final String originalName)
+ public TypeDeclaration getTypeDeclaration(String name)
{
- if( originalName == null || originalName.length() == 0 ) return null;
-
- String name = originalName;
- // get rid of the generics parts.
+ if( name == null || name.length() == 0 ) return null;
+
+ //First check cache
+ TypeDeclaration result = _typeCache.get(name);
+ if (result != null) return result;
+
+ // get rid of the generics parts.
final int index = name.indexOf('<');
if( index != -1 )
name = name.substring(0, index);
@@ -370,19 +374,17 @@ public class BaseProcessorEnv implements AnnotationProcessorEnvironment
typeBinding = ((AbstractTypeDeclaration)node).resolveBinding();
}
}
- TypeDeclaration result = null;
- if( typeBinding != null ) {
- result = Factory.createReferenceType(typeBinding, this);
- }
- else {
- // finally go search for it in the universe.
+
+ // finally go search for it in the universe.
+ if (typeBinding == null)
typeBinding = getTypeDefinitionBindingFromName(name);
- if( typeBinding != null ){
- result = Factory.createReferenceType(typeBinding, this);
- }
- }
-
- return result;
+
+ result = Factory.createReferenceType(typeBinding, this);
+
+ // update cache
+ if (result != null)
+ _typeCache.put(name, result);
+ return result;
}
/**

Back to the top