1
/*******************************************************************************
2
* Copyright (c) 2004, 2010 IBM Corporation and others.
3
* All rights reserved. This program and the accompanying materials
4
* are made available under the terms of the Eclipse Public License v1.0
5
* which accompanies this distribution, and is available at
6
* http://www.eclipse.org/legal/epl-v10.html
9
* IBM - Initial API and implementation
10
*******************************************************************************/
11
package org.eclipse.cdt.internal.core.dom;
13
import java.io.IOException;
15
import org.eclipse.cdt.core.CCorePlugin;
16
import org.eclipse.cdt.core.dom.CDOM;
17
import org.eclipse.cdt.core.index.IIndexFileLocation;
18
import org.eclipse.cdt.core.model.ITranslationUnit;
19
import org.eclipse.cdt.core.parser.CodeReader;
20
import org.eclipse.cdt.core.parser.CodeReaderCache;
21
import org.eclipse.cdt.core.parser.ICodeReaderCache;
22
import org.eclipse.core.runtime.CoreException;
23
import org.eclipse.core.runtime.Preferences;
29
public class SavedCodeReaderFactory extends AbstractCodeReaderFactory {
31
private static ICodeReaderCache cache;
32
private static SavedCodeReaderFactory instance = new SavedCodeReaderFactory(null);
34
public static SavedCodeReaderFactory getInstance() {
38
public static SavedCodeReaderFactory createInstance(IIncludeFileResolutionHeuristics heuristics) {
39
return new SavedCodeReaderFactory(heuristics);
43
private SavedCodeReaderFactory(IIncludeFileResolutionHeuristics heuristics) {
47
int size= CodeReaderCache.DEFAULT_CACHE_SIZE_IN_MB;
48
final CCorePlugin corePlugin = CCorePlugin.getDefault();
49
if (corePlugin != null) {
50
Preferences pluginPreferences = corePlugin.getPluginPreferences();
51
if (pluginPreferences != null) {
52
size = pluginPreferences.getInt(CodeReaderCache.CODE_READER_BUFFER);
54
String [] properties = pluginPreferences.propertyNames();
55
boolean found = false;
56
for (int j = 0; j < properties.length; ++j) {
57
if (properties[j].equals( CodeReaderCache.CODE_READER_BUFFER)) {
63
size= CodeReaderCache.DEFAULT_CACHE_SIZE_IN_MB;
65
} else if (size < 0) {
66
size= CodeReaderCache.DEFAULT_CACHE_SIZE_IN_MB;
70
cache= new CodeReaderCache(size);
74
* @see org.eclipse.cdt.core.dom.ICodeReaderFactory#getUniqueIdentifier()
76
public int getUniqueIdentifier() {
77
return CDOM.PARSE_SAVED_RESOURCES;
81
* @see org.eclipse.cdt.core.dom.ICodeReaderFactory#createCodeReaderForTranslationUnit(java.lang.String)
83
public CodeReader createCodeReaderForTranslationUnit(String path) {
84
return cache.get(path);
87
public CodeReader createCodeReaderForTranslationUnit(ITranslationUnit tu) {
88
return new CodeReader(tu.getResource().getLocation().toOSString(), tu.getContents());
92
* @see org.eclipse.cdt.core.dom.ICodeReaderFactory#createCodeReaderForInclusion(java.lang.String)
94
public CodeReader createCodeReaderForInclusion(String path) {
95
return cache.get(path);
99
public CodeReader createCodeReaderForInclusion(IIndexFileLocation ifl, String astPath)
100
throws CoreException, IOException {
101
return cache.get(astPath, ifl);
105
* @see org.eclipse.cdt.core.dom.ICodeReaderFactory#createCodeReaderForInclusion(java.lang.String)
107
public ICodeReaderCache getCodeReaderCache() {