Changeset 5c182b6e475d5851c54cdb2117f25af21723b62a

Show
Ignore:
Timestamp:
06/29/09 07:06:59 (8 months ago)
Author:
mb0 <mb0@…>
Parents:
2aa064d78a2c1162da70e2413b7c386278a1473d
Children:
8a0050b3611b877b0c6c480dc26f48d9afa9c369
git-committer:
mb0 <mb0@mb0.org> / 2009-06-29T07:06:59Z+0200
Message:

memory clean up ! (and several minor fixes)

  • merged symboltablevisitor and indexingvisitor together with some basic syntax checks to form as3analysis
  • index0r can now be used to request details on demand.
  • axdoc parser ignores whitespace textnodes and now parses the member code span
  • axdoc model: moved level property to indexnode and changed it to be persisted
  • changed axlevel literals
  • discover memory leak http://bugs.eclipse.org/281790, cleaned up with editor service.
  • moved usefull generally useful methods out of as3 content proposer into as3 source helper
  • when no index exists for a source folder the project will be built and cached.
  • builder does not cache anymore instead builds two times. the first time to index. the second time to resolve.
  • lexer helper error detection fixed ater working through the sparce documentation on lpgs deterministic parser.
  • moved top level symbol table to the program ast node
  • some minor parser changed
Files:
5 added
2 removed
33 modified

Legend:

Unmodified
Added
Removed
  • org.axdt.as3.test/src/org/axdt/as3/imp/parser/BasicParserTest.java

    rb32f7a4 r5c182b6  
    1919import org.axdt.as3.imp.parser.Ast.StringLiteral; 
    2020import org.axdt.as3.imp.parser.Ast.VariableDefinition; 
     21import org.axdt.as3.imp.parser.ParseUtil.ParserContext; 
    2122 
    2223public class BasicParserTest extends TestCase { 
    23         private AS3Parser parser; 
     24        private ParserContext context; 
    2425        private Program parse(String content) { 
    25                 parser = ParseUtil.parser(content); 
    26                 return ParseUtil.parse(parser,0); 
     26                context = ParseUtil.parser(content); 
     27                return context.parse(0); 
    2728        } 
    2829        private <T extends IDirective> T assertFirstDirective(String string, Class<T> clazz) { 
    29                 parser = ParseUtil.parser(string); 
    30                 Program result = ParseUtil.parse(parser,0); 
     30                context = ParseUtil.parser(string); 
     31                Program result = context.parse(0); 
    3132                return assertFirstDirective(result, clazz); 
    3233        } 
     
    3839                } else { 
    3940                        // TODO gather some info 
    40                         ArrayList tokens = parser.getIPrsStream().getTokens(); 
     41                        ArrayList tokens = context.parser.getIPrsStream().getTokens(); 
    4142                        assertNotNull("parser error "+ tokens.toString(),prog); 
    4243                } 
     
    7980 
    8081                // bom works just as expected 
    81                 assertNotNull(parse("\u00ef\u00bb\u00bf package {}")); 
     82                prog = parse("\u00ef\u00bb\u00bf package {}"); 
     83                assertNotNull(prog); 
    8284                System.out.print("expected"); 
    83                 assertNull(parse("package \u00ef\u00bb\u00bf {}")); 
     85                prog = parse("package \u00ef\u00bb\u00bf {}"); 
     86                // when using parseActions used as unicode package name ?! 
     87            assertNull(prog); 
    8488                 
    8589                prog = parse("package P{} package Q{}"); 
     
    9397                System.out.print("expected"); 
    9498                prog = parse("package P{} function f(){} package Q{}"); 
     99                // when using parseActions finds the first package but fails to parse the following directives  
    95100                assertNull(prog); 
    96101        } 
     
    157162                def = assertFirstDirective("function f():void{}",FunctionDefinition.class); 
    158163 
    159                 def = assertFirstDirective("function f(b:B){a = b;a.c();}",FunctionDefinition.class); 
     164                def = assertFirstDirective("function f(a:A,b:B){a = b;a.c();}",FunctionDefinition.class); 
    160165                assertEquals("f", def.getName().toString()); 
    161166                assertEquals(2, def.getBlock().getDirectives().size()); 
    162167                FunctionCommon common = def.getCommon(); 
    163168                assertEquals(null, common.getResultType()); 
     169                assertEquals(2, common.getParameters().size()); 
    164170 
    165171                def = assertFirstDirective("function f(){}",FunctionDefinition.class); 
     
    171177                def = assertFirstDirective("function get f(i){}",FunctionDefinition.class); 
    172178                def = assertFirstDirective("function get f(a:A,b:B){}",FunctionDefinition.class); 
    173                 // TODO fix parameter declaration 
    174179                def = assertFirstDirective("function set(){}",FunctionDefinition.class); 
    175180                def = assertFirstDirective("function get(a,b){}",FunctionDefinition.class); 
  • org.axdt.as3.test/src/org/axdt/as3/imp/parser/ExpressionTest.java

    rb32f7a4 r5c182b6  
    122122                assertExpression(parse("i..x"), Query.class); 
    123123                assertExpression(parse("i..x::y"), Query.class); 
    124                 assertExpression(parse("i.(@a::y.c)"), Query.class); 
     124                assertExpression(parse("i.(y,x)"), Query.class); 
     125                assertExpression(parse("i.(y)"), Query.class); 
    125126                assertExpression(parse("i++"), PostIncrementExpression.class); 
    126127                assertExpression(parse("i--"), PostDecrementExpression.class); 
     128                assertExpression(parse("i..(y)::id"), Query.class); 
     129                assertExpression(parse("i..@(y)::id"), Query.class); 
     130                assertExpression(parse("i..@[0]"), Query.class); 
    127131        } 
    128132        public void testNew() throws Exception { 
  • org.axdt.as3.test/src/org/axdt/as3/imp/parser/ParseUtil.java

    rb32f7a4 r5c182b6  
    2020        } 
    2121        public static Program parse(String content, int repair) { 
    22                 AS3Parser parser = parser(content); 
    23                 return parse(parser,repair); 
     22                ParserContext context = parser(content); 
     23                return context.parse(repair); 
    2424        } 
    2525        public static Program parse(AS3Parser parser, int repair) { 
     
    2929                return null; 
    3030        } 
    31         public static AS3Parser parser(String content) { 
     31        public static ParserContext parser(String content) { 
    3232                char[] charArray = content.toCharArray(); 
    33                 AS3Lexer lexer = new AS3Lexer(); 
    34                 lexer.reset(charArray, "name"); 
    35                 AS3Parser parser = new AS3Parser(); 
    36                 parser.reset(lexer.getILexStream()); 
    37                 lexer.lexer(null, parser); 
    38                 return parser; 
     33                ParserContext context = new ParserContext(charArray); 
     34                context.lex(); 
     35                return context; 
     36        } 
     37        public static class ParserContext { 
     38                public AS3Lexer lexer = new AS3Lexer(); 
     39                public AS3Parser parser = new AS3Parser(); 
     40                public boolean lexSuccess; 
     41                 
     42                public ParserContext(char[] charArray) { 
     43                        lexer.reset(charArray, "name"); 
     44                        parser.reset(lexer.getILexStream()); 
     45                } 
     46                public Program parse(int repair) { 
     47                        Object result = null; 
     48                        if (lexSuccess) { 
     49                                result = parser.parserActions(null, repair); 
     50                        } else { 
     51                                result = parser.parser(null, repair); 
     52                        } 
     53                        return result instanceof Program ? (Program) result : null;  
     54                } 
     55                public boolean lex() { 
     56                        lexSuccess = lexer.lexer(null, parser); 
     57                        return lexSuccess; 
     58                } 
    3959        } 
    4060} 
  • org.axdt.as3.test/src/org/axdt/as3/imp/parser/VirtualSemiTest.java

    rb32f7a4 r5c182b6  
    11package org.axdt.as3.imp.parser; 
    22 
     3import java.util.ArrayList; 
     4 
    35import org.axdt.as3.imp.parser.Ast.Program; 
     6import org.axdt.as3.imp.parser.ParseUtil.ParserContext; 
    47 
    58import junit.framework.TestCase; 
     9import lpg.runtime.IToken; 
    610 
    711public class VirtualSemiTest extends TestCase { 
    812 
    9         public static Program parse(String content) { 
    10                 return ParseUtil.parse(content, 0); 
     13        @SuppressWarnings("unchecked") 
     14        public void assertVSemiInsertion(String content, int expected) { 
     15                ParserContext context = ParseUtil.parser(content); 
     16                Program parse = context.parse(-1); 
     17                assertNotNull(parse); 
     18                ArrayList<IToken> tokens = context.parser.getIPrsStream().getTokens(); 
     19                int result = 0; 
     20                for (IToken t:tokens) { 
     21                        if (t.getKind() == AS3Parsersym.TK_VirtualSemicolon) 
     22                                result++; 
     23                } 
     24                assertEquals(expected, result); 
    1125        } 
    1226        public void testLineBreakVirtualSemi() throws Exception { 
    13                 // TODO check that the parser should not insert v semi 
    14                 assertNotNull(parse("{var i = 0;\nvar j = 1;}")); 
    15                 // TODO dont insert if there is a semi  
    16                 assertNotNull(parse("{var i = 0\n;var j = 1;}")); 
    17                 assertNotNull(parse("{var i = 0\nvar j = 1;}")); 
     27                // check that the parser should not insert v semi 
     28                assertVSemiInsertion("{var i = 0;\nvar j = 1;}",0); 
     29                // dont insert if there is a semi  
     30                assertVSemiInsertion("{var i = 0\n;var j = 1;}",0); 
     31                assertVSemiInsertion("{var i = 0\nvar j = 1;}",1); 
    1832        } 
    1933        public void testGrammarVirtualSemi() throws Exception { 
    2034                // abbrev semi is inserted before RCURLY or EOF 
    21                 assertNotNull(parse("var j = 1")); 
    22                 assertNotNull(parse("var j = 1;")); 
    23                 assertNotNull(parse("{var i = 0;var j = 1}")); 
     35                assertVSemiInsertion("var j = 1",1); 
     36                assertVSemiInsertion("var j = 1;",0); 
     37                assertVSemiInsertion("{var i = 0;var j = 1}",1); 
    2438        } 
    2539} 
  • org.axdt.as3/src/org/axdt/as3/AS3Plugin.java

    r364575f r5c182b6  
    44import java.net.URL; 
    55 
     6import org.axdt.as3.imp.builders.AS3Builder; 
    67import org.axdt.as3.imp.builders.AS3Nature; 
    78import org.axdt.as3.preferences.AS3Preferences; 
    89import org.axdt.as3.templates.AS3ContextType; 
    9 import org.axdt.axdoc.model.AXRootType; 
     10import org.axdt.axdoc.model.AXRoot; 
    1011import org.axdt.axdoc.util.Index0r; 
    1112import org.axdt.common.preferences.AxdtPreferences; 
    1213import org.eclipse.core.resources.IContainer; 
    1314import org.eclipse.core.resources.IProject; 
     15import org.eclipse.core.resources.IncrementalProjectBuilder; 
    1416import org.eclipse.core.resources.ResourcesPlugin; 
    1517import org.eclipse.core.runtime.CoreException; 
    1618import org.eclipse.core.runtime.FileLocator; 
    1719import org.eclipse.core.runtime.IPath; 
     20import org.eclipse.core.runtime.IProgressMonitor; 
    1821import org.eclipse.core.runtime.Path; 
    1922import org.eclipse.core.runtime.Status; 
    2023import org.eclipse.core.runtime.preferences.ConfigurationScope; 
    2124import org.eclipse.core.runtime.preferences.IScopeContext; 
    22 import org.eclipse.emf.common.util.URI; 
    2325import org.eclipse.imp.runtime.PluginBase; 
    2426import org.eclipse.jface.preference.IPreferenceStore; 
     
    161163         
    162164        private void initializeIndex() { 
     165                IProgressMonitor monitor = null; 
    163166                Index0r index0r = Index0r.getInstance(); 
    164167                // asdoc locations are added on axdoc plugin start 
     
    172175                        } 
    173176                        IContainer[] paths = AS3Preferences.getSourcePaths(project); 
     177                        boolean needsBuild = false; 
    174178                        for (IContainer srcPath:paths) { 
    175179                                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); 
     180                                AXRoot root = index0r.addSourceRoot(srcPath); 
     181                                try { 
     182                                        needsBuild = needsBuild || root.eContents().isEmpty() && srcPath.members().length > 0; 
     183                                } catch (CoreException e) {/* ignore */ } 
     184                                index0r.saveRoot(root); 
     185                                index0r.cachePackages(root); 
     186                        } 
     187                        if (needsBuild) { 
     188                                try { 
     189                                        project.build(IncrementalProjectBuilder.FULL_BUILD, AS3Builder.BUILDER_ID, null, monitor); 
     190                                } catch (CoreException e) { 
     191                                        log("error invoking initial build", e); 
     192                                } 
    179193                        } 
    180194                } 
  • org.axdt.as3/src/org/axdt/as3/imp/builders/AS3Builder.java

    r2aa064d r5c182b6  
    11package org.axdt.as3.imp.builders; 
    22 
    3 import java.util.ArrayList; 
    43import java.util.Arrays; 
     4import java.util.Collection; 
     5import java.util.HashSet; 
    56import java.util.List; 
    67import java.util.Map; 
     
    89import org.axdt.as3.AS3Plugin; 
    910import org.axdt.as3.imp.parser.AS3ParseController; 
     11import org.axdt.as3.imp.parser.ResolvingVisitor; 
     12import org.axdt.as3.imp.parser.Ast.ASTNode; 
    1013import org.axdt.as3.preferences.AS3Preferences; 
    11 import org.axdt.as3.util.AS3Util; 
    1214import org.axdt.axdoc.model.AXRoot; 
    1315import org.axdt.axdoc.util.Index0r; 
     
    1618import org.eclipse.core.resources.IProject; 
    1719import org.eclipse.core.resources.IResource; 
     20import org.eclipse.core.resources.IResourceDelta; 
     21import org.eclipse.core.resources.IResourceDeltaVisitor; 
     22import org.eclipse.core.resources.IResourceVisitor; 
     23import org.eclipse.core.resources.IncrementalProjectBuilder; 
    1824import org.eclipse.core.runtime.CoreException; 
    1925import org.eclipse.core.runtime.IPath; 
    2026import org.eclipse.core.runtime.IProgressMonitor; 
     27import org.eclipse.core.runtime.SubProgressMonitor; 
    2128import org.eclipse.core.runtime.content.IContentDescription; 
    22 import org.eclipse.imp.builder.BuilderBase; 
    2329import org.eclipse.imp.builder.BuilderUtils; 
    2430import org.eclipse.imp.builder.MarkerCreator; 
     
    2834import org.eclipse.imp.model.ModelFactory; 
    2935import org.eclipse.imp.model.ModelFactory.ModelException; 
     36import org.eclipse.imp.parser.IMessageHandler; 
    3037import org.eclipse.imp.runtime.PluginBase; 
    3138import org.eclipse.imp.services.IAnnotationTypeInfo; 
     
    3643 * "Build" a project. 
    3744 */ 
    38 public class AS3Builder extends BuilderBase { 
    39  
     45public class AS3Builder extends IncrementalProjectBuilder { 
    4046        public static final String BUILDER_ID = AS3Plugin.PLUGIN_ID + ".imp.builder"; 
    4147        public static final String PROBLEM_MARKER_ID = AS3Plugin.PLUGIN_ID + ".imp.builder.problem"; 
    4248        public static final Language LANGUAGE = LanguageRegistry.findLanguage(AS3Plugin.LANGUAGE); 
    43         private boolean isFullBuild = false; 
    44         private List<AS3ParseController> astnodes; 
    45  
    46         public AS3Builder() { 
    47                 super(); 
    48         } 
     49         
     50        protected Index0r fIndex0r; 
     51        protected Collection<IFile> fSourcesToCompile; 
     52        protected IContainer fDeployContainer; 
     53        protected IContainer[] fSourceContainer; 
    4954 
    5055        protected PluginBase getPlugin() { 
     
    5661        } 
    5762 
    58         protected String getWarningMarkerID() { 
    59                 return PROBLEM_MARKER_ID; 
    60         } 
    61  
    62         protected String getInfoMarkerID() { 
    63                 return PROBLEM_MARKER_ID; 
    64         } 
    65  
    66         /** 
    67          * Decide whether a file needs to be build using this builder. Note that 
    68          * <code>isNonRootSourceFile()</code> and <code>isSourceFile()</code> 
    69          * should never return true for the same file. 
    70          *  
    71          * @return true if an arbitrary file is a AS3 source file. 
    72          */ 
    73         protected boolean isSourceFile(IFile file) { 
    74                 IPath path = file.getRawLocation(); 
    75                 if (path == null || !LANGUAGE.hasExtension(path.getFileExtension()))  
    76                         return false; 
    77                 IContainer sourceFolder = AS3Util.getSourceFolder(file); 
    78                 return sourceFolder != null; 
    79         } 
    80  
    81         /** 
    82          * Decide whether or not to scan a file for dependencies. Note: 
    83          * <code>isNonRootSourceFile()</code> and <code>isSourceFile()</code> 
    84          * should never return true for the same file. 
    85          *  
    86          * @return true if the given file is a source file that this builder should 
    87          *         scan for dependencies, but not compile as a top-level compilation 
    88          *         unit. 
    89          */ 
    90         protected boolean isNonRootSourceFile(IFile resource) { 
    91                 return false; 
    92         } 
    93  
    94         /** 
    95          * Collects compilation-unit dependencies for the given file, and records 
    96          * them via calls to <code>fDependency.addDependency()</code>. 
    97          */ 
    98         protected void collectDependencies(IFile file) { 
    99                 // TODO: implement dependency collector 
    100                 // fDependencyInfo.addDependency(fromPath, uponPath); 
    101         } 
    102  
    103         /** 
    104          * @return true if this resource identifies the output folder 
    105          */ 
    106         protected boolean isOutputFolder(IResource resource) { 
    107                 if (resource == null || !(resource instanceof IContainer)) return false; 
    108                 return resource.equals(AS3Preferences.getDeployPath(resource)); 
    109         } 
     63        protected void initBuilder(int kind, Map args) { 
     64                fIndex0r = Index0r.getInstance(); 
     65                fSourcesToCompile = new HashSet<IFile>(); 
     66                fDeployContainer = AS3Preferences.getDeployPath(getProject()); 
     67                fSourceContainer = AS3Preferences.getSourcePaths(getProject()); 
     68        } 
     69 
     70        protected void clearBuilder() { 
     71                fIndex0r = null; 
     72                fSourcesToCompile = null; 
     73                fDeployContainer = null; 
     74                fSourceContainer = null; 
     75        } 
     76         
    11077        @Override 
    11178        @SuppressWarnings("unchecked") 
    11279        protected IProject[] build(int kind, Map args, IProgressMonitor monitor) { 
    113                 isFullBuild  = kind == FULL_BUILD || kind == CLEAN_BUILD; 
    114                 if (isFullBuild) { 
    115                         Index0r index0r = Index0r.getInstance(); 
    116                         IContainer[] srcFolders = AS3Preferences.getSourcePaths(getProject()); 
    117                         for (IContainer srcFolder:srcFolders) { 
    118                                 AXRoot root = index0r.getSourceRoot(srcFolder); 
    119                                 index0r.clearRoot(root); 
     80                monitor.beginTask("Building",51); 
     81                try { 
     82                        initBuilder(kind, args); 
     83                        monitor.worked(1); 
     84                        boolean isFullBuild  = kind == FULL_BUILD || kind == CLEAN_BUILD; 
     85                        SubProgressMonitor subMonitor = new SubProgressMonitor(monitor,50,SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK); 
     86                        if (isFullBuild) { 
     87                                buildFull(args, subMonitor); 
     88                        } else { 
     89                                buildChanged(args, subMonitor); 
    12090                        } 
    121                         astnodes = new ArrayList<AS3ParseController>(); 
     91                } finally { 
     92                        clearBuilder(); 
     93                        monitor.done(); 
     94                } 
     95                return new IProject[0]; 
     96        } 
     97        private void buildChanged(Map args, IProgressMonitor monitor) { 
     98                monitor.beginTask(" changed Resources", 11); 
     99                try { 
     100                        IResourceDelta delta = getDelta(getProject()); 
     101                        if (delta != null) { 
     102                                delta.accept(new SourceDeltaVisitor()); 
     103                        } else { 
     104                                getProject().accept(new SourceCollectVisitor()); 
     105                        } 
     106                        monitor.worked(1); 
     107                        SubProgressMonitor subMonitor = new SubProgressMonitor(monitor,10,SubProgressMonitor.SUPPRESS_SUBTASK_LABEL); 
     108                        compileNecessarySources(subMonitor); 
     109                } catch (CoreException e) { 
     110                        AS3Plugin.getDefault().debug("Error collecting sources", e); 
     111                } finally { 
     112                        monitor.done(); 
     113                } 
     114        } 
     115 
     116        private void buildFull(Map args, IProgressMonitor monitor) { 
     117                monitor.beginTask(" all Resources", 13); 
     118                try { 
     119                        getProject().accept(new SourceCollectVisitor()); 
     120                        monitor.worked(1); 
     121                        clearIndex(); 
     122                        monitor.worked(1); 
    122123                        // do the build. it should index the whole project 
    123                         super.build(kind, args, monitor); 
    124                         for (AS3ParseController control:astnodes) { 
    125                                 control.resolveDeclarations(control.getCurrentAst()); 
    126                         } 
    127                         astnodes = null; 
     124                        SubProgressMonitor subMonitor = new SubProgressMonitor(monitor,10,SubProgressMonitor.SUPPRESS_SUBTASK_LABEL); 
     125                        compileNecessarySources(subMonitor); 
    128126                        // build done save and cache the index 
    129                         for (IContainer srcFolder:srcFolders) { 
    130                                 AXRoot root = index0r.getSourceRoot(srcFolder); 
    131                                 index0r.saveRoot(root); 
    132                                 index0r.cachePackages(root); 
    133                         } 
    134                         return new IProject[0]; 
    135                 } else { 
    136                         // proceed with normal build 
    137                         return super.build(kind, args, monitor); 
    138                 } 
    139         } 
     127                        cacheIndex(); 
     128                        monitor.worked(1); 
     129                } catch (Exception e) { 
     130                        AS3Plugin.getDefault().debug("Error collecting sources", e); 
     131                } finally { 
     132                        monitor.done(); 
     133                } 
     134        } 
     135    protected void compileNecessarySources(IProgressMonitor monitor) { 
     136                monitor.beginTask("", fSourcesToCompile.size()*2); 
     137                try { 
     138                        // first we lex and parse once without resolving or error reporting 
     139                for(IFile file : fSourcesToCompile) { 
     140                    clearMarkersOn(file); 
     141                    compile(file, new SubProgressMonitor(monitor,1), false); 
     142                } 
     143                // the second time the index is build and we can resolve after parsing 
     144                for(IFile file : fSourcesToCompile) { 
     145                    clearMarkersOn(file); 
     146                    compile(file, new SubProgressMonitor(monitor,1), true); 
     147                } 
     148                // the reason to parse the files twice is that caching is to expensive (mem peak) 
     149                // and cpu cycles cheap enough. the ideal solution would be a cheap and clean  
     150                // dependency analysis. 
     151                } finally { 
     152                        monitor.done(); 
     153                } 
     154    } 
     155 
     156        protected void cacheIndex() { 
     157                for (IContainer srcFolder:fSourceContainer) { 
     158                        AXRoot root = fIndex0r.getSourceRoot(srcFolder); 
     159                        fIndex0r.saveRoot(root); 
     160                        fIndex0r.cachePackages(root); 
     161                } 
     162        } 
     163 
     164        protected void clearIndex() { 
     165                for (IContainer folder:fSourceContainer) { 
     166                        AXRoot root = fIndex0r.getSourceRoot(folder); 
     167                        fIndex0r.clearRoot(root); 
     168                } 
     169        } 
     170 
     171        protected void clearMarkersOn(IFile file) { 
     172        try { 
     173                file.deleteMarkers(getErrorMarkerID(), true, IResource.DEPTH_INFINITE); 
     174        } catch (CoreException e) { 
     175        } 
     176    } 
     177 
    140178        /** 
    141179         * Compile one AS3 file. 
    142180         * It will not actually compile, but analyze and index the model. 
    143181         */ 
    144         protected void compile(final IFile file, IProgressMonitor monitor) { 
    145                 AS3ParseController parse = getParseController(file); 
     182        protected void compile(IFile file, IProgressMonitor monitor, boolean resolve) { 
     183                AS3ParseController parse = getParseController(file, resolve); 
    146184                // if controller could not be created or initialized  
    147185                if (parse == null || parse.getProject() == null)  
    148186                        return; 
     187                monitor.beginTask("", 10); 
     188                try { 
     189                        parse.parse(getContents(file), resolve, new SubProgressMonitor(monitor,10)); 
     190                } finally { 
     191                        parse.dispose(); 
     192                        monitor.done(); 
     193                } 
     194        } 
     195         
     196        protected String getContents(IFile file) { 
    149197                String contents = BuilderUtils.getFileContents(file); 
    150                 if (hasBom(file)) contents = removeBom(contents); 
    151                 Object ast = parse.parse(contents, false, monitor); 
    152                 if (ast != null && astnodes != null) { 
    153                         astnodes.add(parse); 
    154                 } 
    155         } 
    156  
    157         private String removeBom(String contents) { 
     198                return hasBom(file) ? removeBom(contents) : contents; 
     199        } 
     200 
     201        protected String removeBom(String contents) { 
    158202                // first char might be misread utf8 char 
    159203                return contents.charAt(0) == 0xfeff ?    
     
    161205        } 
    162206 
    163         private boolean hasBom(IFile file) { 
     207        protected boolean hasBom(IFile file) { 
    164208                try { 
    165209                        IContentDescription info = file.getContentDescription(); 
     
    170214 
    171215        @SuppressWarnings("unchecked") 
    172         private AS3ParseController getParseController(IFile file) { 
     216        protected AS3ParseController getParseController(IFile file, boolean reportErrors) { 
    173217                AS3ParseController controller = new AS3ParseController(); 
    174                 IAnnotationTypeInfo typeInfo = controller.getAnnotationTypeInfo(); 
     218                addMarkerTypeOnce(controller.getAnnotationTypeInfo()); 
     219                IMessageHandler marker = reportErrors ? new MarkerCreator(file, controller, PROBLEM_MARKER_ID) 
     220                                                                        : null; 
     221                IPath relativePath = file.getProjectRelativePath(); 
     222                try { 
     223                        ISourceProject sourceProject = ModelFactory.open(file.getProject()); 
     224                        controller.initialize(relativePath, sourceProject, marker); 
     225                } catch (ModelException e) { 
     226                        getPlugin().logException("Cannot create parse controller", e); 
     227                } 
     228                return controller; 
     229        } 
     230        private void addMarkerTypeOnce(IAnnotationTypeInfo typeInfo) { 
    175231                List<List<String>> lists = Arrays.asList(typeInfo.getProblemMarkerTypes()); 
    176232                boolean found = false; 
     
    182238                } 
    183239                if (!found) typeInfo.addProblemMarkerType(getErrorMarkerID()); 
    184                 MarkerCreator marker = new MarkerCreator(file, controller, PROBLEM_MARKER_ID); 
    185                 IPath relativePath = file.getProjectRelativePath(); 
    186                 try { 
    187                         ISourceProject sourceProject = ModelFactory.open(file.getProject()); 
    188                         controller.initialize(relativePath, sourceProject, marker); 
    189                 } catch (ModelException e) { 
    190                         getPlugin().logException("Cannot create parse controller", e); 
    191                 } 
    192                 return controller; 
    193         } 
    194         @Override 
    195         protected void clearMarkersOn(IFile file) { 
    196                 try { 
    197             file.deleteMarkers(getErrorMarkerID(), true, IResource.DEPTH_INFINITE); 
    198         } catch (CoreException e) { 
    199         } 
    200                 //super.clearMarkersOn(file); 
     240        } 
     241 
     242        protected class SourceCollectVisitor implements IResourceVisitor { 
     243                public boolean visit(IResource resource) throws CoreException { 
     244                        return processResource(resource, fSourcesToCompile); 
     245                } 
     246        } 
     247        protected class SourceDeltaVisitor implements IResourceDeltaVisitor { 
     248        public boolean visit(IResourceDelta delta) throws CoreException { 
     249            return processResource(delta.getResource(), fSourcesToCompile); 
     250        } 
     251    } 
     252        protected boolean processResource(IResource resource, Collection<IFile> result) { 
     253                if (resource instanceof IFile) { 
     254                        IFile file = (IFile) resource; 
     255                        if (isSourceFile(file)) result.add(file); 
     256                } else if (resource.equals(fDeployContainer)) { 
     257                        return false; 
     258                } 
     259                return true; 
     260        } 
     261        public boolean isSourceFile(IFile file) { 
     262                if (file != null && file.exists() && LANGUAGE.hasExtension(file.getFileExtension())) 
     263                        for (IContainer folder:fSourceContainer) 
     264                                if (folder.getFullPath().isPrefixOf(file.getFullPath())) 
     265                                        return true; 
     266                return false; 
    201267        } 
    202268} 
     269class CustomResolvingVisitor extends ResolvingVisitor { 
     270        private ASTNode node; 
     271        public CustomResolvingVisitor(IFile myfile, ASTNode node) { 
     272                super(myfile, node.getLeftIToken().getILexStream()); 
     273                this.node = node; 
     274        } 
     275        public void run() { 
     276                node.accept(this); 
     277        } 
     278} 
  • org.axdt.as3/src/org/axdt/as3/imp/parser/AS3LexHelper.java

    rb32f7a4 r5c182b6  
    6363                        HelperAst ast = parseXml(offset); 
    6464                        return tryAst(ast, AS3Parsersym.TK_Xml); 
    65                 } else 
    66                         errorDetected(); 
     65                } 
    6766                return false; 
    6867        } 
     
    7473                        HelperAst ast = parseRegex(offset); 
    7574                        return tryAst(ast, AS3Parsersym.TK_RegularExpression); 
    76                 } else 
    77                         errorDetected(); 
     75                } 
    7876                return false; 
    7977        } 
     
    8482                prs.makeToken(ast.start, ast.end, kind); 
    8583                lexer.getParser().resetTokenStream(ast.end + 1); 
     84                prs.reset(ast.end + 1); 
    8685                return true; 
    8786        } 
     
    146145                boolean isNewLine = detectedLineBreak; 
    147146                detectedLineBreak = false; 
    148                 if (hasError(kind)) { 
    149                         int lastKind = getKind(getLast()); 
    150                         switch (kind) { 
    151                         case AS3Parsersym.TK_LPAREN: 
    152                                 if (lastKind == AS3Parsersym.TK_get 
    153                                                 || lastKind == AS3Parsersym.TK_set) { 
    154                                         parser.errorReset(); 
    155                                         getLast().setKind(AS3Parsersym.TK_IDENTIFIER); 
    156                                 } 
     147                boolean checkAgain = true; 
     148                int lastKind = getKind(getLast()); 
     149                boolean found = false; 
     150                switch (kind) { 
     151                case AS3Parsersym.TK_get: 
     152                case AS3Parsersym.TK_set: 
     153                        if (lastKind == AS3Parsersym.TK_function) { 
     154                                int c = lex.getIntValue(e+1); 
     155                                for (int i=e+2;Character.isWhitespace(c);i++) { 
     156                                        // TODO: also skip comments 
     157                                        c = lex.getCharValue(i); 
     158                                } 
     159                                if (Character.isJavaIdentifierStart(c)) { 
     160                                        break; 
     161                                } 
     162                        } 
     163                        found = true; 
     164                case AS3Parsersym.TK_namespace: 
     165                case AS3Parsersym.TK_each: 
     166                case AS3Parsersym.TK_include: 
     167                case AS3Parsersym.TK_xml: 
     168                        if (!found && !hasError(kind)) { 
     169                                checkAgain = false; 
    157170                                break; 
    158                         case AS3Parsersym.TK_get: 
    159                         case AS3Parsersym.TK_set: 
    160                                 if (getKind(getLast()) == AS3Parsersym.TK_function) { 
    161                                         break; 
    162                                 } 
    163                         case AS3Parsersym.TK_each: 
    164                         case AS3Parsersym.TK_namespace: 
    165                         case AS3Parsersym.TK_include: 
    166                         case AS3Parsersym.TK_xml: 
    167                                 if (!hasError(AS3Parsersym.TK_IDENTIFIER)) { 
    168                                         kind = AS3Parsersym.TK_IDENTIFIER; 
    169                                 } 
    170                                 break; 
    171                         } 
     171                        } 
     172                        if (!hasError(AS3Parsersym.TK_IDENTIFIER)) { 
     173                                checkAgain = false; 
     174                                kind = AS3Parsersym.TK_IDENTIFIER; 
     175                        } 
     176                } 
     177                if (checkAgain && hasError(kind)) { 
    172178                        if (isNewLine) { 
    173179                                // line-break semicolon insertion 
     
    183189                                        int end = getLast().getEndOffset(); 
    184190                                        prs.makeToken(end + 1, end, AS3Parsersym.TK_NO_LINE_BREAK); 
    185                                 } else 
    186                                         errorDetected(); 
    187                         } 
     191                                } 
     192                        } 
     193                        if (tryXmlOrRegex(kind,s)) return; 
    188194                        if (hasError(kind)) 
    189195                                errorDetected(); 
    190                 } 
     196                } else if (tryXmlOrRegex(kind, s)) { 
     197                        return; 
     198                } 
     199                prs.makeToken(s, e, kind); 
     200        } 
     201        private boolean tryXmlOrRegex(int kind, int s) { 
    191202                switch (kind) { 
    192203                // check for xml 
    193204                case AS3Parsersym.TK_LT: 
    194                         if (tryXml(s)) 
    195                                 return; 
    196                         else 
    197                                 break; 
     205                        return tryXml(s); 
    198206                        // check for regex 
    199207                case AS3Parsersym.TK_DIV: 
    200208                case AS3Parsersym.TK_DIV_ASSIGN: 
    201                         if (tryRegex(s)) 
    202                                 return; 
    203                         else 
    204                                 break; 
    205                 } 
    206                 prs.makeToken(s, e, kind); 
    207         } 
    208  
     209                        return tryRegex(s); 
     210                } 
     211                return false; 
     212        } 
    209213        private void tryToInsertSemicolon() { 
    210214                if (!hasError(AS3Parsersym.TK_VirtualSemicolon)) { 
     
    212216                        prs.makeToken(end + 1, end, AS3Parsersym.TK_VirtualSemicolon); 
    213217                        insertedVirtualSemicolons++; 
    214                 } else 
    215                         errorDetected(); 
     218                } 
    216219        } 
    217220 
  • org.axdt.as3/src/org/axdt/as3/imp/parser/AS3Lexer.gi

    rb32f7a4 r5c182b6  
    632632                lexParser.parseCharacters(monitor); 
    633633                make.eof(); 
    634                 return !make.detectedError; 
     634                boolean hadErrors = make.detectedError; 
     635                make = null; 
     636                return !hadErrors; 
    635637            } 
    636638            public int [] getKeywordKinds() { 
  • org.axdt.as3/src/org/axdt/as3/imp/parser/AS3ParseController.java

    rb32f7a4 r5c182b6  
    44import java.util.Iterator; 
    55 
    6 import lpg.runtime.IAst; 
    7  
    86import org.axdt.as3.AS3Plugin; 
     7import org.axdt.as3.analysis.AS3Analysis; 
    98import org.axdt.as3.imp.parser.Ast.ASTNode; 
    109import org.axdt.as3.imp.services.AS3SyntaxProperties; 
    1110import org.eclipse.core.runtime.IPath; 
    1211import org.eclipse.core.runtime.IProgressMonitor; 
    13 import org.eclipse.core.runtime.NullProgressMonitor; 
    1412import org.eclipse.imp.model.ISourceProject; 
    1513import org.eclipse.imp.parser.ILexer; 
     
    3331        private IPath location; 
    3432 
    35         private SymbolTable topLevelSymbolTable = null; 
     33        private AS3Analysis analysis; 
    3634 
    3735        public AS3ParseController() { 
     
    7775         */ 
    7876        public Object parse(String contents, boolean resolve, IProgressMonitor monitor) { 
    79                 if (monitor == null) monitor = new NullProgressMonitor(); 
     77                //if (monitor == null) monitor = new NullProgressMonitor(); 
    8078                int newHash = contents.hashCode(); 
    8179                if (lastHash == newHash) { 
     
    8583                AS3Plugin.getDefault().debug("parsing "+ getPath().toString()); 
    8684                lastHash = newHash; 
    87                 topLevelSymbolTable = null; 
    8885                PMMonitor my_monitor = new PMMonitor(monitor); 
    8986                char[] contentsArray = contents.toCharArray(); 
     
    9693 
    9794                if (parser == null) { 
    98                         parser = new AS3Parser(lexer.getILexStream()); 
     95                        parser = new AS3Parser(); 
    9996                } 
    10097                parser.reset(lexer.getILexStream()); 
     
    10299 
    103100                // Lex the stream to produce the token stream 
    104                 lexer.lexer(my_monitor, parser);  
     101                boolean success = lexer.lexer(my_monitor, parser);  
    105102                // fCurrentAst might (probably will) be 
    106103                // inconsistent wrt the lex stream now 
     
    109106                if (fCurrentAst != null) 
    110107                        backupAst = fCurrentAst; 
     108                if (success) { 
     109                        // the lexer called the deterministic parser incrementally and we can just assemble the ast 
     110                        fCurrentAst = parser.parserActions(my_monitor, 0); 
     111                } else { 
     112                        // do parseActions anyway we have no other way to clear the deterministicparser.action field 
     113                        // and we have a memory leak otherwise 
     114                        parser.parserActions(my_monitor, 0); 
     115                        fCurrentAst = parser.parser(my_monitor, -1); 
     116                } 
     117                if (fCurrentAst != null) 
     118                        backupAst = null; 
     119                 
     120                if (analysis == null) 
     121                        analysis = new AS3Analysis(this); 
     122                analysis.analyse(fCurrentAst); 
    111123 
    112                 fCurrentAst = parser.parser(my_monitor, -1); 
    113  
    114                 if (fCurrentAst instanceof ASTNode) { 
     124                if (resolve && fCurrentAst instanceof ASTNode) { 
    115125                        ASTNode node = (ASTNode) fCurrentAst; 
    116                         topLevelSymbolTable = resolveSymbolTable(node); 
    117                         buildIndex(node); 
    118                         if (resolve) { 
    119                                 resolveDeclarations(node); 
    120                         } 
     126                        resolveDeclarations(node); 
    121127                } 
    122128 
     
    124130 
    125131                return fCurrentAst; 
    126         } 
    127          
    128         public void buildIndex(Object object) { 
    129                 if (object instanceof ASTNode) { 
    130                         ((ASTNode)object).accept(new IndexingVisitor(this)); 
    131                 } 
    132132        } 
    133133         
     
    138138        } 
    139139 
    140         protected SymbolTable resolveSymbolTable(ASTNode root) { 
    141                 SymbolTableVisitor symbolTableVisitor = new SymbolTableVisitor(this); 
    142                 root.accept(symbolTableVisitor); 
    143                 return symbolTableVisitor.getTopLevelSymbolTable(); 
    144         } 
    145  
    146140        public Object getBackupAst() { 
    147141                return backupAst; 
    148         } 
    149  
    150         public SymbolTable getEnclosingSymbolTable(IAst node) { 
    151                 if (topLevelSymbolTable  != null) { 
    152                         return topLevelSymbolTable.getEnclosingSymbolTable(node); 
    153                 } 
    154                 return null; 
    155142        } 
    156143 
     
    161148                return super.getTokenIterator(region); 
    162149        } 
     150 
     151        public void dispose() { 
     152                parser = null; 
     153                lexer = null; 
     154                backupAst = null; 
     155                fCurrentAst = null; 
     156                handler = null; 
     157                analysis = null; 
     158        } 
    163159} 
  • org.axdt.as3/src/org/axdt/as3/imp/parser/AS3Parser.g

    rb32f7a4 r5c182b6  
    487487          | Statement_sif 
    488488          | VariableDefinition_allowin 
    489           | Attributes --NO_LINE_BREAK$  
    490                 LCURLY$ Substatements RCURLY$ 
     489--        | Attributes --NO_LINE_BREAK$  
     490--              LCURLY$ Substatements RCURLY$ 
    491491 
    492492Substatement_nosif$Substatement 
     
    494494          | Statement_nosif 
    495495          | VariableDefinition_allowin 
    496           | Attributes --NO_LINE_BREAK$  
    497                 LCURLY$ Substatements RCURLY$ 
    498  
    499 Substatements$Substatements$Substatement ::= %empty 
    500 Substatements$Substatements$Substatement ::= Substatements Substatement_sif 
     496--        | Attributes --NO_LINE_BREAK$  
     497--              LCURLY$ Substatements RCURLY$ 
     498 
     499--Substatements$Substatements$Substatement ::= %empty 
     500--Substatements$Substatements$Substatement ::= Substatements Substatement_sif 
    501501 
    502502-- no empty semicolon ! use virtual semi instead ! 
     
    521521Block$Block ::= LCURLY$ RCURLY$ 
    522522/. 
    523         public static final int OTHER = 0; 
    524         public static final int METHOD = 4; 
    525         public static final int FUNCTION = 5; 
    526         public static final int PACKAGE = 1; 
    527         public static final int CLASS = 2; 
    528         public static final int INTERFACE = 3; 
    529         public int type; 
    530523        SymbolTable symbolTable; 
    531524        public void setSymbolTable(SymbolTable symbolTable) { this.symbolTable = symbolTable; } 
     
    626619AnnotatedDirective 
    627620        ::= Attributes --NO_LINE_BREAK$  
    628                 AnnotatableDirective 
    629           | AnnotatableDirective 
     621                AnnotatableDirective$Directive 
     622          | AnnotatableDirective$Directive 
    630623Directive ::= AnnotatedDirective 
    631624          | EmptyStatment 
     
    710703VariableBindingList_noin$VariableBindingsNoin$VariableBinding_noin ::= VariableBindingList_noin COMMA$ VariableBinding_noin 
    711704 
    712 VariableBindingList ::= VariableBindingList_allowin | VariableBindingList_noin 
     705 
    713706 --B 
    714707VariableBinding_allowin$VariableBinding  
     
    766759-- 17.2.1 Function body 
    767760FunctionCommon$FunctionCommon ::= LPAREN$ Parameters RPAREN$ ResultType 
     761FunctionCommon$FunctionCommon ::= LPAREN$ RPAREN$ ResultType 
    768762 
    769763-- 17.2.2 Function signature 
    770764 
    771765-- 17.2.3 Parameter list  
    772 Parameters$Parameters$Parameter ::= %empty 
    773 Parameters$Parameters$Parameter ::= NonemptyParameters 
    774 NonemptyParameters$Parameters$Parameter ::= Parameter 
    775 NonemptyParameters$Parameters$Parameter ::= PlainParameter COMMA$ NonemptyParameters 
     766Parameters$Parameters$Parameter ::= Parameter 
     767-- rest is only allowed as last parameter but check that later 
     768Parameters$Parameters$Parameter ::= Parameter COMMA$ Parameters 
    776769Parameter ::= PlainParameter | RestParameter 
    777770PlainParameter$PlainParameter ::= TypedIdentifier_allowin$Ident 
    778771PlainParameter$PlainParameter ::= TypedIdentifier_allowin$Ident ASSIGN$ AssignmentExpression_allowin$Initializer 
    779772RestParameter$RestParameter ::= REST$ 
    780 RestParameter$RestParameter ::= REST$ Identifier$Untyped 
    781773RestParameter$RestParameter ::= REST$ TypedIdentifier_allowin$Ident 
    782774 
     
    826818InterfaceDefinition ::= interface$ Name ExtendsList InterfaceBlock$Body 
    827819/. 
     820        SymbolTable symbolTable; 
     821        public void setSymbolTable(SymbolTable symbolTable) { this.symbolTable = symbolTable; } 
     822        public SymbolTable getSymbolTable() { return symbolTable; } 
    828823        public Attributes getAttributes() { 
    829824                if (!(getParent() instanceof AnnotatedDirective)) return null; 
     
    842837InterfaceBlock$InterfaceBlock ::= LCURLY$ RCURLY$ 
    843838InterfaceBlock$InterfaceBlock ::= LCURLY$ InterfaceDirectives$Directives RCURLY$ 
    844 /. 
    845         SymbolTable symbolTable; 
    846         public void setSymbolTable(SymbolTable symbolTable) { this.symbolTable = symbolTable; } 
    847         public SymbolTable getSymbolTable() { return symbolTable; } 
    848 ./ 
     839 
    849840InterfaceDirectives$InterfaceDirectives$FunctionSignature ::= FunctionSignature 
    850841InterfaceDirectives$InterfaceDirectives$FunctionSignature ::= InterfaceDirectives FunctionSignature 
     
    874865                return _Packages.getPackageDefinitionAt(0); 
    875866        } 
     867        SymbolTable symbolTable; 
     868        public void setSymbolTable(SymbolTable symbolTable) { this.symbolTable = symbolTable; } 
     869        public SymbolTable getSymbolTable() { return symbolTable; } 
    876870./ 
    877871 
     
    883877VariableDefinition ::= VariableDefinition_allowin | VariableDefinition_noin 
    884878VariableBinding ::= VariableBinding_allowin | VariableBinding_noin 
     879VariableBindingList ::= VariableBindingList_allowin | VariableBindingList_noin 
    885880Statement ::= Statement_sif | Statement_nosif 
    886881Substatement ::= Substatement_sif | Substatement_nosif 
     
    890885%Headers 
    891886/. 
     887    public Object parserActions(Monitor monitor, int error_repair_count) 
     888    { 
     889        dtParser.setMonitor(monitor); 
     890 
     891        try 
     892        { 
     893            return (Object) dtParser.parseActions(); 
     894        } 
     895        catch (BadParseException e) 
     896        { 
     897            prsStream.reset(e.error_token); // point to error token 
     898 
     899            DiagnoseParser diagnoseParser = new DiagnoseParser(prsStream, prsTable); 
     900            diagnoseParser.diagnose(e.error_token); 
     901        } 
     902 
     903        return null; 
     904    } 
    892905./ 
    893906%End 
  • org.axdt.as3/src/org/axdt/as3/imp/parser/DiagnoseVisitor.java

    r25b5d22 r5c182b6  
    11package org.axdt.as3.imp.parser; 
    22 
     3import lpg.runtime.IAst; 
    34import lpg.runtime.ILexStream; 
    45import lpg.runtime.IMessageHandler; 
    5 import lpg.runtime.IPrsStream; 
    66import lpg.runtime.IToken; 
    77import lpg.runtime.ParseErrorCodes; 
    88 
    9 import org.axdt.as3.imp.parser.Ast.ASTNode; 
    109import org.axdt.as3.imp.parser.Ast.AbstractVisitor; 
    1110import org.eclipse.core.resources.IFile; 
     
    1312 
    1413public class DiagnoseVisitor extends AbstractVisitor { 
    15         protected static int[] NULL_LOCATION = new int[] {0,0}; 
     14        protected static int[] NULL_LOCATION = null; 
    1615         
    17         protected final IPrsStream prsStream; 
    1816        protected final ILexStream lexStream; 
    19         protected AS3ParseController parseController; 
    20         protected int errorCount = 0; 
     17        protected final IFile file; 
     18         
     19        public int errorCount = 0; 
    2120        protected boolean severeError = false; 
    2221 
    23         public DiagnoseVisitor(AS3ParseController parseController) { 
    24                 this.parseController = parseController; 
    25                 this.prsStream = parseController.getParser().getIPrsStream(); 
    26                 this.lexStream = prsStream.getILexStream(); 
     22        public DiagnoseVisitor(IFile file, ILexStream stream) { 
     23                this.file = file; 
     24                this.lexStream = stream; 
    2725        } 
    2826 
    2927        protected IProject getProject() { 
    30                 return parseController.getProject().getRawProject(); 
     28                return file.getProject(); 
    3129        } 
    3230         
    3331        protected IFile getFile() { 
    34                 return getProject().getFile(parseController.getPath()); 
     32                return file; 
     33        } 
     34 
     35        public void emitError(Object node, String message) { 
     36                emitError((IAst) node, message); 
    3537        } 
    3638 
     
    3941        } 
    4042 
    41         public void emitError(ASTNode node, String message) { 
     43        public void emitError(IAst node, String message) { 
    4244                emitError(node.getLeftIToken().getStartOffset(), node.getRightIToken().getEndOffset(), message); 
    4345        } 
     
    4648                emitError(ParseErrorCodes.NO_MESSAGE_CODE, startOffset, endOffset, message); 
    4749        } 
     50 
     51        public void emitError(int code, IToken id, String message) { 
     52                emitError(code, id.getStartOffset(), id.getEndOffset(), message); 
     53        } 
     54 
     55        public void emitError(int code, IAst node, String message) { 
     56                emitError(code, node.getLeftIToken().getStartOffset(), node.getRightIToken().getEndOffset(), message); 
     57        } 
    4858        public void emitError(int code, int startOffset, int endOffset, String message) { 
    49                 int[] loc = lexStream.getLocation(startOffset, endOffset); 
     59                int[] loc = lexStream.getLocation(Math.min(startOffset,lexStream.getStreamLength()), Math.min(endOffset, lexStream.getStreamLength())); 
     60                if (NULL_LOCATION == null) 
     61                        NULL_LOCATION = lexStream.getLocation(0, 0); 
    5062                String[] msgs = new String[] {message}; 
    5163                IMessageHandler handler = lexStream.getMessageHandler(); 
    52                 handler.handleMessage(code, loc, NULL_LOCATION, prsStream.getFileName(), msgs); 
     64                handler.handleMessage(code, loc, NULL_LOCATION, file.getName(), msgs); 
    5365                errorCount++; 
    5466        } 
  • org.axdt.as3/src/org/axdt/as3/imp/parser/ResolvingVisitor.java

    r2aa064d r5c182b6  
    55 
    66import lpg.runtime.IAst; 
     7import lpg.runtime.ILexStream; 
    78 
    89import org.axdt.as3.AS3Plugin; 
     
    1415import org.axdt.as3.imp.parser.Ast.ExtendsList; 
    1516import org.axdt.as3.imp.parser.Ast.FunctionDefinition; 
    16 import org.axdt.as3.imp.parser.Ast.FunctionExpression; 
    1717import org.axdt.as3.imp.parser.Ast.IName; 
    18 import org.axdt.as3.imp.parser.Ast.IPostfixExpression; 
    1918import org.axdt.as3.imp.parser.Ast.ITypeExpression_allowin; 
    20 import org.axdt.as3.imp.parser.Ast.ITypeExpression_noin; 
    2119import org.axdt.as3.imp.parser.Ast.Ident; 
    2220import org.axdt.as3.imp.parser.Ast.ImportDirective; 
     
    2422import org.axdt.as3.imp.parser.Ast.InterfaceDefinition; 
    2523import org.axdt.as3.imp.parser.Ast.Name; 
     24import org.axdt.as3.imp.parser.Ast.NewExpression; 
    2625import org.axdt.as3.imp.parser.Ast.PackageDefinition; 
     26import org.axdt.as3.imp.parser.Ast.Parameters; 
     27import org.axdt.as3.imp.parser.Ast.RestParameter; 
    2728import org.axdt.as3.imp.parser.Ast.ResultType; 
    2829import org.axdt.as3.imp.parser.Ast.TypeExpressionList; 
    2930import org.axdt.as3.imp.parser.Ast.TypedIdentifier; 
    30 import org.axdt.as3.imp.parser.Ast.VariableBinding; 
     31import org.axdt.as3.util.AS3ASTUtil; 
    3132import org.axdt.as3.util.AS3Util; 
    3233import org.axdt.axdoc.model.AXEntry; 
     
    3536import org.axdt.axdoc.util.Index0r; 
    3637import org.axdt.common.preferences.AxdtPreferences; 
     38import org.eclipse.core.resources.IFile; 
    3739 
    3840public class ResolvingVisitor extends DiagnoseVisitor { 
     
    4244        private ArrayList<AXEntry> importedTypes; 
    4345        private String expectedPackageName; 
    44  
    45         public ResolvingVisitor(AS3ParseController parseController) { 
    46                 super(parseController); 
     46        public ResolvingVisitor(AS3ParseController pc) { 
     47                this(pc.getProject().getRawProject().getFile(pc.getPath()), pc.getLexer().getILexStream()); 
     48        } 
     49        public ResolvingVisitor(IFile file, ILexStream stream) { 
     50                super(file, stream); 
    4751                addDebugErrors = AS3Plugin.getDefault() != null && AxdtPreferences.doDebug(); 
    4852                index0r = Index0r.getInstance(); 
     
    6064                        } 
    6165                } 
     66                // add same package 
    6267                AXIndex[] sameIndexes = index0r.findPackage(expectedPackageName); 
    6368                for (AXIndex index:sameIndexes) { 
    6469                        importedPackages.add(index); 
    6570                } 
     71                // file private names are resolved with the local symbol table 
    6672        } 
    6773        protected AXEntry resolveType(String name) { 
    6874                for (AXEntry entry:importedTypes) { 
    69                         if (entry.getName().equals(name)) 
     75                        if (entry.getName().equals(name)) { 
     76                                index0r.requestFull(entry); 
    7077                                return entry; 
     78                        } 
    7179                } 
    7280                for (AXIndex index:importedPackages) { 
    7381                        for (AXEntry entry:index.getTypes()) { 
    7482                                if (entry.getName().equals(name)) { 
     83                                        index0r.requestFull(entry); 
    7584                                        return entry; 
    7685                                } 
     
    7988                return null; 
    8089        } 
    81         protected String resolveType(ITypeExpression_noin type) { 
     90        protected Object resolveType(Object type) { 
    8291                return type instanceof ASTNode ? resolveNode((ASTNode) type) : null; 
    8392        } 
    84         protected String resolveType(ITypeExpression_allowin type) { 
    85                 return type instanceof ASTNode ? resolveNode((ASTNode) type) : null; 
    86         } 
    87         protected String resolveType(IPostfixExpression type) { 
    88                 return type instanceof ASTNode ? resolveNode((ASTNode) type) : null; 
    89         } 
    90         protected String resolveNode(ASTNode type) { 
    91                 if (type == null)  
    92                         return null; 
     93        protected Object resolveConstructor(Object type) { 
     94                if (type == null) return null; 
    9395                String typeName = type.toString(); 
    9496                AXEntry entry = resolveType(typeName); 
    95                 if (entry == null) { 
    96                         if (!typeName.equals("*")) 
    97                                 emitError((ASTNode)type, "could not resolve type"); 
    98                         return null; 
    99                 } 
    100                 String id = entry.getId(); 
    101                 if (type instanceof Ident) { 
    102                         ((Ident)type).setDeclaration(id); 
    103                 } else if (addDebugErrors) { 
    104                         emitError((ASTNode)type, "todo: not expected other than ident"); 
    105                 } 
    106                 return id; 
     97                Object declaration = null; 
     98                if (entry != null) { 
     99                        AXEntry member = entry.localMember(typeName); 
     100                        if (member != null){ 
     101                                declaration = member.getId(); 
     102                        } else { 
     103                                declaration = entry.getId(); 
     104                        } 
     105                } else { 
     106                        // might be file private member 
     107                        SymbolTable table = AS3ASTUtil.getEnclosingSymbolTable((IAst)type).getRoot(); 
     108                        declaration = table.findDeclaration(typeName); 
     109                } 
     110                setDeclaration(type, declaration); 
     111                return declaration; 
     112        } 
     113        protected Object resolveNode(ASTNode type) { 
     114                if (type == null) return null; 
     115                Object declaration = null; 
     116                String typeName = type.toString(); 
     117                if (typeName.equals("*")) { 
     118                        declaration = "*"; 
     119                } else { 
     120                        AXEntry entry = resolveType(typeName); 
     121                        if (entry != null) { 
     122                                declaration = entry.getId(); 
     123                        } else { 
     124                                // might be file private member 
     125                                SymbolTable table = AS3ASTUtil.getEnclosingSymbolTable(type).getRoot(); 
     126                                declaration = table.findDeclaration(typeName); 
     127                        } 
     128                } 
     129                setDeclaration(type, declaration); 
     130                return declaration; 
     131        } 
     132        protected void setDeclaration(Object type, Object declaration) { 
     133                if (declaration != null) { 
     134                        if (type instanceof Ident) { 
     135                                ((Ident)type).setDeclaration(declaration); 
     136                        } else if (addDebugErrors) { 
     137                                emitError((ASTNode)type, "todo: not expected other than ident"); 
     138                        } 
     139                } else { 
     140                        emitError((ASTNode)type, "could not resolve type"); 
     141                } 
    107142        } 
    108143        protected void resolveTypes(TypeExpressionList list) { 
     
    121156        @Override 
    122157        public boolean visit(PackageDefinition n) { 
    123                 String packageName = AS3Util.getExpectedPackageName(getFile()); 
    124                 // is not inside a valid source path 
    125                 if (packageName == null) { 
    126                         emitError(n, "file should be inside a configured source path"); 
    127                         return false; 
    128                 } 
    129                 // check if name corresponds with folder names 
    130                 if (n.getName() != null) { 
    131                         Name nameNode = (Name) n.getName(); 
    132                         String name = nameNode.toString(); 
    133                         if (!name.equals(packageName)) 
    134                                 emitError(nameNode, "package name sould be: "+ packageName); 
    135                         // fill declaration with false 
    136                         Name current = nameNode; 
    137                         while (current!=null) { 
    138                                 current.getIdent().setDeclaration(Boolean.FALSE); 
    139                                 current = current.getQualifier() instanceof Name ? 
    140                                                 (Name)current.getQualifier() : null; 
    141                         } 
    142                 } else if (packageName != null && packageName.length() > 0) { 
    143                         emitError(n.getLeftIToken(), "package name sould be: "+ packageName); 
    144                 } 
    145158                return true; 
    146159        } 
     
    187200        } 
    188201        @Override 
    189         public boolean visit(ClassDefinition n) { 
    190                 Name name = (Name) n.getName(); 
    191                 checkTypeName(name); 
    192                 checkPackageDirectiveName(name); 
    193                 return true; 
    194         } 
    195         @Override 
    196202        public boolean visit(Inheritance n) { 
    197203                ClassDefinition parent = (ClassDefinition) n.getParent(); 
     
    202208        } 
    203209        @Override 
    204         public boolean visit(InterfaceDefinition n) { 
    205                 Name name = (Name) n.getName(); 
    206                 checkTypeName(name); 
    207                 checkPackageDirectiveName(name); 
    208                 return true; 
    209         } 
    210         @Override 
    211210        public boolean visit(ExtendsList n) { 
    212211                InterfaceDefinition parent = (InterfaceDefinition) n.getParent(); 
     
    214213                return false; 
    215214        } 
    216         private void checkTypeName(Name name) { 
    217                 if (name.getQualifier()!=null) 
    218                         emitError(name, "type names are not qualified. the package name belongs in the package declaration"); 
    219                 name.getIdent().setDeclaration(Boolean.FALSE); 
    220         } 
    221         private void checkPackageDirectiveName(Name name) { 
    222                 IAst grandp = name; 
    223                 while (grandp != null) { 
    224                         grandp = grandp.getParent(); 
    225                         if (grandp instanceof PackageDefinition) 
    226                                 break; 
    227                 } 
    228                 if (grandp != null) { 
    229                         String nameString = name.getIdent().toString(); 
    230                         String expectedName = AS3Util.getExpectedMemberName(getFile()); 
    231                         if (!nameString.equals(expectedName))  
    232                                 emitError(name, "public package member name should match the file name"); 
    233                 } 
    234         } 
    235215         
     216        @Override 
     217        public boolean visit(FunctionDefinition n) { 
     218                Ident name = n.getName(); 
     219                if (name == null) { 
     220                        emitError(n, "must have a name"); 
     221                        // TODO check for overrides ? 
     222                        //  
     223                } 
     224                return true; 
     225        } 
     226        @Override 
     227        public boolean visit(RestParameter n) { 
     228                // TODO: move to more basic checking phase  
     229                IAst parent = n.getParent(); 
     230                if (parent instanceof Parameters) { 
     231                        Parameters params = (Parameters) parent; 
     232                        if (n != params.getParameterAt(params.size()-1)) { 
     233                                emitError(n, "rest parameter can only occur as last parameter"); 
     234                        } 
     235                } else { 
     236                        emitError(parent, "todo: rest parameters parent should be parameters ?!"); 
     237                } 
     238                return true; 
     239        } 
     240        @Override 
    236241        public boolean visit(TypedIdentifier n) { 
    237                 if (n != null) 
     242                if (n != null) { 
    238243                        resolveNode(n.getType()); 
    239                 return false; 
    240         } 
     244                        n.getName().setDeclaration(Boolean.FALSE); 
     245                } 
     246                return false; 
     247        } 
     248        @Override 
    241249        public boolean visit(ResultType n) { 
    242250                if (n != null) 
     
    244252                return false; 
    245253        } 
    246  
     254        @Override 
     255        public void endVisit(NewExpression n) { 
     256                // TODO check expression for type 
     257                if (n != null) { 
     258                        resolveConstructor(n.getExpression()); 
     259                } 
     260        } 
     261        @Override 
     262        public void endVisit(AssignmentExpression n) { 
     263                // TODO check if left type is assignable from right type 
     264                n.toString(); 
     265        } 
     266        @Override 
     267        public boolean visit(ExpressionStatement n) { 
     268                return true; 
     269        } 
    247270} 
  • org.axdt.as3/src/org/axdt/as3/imp/parser/SymbolTable.java

    re9006de r5c182b6  
    22 
    33import java.util.ArrayList; 
    4 import java.util.Hashtable; 
     4import java.util.HashMap; 
    55import java.util.List; 
     6import java.util.Map; 
    67 
    78import lpg.runtime.IAst; 
    89 
    9 import org.axdt.as3.imp.parser.Ast.Block; 
    10 import org.axdt.as3.imp.parser.Ast.ClassDefinition; 
    11 import org.axdt.as3.imp.parser.Ast.FunctionDefinition; 
    12 import org.axdt.as3.imp.parser.Ast.FunctionExpression; 
    13 import org.axdt.as3.imp.parser.Ast.InterfaceBlock; 
     10import org.axdt.as3.util.AS3ASTUtil; 
    1411 
    15 public class SymbolTable extends Hashtable<String, IAst> { 
     12public class SymbolTable { 
     13        public class SymbolEntry { 
     14 
     15                private IAst node; 
     16 
     17                public SymbolEntry(IAst node) { 
     18                        this.node = node; 
     19                } 
     20 
     21                public IAst getAst() { 
     22                        return node; 
     23                } 
     24 
     25        } 
    1626        private static final long serialVersionUID = 1L; 
    17         SymbolTable parent; 
    18         Class<?> nodeClass; 
     27        private Map<String,SymbolEntry> store; 
     28        private SymbolTable parent; 
     29        private Class<?> nodeClass; 
    1930         
    20         SymbolTable(SymbolTable parent, Class<?> clazz) { 
     31        public SymbolTable(SymbolTable parent, Class<?> clazz) { 
    2132                this.parent = parent; 
    2233                this.nodeClass = clazz; 
     34                store = new HashMap<String, SymbolEntry>(); 
    2335        } 
    2436 
    2537        public IAst findDeclaration(String name) { 
    26                 IAst decl = (IAst) get(name); 
    27                 if (decl != null) return decl; 
     38                SymbolEntry entry = store.get(name); 
     39                if (entry != null) return entry.getAst(); 
    2840                if (parent != null) return parent.findDeclaration(name); 
    2941                return null; 
     
    3345                return parent; 
    3446        } 
     47        public SymbolTable getRoot() { 
     48                return parent == null ? this : parent.getRoot(); 
     49        } 
    3550 
    3651        public boolean create(String name, IAst node) { 
    37                 if (get(name) == null) { 
    38                         put(name, node); 
     52                if (store.get(name) == null) { 
     53                        store.put(name, new SymbolEntry(node)); 
    3954                        return true; 
    4055                } 
     
    4560                if (list == null) 
    4661                        list = new ArrayList<String>(); 
    47                 list.addAll(keySet()); 
     62                list.addAll(store.keySet()); 
    4863                if (parent != null) parent.getAllKeys(list); 
    4964                return list; 
    5065        } 
    5166        public SymbolTable getEnclosingSymbolTable(IAst n) { 
    52                 SymbolTable enclosing = getEnclosing(n); 
     67                SymbolTable enclosing = AS3ASTUtil.getEnclosingSymbolTable(n); 
    5368                if (enclosing != null) return enclosing; 
    5469                return this; 
    55         } 
    56         public static SymbolTable getEnclosing(IAst n) { 
    57                 for (; n != null; n = n.getParent()) { 
    58                         if (n instanceof Block) return ((Block) n).getSymbolTable(); 
    59                         if (n instanceof InterfaceBlock) return ((InterfaceBlock) n).getSymbolTable(); 
    60                         if (n instanceof FunctionDefinition) return ((FunctionDefinition) n).getSymbolTable(); 
    61                         if (n instanceof FunctionExpression) return ((FunctionExpression) n).getSymbolTable(); 
    62                         if (n instanceof ClassDefinition) return ((ClassDefinition) n).getSymbolTable(); 
    63                 } 
    64                 return null; 
    6570        } 
    6671        public String cleanName(String key) { 
  • org.axdt.as3/src/org/axdt/as3/imp/services/AS3ContentProposer.java

    rb32f7a4 r5c182b6  
    77 
    88import lpg.runtime.IAst; 
    9 import lpg.runtime.IPrsStream; 
    10 import lpg.runtime.IToken; 
    119 
    12 import org.axdt.as3.AS3Plugin; 
    13 import org.axdt.as3.imp.parser.AS3ASTNodeLocator; 
     10import org.axdt.as3.analysis.AS3TokenHelper; 
    1411import org.axdt.as3.imp.parser.AS3ParseController; 
    15 import org.axdt.as3.imp.parser.AS3Parsersym; 
    1612import org.axdt.as3.imp.parser.SymbolTable; 
    1713import org.axdt.as3.imp.parser.Ast.ASTNode; 
    18 import org.axdt.as3.imp.parser.Ast.IAnnotatableDirective; 
    1914import org.axdt.as3.imp.parser.Ast.IName; 
    2015import org.axdt.as3.imp.parser.Ast.ImportDirective; 
    2116import org.axdt.as3.imp.parser.Ast.PackageDefinition; 
    2217import org.axdt.as3.templates.AS3TemplateCompletionProcessor; 
     18import org.axdt.as3.util.AS3ASTUtil; 
    2319import org.axdt.as3.util.AS3Util; 
    2420import org.axdt.axdoc.model.AXEntry; 
     
    2824import org.eclipse.imp.editor.SourceProposal; 
    2925import org.eclipse.imp.parser.IParseController; 
    30 import org.eclipse.imp.parser.IParser; 
    3126import org.eclipse.imp.services.IContentProposer; 
    3227import org.eclipse.jface.text.ITextViewer; 
     
    3530public class AS3ContentProposer implements IContentProposer { 
    3631         
    37         private static AS3ASTNodeLocator locator = new AS3ASTNodeLocator(); 
     32        private AS3SourceHelper helper; 
    3833         
    39         private boolean offsetWithinToken; 
    40         private int offset; 
    41         private AS3ParseController control; 
    42         private IToken token; 
    43         private String prefix; 
    44         private ASTNode ast; 
    45         private ASTNode node; 
    46  
    47         private ArrayList<IAst> ancestors; 
    48  
    49         private IToken previous; 
    50  
    51         private IToken next; 
    52  
    53         private boolean offsetAfterToken; 
    54  
    55         private ITextViewer viewer; 
    56  
    57         private boolean usingBackup; 
    58  
    59         private int originalOffset; 
    60  
    61  
    62         private int offsetDiff; 
    63  
    64         private boolean nextIsSemi; 
    65          
    66         private void clear() { 
    67                 offsetWithinToken = offsetAfterToken = nextIsSemi = false; 
    68                 prefix = null;  
    69                 ancestors = null; 
    70                 token = previous = next = null; 
    71                 node = null; 
    72         } 
    73  
    7434        public AS3ContentProposer() { 
    75         } 
    76         protected boolean collectInfo(IParseController controller, int offset, ITextViewer viewer) { 
    77                 this.viewer = viewer; 
    78                 this.control = (AS3ParseController) controller; 
    79                 this.offset = offset; 
    80                 offsetDiff = offset - originalOffset; 
    81                 usingBackup = false; 
    82                 ast = null; 
    83                 ASTNode newast = getAst(); 
    84                 if (newast != null && newast == ast) { 
    85                         AS3Plugin.getDefault().debug("using old ast nothing changed"); 
    86                         return true; 
    87                 } 
    88                 IParser parser = control.getParser(); 
    89                 IPrsStream stream = parser.getIPrsStream(); 
    90                 if (stream == null)  { 
    91                         AS3Plugin.getDefault().debug("no error lexing."); 
    92                         return false; 
    93                 } 
    94                 if (newast == null) { 
    95                         AS3Plugin.getDefault().debug("no ast available try to recover"); 
    96                         Object backupAst = control.getBackupAst(); 
    97                         if (! (backupAst instanceof ASTNode)) { 
    98                                 AS3Plugin.getDefault().debug("no backup ast. recover failed."); 
    99                                 return false; 
    100                         } 
    101                         newast = (ASTNode) backupAst; 
    102                         usingBackup = true; 
    103                 } else { 
    104                         originalOffset = offset; 
    105                 } 
    106                 clear(); 
    107                 try { 
    108                         ast = newast; 
    109                         int myOffset = offset; 
    110                         int index = stream.getTokenIndexAtCharacter(myOffset); 
    111                         token = getToken(stream, index < 0 ? -index + 1: index); 
    112                         previous = getToken(stream, token.getTokenIndex()-1); 
    113                         offsetAfterToken = previous.getEndOffset() == myOffset - 1; 
    114                         if (offsetAfterToken || token.getKind() == Sym.TK_SEMI  
    115                                 || (myOffset < token.getStartOffset()&& stream.getILexStream().getLineNumberOfCharAt(myOffset) < token.getLine())) { 
    116                                 next = token; 
    117                                 token = previous; 
    118                                 previous = stream.getIToken(token.getTokenIndex()-1); 
    119                         } 
    120                         if (next == null){ 
    121                                 next = stream.getIToken(stream.getNext(token.getTokenIndex())); 
    122                         } 
    123                         nextIsSemi = next.getKind() == Sym.TK_SEMI; 
    124                         offsetWithinToken = Sym.isWithinToken(myOffset, token); 
    125                         if ((offsetAfterToken||offsetWithinToken) && Sym.isKeyword(token))  
    126                                 return false; 
    127                         this.prefix = offsetWithinToken ? Sym.getPrefix(myOffset, token)  
    128                                         : ( offsetAfterToken ? token.toString() : ""); 
    129                         node = getNode(token); 
    130                         collectAncestorInfo(node); 
    131                 } catch (Exception e) { 
    132                         AS3Plugin.getDefault().debug("error collecting context info for completion proposals", e); 
    133                 } 
    134                 return true; 
    135         } 
    136         private IToken getToken(IPrsStream s, int index) { 
    137                 IToken result = s.getIToken(index); 
    138                 if (result.getKind() == Sym.TK_VirtualSemicolon) 
    139                         result = s.getIToken(index-1); 
    140                 return result; 
    141         } 
    142         private void collectAncestorInfo(ASTNode node) { 
    143                 ancestors = new ArrayList<IAst>(); 
    144                 for (IAst n = node; n != null; n = n.getParent()) { 
    145                         if (n instanceof IAnnotatableDirective 
    146                          || n instanceof ImportDirective 
    147                          || n instanceof PackageDefinition 
    148                          ) { 
    149                                 ancestors.add(n); 
    150                         } 
    151                 } 
    152         } 
    153         private ASTNode getNode(IToken t) { 
    154                 Object object = locator.findNode(ast, t.getStartOffset(), t.getEndOffset()); 
    155                 return (object instanceof ASTNode) ? (ASTNode) object : null; 
    156         } 
    157         private ASTNode getAst() { 
    158                 Object object = control.parse(viewer.getDocument().get(), null); 
    159                 return (object instanceof ASTNode) ? (ASTNode) object : null; 
    16035        } 
    16136        /** 
     
    18055        public ICompletionProposal[] getContentProposals(IParseController controller, int offset, 
    18156                        ITextViewer viewer) { 
    182                 boolean precede = collectInfo(controller, offset, viewer); 
     57                helper = new AS3SourceHelper((AS3ParseController)controller, viewer); 
     58                boolean precede = helper.init(offset); 
    18359                if (!precede) { 
    18460                        return new ICompletionProposal[0]; 
    18561                } 
    18662                ProposalHelper proposals = new ProposalHelper(); 
    187                 if (ast != null) { 
    188                         if (ancestors != null && ancestors.size() > 0) { 
    189                                 IAst ancestor = ancestors.get(0); 
     63                if (helper.hasAst()) { 
     64                        if (helper.hasAncestors()) { 
     65                                IAst ancestor = helper.ancestors.get(0); 
    19066                                if (ancestor instanceof PackageDefinition) { 
    19167                                        PackageDefinition packdef = (PackageDefinition)ancestor; 
    192                                         if (packdef.getBody() == null || offset < packdef.getBody().getLeftIToken().getStartOffset()+offsetDiff) { 
     68                                        if (packdef.getBody() == null || offset <= packdef.getBody().getLeftIToken().getStartOffset()) { 
    19369                                                // in package header 
    19470                                                IName nameNode = packdef.getName(); 
    195                                                 if (!usingBackup) 
    196                                                         prefix = fetchName((IAst) nameNode); 
    197                                                 IResource project = control.getProject().getResource(); 
    198                                                 String expectedName = AS3Util.getExpectedPackageName(project,project.getFullPath().append(control.getPath())); 
    199                                                 if (!prefix.equals(expectedName)) 
    200                                                         proposals.addSourceProposal(expectedName, prefix,PackageDefinition.class); 
     71                                                helper.updatePrefix(helper.fetchName((IAst) nameNode)); 
     72                                                IResource project = helper.control.getProject().getResource(); 
     73                                                String expectedName = AS3Util.getExpectedPackageName(project,project.getFullPath().append(helper.control.getPath())); 
     74                                                if (!helper.prefix.equals(expectedName)) 
     75                                                        proposals.addSourceProposal(expectedName, helper.prefix,PackageDefinition.class); 
    20176                                        } else { 
    202                                                 proposals.addUnitScopeProposals(node); 
    203                                                 boolean isImport = token.getKind() == Sym.TK_import; 
    204                                                 if (isImport || prefix.startsWith("import")) { 
     77                                                proposals.addUnitScopeProposals(helper.node); 
     78                                                boolean isImport = helper.token.getKind() == AS3TokenHelper.TK_import; 
     79                                                if (isImport || helper.prefix.startsWith("import")) { 
    20580                                                        for (String packname:Index0r.getInstance().getPackageNames()) { 
    20681                                                                String proposed = (isImport ? "":"import ")+packname+".*"; 
    207                                                                 proposals.addSourceProposal(proposed, prefix, ImportDirective.class, !nextIsSemi); 
     82                                                                proposals.addSourceProposal(proposed, helper.prefix, ImportDirective.class, !helper.nextIsSemi()); 
    20883                                                        } 
    20984                                                } 
     
    21186                                } else if (ancestor instanceof ImportDirective) { 
    21287                                        IName nameNode = ((ImportDirective)ancestor).getName(); 
    213                                         if (!usingBackup) 
    214                                                 prefix = fetchName((IAst) nameNode); 
    215                                         int dotIndex = prefix.lastIndexOf('.'); 
     88                                        helper.updatePrefix(helper.fetchName((IAst) nameNode)); 
     89                                        int dotIndex = helper.prefix.lastIndexOf('.'); 
    21690                                        Collection<String> packageNames = Index0r.getInstance().getPackageNames(); 
    21791                                        if (dotIndex > 0) { 
    218                                                 String packname = prefix.substring(0,dotIndex); 
    219                                                 String rest = prefix.substring(dotIndex+1); 
     92                                                String packname = helper.prefix.substring(0,dotIndex); 
     93                                                String rest = helper.prefix.substring(dotIndex+1); 
    22094                                                if (packageNames.contains(packname)) { 
    22195                                                        if ("*".equals(rest)) { 
     
    226100                                                                        String entryname = entry.getName(); 
    227101                                                                        if (entryname != null && (rest.length() == 0 || entryname.startsWith(rest))) { 
    228                                                                                 proposals.addSourceProposal(packname+"."+entryname, prefix, ImportDirective.class, !nextIsSemi); 
     102                                                                                proposals.addSourceProposal(packname+"."+entryname, helper.prefix, ImportDirective.class, !helper.nextIsSemi()); 
    229103                                                                        } 
    230104                                                                } 
    231105                                                                if (rest.length() == 0) { 
    232                                                                         proposals.addSourceProposal(packname+".*", prefix, ImportDirective.class, !nextIsSemi); 
     106                                                                        proposals.addSourceProposal(packname+".*", helper.prefix, ImportDirective.class, !helper.nextIsSemi()); 
    233107                                                                } 
    234108                                                        } 
     
    236110                                        } 
    237111                                        for (String packname:packageNames) { 
    238                                                 if (packname.startsWith(prefix)) { 
    239                                                         proposals.addSourceProposal(packname+".*", prefix, ImportDirective.class, !nextIsSemi); 
     112                                                if (packname.startsWith(helper.prefix)) { 
     113                                                        proposals.addSourceProposal(packname+".*", helper.prefix, ImportDirective.class, !helper.nextIsSemi()); 
    240114                                                } 
    241115                                        } 
    242116                                } else { 
    243                                         proposals.addUnitScopeProposals(node); 
     117                                        proposals.addUnitScopeProposals(helper.node); 
    244118                                } 
    245119                        } else { 
     
    247121                        } 
    248122                } 
    249                 if (prefix != null && prefix.length() > 0) { 
     123                if (helper.hasPrefix()) { 
    250124                        proposals.addKeywordProposals(); 
    251125                        proposals.addTemplateProposals(viewer); 
    252126                } 
    253127                return proposals.getResult(); 
    254         } 
    255         protected String fetchName(IAst nameNode) { 
    256                 String name = nameNode == null ? "" : nameNode.toString(); 
    257                 int startOffset = nameNode == null ? offset : nameNode.getLeftIToken().getStartOffset(); 
    258                 if (offset > startOffset + name.length()) { 
    259                         try { 
    260                                 name = viewer.getDocument().get(startOffset, offset - startOffset); 
    261                         } catch (Exception e) { 
    262                                 AS3Plugin.getDefault().debug("error fetching real name",e); 
    263                         } 
    264                 } 
    265                 return name; 
    266128        } 
    267129        public static final Comparator<ICompletionProposal> ProposalComparator = new Comparator<ICompletionProposal>() { 
     
    270132                } 
    271133        }; 
    272         private class ProposalHelper implements AS3Parsersym { 
     134        private class ProposalHelper { 
    273135                ArrayList<ICompletionProposal> result = new ArrayList<ICompletionProposal>(); 
    274136                 
    275137                void addUnitScopeProposals(ASTNode node) { 
    276                         SymbolTable table = SymbolTable.getEnclosing(node); 
     138                        SymbolTable table = AS3ASTUtil.getEnclosingSymbolTable(node); 
    277139                        if (table == null) return; 
    278140                        for (String key:table.getAllKeys(null)) { 
    279141                                String name = table.cleanName(key); 
    280                                 if (name.startsWith(prefix)) { 
     142                                if (name.startsWith(helper.prefix)) { 
    281143                                        IAst ast = table.findDeclaration(key); 
    282                                         result.add(new AS3SourceProposal(name, prefix, offset, ast.getClass())); 
     144                                        result.add(new AS3SourceProposal(name, helper.prefix, helper.offset, ast.getClass())); 
    283145                                } 
    284146                        } 
    285147                } 
    286148                void addSourceProposal(String packageName, String usePrefix, ASTNode node) { 
    287                         result.add(new AS3SourceProposal(packageName, usePrefix, offset, node.getClass())); 
     149                        result.add(new AS3SourceProposal(packageName, usePrefix, helper.offset, node.getClass())); 
    288150                } 
    289151                void addSourceProposal(String packageName, String usePrefix, Class<?> nodeClass) { 
    290                         result.add(new AS3SourceProposal(packageName, usePrefix, offset, nodeClass)); 
     152                        result.add(new AS3SourceProposal(packageName, usePrefix, helper.offset, nodeClass)); 
    291153                } 
    292154                void addSourceProposal(String packageName, String usePrefix, Class<?> nodeClass, boolean addSemi) { 
    293155                        if (addSemi) packageName += ";"; 
    294                         result.add(new AS3SourceProposal(packageName, usePrefix, offset, nodeClass)); 
     156                        result.add(new AS3SourceProposal(packageName, usePrefix, helper.offset, nodeClass)); 
    295157                } 
    296158                void addKeywordProposals() { 
    297                         for (String key:Sym.getKeyWords()) { 
    298                                 if (!key.equals(prefix) && key.startsWith(prefix)) { 
    299                                         SourceProposal proposal = new SourceProposal(key, prefix, offset); 
     159                        for (String key:AS3TokenHelper.getKeyWords()) { 
     160                                if (!key.equals(helper.prefix) && key.startsWith(helper.prefix)) { 
     161                                        SourceProposal proposal = new SourceProposal(key, helper.prefix, helper.offset); 
    300162                                        result.add(proposal); 
    301163                                } 
     
    304166                void addTemplateProposals(ITextViewer viewer) { 
    305167                        AS3TemplateCompletionProcessor processor = new AS3TemplateCompletionProcessor(); 
    306                         result.addAll(processor.computeCompletionProposalList(viewer, offset, prefix)); 
     168                        result.addAll(processor.computeCompletionProposalList(viewer, helper.offset, helper.prefix)); 
    307169                } 
    308170                ICompletionProposal[] getResult() { 
     
    311173                } 
    312174        } 
    313         public static class Sym implements AS3Parsersym { 
    314                 private static String[] keywords = null; 
    315                  
    316                 public static String[] getKeyWords() { 
    317                         if (keywords == null) 
    318                                 keywords = createKeywords(); 
    319                         return keywords; 
    320                 } 
    321                  
    322                 public static boolean isKeyword(IToken t) { 
    323                         int kind = t.getKind(); 
    324                         if (kind > 1 && kind < orderedTerminalSymbols.length) { 
    325                                 return orderedTerminalSymbols[kind].charAt(0) > 'Z'; 
    326                         } 
    327                         return false; 
    328                 } 
    329  
    330                 public static String getPrefix(int o, IToken t) { 
    331                         return t.getKind() == Sym.TK_IDENTIFIER ? 
    332                                         t.toString().substring(0, o-t.getStartOffset()) : ""; 
    333                 } 
    334  
    335                 public static boolean isWithinToken(int o, IToken t) { 
    336                         return o >= t.getStartOffset() && o <= t.getEndOffset(); 
    337                 } 
    338                  
    339                 private static String[] createKeywords() { 
    340                         ArrayList<String> result = new ArrayList<String>(); 
    341                         for (int i = 1; i < orderedTerminalSymbols.length; i++) { 
    342                                 if (orderedTerminalSymbols[i].charAt(0) > 'Z') 
    343                                         result.add(orderedTerminalSymbols[i]); 
    344                         } 
    345                         return result.toArray(new String[result.size()]); 
    346                 } 
    347         } 
    348175} 
  • org.axdt.as3/src/org/axdt/as3/imp/services/AS3EditorService.java

    r3d0622c r5c182b6  
    66 
    77import org.axdt.as3.AS3Plugin; 
     8import org.axdt.as3.imp.parser.AS3ParseController; 
    89import org.eclipse.core.runtime.IPath; 
    910import org.eclipse.core.runtime.IProgressMonitor; 
     
    3839        public void update(IParseController parseController, 
    3940                        IProgressMonitor monitor) { 
    40                 // TODO do update ?! we do the work in the as3 parse controller for now  
    4141        } 
    4242 
     
    7171                        if (editor != part) return; 
    7272                        partService.removePartListener(this); 
    73                         if (path != null)openFilePaths.remove(path); 
     73                         
     74                        // clean up as long as there is the memory leak http://bugs.eclipse.org/281790 
     75                        editor.fParserScheduler.cancel(); 
     76                        editor.fParserScheduler = null; 
     77                        if (editor.getParseController() instanceof AS3ParseController) { 
     78                                AS3ParseController control = ((AS3ParseController) editor.getParseController()); 
     79                                control.dispose();  
     80                        } 
     81                         
     82                        if (path != null) openFilePaths.remove(path); 
    7483                        AS3Plugin.getDefault().debug("as3 editor closed"); 
    7584                } 
  • org.axdt.as3/src/org/axdt/as3/imp/services/AS3ReferenceResolver.java

    rb32f7a4 r5c182b6  
    33import lpg.runtime.IAst; 
    44 
    5 import org.axdt.as3.imp.parser.AS3ParseController; 
    65import org.axdt.as3.imp.parser.SymbolTable; 
    76import org.axdt.as3.imp.parser.Ast.Ident; 
     
    5857 
    5958        private Object lookInSymbolTable(IParseController controller, IAst node, String stringId) { 
    60                 SymbolTable symtab = ((AS3ParseController) controller).getEnclosingSymbolTable(node); 
     59                SymbolTable symtab = AS3ASTUtil.getEnclosingSymbolTable(node); 
    6160                return symtab.findDeclaration(stringId); 
    6261        } 
  • org.axdt.as3/src/org/axdt/as3/imp/services/AS3TokenColorer.java

    rb32f7a4 r5c182b6  
    44import lpg.runtime.IToken; 
    55 
    6 import org.axdt.as3.imp.parser.AS3ParseController; 
     6import org.axdt.as3.analysis.AS3TokenHelper; 
    77import org.axdt.as3.imp.parser.AS3Parsersym; 
    88import org.eclipse.imp.parser.IParseController; 
     
    4040                                return null; 
    4141                        } 
    42                         if (((AS3ParseController) controller).isKeyword(token.getKind())) 
     42                        if (AS3TokenHelper.isKeyword(token)) 
    4343                                return keywordAttribute; 
    4444                        return super.getColoring(controller, token); 
  • org.axdt.as3/src/org/axdt/as3/util/AS3ASTUtil.java

    r69d1ca8 r5c182b6  
    33import lpg.runtime.IAst; 
    44 
     5import org.axdt.as3.imp.parser.SymbolTable; 
    56import org.axdt.as3.imp.parser.Ast.ASTNode; 
     7import org.axdt.as3.imp.parser.Ast.Block; 
     8import org.axdt.as3.imp.parser.Ast.ClassDefinition; 
     9import org.axdt.as3.imp.parser.Ast.FunctionDefinition; 
     10import org.axdt.as3.imp.parser.Ast.FunctionExpression; 
    611import org.axdt.as3.imp.parser.Ast.IDirective; 
    712import org.axdt.as3.imp.parser.Ast.IPackageDefinition; 
     13import org.axdt.as3.imp.parser.Ast.ITypedIdentifier_noin; 
    814import org.axdt.as3.imp.parser.Ast.Ident; 
     15import org.axdt.as3.imp.parser.Ast.InterfaceDefinition; 
    916import org.axdt.as3.imp.parser.Ast.Name; 
     17import org.axdt.as3.imp.parser.Ast.Program; 
    1018 
    1119public class AS3ASTUtil { 
     
    1321                return parent instanceof IDirective 
    1422                        || parent instanceof IPackageDefinition; 
     23        } 
     24        public static boolean isNameParent(IAst parent) { 
     25                return parent instanceof IDirective 
     26                        || parent instanceof IPackageDefinition 
     27                        || parent instanceof ITypedIdentifier_noin; 
    1528        } 
    1629        public static ASTNode getDirective(ASTNode node) { 
     
    3750                } 
    3851                if (Boolean.FALSE.equals(declaration)) { 
    39                         IAst parent = current.getParent(); 
    40                         while (parent != null && !isDirective(parent.getParent())) 
     52                        IAst parent = current; 
     53                        while (parent != null && !isNameParent(parent.getParent())) 
    4154                                parent = parent.getParent(); 
    4255                        return parent; 
     
    4457                return declaration; 
    4558        } 
     59        public static SymbolTable getEnclosingSymbolTable(IAst n) { 
     60                for (; n != null; n = n.getParent()) { 
     61                        if (n instanceof Block) return ((Block) n).getSymbolTable(); 
     62                        if (n instanceof FunctionDefinition) return ((FunctionDefinition) n).getSymbolTable(); 
     63                        if (n instanceof FunctionExpression) return ((FunctionExpression) n).getSymbolTable(); 
     64                        if (n instanceof ClassDefinition) return ((ClassDefinition) n).getSymbolTable(); 
     65                        if (n instanceof InterfaceDefinition) return ((InterfaceDefinition) n).getSymbolTable(); 
     66                        if (n instanceof Program) return ((Program) n).getSymbolTable(); 
     67                } 
     68                return null; 
     69        } 
    4670} 
  • org.axdt.axdoc.model/model/AXDoc.ecore

    r2aa064d r5c182b6  
    2626  </eClassifiers> 
    2727  <eClassifiers xsi:type="ecore:EEnum" name="AXLevel"> 
    28     <eLiterals name="EMPTY"/> 
    29     <eLiterals name="PACKAGE" value="1"/> 
    30     <eLiterals name="TYPE" value="2"/> 
    31     <eLiterals name="MEMBER" value="4"/> 
     28    <eLiterals name="EMPTY" literal="e"/> 
     29    <eLiterals name="PACKAGE" value="1" literal="p"/> 
     30    <eLiterals name="TYPE" value="2" literal="t"/> 
     31    <eLiterals name="MEMBER" value="4" literal="m"/> 
    3232  </eClassifiers> 
    3333  <eClassifiers xsi:type="ecore:EClass" name="AXIndex" eSuperTypes="#//AXIndexNode"> 
     
    4040    <eOperations name="getOrCreateReference" eType="#//AXPackage"/> 
    4141    <eStructuralFeatures xsi:type="ecore:EReference" name="reference" eType="#//AXPackage"/> 
    42     <eStructuralFeatures xsi:type="ecore:EAttribute" name="level" eType="#//AXLevel" 
    43         transient="true"/> 
    4442    <eStructuralFeatures xsi:type="ecore:EReference" name="indexes" upperBound="-1" 
    4543        eType="#//AXIndex" containment="true" resolveProxies="false" eOpposite="#//AXIndex/parent" 
     
    108106    <eStructuralFeatures xsi:type="ecore:EReference" name="basicParent" eType="#//AXIndexNode" 
    109107        changeable="false" volatile="true" transient="true"/> 
     108    <eStructuralFeatures xsi:type="ecore:EAttribute" name="level" eType="#//AXLevel"/> 
    110109  </eClassifiers> 
    111110  <eClassifiers xsi:type="ecore:EEnum" name="AXEntryType"> 
  • org.axdt.axdoc.model/model/AXDocXML.xsd

    r2aa064d r5c182b6  
    103103    </xsd:sequence> 
    104104    <xsd:attribute name="name" type="xsd:string" use="required"/> 
     105    <xsd:attribute name="level" type="axdoc:AXLevel"/> 
    105106  </xsd:complexType> 
    106107</xsd:schema> 
  • org.axdt.axdoc.model/src/org/axdt/axdoc/model/AXDocPackage.java

    <
    r2aa064d r5c182b6  
    347347 
    348348        /** 
     349         * The feature id for the '<em><b>Level</b></em>' attribute. 
     350         * <!-- begin-user-doc --> 
     351         * <!-- end-user-doc --> 
     352         * @generated 
     353         * @ordered 
     354         */ 
     355        int AX_INDEX_NODE__LEVEL = 4; 
     356 
     357        /** 
    349358         * The number of structural features of the '<em>AX Index Node</em>' class. 
    350359         * <!-- begin-user-doc --> 
     
    353362         * @ordered 
    354363         */ 
    355         int AX_INDEX_NODE_FEATURE_COUNT = 4; 
     364        int AX_INDEX_NODE_FEATURE_COUNT = 5; 
    356365 
    357366        /** 
     
    402411 
    403412        /** 
     413         * The feature id for the '<em><b>Level</b></em>' attribute. 
     414         * <!-- begin-user-doc --> 
     415         * <!-- end-user-doc --> 
     416         * @generated 
     417         * @ordered 
     418         */ 
     419        int AX_INDEX__LEVEL = AX_INDEX_NODE__LEVEL; 
     420 
     421        /** 
    404422         * The feature id for the '<em><b>Reference</b></em>' reference. 
    405423         * <!-- begin-user-doc --> 
     
    411429 
    412430        /** 
    413          * The feature id for the '<em><b>Level</b></em>' attribute. 
    414          * <!-- begin-user-doc --> 
    415          * <!-- end-user-doc --> 
    416          * @generated 
    417          * @ordered 
    418          */ 
    419         int AX_INDEX__LEVEL = AX_INDEX_NODE_FEATURE_COUNT + 1; 
    420  
    421         /** 
    422431         * The feature id for the '<em><b>Indexes</b></em>' containment reference list. 
    423432         * <!-- begin-user-doc --> 
     
    426435         * @ordered 
    427436         */ 
    428         int AX_INDEX__INDEXES = AX_INDEX_NODE_FEATURE_COUNT + 2; 
     437        int AX_INDEX__INDEXES = AX_INDEX_NODE_FEATURE_COUNT + 1; 
    429438 
    430439        /** 
     
    435444         * @ordered 
    436445         */ 
    437         int AX_INDEX__PARENT = AX_INDEX_NODE_FEATURE_COUNT + 3; 
     446        int AX_INDEX__PARENT = AX_INDEX_NODE_FEATURE_COUNT + 2; 
    438447 
    439448        /** 
     
    444453         * @ordered 
    445454         */ 
    446         int AX_INDEX_FEATURE_COUNT = AX_INDEX_NODE_FEATURE_COUNT + 4; 
     455        int AX_INDEX_FEATURE_COUNT = AX_INDEX_NODE_FEATURE_COUNT + 3; 
    447456 
    448457        /** 
     
    493502 
    494503        /** 
     504         * The feature id for the '<em><b>Level</b></em>' attribute. 
     505         * <!-- begin-user-doc --> 
     506         * <!-- end-user-doc --> 
     507         * @generated 
     508         * @ordered 
     509         */ 
     510        int AX_ROOT__LEVEL = AX_INDEX__LEVEL; 
     511 
     512        /** 
    495513         * The feature id for the '<em><b>Reference</b></em>' reference. 
    496514         * <!-- begin-user-doc --> 
     
    500518         */ 
    501519        int AX_ROOT__REFERENCE = AX_INDEX__REFERENCE; 
    502  
    503         /** 
    504          * The feature id for the '<em><b>Level</b></em>' attribute. 
    505          * <!-- begin-user-doc --> 
    506          * <!-- end-user-doc --> 
    507          * @generated 
    508          * @ordered 
    509          */ 
    510         int AX_ROOT__LEVEL = AX_INDEX__LEVEL; 
    511520 
    512521        /** 
     
    618627         */ 
    619628        int AX_ENTRY__BASIC_PARENT = AX_INDEX_NODE__BASIC_PARENT; 
     629 
     630        /** 
     631         * The feature id for the '<em><b>Level</b></em>' attribute. 
     632         * <!-- begin-user-doc --> 
     633         * <!-- end-user-doc --> 
     634         * @generated 
     635         * @ordered 
     636         */ 
     637        int AX_ENTRY__LEVEL = AX_INDEX_NODE__LEVEL; 
    620638 
    621639        /** 
     
    824842 
    825843        /** 
    826          * Returns the meta object for the attribute '{@link org.axdt.axdoc.model.AXIndex#getLevel <em>Level</em>}'. 
    827          * <!-- begin-user-doc --> 
    828          * <!-- end-user-doc --> 
    829          * @return the meta object for the attribute '<em>Level</em>'. 
    830          * @see org.axdt.axdoc.model.AXIndex#getLevel() 
    831          * @see #getAXIndex() 
    832          * @generated 
    833          */ 
    834         EAttribute getAXIndex_Level(); 
    835  
    836         /** 
    837844         * Returns the meta object for class '{@link org.axdt.axdoc.model.AXRoot <em>AX Root</em>}'. 
    838845         * <!-- begin-user-doc --> 
     
    984991         */ 
    985992        EReference getAXIndexNode_BasicParent(); 
     993 
     994        /**