Changeset 364575fc79ca0a2d7d0efbd5c165c1d2dfc36a3b
- Timestamp:
- 06/28/09 23:36:50 (15 months ago)
- Children:
- 1567fcce2711ee19e98902f8ef734f1a7dd9731f
- Parents:
- 25b5d220afcf17776b844086f439554f14dc63dc
- git-author:
- mb0 <mb0@…> (06/11/09 05:25:41)
- git-committer:
- mb0 <mb0@…> (06/28/09 23:36:50)
- Files:
-
- 9 modified
-
org.axdt.as3/src/org/axdt/as3/AS3Plugin.java (modified) (4 diffs)
-
org.axdt.as3/src/org/axdt/as3/imp/builders/AS3Builder.java (modified) (6 diffs)
-
org.axdt.as3/src/org/axdt/as3/imp/parser/AS3ParseController.java (modified) (4 diffs)
-
org.axdt.as3/src/org/axdt/as3/imp/parser/IndexingVisitor.java (modified) (3 diffs)
-
org.axdt.as3/src/org/axdt/as3/imp/services/AS3HyperLinkDetector.java (modified) (2 diffs)
-
org.axdt.axdoc/src/org/axdt/axdoc/AXDocPlugin.java (modified) (4 diffs)
-
org.axdt.axdoc/src/org/axdt/axdoc/preferences/AXDocPreferences.java (modified) (2 diffs)
-
org.axdt.axdoc/src/org/axdt/axdoc/util/AXDocParser.java (modified) (2 diffs)
-
org.axdt.axdoc/src/org/axdt/axdoc/util/Index0r.java (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
org.axdt.as3/src/org/axdt/as3/AS3Plugin.java
r87f02d1 r364575f 4 4 import java.net.URL; 5 5 6 import org.axdt.as3.imp.builders.AS3Nature; 7 import org.axdt.as3.preferences.AS3Preferences; 6 8 import org.axdt.as3.templates.AS3ContextType; 9 import org.axdt.axdoc.model.AXRootType; 10 import org.axdt.axdoc.util.Index0r; 7 11 import org.axdt.common.preferences.AxdtPreferences; 12 import org.eclipse.core.resources.IContainer; 13 import org.eclipse.core.resources.IProject; 14 import org.eclipse.core.resources.ResourcesPlugin; 15 import org.eclipse.core.runtime.CoreException; 8 16 import org.eclipse.core.runtime.FileLocator; 9 17 import org.eclipse.core.runtime.IPath; … … 12 20 import org.eclipse.core.runtime.preferences.ConfigurationScope; 13 21 import org.eclipse.core.runtime.preferences.IScopeContext; 22 import org.eclipse.emf.common.util.URI; 14 23 import org.eclipse.imp.runtime.PluginBase; 15 24 import org.eclipse.jface.preference.IPreferenceStore; … … 53 62 super.start(context); 54 63 plugin = this; 64 try { initializeIndex(); } 65 catch (Exception e) { 66 log("error initializing source index", e); 67 } 55 68 } 56 69 … … 146 159 return LANGUAGE; 147 160 } 161 162 private void initializeIndex() { 163 Index0r index0r = Index0r.getInstance(); 164 // asdoc locations are added on axdoc plugin start 165 IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); 166 for (IProject project:projects) { 167 try { 168 if (!project.hasNature(AS3Nature.k_natureID)) 169 continue; 170 } catch (CoreException e) { 171 continue; 172 } 173 IContainer[] paths = AS3Preferences.getSourcePaths(project); 174 for (IContainer srcPath:paths) { 175 if (!srcPath.exists()) continue; 176 String name = "source "+srcPath.getFullPath(); 177 URI uri = URI.createPlatformResourceURI(srcPath.getFullPath().toString(), true); 178 index0r.addRoot(name, uri.toString(), AXRootType.SOURCE); 179 } 180 } 181 } 182 148 183 } -
org.axdt.as3/src/org/axdt/as3/imp/builders/AS3Builder.java
r49cbb50 r364575f 1 1 package org.axdt.as3.imp.builders; 2 2 3 import java.util.ArrayList; 4 import java.util.Arrays; 3 5 import java.util.HashMap; 6 import java.util.List; 7 import java.util.Map; 4 8 5 9 import org.axdt.as3.AS3Plugin; 6 10 import org.axdt.as3.imp.parser.AS3ParseController; 7 import org.axdt.as3.imp.services.AS3EditorService;8 11 import org.axdt.as3.preferences.AS3Preferences; 9 12 import org.axdt.as3.util.AS3Util; 13 import org.axdt.axdoc.model.AXRoot; 14 import org.axdt.axdoc.util.Index0r; 10 15 import org.eclipse.core.resources.IContainer; 11 16 import org.eclipse.core.resources.IFile; 17 import org.eclipse.core.resources.IProject; 12 18 import org.eclipse.core.resources.IResource; 19 import org.eclipse.core.runtime.CoreException; 13 20 import org.eclipse.core.runtime.IPath; 14 21 import org.eclipse.core.runtime.IProgressMonitor; … … 23 30 import org.eclipse.imp.model.ModelFactory.ModelException; 24 31 import org.eclipse.imp.runtime.PluginBase; 32 import org.eclipse.imp.services.IAnnotationTypeInfo; 25 33 26 34 /** … … 35 43 public static final Language LANGUAGE = LanguageRegistry.findLanguage(AS3Plugin.LANGUAGE); 36 44 private HashMap<IPath, AS3ParseController> files; 45 private boolean isFullBuild = false; 46 private List<AS3ParseController> astnodes; 37 47 38 48 public AS3Builder() { … … 99 109 protected boolean isOutputFolder(IResource resource) { 100 110 if (resource == null || !(resource instanceof IContainer)) return false; 101 IContainer deployContainer = AS3Preferences.getDeployPath(resource); 102 return resource.equals(deployContainer); 103 } 104 111 return resource.equals(AS3Preferences.getDeployPath(resource)); 112 } 113 @Override 114 @SuppressWarnings("unchecked") 115 protected IProject[] build(int kind, Map args, IProgressMonitor monitor) { 116 isFullBuild = kind == FULL_BUILD || kind == CLEAN_BUILD; 117 if (isFullBuild) { 118 Index0r index0r = Index0r.getInstance(); 119 IContainer[] srcFolders = AS3Preferences.getSourcePaths(getProject()); 120 for (IContainer srcFolder:srcFolders) { 121 AXRoot root = index0r.getSourceRoot(srcFolder); 122 index0r.clearRoot(root); 123 } 124 astnodes = new ArrayList<AS3ParseController>(); 125 // do the build. it should index the whole project 126 super.build(kind, args, monitor); 127 for (AS3ParseController control:astnodes) { 128 control.resolveDeclarations(control.getCurrentAst()); 129 } 130 astnodes = null; 131 // build done save and cache the index 132 for (IContainer srcFolder:srcFolders) { 133 AXRoot root = index0r.getSourceRoot(srcFolder); 134 index0r.saveRoot(root); 135 index0r.cachePackages(root); 136 } 137 return new IProject[0]; 138 } else { 139 // proceed with normal build 140 return super.build(kind, args, monitor); 141 } 142 } 105 143 /** 106 144 * Compile one AS3 file. … … 108 146 */ 109 147 protected void compile(final IFile file, IProgressMonitor monitor) { 148 AS3ParseController parse = getParseController(file); 149 // if controller could not be created or initialized 150 if (parse == null || parse.getProject() == null) 151 return; 152 String contents = BuilderUtils.getFileContents(file); 153 if (hasBom(file)) contents = removeBom(contents); 154 Object ast = parse.parse(contents, false, monitor); 155 if (ast != null && astnodes != null) { 156 astnodes.add(parse); 157 } 158 } 159 160 private String removeBom(String contents) { 161 // first char might be misread utf8 char 162 return contents.charAt(0) == 0xfeff ? 163 contents = contents.substring(1): contents; 164 } 165 166 private boolean hasBom(IFile file) { 110 167 try { 111 if (AS3EditorService.isOpen(file.getFullPath())) { 112 // skip if editor is open. the parser scheduler will handle things 113 AS3Plugin.getDefault().debug("skip build for opened file."); 114 } 115 AS3ParseController parse = getParseController(file); 116 117 MarkerCreator marker = new MarkerCreator(file, parse, PROBLEM_MARKER_ID); 118 parse.getAnnotationTypeInfo().addProblemMarkerType(getErrorMarkerID()); 119 120 ISourceProject sourceProject = ModelFactory.open(file.getProject()); 121 IPath path = file.getProjectRelativePath(); 122 parse.initialize(path, sourceProject, marker); 123 boolean hasBom = false; 124 try { 125 IContentDescription info = file.getContentDescription(); 126 hasBom = info != null && null != info.getProperty(IContentDescription.BYTE_ORDER_MARK); 127 } catch (Exception e) { /* ignore */} 128 String contents = BuilderUtils.getFileContents(file); 129 if (hasBom) { 130 // file info says there is a bom 131 if (contents.charAt(0)==0xfeff) { 132 // first char is misread utf8 char 133 contents = contents.substring(1); 134 } 135 } 136 parse.parse(contents, true, monitor); 137 138 } catch (ModelException e) { 139 getPlugin().logException( 140 "Example builder returns without parsing due to a ModelException", e); 141 } 142 } 143 168 IContentDescription info = file.getContentDescription(); 169 return info != null && null != info.getProperty(IContentDescription.BYTE_ORDER_MARK); 170 } catch (Exception e) { /* ignore */} 171 return false; 172 } 173 174 @SuppressWarnings("unchecked") 144 175 private AS3ParseController getParseController(IFile file) { 145 176 IPath path = file.getFullPath(); … … 147 178 if (controller == null) { 148 179 controller = new AS3ParseController(); 149 files.put(path, controller); 150 } else { 151 AS3Plugin.getDefault().debug("reusing builder parse controller for "+ path); 180 IAnnotationTypeInfo typeInfo = controller.getAnnotationTypeInfo(); 181 List<List<String>> lists = Arrays.asList(typeInfo.getProblemMarkerTypes()); 182 boolean found = false; 183 for (List<String> list:lists) { 184 if (list.contains(getErrorMarkerID())) { 185 found = true; 186 break; 187 } 188 } 189 if (!found) typeInfo.addProblemMarkerType(getErrorMarkerID()); 190 MarkerCreator marker = new MarkerCreator(file, controller, PROBLEM_MARKER_ID); 191 IPath relativePath = file.getProjectRelativePath(); 192 try { 193 ISourceProject sourceProject = ModelFactory.open(file.getProject()); 194 controller.initialize(relativePath, sourceProject, marker); 195 files.put(relativePath, controller); 196 } catch (ModelException e) { 197 getPlugin().logException("Cannot create parse controller", e); 198 } 152 199 } 153 200 return controller; 154 201 } 202 @Override 203 protected void clearMarkersOn(IFile file) { 204 try { 205 file.deleteMarkers(getErrorMarkerID(), true, IResource.DEPTH_INFINITE); 206 } catch (CoreException e) { 207 } 208 //super.clearMarkersOn(file); 209 } 155 210 } -
org.axdt.as3/src/org/axdt/as3/imp/parser/AS3ParseController.java
r25b5d22 r364575f 1 1 package org.axdt.as3.imp.parser; 2 2 3 import java.util. HashSet;3 import java.util.Collections; 4 4 import java.util.Iterator; 5 5 6 6 import lpg.runtime.IAst; 7 import lpg.runtime.IToken;8 7 9 8 import org.axdt.as3.AS3Plugin; … … 116 115 ASTNode node = (ASTNode) fCurrentAst; 117 116 topLevelSymbolTable = resolveSymbolTable(node); 117 buildIndex(node); 118 118 if (resolve) { 119 buildIndex(node);120 119 resolveDeclarations(node); 121 120 } … … 127 126 } 128 127 129 protected void buildIndex(ASTNode root) { 130 root.accept(new IndexingVisitor(this)); 128 public void buildIndex(Object object) { 129 if (object instanceof ASTNode) { 130 ((ASTNode)object).accept(new IndexingVisitor(this)); 131 } 131 132 } 132 133 133 protected void resolveDeclarations(ASTNode root) { 134 root.accept(new ResolvingVisitor(this)); 134 public void resolveDeclarations(Object object) { 135 if (object instanceof ASTNode) { 136 ((ASTNode)object).accept(new ResolvingVisitor(this)); 137 } 135 138 } 136 139 … … 151 154 return null; 152 155 } 156 157 @Override 158 @SuppressWarnings("unchecked") 159 public Iterator getTokenIterator(IRegion region) { 160 if (parser == null) return Collections.EMPTY_SET.iterator(); 161 return super.getTokenIterator(region); 162 } 153 163 } -
org.axdt.as3/src/org/axdt/as3/imp/parser/IndexingVisitor.java
r25b5d22 r364575f 18 18 import org.axdt.axdoc.model.AXNode; 19 19 import org.axdt.axdoc.model.AXRoot; 20 import org.axdt.axdoc.model.AXRootType;21 20 import org.axdt.axdoc.util.Index0r; 22 21 import org.eclipse.core.resources.IContainer; 22 import org.eclipse.emf.common.util.EList; 23 23 24 24 public class IndexingVisitor extends DiagnoseVisitor { … … 31 31 super(parseController); 32 32 IContainer sourceFolder = AS3Util.getSourceFolder(getFile()); 33 String url = "platform:/resource"+ sourceFolder.getFullPath().toString(); 34 root = Index0r.getInstance().addRoot("source "+sourceFolder.getFullPath(), url.toString(), AXRootType.SOURCE); 33 root = Index0r.getInstance().addSourceRoot(sourceFolder); 35 34 } 36 35 … … 51 50 52 51 private void addDoc(AXIndexNode index, IAst ast) { 52 if (index == null || ast == null) return; 53 53 IToken[] tokens = ast.getPrecedingAdjuncts(); 54 54 if (tokens == null || tokens.length == 0) return; 55 AXNode reference = index.getOrCreateReference(); 56 if (reference == null) 57 return; 58 EList<String> asdoc = reference.getAsdoc(); 59 asdoc.clear(); 55 60 for (IToken token:tokens) { 56 AXNode reference = index.getOrCreateReference(); 57 reference.getAsdoc().add(token.toString()); 61 asdoc.add(token.toString()); 58 62 } 59 63 } -
org.axdt.as3/src/org/axdt/as3/imp/services/AS3HyperLinkDetector.java
r25b5d22 r364575f 69 69 } 70 70 } catch (Exception e) { 71 e.printStackTrace();72 71 } 73 72 } else { … … 78 77 } 79 78 } 80 return result. toArray(new IHyperlink[result.size()]);79 return result.isEmpty() ? null : result.toArray(new IHyperlink[result.size()]); 81 80 } 82 81 // The target (depending on what--and where--the target is) may not have a -
org.axdt.axdoc/src/org/axdt/axdoc/AXDocPlugin.java
r85b4650 r364575f 4 4 import java.net.URL; 5 5 6 import org.axdt.axdoc.preferences.AXDocPreferences; 7 import org.axdt.axdoc.util.Index0r; 6 8 import org.eclipse.core.runtime.FileLocator; 7 9 import org.eclipse.core.runtime.Path; … … 49 51 super.start(context); 50 52 plugin = this; 53 try { initializeIndex(); } 54 catch (Exception e) { 55 log("error initializing source index", e); 56 } 51 57 } 52 58 … … 59 65 plugin = null; 60 66 super.stop(context); 67 disposeIndex(); 61 68 } 69 62 70 63 71 /** … … 101 109 getLog().log(new Status(Status.ERROR, PLUGIN_ID, Status.OK, msg, e)); 102 110 } 111 112 private void initializeIndex() { 113 Index0r index0r = Index0r.getInstance(); 114 // add asdoc locations from preference 115 AXDocPreferences.checkAXDocPaths(index0r); 116 // source indexes are initialized in as3 plugin 117 } 118 119 private void disposeIndex() { 120 121 } 103 122 } -
org.axdt.axdoc/src/org/axdt/axdoc/preferences/AXDocPreferences.java
r2d81bf0 r364575f 1 1 package org.axdt.axdoc.preferences; 2 3 import java.util.ArrayList; 2 4 3 5 import org.axdt.axdoc.AXDocPlugin; … … 35 37 } 36 38 37 public static String get LangRefPathString() {39 public static String getAXDocUrlsString() { 38 40 IPreferenceStore store = getInstance().getStore(); 39 41 return store.getString(AXDOC_URLS); 40 42 } 43 private static Object[] getDocItems() { 44 String string = getAXDocUrlsString(); 45 return DocTableFieldEditor.deserializeValue(string); 46 } 47 public static String[] getAXDocURIs() { 48 ArrayList<String> list = new ArrayList<String>(); 49 for (Object value:getDocItems()) { 50 if (value instanceof DocItem) { 51 DocItem item = (DocItem) value; 52 list.add(item.url); 53 } 54 } 55 return list.toArray(new String[list.size()]); 56 } 41 57 public static void checkAXDocPaths(Index0r index0r) { 42 String string = getLangRefPathString(); 43 Object[] values = DocTableFieldEditor.deserializeValue(string); 44 for (Object value:values) { 58 for (Object value:getDocItems()) { 45 59 if (value instanceof DocItem) { 46 60 DocItem item = (DocItem) value; -
org.axdt.axdoc/src/org/axdt/axdoc/util/AXDocParser.java
r2d81bf0 r364575f 16 16 import org.axdt.axdoc.model.AXRoot; 17 17 import org.axdt.axdoc.model.util.AXUtil; 18 import org.eclipse.emf.common.util.EList; 18 19 import org.w3c.dom.DOMException; 19 20 import org.w3c.dom.Node; … … 125 126 String docContent = docNode.getTextContent().replaceAll("\\W+"," ").trim(); 126 127 if (docContent.trim().equals("")) return; 127 node.getOrCreateReference().getAsdoc().add(docContent); 128 EList<String> list = node.getOrCreateReference().getAsdoc(); 129 if (!list.contains(docContent)) 130 list.add(docContent); 128 131 } 129 132 public void parseTypeLevel(AXIndex index) { -
org.axdt.axdoc/src/org/axdt/axdoc/util/Index0r.java
r2d81bf0 r364575f 4 4 import java.util.ArrayList; 5 5 import java.util.Collection; 6 import java.util.Collections; 6 7 import java.util.HashMap; 7 8 import java.util.List; … … 16 17 import org.axdt.axdoc.model.AXRootType; 17 18 import org.axdt.axdoc.model.util.AXUtil; 18 import org.axdt.axdoc.preferences.AXDocPreferences; 19 import org.eclipse.core.resources.IContainer; 20 import org.eclipse.core.resources.IResource; 19 21 import org.eclipse.core.runtime.Path; 20 22 import org.eclipse.emf.common.CommonPlugin; … … 33 35 if (instance == null) { 34 36 instance = new Index0r(); 35 AXDocPreferences.checkAXDocPaths(instance);36 37 } 37 38 return instance; … … 44 45 45 46 public Index0r() { 46 roots = new HashMap<String, AXRoot>();47 packages = new HashMap<String, List<AXIndex>>();47 roots = Collections.synchronizedMap(new HashMap<String, AXRoot>()); 48 packages = Collections.synchronizedMap(new HashMap<String, List<AXIndex>>()); 48 49 docParser = new AXDocParser(); 49 50 baseURI = createBaseUri(); … … 95 96 } 96 97 return result.toArray(new AXIndex[result.size()]); 98 } 99 public AXRoot getSourceRoot(IContainer sourcefolder) { 100 String uri = getSourceUri(sourcefolder); 101 return roots.get(uri); 102 } 103 public String getSourceUri(IResource res) { 104 String path = res.getFullPath().toString(); 105 return URI.createPlatformResourceURI(path, true).toString(); 106 } 107 public AXRoot addSourceRoot(IContainer sourcefolder) { 108 String uri = getSourceUri(sourcefolder); 109 AXRoot root = roots.get(uri); 110 if (root == null) { 111 String path = sourcefolder.getFullPath().toString(); 112 root = Index0r.getInstance().addRoot("source "+path, uri, AXRootType.SOURCE); 113 } 114 return root; 97 115 } 98 116 public AXRoot addRoot(String name, String url, AXRootType type) { … … 143 161 cachePackages(root); 144 162 } 145 protected void saveRoot(AXRoot root) throws IOException { 163 public void saveRoot(AXRoot root) { 164 if (root == null) return; 146 165 Resource index = root.eResource(); 147 index.save(null); 166 if (index == null) 167 return; 168 try { 169 index.save(null); 170 } catch (IOException e) { 171 log("error saving asdoc at "+root.getUrl(), e); 172 } 148 173 EList<Resource> resources = index.getResourceSet().getResources(); 149 174 for (Resource res:resources) { 150 if (index.getURI().equals(res.getURI())) continue; 175 if (index.equals(res)) 176 continue; 151 177 try { 152 178 res.save(null); 153 179 } catch (IOException e) { 154 log("error parsing asdoc at "+root.getUrl(), e); 155 } 156 } 180 log("error saving asdoc at "+root.getUrl(), e); 181 } 182 } 183 } 184 public void clearRoot(AXRoot root) { 185 if (root == null) return; 186 Resource index = root.eResource(); 187 if (index == null) return; 188 clearCache(index); 189 EList<Resource> list = index.getResourceSet().getResources(); 190 Resource[] resources = list.toArray(new Resource[list.size()]); 191 for (Resource res:resources) { 192 if (index.equals(res)) continue; 193 try { 194 res.delete(null); 195 } catch (IOException e) { 196 log("error deleting asdoc at "+root.getUrl(), e); 197 } 198 } 199 index.getContents().clear(); 157 200 } 158 201 protected void log(String text, Exception e) { … … 168 211 return packages.keySet(); 169 212 } 170 private void cachePackages(AXIndex index) { 213 public void cachePackages(AXIndex index) { 214 if (index == null) return; 171 215 String id = index.getId(); 172 216 if (id != null && id.length()>0) { … … 184 228 } 185 229 } 230 public void clearCache(Resource resource) { 231 if (resource == null) return; 232 List<String> toRemove = new ArrayList<String>(); 233 for (String packName:packages.keySet()) { 234 List<AXIndex> packs = packages.get(packName); 235 AXIndex[] indexs = packs.toArray(new AXIndex[packs.size()]); 236 for (AXIndex index:indexs) { 237 if (resource.equals(index.eResource())) { 238 packs.remove(index); 239 } 240 } 241 if (packs.isEmpty()) { 242 toRemove.add(packName); 243 } 244 } 245 for (String id:toRemove) { 246 packages.remove(id); 247 } 248 } 186 249 protected void cachePackages() { 187 250 for (AXRoot root:roots.values()) {
