Changeset 364575fc79ca0a2d7d0efbd5c165c1d2dfc36a3b

Show
Ignore:
Timestamp:
06/28/09 23:36:50 (15 months ago)
Author:
mb0 <mb0@…>
Children:
1567fcce2711ee19e98902f8ef734f1a7dd9731f
Parents:
25b5d220afcf17776b844086f439554f14dc63dc
git-author:
mb0 <mb0@…> (06/11/09 05:25:41)
git-committer:
mb0 <mb0@…> (06/28/09 23:36:50)
Message:

moved indexer initialization to axdoc and as3 plugin start
builder now saves the axroot and builds the caches on full build and clean
on as3 plugin start serialized source indexes will be loaded.
and some fixes as minor changes.

Files:
9 modified

Legend:

Unmodified
Added
Removed
  • org.axdt.as3/src/org/axdt/as3/AS3Plugin.java

    r87f02d1 r364575f  
    44import java.net.URL; 
    55 
     6import org.axdt.as3.imp.builders.AS3Nature; 
     7import org.axdt.as3.preferences.AS3Preferences; 
    68import org.axdt.as3.templates.AS3ContextType; 
     9import org.axdt.axdoc.model.AXRootType; 
     10import org.axdt.axdoc.util.Index0r; 
    711import org.axdt.common.preferences.AxdtPreferences; 
     12import org.eclipse.core.resources.IContainer; 
     13import org.eclipse.core.resources.IProject; 
     14import org.eclipse.core.resources.ResourcesPlugin; 
     15import org.eclipse.core.runtime.CoreException; 
    816import org.eclipse.core.runtime.FileLocator; 
    917import org.eclipse.core.runtime.IPath; 
     
    1220import org.eclipse.core.runtime.preferences.ConfigurationScope; 
    1321import org.eclipse.core.runtime.preferences.IScopeContext; 
     22import org.eclipse.emf.common.util.URI; 
    1423import org.eclipse.imp.runtime.PluginBase; 
    1524import org.eclipse.jface.preference.IPreferenceStore; 
     
    5362                super.start(context); 
    5463                plugin = this; 
     64                try { initializeIndex(); } 
     65                catch (Exception e) { 
     66                        log("error initializing source index", e); 
     67                } 
    5568        } 
    5669 
     
    146159                return LANGUAGE; 
    147160        } 
     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 
    148183} 
  • org.axdt.as3/src/org/axdt/as3/imp/builders/AS3Builder.java

    r49cbb50 r364575f  
    11package org.axdt.as3.imp.builders; 
    22 
     3import java.util.ArrayList; 
     4import java.util.Arrays; 
    35import java.util.HashMap; 
     6import java.util.List; 
     7import java.util.Map; 
    48 
    59import org.axdt.as3.AS3Plugin; 
    610import org.axdt.as3.imp.parser.AS3ParseController; 
    7 import org.axdt.as3.imp.services.AS3EditorService; 
    811import org.axdt.as3.preferences.AS3Preferences; 
    912import org.axdt.as3.util.AS3Util; 
     13import org.axdt.axdoc.model.AXRoot; 
     14import org.axdt.axdoc.util.Index0r; 
    1015import org.eclipse.core.resources.IContainer; 
    1116import org.eclipse.core.resources.IFile; 
     17import org.eclipse.core.resources.IProject; 
    1218import org.eclipse.core.resources.IResource; 
     19import org.eclipse.core.runtime.CoreException; 
    1320import org.eclipse.core.runtime.IPath; 
    1421import org.eclipse.core.runtime.IProgressMonitor; 
     
    2330import org.eclipse.imp.model.ModelFactory.ModelException; 
    2431import org.eclipse.imp.runtime.PluginBase; 
     32import org.eclipse.imp.services.IAnnotationTypeInfo; 
    2533 
    2634/** 
     
    3543        public static final Language LANGUAGE = LanguageRegistry.findLanguage(AS3Plugin.LANGUAGE); 
    3644        private HashMap<IPath, AS3ParseController> files; 
     45        private boolean isFullBuild = false; 
     46        private List<AS3ParseController> astnodes; 
    3747 
    3848        public AS3Builder() { 
     
    99109        protected boolean isOutputFolder(IResource resource) { 
    100110                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        } 
    105143        /** 
    106144         * Compile one AS3 file. 
     
    108146         */ 
    109147        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) { 
    110167                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") 
    144175        private AS3ParseController getParseController(IFile file) { 
    145176                IPath path = file.getFullPath(); 
     
    147178                if (controller == null) { 
    148179                        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                        } 
    152199                } 
    153200                return controller; 
    154201        } 
     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        } 
    155210} 
  • org.axdt.as3/src/org/axdt/as3/imp/parser/AS3ParseController.java

    r25b5d22 r364575f  
    11package org.axdt.as3.imp.parser; 
    22 
    3 import java.util.HashSet; 
     3import java.util.Collections; 
    44import java.util.Iterator; 
    55 
    66import lpg.runtime.IAst; 
    7 import lpg.runtime.IToken; 
    87 
    98import org.axdt.as3.AS3Plugin; 
     
    116115                        ASTNode node = (ASTNode) fCurrentAst; 
    117116                        topLevelSymbolTable = resolveSymbolTable(node); 
     117                        buildIndex(node); 
    118118                        if (resolve) { 
    119                                 buildIndex(node); 
    120119                                resolveDeclarations(node); 
    121120                        } 
     
    127126        } 
    128127         
    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                } 
    131132        } 
    132133         
    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                } 
    135138        } 
    136139 
     
    151154                return null; 
    152155        } 
     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        } 
    153163} 
  • org.axdt.as3/src/org/axdt/as3/imp/parser/IndexingVisitor.java

    r25b5d22 r364575f  
    1818import org.axdt.axdoc.model.AXNode; 
    1919import org.axdt.axdoc.model.AXRoot; 
    20 import org.axdt.axdoc.model.AXRootType; 
    2120import org.axdt.axdoc.util.Index0r; 
    2221import org.eclipse.core.resources.IContainer; 
     22import org.eclipse.emf.common.util.EList; 
    2323 
    2424public class IndexingVisitor extends DiagnoseVisitor { 
     
    3131                super(parseController); 
    3232                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); 
    3534        } 
    3635 
     
    5150 
    5251        private void addDoc(AXIndexNode index, IAst ast) { 
     52                if (index  == null || ast == null) return; 
    5353                IToken[] tokens = ast.getPrecedingAdjuncts(); 
    5454                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(); 
    5560                for (IToken token:tokens) { 
    56                         AXNode reference = index.getOrCreateReference(); 
    57                         reference.getAsdoc().add(token.toString()); 
     61                        asdoc.add(token.toString()); 
    5862                } 
    5963        } 
  • org.axdt.as3/src/org/axdt/as3/imp/services/AS3HyperLinkDetector.java

    r25b5d22 r364575f  
    6969                                                } 
    7070                                        } catch (Exception e) { 
    71                                                 e.printStackTrace(); 
    7271                                        } 
    7372                        } else {  
     
    7877                        } 
    7978                } 
    80                 return result.toArray(new IHyperlink[result.size()]); 
     79                return result.isEmpty() ? null : result.toArray(new IHyperlink[result.size()]); 
    8180        } 
    8281        // 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  
    44import java.net.URL; 
    55 
     6import org.axdt.axdoc.preferences.AXDocPreferences; 
     7import org.axdt.axdoc.util.Index0r; 
    68import org.eclipse.core.runtime.FileLocator; 
    79import org.eclipse.core.runtime.Path; 
     
    4951                super.start(context); 
    5052                plugin = this; 
     53                try { initializeIndex(); } 
     54                catch (Exception e) { 
     55                        log("error initializing source index", e); 
     56                } 
    5157        } 
    5258 
     
    5965                plugin = null; 
    6066                super.stop(context); 
     67                disposeIndex(); 
    6168        } 
     69 
    6270 
    6371        /** 
     
    101109                getLog().log(new Status(Status.ERROR, PLUGIN_ID, Status.OK, msg, e)); 
    102110        } 
     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        } 
    103122} 
  • org.axdt.axdoc/src/org/axdt/axdoc/preferences/AXDocPreferences.java

    r2d81bf0 r364575f  
    11package org.axdt.axdoc.preferences; 
     2 
     3import java.util.ArrayList; 
    24 
    35import org.axdt.axdoc.AXDocPlugin; 
     
    3537        } 
    3638 
    37         public static String getLangRefPathString() { 
     39        public static String getAXDocUrlsString() { 
    3840                IPreferenceStore store = getInstance().getStore(); 
    3941                return store.getString(AXDOC_URLS); 
    4042        } 
     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        } 
    4157        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()) { 
    4559                        if (value instanceof DocItem) { 
    4660                                DocItem item = (DocItem) value; 
  • org.axdt.axdoc/src/org/axdt/axdoc/util/AXDocParser.java

    r2d81bf0 r364575f  
    1616import org.axdt.axdoc.model.AXRoot; 
    1717import org.axdt.axdoc.model.util.AXUtil; 
     18import org.eclipse.emf.common.util.EList; 
    1819import org.w3c.dom.DOMException; 
    1920import org.w3c.dom.Node; 
     
    125126                String docContent = docNode.getTextContent().replaceAll("\\W+"," ").trim(); 
    126127                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);  
    128131        } 
    129132        public void parseTypeLevel(AXIndex index) { 
  • org.axdt.axdoc/src/org/axdt/axdoc/util/Index0r.java

    r2d81bf0 r364575f  
    44import java.util.ArrayList; 
    55import java.util.Collection; 
     6import java.util.Collections; 
    67import java.util.HashMap; 
    78import java.util.List; 
     
    1617import org.axdt.axdoc.model.AXRootType; 
    1718import org.axdt.axdoc.model.util.AXUtil; 
    18 import org.axdt.axdoc.preferences.AXDocPreferences; 
     19import org.eclipse.core.resources.IContainer; 
     20import org.eclipse.core.resources.IResource; 
    1921import org.eclipse.core.runtime.Path; 
    2022import org.eclipse.emf.common.CommonPlugin; 
     
    3335                if (instance == null) { 
    3436                        instance = new Index0r(); 
    35                         AXDocPreferences.checkAXDocPaths(instance); 
    3637                } 
    3738                return instance; 
     
    4445         
    4546        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>>()); 
    4849                docParser = new AXDocParser(); 
    4950                baseURI = createBaseUri(); 
     
    9596                } 
    9697                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; 
    97115        } 
    98116        public AXRoot addRoot(String name, String url, AXRootType type) { 
     
    143161                cachePackages(root); 
    144162        } 
    145         protected void saveRoot(AXRoot root) throws IOException { 
     163        public void saveRoot(AXRoot root) { 
     164                if (root == null) return; 
    146165                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                } 
    148173                EList<Resource> resources = index.getResourceSet().getResources(); 
    149174                for (Resource res:resources) { 
    150                         if (index.getURI().equals(res.getURI())) continue; 
     175                        if (index.equals(res))  
     176                                continue; 
    151177                        try { 
    152178                                res.save(null); 
    153179                        } 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(); 
    157200        } 
    158201        protected void log(String text, Exception e) { 
     
    168211                return packages.keySet(); 
    169212        } 
    170         private void cachePackages(AXIndex index) { 
     213        public void cachePackages(AXIndex index) { 
     214                if (index == null) return; 
    171215                String id = index.getId(); 
    172216                if (id != null && id.length()>0) { 
     
    184228                } 
    185229        } 
     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        } 
    186249        protected void cachePackages() { 
    187250                for (AXRoot root:roots.values()) {