Changeset 43

Show
Ignore:
Timestamp:
06/11/08 11:15:57 (7 months ago)
Author:
mb0
Message:
  • added some simple completion proposals
  • added simple swf viewer
  • added launcher that compiles and shows the swf

note: the builder does not compile anymore use the launcher instead

  • updated to version 0.0.2
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • axdt/trunk/org.axdt.as3/META-INF/MANIFEST.MF

    r31 r43  
    33Bundle-Name: Axdt Core Plug-in 
    44Bundle-SymbolicName: org.axdt.as3;singleton:=true 
    5 Bundle-Version: 0.0.1 
     5Bundle-Version: 0.0.2 
    66Bundle-Vendor: http://axdt.org 
    77Require-Bundle: org.eclipse.ui, 
  • axdt/trunk/org.axdt.as3/plugin.xml

    r31 r43  
    186186               id="org.eclipse.ui.views.ContentOutline"> 
    187187         </view> 
     188         <actionSet id="org.eclipse.debug.ui.launchActionSet"/> 
    188189      </perspectiveExtension> 
    189190   </extension> 
  • axdt/trunk/org.axdt.as3/src/org/axdt/as3/AS3Plugin.java

    r31 r43  
    11package org.axdt.as3; 
    22 
     3import java.net.URL; 
     4 
    35import org.eclipse.core.resources.ResourcesPlugin; 
     6import org.eclipse.core.runtime.FileLocator; 
     7import org.eclipse.core.runtime.IPath; 
     8import org.eclipse.core.runtime.Path; 
    49import org.eclipse.core.runtime.preferences.DefaultScope; 
    510import org.eclipse.imp.preferences.PreferencesService; 
    611import org.eclipse.imp.runtime.PluginBase; 
    712import org.eclipse.jface.resource.ImageDescriptor; 
     13import org.eclipse.jface.resource.ImageRegistry; 
     14import org.osgi.framework.Bundle; 
    815import org.osgi.framework.BundleContext; 
    916 
     
    4350        } 
    4451 
     52        /* 
     53         * (non-Javadoc) 
     54         * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext) 
     55         */ 
    4556        public void start(BundleContext context) throws Exception { 
    4657                super.start(context); 
    47  
    4858        } 
    4959 
     
    7484        // Definitions for image management 
    7585 
    76         public static final org.eclipse.core.runtime.IPath ICONS_PATH = new org.eclipse.core.runtime.Path( 
    77                         "icons/"); //$NON-NLS-1$("icons/"); //$NON-NLS-1$ 
     86        public static final IPath ICONS_PATH = new Path("icons/"); //$NON-NLS-1$ 
    7887 
    79         protected void initializeImageRegistry( 
    80                         org.eclipse.jface.resource.ImageRegistry reg) { 
     88        protected void initializeImageRegistry(ImageRegistry reg) { 
    8189                 
    8290                reg.put(IAS3Resources.AS3_DEFAULT_IMAGE, createImage("as3_default_image.gif"));//$NON-NLS-1$ 
     
    104112        } 
    105113 
    106         public static org.eclipse.jface.resource.ImageDescriptor createImageDescriptor( 
    107                         org.osgi.framework.Bundle bundle, 
    108                         org.eclipse.core.runtime.IPath path) { 
    109                 java.net.URL url = org.eclipse.core.runtime.FileLocator.find(bundle, 
    110                                 path, null); 
     114        public static ImageDescriptor createImageDescriptor(Bundle bundle, IPath path) { 
     115                URL url = FileLocator.find(bundle, path, null); 
    111116                if (url != null) { 
    112                         return org.eclipse.jface.resource.ImageDescriptor 
    113                                         .createFromURL(url); 
     117                        return ImageDescriptor.createFromURL(url); 
    114118                } 
    115119                return null; 
  • axdt/trunk/org.axdt.as3/src/org/axdt/as3/compiler/AS3Compiler.java

    r31 r43  
    11package org.axdt.as3.compiler; 
    22 
    3 import java.util.ArrayList; 
    4 import java.util.List; 
     3import java.util.HashMap; 
    54 
    65import org.axdt.as3.AS3Plugin; 
     
    1514public class AS3Compiler implements IAS3Compiler { 
    1615 
    17         private static List<Class<? extends IAS3Compiler>> compilers = new ArrayList<Class<? extends IAS3Compiler>>(); 
    18         private IAS3Compiler newInstance; 
     16        private static AS3Compiler instance = null; 
     17         
     18        private HashMap<String, AS3CompilerTarget> targets = null; 
     19         
     20        public static AS3Compiler getInstance() { 
     21                if (instance == null) { 
     22                        instance = new AS3Compiler(); 
     23                } 
     24                return instance; 
     25        } 
     26         
     27        public AS3Compiler() { 
     28                targets = new HashMap<String, AS3CompilerTarget>(); 
     29        } 
     30         
     31        private IAS3Compiler defaultCompiler; 
    1932 
    20         private IAS3Compiler getDefaultCompiler() { 
     33        public IExtension[] getComilersContributions() { 
    2134                IExtensionRegistry reg = Platform.getExtensionRegistry(); 
    2235                IExtensionPoint ep = reg.getExtensionPoint("org.axdt.as3.compilerContribution"); 
    23                 IExtension[] extensions = ep.getExtensions(); 
     36                return ep.getExtensions(); 
     37        } 
     38         
     39        private IAS3Compiler getDefaultCompiler() { 
     40                IExtension[] extensions = getComilersContributions(); 
    2441                for (int i = 0; i < extensions.length; i++) { 
    2542                        IExtension ext = extensions[i]; 
     
    3552                return null; 
    3653        } 
     54         
     55        public AS3CompilerTarget getTargetFor(IFile file) { 
     56                String key = file.getLocation().toOSString(); 
     57                if (!targets.containsKey(file.getLocation().toOSString())) { 
     58                        targets.put(key, new AS3CompilerTarget(file)); 
     59                } 
     60                return targets.get(key); 
     61        } 
    3762 
    3863        @Override 
    39         public void compileAS(IFile file, IProgressMonitor monitor) 
     64        public void compile(AS3CompilerTarget target, IProgressMonitor monitor) 
    4065                        throws Exception { 
    41                 if (newInstance == null) { 
    42                         newInstance = getDefaultCompiler(); 
     66                if (defaultCompiler == null) { 
     67                        defaultCompiler = getDefaultCompiler(); 
    4368                } 
    44                 newInstance.compileAS(file, monitor); 
    45         } 
    46  
    47         public static void registerCompiler(Class<? extends IAS3Compiler> class1) { 
    48                 compilers.add(class1); 
     69                defaultCompiler.compile(target, monitor); 
    4970        } 
    5071 
  • axdt/trunk/org.axdt.as3/src/org/axdt/as3/compiler/AS3CompilerTarget.java

    r31 r43  
    1111public class AS3CompilerTarget { 
    1212 
     13        protected Object context = null; 
    1314        private IResource resource; 
    1415        private String name; 
     
    2021        } 
    2122         
    22         public File getDeployFile() { 
    23                 return new File(getDeployPath().toOSString(),name); 
     23        public IPath getDeployFile() { 
     24                return getDeployPath().append(name); 
    2425        } 
    2526        public IPath getDeployPath() { 
     
    4849                return resource.getLocation().toOSString(); 
    4950        } 
    50         public String getName() { 
     51        public String getDeployName() { 
    5152                return name; 
    5253        } 
     54        public Object getContext() { 
     55                return context; 
     56        } 
     57        @SuppressWarnings("unchecked") 
     58        public <T> T getAdapter(Class<T> clazz) { 
     59                if (context != null && clazz.isAssignableFrom(context.getClass())) { 
     60                        return (T) context; 
     61                } 
     62                return null; 
     63        } 
     64 
     65        public void setContext(Object context) { 
     66                this.context = context; 
     67        } 
    5368} 
  • axdt/trunk/org.axdt.as3/src/org/axdt/as3/compiler/IAS3Compiler.java

    r31 r43  
    11package org.axdt.as3.compiler; 
    22 
    3 import org.axdt.as3.AS3Plugin; 
    4 import org.eclipse.core.resources.IFile; 
    53import org.eclipse.core.runtime.IProgressMonitor; 
    64 
    75public interface IAS3Compiler { 
    86 
    9         void compileAS(IFile file, IProgressMonitor monitor) throws Exception; 
     7        void compile(AS3CompilerTarget target, IProgressMonitor monitor) throws Exception; 
    108         
    119} 
  • axdt/trunk/org.axdt.as3/src/org/axdt/as3/imp/builders/AS3Builder.java

    r31 r43  
    137137         */ 
    138138        protected void compile(final IFile file, IProgressMonitor monitor) { 
    139                 monitor.beginTask("Building AS3 file: " + file.getName(), 100); 
    140                 boolean doCompile = runParserForCompiler(file, monitor); 
    141                 if (doCompile) { 
    142                         getPlugin().writeInfoMsg("Building AS3 file: " + file.getName()); 
    143                         try { 
    144                                 IAS3Compiler compiler = getCompiler(); 
    145                                 compiler.compileAS(file, monitor); 
    146                         } catch (Exception e) { 
    147                                 // catch Exception, because any exception could break the 
    148                                 // builder infra-structure. 
    149                                 getPlugin().logException(e.getMessage(), e); 
    150                         } 
    151                         doRefresh(file.getParent()); 
    152                 } 
    153                 monitor.done(); 
     139                runParserForCompiler(file, monitor); 
    154140        } 
    155141 
     
    166152         *            progress monitor 
    167153         */ 
    168         protected boolean runParserForCompiler(final IFile file, 
     154        protected void runParserForCompiler(final IFile file, 
    169155                        IProgressMonitor monitor) { 
    170156                try { 
     
    189175                                                        e); 
    190176                } 
    191                 return true; 
    192177        } 
    193178} 
  • axdt/trunk/org.axdt.as3/src/org/axdt/as3/imp/contentProposer/AS3ContentProposer.java

    r41 r43  
    1616 
    1717public class AS3ContentProposer implements IContentProposer { 
    18         private HashMap getVisibleVariables(AS3Parser parser, ASTNode n) { 
    19                 HashMap map = new HashMap(); 
    20                 for (AS3Parser.SymbolTable s = parser.getEnclosingSymbolTable(n); s != null; s = s 
    21                                 .getParent()) 
    22                         for (Enumeration e = s.keys(); e.hasMoreElements();) { 
    23                                 Object key = e.nextElement(); 
    24                                 if (!map.containsKey(key)) 
    25                                         map.put(key, s.get(key)); 
    26                         } 
    2718 
    28                 return map; 
    29         } 
    30  
    31         private String getVariableName(IAst decl) { 
    32                 if (decl instanceof VariableDeclarator) 
    33                         return ((VariableDeclarator) decl).getName().toString(); 
    34                 else if (decl instanceof MethodDeclaration) 
    35                         return ((MethodDeclaration) decl).getName().toString(); 
    36                 return ""; 
    37         } 
    38  
    39         // SMS 23 Apr 2008:  original 
    40         private String getVariableProposal(IAst decl) { 
    41                 String string = ""; 
    42                 if (decl instanceof VariableDeclarator) { 
    43                         string = ((VariableDeclarator) decl).getName().toString() + "  (" 
    44                                         + ((VariableDeclarator) decl).getType().toString() + ")"; 
    45                 } else if (decl instanceof MethodDeclaration) { 
    46                         MethodDeclaration fdecl = (MethodDeclaration) decl; 
    47                         FormalParameterList parameters = fdecl.getParameterBlock().getParameters(); 
    48                         string = fdecl.getReturnType().toString() + " " 
    49                                         + fdecl.getName().toString() + "("; 
    50                         for (int i = 0; i < parameters.size(); i++) 
    51                                 string += parameters.getFormalParameterAt(i).getType().toString() 
    52                                                 + (i < parameters.size() - 1 ? ", " : ""); 
    53                         string += ")"; 
    54                 } 
    55                 return string; 
    56         } 
    57  
    58         // SMS 23 Apr 2008:  which had been replaced by ... 
    59         private SourceProposal getDeclProposal(IAst decl, String prefix, int offset) { 
    60                 if (decl instanceof VariableDeclarator) { 
    61                         String s = ((VariableDeclarator) decl).getType().toString() + " " 
    62                                         + ((VariableDeclarator) decl).getName().toString(); 
    63                         return new SourceProposal(s, s, prefix, offset); 
    64                 } else if (decl instanceof MethodDeclaration) { 
    65                         MethodDeclaration fdecl = (MethodDeclaration) decl; 
    66                         FormalParameterList parameters = fdecl.getParameterBlock().getParameters(); 
    67                         String newText; 
    68  
    69                         newText = fdecl.getName().toString() 
    70                                         + "("; 
    71                         for (int i = 0; i < parameters.size(); i++) 
    72                                 newText += parameters.getFormalParameterAt(i).getType() 
    73                                                 + (i < parameters.size() - 1 ? ", " : ""); 
    74                         newText += ")"; 
    75                         String proposal = fdecl.getReturnType().toString() 
    76                                         + " " + newText; 
    77                         return new SourceProposal(proposal, newText, prefix, offset); 
    78                 } 
    79                 return null; 
    80         } 
    81  
    82         private ArrayList filterSymbols(HashMap in_symbols, String prefix) { 
    83                 ArrayList symbols = new ArrayList(); 
    84                 for (Iterator i = in_symbols.values().iterator(); i.hasNext();) { 
    85                         IAst decl = (IAst) i.next(); 
    86                         String name = getVariableName(decl); 
    87                         if (name.length() >= prefix.length() 
    88                                         && prefix.equals(name.substring(0, prefix.length()))) 
    89                                 symbols.add(decl); 
    90                 } 
    91  
    92                 return symbols; 
    93         } 
     19        private static final String[] keywords = new String[] {"public","private","protected","internal", 
     20                        "static","final","dynamic","override", 
     21                        "class","interface","use","namespace","function","var","const", 
     22                        "import"}; 
    9423 
    9524        private IToken getToken(IParseController controller, int offset) { 
     
    11342                return ""; 
    11443        } 
    115  
    116         private static String[] keywords = new String[] {"public","private","protected","internal", 
    117                         "static","final","dynamic","override", 
    118                         "class","interface","use","namespace","function","var","const", 
    119                         "import"}; 
    12044        /** 
    12145         * Returns an array of content proposals applicable relative to the AST of the given 
     
    200124                                        "no info available due to Syntax error(s)", "", offset)); 
    201125                } 
    202                 return (ICompletionProposal[]) list 
    203                                 .toArray(new ICompletionProposal[list.size()]); 
     126                return (ICompletionProposal[]) list.toArray(new ICompletionProposal[list.size()]); 
    204127        } 
    205128} 
  • axdt/trunk/org.axdt.feature/feature.xml

    r34 r43  
    33      id="org.axdt.feature" 
    44      label="AXDT Feature" 
    5       version="0.0.1
     5      version="0.0.2
    66      provider-name="http://axdt.org"> 
    77 
     
    4040         version="0.0.0"/> 
    4141 
     42   <plugin 
     43         id="org.axdt.as3.launcher" 
     44         download-size="0" 
     45         install-size="0" 
     46         version="0.0.0" 
     47         unpack="false"/> 
     48 
     49   <plugin 
     50         id="org.axdt.swfview" 
     51         download-size="0" 
     52         install-size="0" 
     53         version="0.0.0" 
     54         unpack="false"/> 
     55 
    4256</feature> 
  • axdt/trunk/org.axdt.flex3sdk/META-INF/MANIFEST.MF

    r31 r43  
    33Bundle-Name: AXDT Flex3 SDK Integration Plug-in 
    44Bundle-SymbolicName: org.axdt.flex3sdk;singleton:=true 
    5 Bundle-Version: 0.0.1 
     5Bundle-Version: 0.0.2 
    66Bundle-Activator: org.axdt.flex3sdk.Activator 
    77Bundle-Vendor: http://axdt.org 
    88Require-Bundle: org.eclipse.core.runtime, 
    9  org.axdt.as3;bundle-version="0.0.1"
     9 org.axdt.as3
    1010 org.eclipse.core.resources, 
    1111 org.eclipse.imp.runtime 
  • axdt/trunk/org.axdt.flex3sdk/src/org/axdt/flex3sdk/Flex3Compiler.java

    r38 r43  
    11package org.axdt.flex3sdk; 
    22 
    3 import java.util.Collection
    4 import java.util.HashMap
     3import java.io.File
     4import java.io.FileNotFoundException
    55 
    66import org.axdt.as3.AS3Plugin; 
     7import org.axdt.as3.compiler.AS3CompilerTarget; 
    78import org.axdt.as3.compiler.IAS3Compiler; 
    8 import org.eclipse.core.resources.IFile; 
    9 import org.eclipse.core.resources.IProject; 
    10 import org.eclipse.core.resources.IResource; 
    11 import org.eclipse.core.resources.IResourceVisitor; 
    12 import org.eclipse.core.runtime.CoreException; 
    139import org.eclipse.core.runtime.IProgressMonitor; 
    1410import org.eclipse.core.runtime.SubProgressMonitor; 
    1511 
    1612import flex2.tools.oem.Application; 
     13import flex2.tools.oem.Configuration; 
    1714import flex2.tools.oem.Logger; 
    1815import flex2.tools.oem.Message; 
     
    2118public class Flex3Compiler implements Logger, IAS3Compiler { 
    2219 
    23         private HashMap<String, Flex3Target> appmap = null; 
    24  
    2520        public Flex3Compiler() { 
    26                 appmap = new HashMap<String, Flex3Target>(); 
    2721        } 
    2822         
    29         private void updateTargets(IProject project) throws CoreException { 
    30                 project.accept(new IResourceVisitor(){ 
    31                         public boolean visit(IResource resource) throws CoreException { 
    32                                 String myext = resource.getFileExtension(); 
    33                                 if ("as".equals(myext)||"mxml".equals(myext)) { 
    34                                         String id = resource.getLocation().toOSString(); 
    35                                         if (!appmap.containsKey(id)) 
    36                                                 appmap.put(id, new Flex3Target(resource)); 
    37                                 } 
    38                                 return true; 
    39                         }}, 1, false); 
    40         } 
    41  
    42         public void compileAS(IFile file, IProgressMonitor monitor) throws Exception { 
    43                 IProject project = file.getProject(); 
    44                 updateTargets(project); 
    45                 if (!appmap.containsKey(file.getLocation().toOSString())) 
    46                         return; 
    47                 Collection<Flex3Target> targets = appmap.values(); 
    48                 monitor = new SubProgressMonitor(monitor,100); 
    49                 monitor.beginTask("Compiling Targets", 100*targets.size()); 
    50                 for (Flex3Target target:targets) { 
    51                         if (monitor.isCanceled()) return; 
    52                         Application app = target.getApplication(); 
    53                         if (app == null) { 
    54                                 app = target.createApplication(); 
    55                                 app.getConfiguration().optimize(true); 
    56                                 app.setLogger(this); 
    57                         } 
    58                         app.setProgressMeter(new ProgressMonitor(monitor,target.getName())); 
    59                         app.build(true); 
    60                         app.setProgressMeter(null); 
     23        @Override 
     24        public void compile(AS3CompilerTarget target, IProgressMonitor monitor) 
     25                        throws Exception { 
     26                Application app = target.getAdapter(Application.class); 
     27                if (app == null) { 
     28                        app = createApplication(target); 
     29                        app.getConfiguration().optimize(true); 
     30                        app.setLogger(this); 
     31                        target.setContext(app); 
    6132                } 
    62                 monitor.done(); 
     33                File parentFile = app.getOutput().getParentFile(); 
     34                if (!parentFile.exists()) { 
     35                        parentFile.mkdir(); 
     36                } 
     37                app.setProgressMeter(new ProgressMonitor(monitor,target.getDeployName())); 
     38                app.build(true); 
     39                app.setProgressMeter(null); 
    6340        } 
    6441         
     42 
     43        private Application createApplication(AS3CompilerTarget target) throws FileNotFoundException { 
     44                Application app = new Application(target.getFile()); 
     45                File file = target.getDeployFile().toFile(); 
     46                app.setOutput(file); 
     47                Configuration config = app.getDefaultConfiguration(); 
     48                File[] sourcePaths = target.getSourcePaths(); 
     49                config.addSourcePath(sourcePaths); 
     50                config.allowSourcePathOverlap(true); 
     51                app.setConfiguration(config); 
     52                return app; 
     53        } 
    6554 
    6655        public void log(Message msg, int arg1, String arg2) {