java.srclessopen is part of std. distro, deleting it from contrib
authorJan Lahoda <jlahoda@netbeans.org>
Thu, 23 Sep 2010 15:36:26 +0200
changeset 163827b1a1aed83e8
parent 16381 88087e92b614
child 16384 517516a7e27d
java.srclessopen is part of std. distro, deleting it from contrib
java.srclessopen/build.xml
java.srclessopen/manifest.mf
java.srclessopen/nbproject/project.properties
java.srclessopen/nbproject/project.xml
java.srclessopen/src/org/netbeans/modules/java/srclessopen/BinaryElementOpenImpl.java
java.srclessopen/src/org/netbeans/modules/java/srclessopen/Bundle.properties
java.srclessopen/src/org/netbeans/modules/java/srclessopen/CodeGenerator.java
java.srclessopen/src/org/netbeans/modules/java/srclessopen/Index.java
java.srclessopen/src/org/netbeans/modules/java/srclessopen/layer.xml
java.srclessopen/test/unit/src/org/netbeans/modules/java/srclessopen/CodeGeneratorTest.java
     1.1 --- a/java.srclessopen/build.xml	Fri Sep 17 18:38:20 2010 -0400
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,5 +0,0 @@
     1.4 -<?xml version="1.0" encoding="UTF-8"?>
     1.5 -<project basedir="." default="netbeans" name="contrib/java.srclessopen">
     1.6 -    <description>Builds, tests, and runs the project org.netbeans.modules.java.srclessopen</description>
     1.7 -    <import file="../../nbbuild/templates/projectized.xml"/>
     1.8 -</project>
     2.1 --- a/java.srclessopen/manifest.mf	Fri Sep 17 18:38:20 2010 -0400
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,6 +0,0 @@
     2.4 -Manifest-Version: 1.0
     2.5 -OpenIDE-Module: org.netbeans.modules.java.srclessopen/0
     2.6 -OpenIDE-Module-Implementation-Version: 1
     2.7 -xOpenIDE-Module-Layer: org/netbeans/modules/java/srclessopen/layer.xml
     2.8 -OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/java/srclessopen/Bundle.properties
     2.9 -
     3.1 --- a/java.srclessopen/nbproject/project.properties	Fri Sep 17 18:38:20 2010 -0400
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,4 +0,0 @@
     3.4 -javac.compilerargs=-Xlint -Xlint:-serial
     3.5 -javac.source=1.5
     3.6 -spec.version.base=1.3
     3.7 -
     4.1 --- a/java.srclessopen/nbproject/project.xml	Fri Sep 17 18:38:20 2010 -0400
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,108 +0,0 @@
     4.4 -<?xml version="1.0" encoding="UTF-8"?>
     4.5 -<project xmlns="http://www.netbeans.org/ns/project/1">
     4.6 -    <type>org.netbeans.modules.apisupport.project</type>
     4.7 -    <configuration>
     4.8 -        <data xmlns="http://www.netbeans.org/ns/nb-module-project/3">
     4.9 -            <code-name-base>org.netbeans.modules.java.srclessopen</code-name-base>
    4.10 -            <module-dependencies>
    4.11 -                <dependency>
    4.12 -                    <code-name-base>org.netbeans.api.java</code-name-base>
    4.13 -                    <build-prerequisite/>
    4.14 -                    <compile-dependency/>
    4.15 -                    <run-dependency>
    4.16 -                        <release-version>1</release-version>
    4.17 -                        <specification-version>1.18</specification-version>
    4.18 -                    </run-dependency>
    4.19 -                </dependency>
    4.20 -                <dependency>
    4.21 -                    <code-name-base>org.netbeans.api.java.classpath</code-name-base>
    4.22 -                    <build-prerequisite/>
    4.23 -                    <compile-dependency/>
    4.24 -                    <run-dependency>
    4.25 -                        <release-version>1</release-version>
    4.26 -                        <specification-version>1.0</specification-version>
    4.27 -                    </run-dependency>
    4.28 -                </dependency>
    4.29 -                <dependency>
    4.30 -                    <code-name-base>org.netbeans.libs.javacapi</code-name-base>
    4.31 -                    <build-prerequisite/>
    4.32 -                    <compile-dependency/>
    4.33 -                    <run-dependency>
    4.34 -                        <specification-version>0.5</specification-version>
    4.35 -                    </run-dependency>
    4.36 -                </dependency>
    4.37 -                <dependency>
    4.38 -                    <code-name-base>org.netbeans.modules.java.project</code-name-base>
    4.39 -                    <build-prerequisite/>
    4.40 -                    <compile-dependency/>
    4.41 -                    <run-dependency>
    4.42 -                        <release-version>1</release-version>
    4.43 -                        <specification-version>1.12</specification-version>
    4.44 -                    </run-dependency>
    4.45 -                </dependency>
    4.46 -                <dependency>
    4.47 -                    <code-name-base>org.netbeans.modules.java.source</code-name-base>
    4.48 -                    <build-prerequisite/>
    4.49 -                    <compile-dependency/>
    4.50 -                    <run-dependency>
    4.51 -                        <implementation-version/>
    4.52 -                    </run-dependency>
    4.53 -                </dependency>
    4.54 -                <dependency>
    4.55 -                    <code-name-base>org.openide.filesystems</code-name-base>
    4.56 -                    <build-prerequisite/>
    4.57 -                    <compile-dependency/>
    4.58 -                    <run-dependency>
    4.59 -                        <specification-version>7.3</specification-version>
    4.60 -                    </run-dependency>
    4.61 -                </dependency>
    4.62 -                <dependency>
    4.63 -                    <code-name-base>org.openide.loaders</code-name-base>
    4.64 -                    <build-prerequisite/>
    4.65 -                    <compile-dependency/>
    4.66 -                    <run-dependency>
    4.67 -                        <specification-version>6.7</specification-version>
    4.68 -                    </run-dependency>
    4.69 -                </dependency>
    4.70 -                <dependency>
    4.71 -                    <code-name-base>org.openide.nodes</code-name-base>
    4.72 -                    <build-prerequisite/>
    4.73 -                    <compile-dependency/>
    4.74 -                    <run-dependency>
    4.75 -                        <specification-version>7.2</specification-version>
    4.76 -                    </run-dependency>
    4.77 -                </dependency>
    4.78 -                <dependency>
    4.79 -                    <code-name-base>org.openide.util</code-name-base>
    4.80 -                    <build-prerequisite/>
    4.81 -                    <compile-dependency/>
    4.82 -                    <run-dependency>
    4.83 -                        <specification-version>7.9</specification-version>
    4.84 -                    </run-dependency>
    4.85 -                </dependency>
    4.86 -            </module-dependencies>
    4.87 -            <test-dependencies>
    4.88 -                <test-type>
    4.89 -                    <name>unit</name>
    4.90 -                    <test-dependency>
    4.91 -                        <code-name-base>org.netbeans.bootstrap</code-name-base>
    4.92 -                    </test-dependency>
    4.93 -                    <test-dependency>
    4.94 -                        <code-name-base>org.netbeans.core.startup</code-name-base>
    4.95 -                    </test-dependency>
    4.96 -                    <test-dependency>
    4.97 -                        <code-name-base>org.netbeans.modules.editor.mimelookup</code-name-base>
    4.98 -                        <compile-dependency/>
    4.99 -                        <test/>
   4.100 -                    </test-dependency>
   4.101 -                    <test-dependency>
   4.102 -                        <code-name-base>org.netbeans.modules.java.source</code-name-base>
   4.103 -                        <compile-dependency/>
   4.104 -                        <test/>
   4.105 -                    </test-dependency>
   4.106 -                </test-type>
   4.107 -            </test-dependencies>
   4.108 -            <public-packages/>
   4.109 -        </data>
   4.110 -    </configuration>
   4.111 -</project>
     5.1 --- a/java.srclessopen/src/org/netbeans/modules/java/srclessopen/BinaryElementOpenImpl.java	Fri Sep 17 18:38:20 2010 -0400
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,55 +0,0 @@
     5.4 -/*
     5.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     5.6 - * 
     5.7 - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
     5.8 - * 
     5.9 - * The contents of this file are subject to the terms of either the GNU
    5.10 - * General Public License Version 2 only ("GPL") or the Common
    5.11 - * Development and Distribution License("CDDL") (collectively, the
    5.12 - * "License"). You may not use this file except in compliance with the
    5.13 - * License. You can obtain a copy of the License at
    5.14 - * http://www.netbeans.org/cddl-gplv2.html
    5.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    5.16 - * specific language governing permissions and limitations under the
    5.17 - * License.  When distributing the software, include this License Header
    5.18 - * Notice in each file and include the License file at
    5.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
    5.20 - * particular file as subject to the "Classpath" exception as provided
    5.21 - * by Sun in the GPL Version 2 section of the License file that
    5.22 - * accompanied this code. If applicable, add the following below the
    5.23 - * License Header, with the fields enclosed by brackets [] replaced by
    5.24 - * your own identifying information:
    5.25 - * "Portions Copyrighted [year] [name of copyright owner]"
    5.26 - * 
    5.27 - * Contributor(s):
    5.28 - * 
    5.29 - * Portions Copyrighted 2007 Sun Microsystems, Inc.
    5.30 - */
    5.31 -
    5.32 -package org.netbeans.modules.java.srclessopen;
    5.33 -
    5.34 -import javax.lang.model.element.Element;
    5.35 -import org.netbeans.api.java.source.ClasspathInfo;
    5.36 -import org.netbeans.api.java.source.ElementHandle;
    5.37 -import org.netbeans.api.java.source.UiUtils;
    5.38 -import org.netbeans.modules.java.BinaryElementOpen;
    5.39 -import org.openide.filesystems.FileObject;
    5.40 -
    5.41 -/**
    5.42 - *
    5.43 - * @author lahvac
    5.44 - */
    5.45 -@org.openide.util.lookup.ServiceProvider(service=org.netbeans.modules.java.BinaryElementOpen.class)
    5.46 -public class BinaryElementOpenImpl implements BinaryElementOpen {
    5.47 -
    5.48 -    public boolean open(ClasspathInfo cpInfo, ElementHandle<? extends Element> toOpen) {
    5.49 -        FileObject source = CodeGenerator.generateCode(cpInfo, toOpen);
    5.50 -        
    5.51 -        if (source != null) {
    5.52 -            return UiUtils.open(source, 0);
    5.53 -        } else {
    5.54 -            return false;
    5.55 -        }
    5.56 -    }
    5.57 -
    5.58 -}
     6.1 --- a/java.srclessopen/src/org/netbeans/modules/java/srclessopen/Bundle.properties	Fri Sep 17 18:38:20 2010 -0400
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,5 +0,0 @@
     6.4 -OpenIDE-Module-Display-Category=Java
     6.5 -OpenIDE-Module-Long-Description=\
     6.6 -    Allows to open sourceless Java classes in the editor.
     6.7 -OpenIDE-Module-Name=Open Sourceless Java Classes
     6.8 -OpenIDE-Module-Short-Description=Allows to open sourceless Java classes in the editor
     7.1 --- a/java.srclessopen/src/org/netbeans/modules/java/srclessopen/CodeGenerator.java	Fri Sep 17 18:38:20 2010 -0400
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,454 +0,0 @@
     7.4 -/*
     7.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     7.6 - * 
     7.7 - * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
     7.8 - * 
     7.9 - * The contents of this file are subject to the terms of either the GNU
    7.10 - * General Public License Version 2 only ("GPL") or the Common
    7.11 - * Development and Distribution License("CDDL") (collectively, the
    7.12 - * "License"). You may not use this file except in compliance with the
    7.13 - * License. You can obtain a copy of the License at
    7.14 - * http://www.netbeans.org/cddl-gplv2.html
    7.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    7.16 - * specific language governing permissions and limitations under the
    7.17 - * License.  When distributing the software, include this License Header
    7.18 - * Notice in each file and include the License file at
    7.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
    7.20 - * particular file as subject to the "Classpath" exception as provided
    7.21 - * by Sun in the GPL Version 2 section of the License file that
    7.22 - * accompanied this code. If applicable, add the following below the
    7.23 - * License Header, with the fields enclosed by brackets [] replaced by
    7.24 - * your own identifying information:
    7.25 - * "Portions Copyrighted [year] [name of copyright owner]"
    7.26 - * 
    7.27 - * Contributor(s):
    7.28 - * 
    7.29 - * Portions Copyrighted 2007-2009 Sun Microsystems, Inc.
    7.30 - */
    7.31 -
    7.32 -package org.netbeans.modules.java.srclessopen;
    7.33 -import com.sun.source.tree.AnnotationTree;
    7.34 -import com.sun.source.tree.BlockTree;
    7.35 -import com.sun.source.tree.CompilationUnitTree;
    7.36 -import com.sun.source.tree.ExpressionTree;
    7.37 -import com.sun.source.tree.ImportTree;
    7.38 -import com.sun.source.tree.LiteralTree;
    7.39 -import com.sun.source.tree.ModifiersTree;
    7.40 -import com.sun.source.tree.Tree;
    7.41 -import com.sun.source.tree.TypeParameterTree;
    7.42 -import com.sun.source.tree.VariableTree;
    7.43 -import java.io.ByteArrayInputStream;
    7.44 -import java.io.File;
    7.45 -import java.io.IOException;
    7.46 -import java.io.OutputStream;
    7.47 -import java.util.Arrays;
    7.48 -import java.util.Collections;
    7.49 -import java.util.EnumSet;
    7.50 -import java.util.HashMap;
    7.51 -import java.util.LinkedList;
    7.52 -import java.util.List;
    7.53 -import java.util.Map;
    7.54 -import java.util.Map.Entry;
    7.55 -import java.util.Set;
    7.56 -import javax.lang.model.element.AnnotationMirror;
    7.57 -import javax.lang.model.element.AnnotationValue;
    7.58 -import javax.lang.model.element.AnnotationValueVisitor;
    7.59 -import javax.lang.model.element.Element;
    7.60 -import javax.lang.model.element.ElementKind;
    7.61 -import javax.lang.model.element.ExecutableElement;
    7.62 -import javax.lang.model.element.Modifier;
    7.63 -import javax.lang.model.element.PackageElement;
    7.64 -import javax.lang.model.element.TypeElement;
    7.65 -import javax.lang.model.element.TypeParameterElement;
    7.66 -import javax.lang.model.element.VariableElement;
    7.67 -import javax.lang.model.type.DeclaredType;
    7.68 -import javax.lang.model.type.TypeKind;
    7.69 -import javax.lang.model.type.TypeMirror;
    7.70 -import javax.lang.model.util.AbstractElementVisitor6;
    7.71 -import org.netbeans.api.java.classpath.ClassPath;
    7.72 -import org.netbeans.api.java.source.ClasspathInfo;
    7.73 -import org.netbeans.api.java.source.ClasspathInfo.PathKind;
    7.74 -import org.netbeans.api.java.source.ElementHandle;
    7.75 -import org.netbeans.api.java.source.JavaSource;
    7.76 -import org.netbeans.api.java.source.JavaSource.Phase;
    7.77 -import org.netbeans.api.java.source.ModificationResult;
    7.78 -import org.netbeans.api.java.source.Task;
    7.79 -import org.netbeans.api.java.source.TreeMaker;
    7.80 -import org.netbeans.api.java.source.WorkingCopy;
    7.81 -import org.netbeans.spi.java.classpath.support.ClassPathSupport;
    7.82 -import org.openide.filesystems.FileObject;
    7.83 -import org.openide.filesystems.FileUtil;
    7.84 -import org.openide.util.Exceptions;
    7.85 -
    7.86 -/**
    7.87 - *
    7.88 - * @author lahvac
    7.89 - */
    7.90 -public class CodeGenerator {
    7.91 -
    7.92 -    public static FileObject generateCode(final ClasspathInfo cpInfo, final ElementHandle<? extends Element> toOpenHandle) {
    7.93 -        try {
    7.94 -            FileObject file = FileUtil.createMemoryFileSystem().getRoot().createData("test.java");
    7.95 -            OutputStream out = file.getOutputStream();
    7.96 -            
    7.97 -            try {
    7.98 -                FileUtil.copy(new ByteArrayInputStream(""/*"class test{}"*/.getBytes("UTF-8")), out);
    7.99 -            } finally {
   7.100 -                out.close();
   7.101 -            }
   7.102 -            
   7.103 -            JavaSource js = JavaSource.create(cpInfo, file);
   7.104 -            final FileObject[] result = new FileObject[1];
   7.105 -            final boolean[] sourceGenerated = new boolean[1];
   7.106 -
   7.107 -            ModificationResult r = js.runModificationTask(new Task<WorkingCopy>() {
   7.108 -                public void run(WorkingCopy wc) throws Exception {
   7.109 -                    wc.toPhase(Phase.PARSED);
   7.110 -                    
   7.111 -                    Element toOpen = toOpenHandle.resolve(wc);
   7.112 -                    TypeElement te = toOpen != null ? wc.getElementUtilities().outermostTypeElement(toOpen) : null;
   7.113 -
   7.114 -                    if (te == null) {
   7.115 -                        return; //TODO
   7.116 -                    }
   7.117 -
   7.118 -                    te = wc.getElementUtilities().outermostTypeElement(te);
   7.119 -                    
   7.120 -                    ClassPath cp = ClassPathSupport.createProxyClassPath(cpInfo.getClassPath(PathKind.BOOT), cpInfo.getClassPath(PathKind.COMPILE), cpInfo.getClassPath(PathKind.SOURCE));
   7.121 -                    FileObject resource = cp.findResource(te.getQualifiedName().toString().replace('.', '/') + ".class");
   7.122 -                    
   7.123 -                    if (resource == null) {
   7.124 -                        return ;
   7.125 -                    }
   7.126 -                    
   7.127 -                    FileObject root = cp.findOwnerRoot(resource);
   7.128 -                    
   7.129 -                    if (root == null) {
   7.130 -                        return ; //???
   7.131 -                    }
   7.132 -                    
   7.133 -                    File sourceRoot = Index.getSourceFolder(root.getURL(), false);
   7.134 -                    FileObject sourceRootFO = FileUtil.toFileObject(sourceRoot);
   7.135 -                    
   7.136 -                    if (sourceRootFO == null) {
   7.137 -                        return ; //???
   7.138 -                    }
   7.139 -                    
   7.140 -                    String path = te.getQualifiedName().toString().replace('.', '/') + ".java";
   7.141 -                    
   7.142 -                    FileObject source = sourceRootFO.getFileObject(path);
   7.143 -                    
   7.144 -                    if (source != null) {
   7.145 -                        result[0] = source;
   7.146 -                        return ;
   7.147 -                    }
   7.148 -                    
   7.149 -                    result[0] = FileUtil.createData(sourceRootFO, path);
   7.150 -                    CompilationUnitTree cut = generateCode(wc, te);
   7.151 -
   7.152 -                    wc.rewrite(wc.getCompilationUnit(), cut);
   7.153 -                    
   7.154 -                    sourceGenerated[0] = true;
   7.155 -                }
   7.156 -            });
   7.157 -
   7.158 -            if (sourceGenerated[0]) {
   7.159 -                out = result[0].getOutputStream();
   7.160 -                
   7.161 -                try {
   7.162 -                    FileUtil.copy(new ByteArrayInputStream(r.getResultingSource(file).getBytes("UTF-8")), out);
   7.163 -                } finally {
   7.164 -                    out.close();
   7.165 -                }
   7.166 -            }
   7.167 -            
   7.168 -            return result[0];
   7.169 -        } catch (IOException ex) {
   7.170 -            Exceptions.printStackTrace(ex);
   7.171 -            return null;
   7.172 -        }
   7.173 -    }
   7.174 -    
   7.175 -    static CompilationUnitTree generateCode(WorkingCopy wc, TypeElement te) {
   7.176 -        TreeMaker make = wc.getTreeMaker();
   7.177 -        Tree clazz = new TreeBuilder(make, wc).visit(te);
   7.178 -        CompilationUnitTree cut = make.CompilationUnit(make.Identifier(((PackageElement) te.getEnclosingElement()).getQualifiedName()),
   7.179 -                Collections.<ImportTree>emptyList(),
   7.180 -                Collections.singletonList(clazz),
   7.181 -                wc.getCompilationUnit().getSourceFile());
   7.182 -        
   7.183 -        return cut;
   7.184 -    }
   7.185 -
   7.186 -    private static final class TreeBuilder extends AbstractElementVisitor6<Tree, Void> {
   7.187 -
   7.188 -        private TreeMaker make;
   7.189 -        private WorkingCopy wc;
   7.190 -
   7.191 -        public TreeBuilder(TreeMaker make, WorkingCopy wc) {
   7.192 -            this.make = make;
   7.193 -            this.wc = wc;
   7.194 -        }
   7.195 -        
   7.196 -        public Tree visitPackage(PackageElement e, Void p) {
   7.197 -            throw new UnsupportedOperationException("Not supported.");
   7.198 -        }
   7.199 -
   7.200 -        public Tree visitType(TypeElement e, Void p) {
   7.201 -            List<Tree> members = new LinkedList<Tree>();
   7.202 -            
   7.203 -            for (Element m : e.getEnclosedElements()) {
   7.204 -                Tree member = visit(m);
   7.205 -                
   7.206 -                if (member != null)
   7.207 -                    members.add(member);
   7.208 -            }
   7.209 -
   7.210 -            ModifiersTree mods = computeMods(e);
   7.211 -            
   7.212 -            switch (e.getKind()) {
   7.213 -                case CLASS:
   7.214 -                    return make.Class(mods, e.getSimpleName(), constructTypeParams(e.getTypeParameters()), computeSuper(e.getSuperclass()), computeSuper(e.getInterfaces()), members);
   7.215 -                case INTERFACE:
   7.216 -                    return make.Interface(mods, e.getSimpleName(), constructTypeParams(e.getTypeParameters()), computeSuper(e.getInterfaces()), members);
   7.217 -                case ENUM:
   7.218 -                    return make.Enum(mods, e.getSimpleName(), computeSuper(e.getInterfaces()), members);
   7.219 -                case ANNOTATION_TYPE:
   7.220 -                    return make.AnnotationType(mods, e.getSimpleName(), members);
   7.221 -                default:
   7.222 -                    throw new UnsupportedOperationException();
   7.223 -            }
   7.224 -        }
   7.225 -
   7.226 -        private ModifiersTree computeMods(Element e) {
   7.227 -            Set<Modifier> implicitModifiers = IMPLICIT_MODIFIERS.get(Arrays.asList(e.getKind()));
   7.228 -
   7.229 -            if (implicitModifiers == null) {
   7.230 -                implicitModifiers = IMPLICIT_MODIFIERS.get(Arrays.asList(e.getKind(), e.getEnclosingElement().getKind()));
   7.231 -            }
   7.232 -
   7.233 -            Set<Modifier> modifiers = EnumSet.noneOf(Modifier.class);
   7.234 -
   7.235 -            modifiers.addAll(e.getModifiers());
   7.236 -
   7.237 -            if (implicitModifiers != null) {
   7.238 -                modifiers.removeAll(implicitModifiers);
   7.239 -            }
   7.240 -
   7.241 -            List<AnnotationTree> annotations = new LinkedList<AnnotationTree>();
   7.242 -
   7.243 -            for (AnnotationMirror m : e.getAnnotationMirrors()) {
   7.244 -                annotations.add(computeAnnotationTree(m));
   7.245 -            }
   7.246 -            
   7.247 -            return make.Modifiers(modifiers, annotations);
   7.248 -        }
   7.249 -
   7.250 -        private AnnotationTree computeAnnotationTree(AnnotationMirror am) {
   7.251 -            List<ExpressionTree> params = new LinkedList<ExpressionTree>();
   7.252 -
   7.253 -            for (Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : am.getElementValues().entrySet()) {
   7.254 -                ExpressionTree vt = make.Assignment(make.Identifier(entry.getKey().getSimpleName()), createTreeForAnnotationValue(make, entry.getValue()));
   7.255 -
   7.256 -                params.add(vt);
   7.257 -            }
   7.258 -
   7.259 -            return make.Annotation(make.Type(am.getAnnotationType()), params);
   7.260 -        }
   7.261 -        
   7.262 -        private Tree computeSuper(TypeMirror superClass) {
   7.263 -            if (superClass == null) return null;
   7.264 -            if (superClass.getKind() == TypeKind.NONE) return null; //for j.l.Object
   7.265 -            TypeElement jlObject = wc.getElements().getTypeElement("java.lang.Object");
   7.266 -            if (wc.getTypes().isSameType(superClass, jlObject.asType())) return null; //for extends j.l.Object
   7.267 -            
   7.268 -            return make.Type(superClass);
   7.269 -        }
   7.270 -        
   7.271 -        private List<Tree> computeSuper(List<? extends TypeMirror> superTypes) {
   7.272 -            List<Tree> sup = new LinkedList<Tree>();
   7.273 -            
   7.274 -            if (superTypes != null) {
   7.275 -                for (TypeMirror tm : superTypes) {
   7.276 -                    sup.add(make.Type(tm));
   7.277 -                }
   7.278 -            }
   7.279 -            
   7.280 -            return sup;
   7.281 -        }
   7.282 -        
   7.283 -        private List<? extends TypeParameterTree> constructTypeParams(List<? extends TypeParameterElement> params) {
   7.284 -            List<TypeParameterTree> result = new LinkedList<TypeParameterTree>();
   7.285 -            
   7.286 -            for (TypeParameterElement e : params) {
   7.287 -                result.add((TypeParameterTree) visit(e));
   7.288 -            }
   7.289 -            
   7.290 -            return result;
   7.291 -        }
   7.292 -        
   7.293 -        public Tree visitVariable(VariableElement e, Void p) {
   7.294 -            if (e.getKind() == ElementKind.ENUM_CONSTANT) {
   7.295 -                int mods = 1 << 14;
   7.296 -                ModifiersTree modifiers = make.Modifiers(mods, Collections.<AnnotationTree>emptyList());
   7.297 -                
   7.298 -                return make.Variable(modifiers,
   7.299 -                                     e.getSimpleName().toString(),
   7.300 -                                     make.Identifier(e.getEnclosingElement().getSimpleName().toString()),
   7.301 -                                     null);
   7.302 -            }
   7.303 -            
   7.304 -            ModifiersTree mods = computeMods(e);
   7.305 -            LiteralTree init = e.getConstantValue() != null ? make.Literal(e.getConstantValue()) : null;
   7.306 -            
   7.307 -            return make.Variable(mods, e.getSimpleName(), make.Type(e.asType()), init);
   7.308 -        }
   7.309 -
   7.310 -        public Tree visitExecutable(ExecutableElement e, Void p) {
   7.311 -            if (e.getKind() == ElementKind.STATIC_INIT || e.getKind() == ElementKind.INSTANCE_INIT) {
   7.312 -                return null; //XXX
   7.313 -            }
   7.314 -            
   7.315 -            if (wc.getElementUtilities().isSynthetic(e)) {
   7.316 -                return null;
   7.317 -            }
   7.318 -            
   7.319 -            //special case: <parent>[] values(), <parent> value(String) if <parent> is enum:
   7.320 -            if (e.getEnclosingElement().getKind() == ElementKind.ENUM) {
   7.321 -                if ("values".equals(e.getSimpleName().toString()) && e.getParameters().isEmpty()) {
   7.322 -                    return null;
   7.323 -                }
   7.324 -                
   7.325 -                if ("valueOf".equals(e.getSimpleName().toString()) && e.getParameters().size() == 1) {
   7.326 -                    TypeMirror param = e.getParameters().get(0).asType();
   7.327 -                    
   7.328 -                    if (param.getKind() == TypeKind.DECLARED && "java.lang.String".equals(((TypeElement) ((DeclaredType) param).asElement()).getQualifiedName().toString())) {
   7.329 -                        return null;
   7.330 -                    }
   7.331 -                }
   7.332 -            }
   7.333 -            
   7.334 -            ModifiersTree mods = computeMods(e);
   7.335 -            Tree returnValue = e.getReturnType() != null ? make.Type(e.getReturnType()) : null;
   7.336 -            List<VariableTree> parameters = new LinkedList<VariableTree>();
   7.337 -            
   7.338 -            for (VariableElement param : e.getParameters()) {
   7.339 -                parameters.add((VariableTree) visit(param));
   7.340 -            }
   7.341 -            
   7.342 -            List<ExpressionTree> throwsList = new LinkedList<ExpressionTree>();
   7.343 -            
   7.344 -            for (TypeMirror t : e.getThrownTypes()) {
   7.345 -                throwsList.add((ExpressionTree) make.Type(t));
   7.346 -            }
   7.347 -            
   7.348 -            if (e.getModifiers().contains(Modifier.ABSTRACT) || e.getModifiers().contains(Modifier.NATIVE)) {
   7.349 -                ExpressionTree def = createTreeForAnnotationValue(make, e.getDefaultValue());
   7.350 -                return make.Method(mods, e.getSimpleName(), returnValue, constructTypeParams(e.getTypeParameters()), parameters, throwsList, (BlockTree) null, def);
   7.351 -            } else {
   7.352 -                return make.Method(mods, e.getSimpleName(), returnValue, constructTypeParams(e.getTypeParameters()), parameters, throwsList, "{//compiled code\nthrow new RuntimeException(\"Compiled Code\");}", null);
   7.353 -            }
   7.354 -        }
   7.355 -
   7.356 -        public Tree visitTypeParameter(TypeParameterElement e, Void p) {
   7.357 -            List<ExpressionTree> bounds = new LinkedList<ExpressionTree>();
   7.358 -
   7.359 -            for (TypeMirror b : e.getBounds()) {
   7.360 -                bounds.add((ExpressionTree) make.Type(b));
   7.361 -            }
   7.362 -
   7.363 -            return make.TypeParameter(e.getSimpleName(), bounds);
   7.364 -        }
   7.365 -
   7.366 -        private static ExpressionTree createTreeForAnnotationValue(final TreeMaker make, AnnotationValue def) {
   7.367 -            if (def == null) {
   7.368 -                return null;
   7.369 -            }
   7.370 -            return def.accept(new AnnotationValueVisitor<ExpressionTree, Void>() {
   7.371 -                public ExpressionTree visit(AnnotationValue av, Void p) {
   7.372 -                    throw new UnsupportedOperationException("Not supported yet.");
   7.373 -                }
   7.374 -                public ExpressionTree visit(AnnotationValue av) {
   7.375 -                    throw new UnsupportedOperationException("Not supported yet.");
   7.376 -                }
   7.377 -                public ExpressionTree visitBoolean(boolean b, Void p) {
   7.378 -                    return make.Literal(b);
   7.379 -                }
   7.380 -
   7.381 -                public ExpressionTree visitByte(byte b, Void p) {
   7.382 -                    return make.Literal(b);
   7.383 -                }
   7.384 -
   7.385 -                public ExpressionTree visitChar(char c, Void p) {
   7.386 -                    return make.Literal(c);
   7.387 -                }
   7.388 -
   7.389 -                public ExpressionTree visitDouble(double d, Void p) {
   7.390 -                    return make.Literal(d);
   7.391 -                }
   7.392 -
   7.393 -                public ExpressionTree visitFloat(float f, Void p) {
   7.394 -                    return make.Literal(f);
   7.395 -                }
   7.396 -
   7.397 -                public ExpressionTree visitInt(int i, Void p) {
   7.398 -                    return make.Literal(i);
   7.399 -                }
   7.400 -
   7.401 -                public ExpressionTree visitLong(long i, Void p) {
   7.402 -                    return make.Literal(i);
   7.403 -                }
   7.404 -
   7.405 -                public ExpressionTree visitShort(short s, Void p) {
   7.406 -                    return make.Literal(s);
   7.407 -                }
   7.408 -
   7.409 -                public ExpressionTree visitString(String s, Void p) {
   7.410 -                    return make.Literal(s);
   7.411 -                }
   7.412 -
   7.413 -                public ExpressionTree visitType(TypeMirror t, Void p) {
   7.414 -                    return make.MemberSelect((ExpressionTree) make.Type(t), "class");
   7.415 -                }
   7.416 -
   7.417 -                public ExpressionTree visitEnumConstant(VariableElement c, Void p) {
   7.418 -                    return make.QualIdent(c);
   7.419 -                }
   7.420 -
   7.421 -                public ExpressionTree visitAnnotation(AnnotationMirror a, Void p) {
   7.422 -                    return null;//XXX: annotations!
   7.423 -                }
   7.424 -
   7.425 -                public ExpressionTree visitArray(List<? extends AnnotationValue> vals, Void p) {
   7.426 -                    List<ExpressionTree> values = new LinkedList<ExpressionTree>();
   7.427 -                    
   7.428 -                    for (AnnotationValue v : vals) {
   7.429 -                        values.add(createTreeForAnnotationValue(make, v));
   7.430 -                    }
   7.431 -                    
   7.432 -                    return make.NewArray(null, Collections.<ExpressionTree>emptyList(), values);
   7.433 -                }
   7.434 -
   7.435 -                public ExpressionTree visitUnknown(AnnotationValue av, Void p) {
   7.436 -                    throw new UnsupportedOperationException("Not supported yet.");
   7.437 -                }
   7.438 -            }, null);
   7.439 -        }
   7.440 -
   7.441 -    }
   7.442 -
   7.443 -    private static final Map<List<ElementKind>, Set<Modifier>> IMPLICIT_MODIFIERS;
   7.444 -
   7.445 -    static {
   7.446 -        IMPLICIT_MODIFIERS = new HashMap<List<ElementKind>, Set<Modifier>>();
   7.447 -
   7.448 -        IMPLICIT_MODIFIERS.put(Arrays.asList(ElementKind.ENUM), EnumSet.of(Modifier.STATIC, Modifier.ABSTRACT, Modifier.FINAL));
   7.449 -        IMPLICIT_MODIFIERS.put(Arrays.asList(ElementKind.ANNOTATION_TYPE), EnumSet.of(Modifier.STATIC, Modifier.ABSTRACT));
   7.450 -        IMPLICIT_MODIFIERS.put(Arrays.asList(ElementKind.METHOD, ElementKind.ANNOTATION_TYPE), EnumSet.of(Modifier.ABSTRACT));
   7.451 -        IMPLICIT_MODIFIERS.put(Arrays.asList(ElementKind.METHOD, ElementKind.INTERFACE), EnumSet.of(Modifier.ABSTRACT));
   7.452 -    }
   7.453 -
   7.454 -    private CodeGenerator() {
   7.455 -    }
   7.456 -    
   7.457 -}
     8.1 --- a/java.srclessopen/src/org/netbeans/modules/java/srclessopen/Index.java	Fri Sep 17 18:38:20 2010 -0400
     8.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.3 @@ -1,257 +0,0 @@
     8.4 -/*
     8.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     8.6 - *
     8.7 - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
     8.8 - *
     8.9 - * The contents of this file are subject to the terms of either the GNU
    8.10 - * General Public License Version 2 only ("GPL") or the Common
    8.11 - * Development and Distribution License("CDDL") (collectively, the
    8.12 - * "License"). You may not use this file except in compliance with the
    8.13 - * License. You can obtain a copy of the License at
    8.14 - * http://www.netbeans.org/cddl-gplv2.html
    8.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    8.16 - * specific language governing permissions and limitations under the
    8.17 - * License.  When distributing the software, include this License Header
    8.18 - * Notice in each file and include the License file at
    8.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
    8.20 - * particular file as subject to the "Classpath" exception as provided
    8.21 - * by Sun in the GPL Version 2 section of the License file that
    8.22 - * accompanied this code. If applicable, add the following below the
    8.23 - * License Header, with the fields enclosed by brackets [] replaced by
    8.24 - * your own identifying information:
    8.25 - * "Portions Copyrighted [year] [name of copyright owner]"
    8.26 - *
    8.27 - * Contributor(s):
    8.28 - *
    8.29 - * The Original Software is NetBeans. The Initial Developer of the Original
    8.30 - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
    8.31 - * Microsystems, Inc. All Rights Reserved.
    8.32 - *
    8.33 - * If you wish your version of this file to be governed by only the CDDL
    8.34 - * or only the GPL Version 2, indicate your decision by adding
    8.35 - * "[Contributor] elects to include this software in this distribution
    8.36 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
    8.37 - * single choice of license, a recipient has the option to distribute
    8.38 - * your version of this file under either the CDDL, the GPL Version 2 or
    8.39 - * to extend the choice of license to its licensees as provided above.
    8.40 - * However, if you add GPL Version 2 code and therefore, elected the GPL
    8.41 - * Version 2 license, then the option applies only if the new code is
    8.42 - * made subject to such option by the copyright holder.
    8.43 - */
    8.44 -package org.netbeans.modules.java.srclessopen;
    8.45 -
    8.46 -import java.io.File;
    8.47 -import java.io.FileInputStream;
    8.48 -import java.io.FileOutputStream;
    8.49 -import java.io.IOException;
    8.50 -import java.io.InputStream;
    8.51 -import java.io.OutputStream;
    8.52 -import java.net.URISyntaxException;
    8.53 -import java.net.URL;
    8.54 -import java.util.HashMap;
    8.55 -import java.util.Map;
    8.56 -import java.util.Properties;
    8.57 -import org.openide.ErrorManager;
    8.58 -import org.openide.filesystems.FileUtil;
    8.59 -
    8.60 -/**
    8.61 - * Index SPI. Represents an index for usages data
    8.62 - * @author Tomas Zezula
    8.63 - */
    8.64 -public abstract class Index {    
    8.65 -    
    8.66 -    public enum BooleanOperator {
    8.67 -        AND,
    8.68 -        OR
    8.69 -    };
    8.70 -    
    8.71 -    private static final int VERSION = 0;
    8.72 -    private static final int SUBVERSION = 1;
    8.73 -    private static final String NB_USER_DIR = "netbeans.user";   //NOI18N
    8.74 -    private static final String SEGMENTS_FILE = "segments";      //NOI18N
    8.75 -    private static final String SOURCES = "sources";             //NOI18N
    8.76 -    private static final String SLICE_PREFIX = "s";              //NOI18N    
    8.77 -    private static final String INDEX_DIR = "var"+File.separatorChar+"cache"+File.separatorChar+"javasources"+File.separatorChar+VERSION+'.'+SUBVERSION;    //NOI18N
    8.78 -    
    8.79 -    private static Properties segments;
    8.80 -    private static Map<String, String> invertedSegments;
    8.81 -    private static File cacheFolder;
    8.82 -    private static File segmentsFile;
    8.83 -    private static int index = 0;
    8.84 -    
    8.85 -    private static void loadSegments () throws IOException {
    8.86 -        if (segments == null) {
    8.87 -            File cacheFolder = getCacheFolder();
    8.88 -            assert cacheFolder != null;           
    8.89 -            segments = new Properties ();
    8.90 -            invertedSegments = new HashMap<String,String> ();
    8.91 -            segmentsFile = FileUtil.normalizeFile(new File (cacheFolder, SEGMENTS_FILE));
    8.92 -            if (segmentsFile.exists()) {
    8.93 -                InputStream in = new FileInputStream (segmentsFile);
    8.94 -                try {
    8.95 -                    segments.load (in);
    8.96 -                } finally {
    8.97 -                    in.close();
    8.98 -                }
    8.99 -            }
   8.100 -            for (Map.Entry entry : segments.entrySet()) {
   8.101 -                String segment = (String) entry.getKey();
   8.102 -                String root = (String) entry.getValue();
   8.103 -                invertedSegments.put(root,segment);
   8.104 -                try {
   8.105 -                    index = Math.max (index,Integer.parseInt(segment.substring(SLICE_PREFIX.length())));
   8.106 -                } catch (NumberFormatException nfe) {
   8.107 -                    ErrorManager.getDefault().notify(nfe);
   8.108 -                }
   8.109 -            }
   8.110 -            assert segmentsFile != null;
   8.111 -        }        
   8.112 -    }
   8.113 -    
   8.114 -    
   8.115 -    private static void storeSegments () throws IOException {
   8.116 -        assert segmentsFile != null;       
   8.117 -        OutputStream out = new FileOutputStream (segmentsFile);
   8.118 -        try {
   8.119 -            segments.store(out,null);
   8.120 -        } finally {
   8.121 -            out.close();
   8.122 -        }            
   8.123 -    }
   8.124 -    
   8.125 -    
   8.126 -    public static URL getSourceRootForClassFolder (final URL classFolder) {
   8.127 -        if ("file".equals(classFolder.getProtocol())) {           //NOI18N
   8.128 -            try {
   8.129 -                final File file = FileUtil.normalizeFile(new File (classFolder.toURI()));            
   8.130 -                final File segFolder = file.getParentFile();
   8.131 -                if (segFolder == null) {
   8.132 -                    return null;
   8.133 -                }
   8.134 -                final Object cFolder = segFolder.getParentFile();
   8.135 -                if (cFolder == null || !cFolder.equals(cacheFolder)) {
   8.136 -                    return null;
   8.137 -                }   
   8.138 -                String source = segments.getProperty(segFolder.getName());
   8.139 -                if (source != null) {
   8.140 -                    try {            
   8.141 -                        return new URL (source);
   8.142 -                    } catch (IOException ioe) {
   8.143 -                        ErrorManager.getDefault().notify(ioe);            
   8.144 -                    }
   8.145 -                }
   8.146 -            } catch (URISyntaxException e) {
   8.147 -                ErrorManager.getDefault().notify(e);
   8.148 -            }
   8.149 -        }
   8.150 -        return null;
   8.151 -    }
   8.152 -        
   8.153 -    
   8.154 -    public static synchronized File getDataFolder (final URL root) throws IOException {
   8.155 -        return getDataFolder(root, false);
   8.156 -    }
   8.157 -    
   8.158 -    public static synchronized File getDataFolder (final URL root, boolean onlyIfAlreadyExists) throws IOException {
   8.159 -        loadSegments ();
   8.160 -        final String rootName = root.toExternalForm();
   8.161 -        String slice = invertedSegments.get (rootName);
   8.162 -        if ( slice == null) {
   8.163 -            if (onlyIfAlreadyExists)
   8.164 -                return null;
   8.165 -            slice = SLICE_PREFIX + (++index);
   8.166 -            while (segments.getProperty(slice) != null) {                
   8.167 -                slice = SLICE_PREFIX + (++index);
   8.168 -            }
   8.169 -            segments.put (slice,rootName);
   8.170 -            invertedSegments.put(rootName, slice);
   8.171 -            storeSegments ();
   8.172 -        }        
   8.173 -        File result = FileUtil.normalizeFile (new File (cacheFolder, slice));
   8.174 -        if (!result.exists()) {
   8.175 -            if (onlyIfAlreadyExists)
   8.176 -                return null;
   8.177 -            result.mkdir();
   8.178 -        }
   8.179 -        return result;
   8.180 -    }
   8.181 -    
   8.182 -    /**returns null if onlyIfAlreadyExists == true and the cache folder for the given url does not exist.
   8.183 -     */
   8.184 -    public static File getSourceFolder (final URL url, boolean onlyIfAlreadyExists) throws IOException {
   8.185 -        return getSourceFolderImpl(url, onlyIfAlreadyExists);
   8.186 -    }
   8.187 -    
   8.188 -    public static File getSourceFolder (final URL url) throws IOException {                
   8.189 -        return getSourceFolder(url, false);
   8.190 -    }
   8.191 -    
   8.192 -    public static File getSourceFolder (final File root) throws IOException {
   8.193 -        URL url = root.toURI().toURL();
   8.194 -        if (!root.exists()) {
   8.195 -            final String surl = url.toExternalForm();
   8.196 -            if (!surl.endsWith("/")) {
   8.197 -                url = new URL (surl+'/');
   8.198 -            }
   8.199 -        }
   8.200 -        return getSourceFolderImpl(url, false);
   8.201 -    }        
   8.202 -    
   8.203 -    private static File getSourceFolderImpl (final URL url, boolean onlyIfAlreadyExists) throws IOException {
   8.204 -        final File dataFolder = getDataFolder (url, onlyIfAlreadyExists);
   8.205 -        if (onlyIfAlreadyExists && dataFolder == null)
   8.206 -            return null;
   8.207 -        final File result = FileUtil.normalizeFile(new File (dataFolder, SOURCES));
   8.208 -        if (!result.exists()) {
   8.209 -            if (onlyIfAlreadyExists)
   8.210 -                return null;
   8.211 -            result.mkdir();
   8.212 -        }
   8.213 -        return result;
   8.214 -    }
   8.215 -    
   8.216 -    
   8.217 -    
   8.218 -    /**
   8.219 -     *  Returns non cached netbeans user dir.
   8.220 -     *  For performance reasons the returned {@link File} is not normalized.
   8.221 -     *  Client is responsible to call {@link FileUtil.normalizeFile}
   8.222 -     *  before using the returned value.
   8.223 -     *  @return netbeans user dir.
   8.224 -     */
   8.225 -    static String getNbUserDir () {
   8.226 -        final String nbUserProp = System.getProperty(NB_USER_DIR);
   8.227 -        return nbUserProp;
   8.228 -    }
   8.229 -    
   8.230 -    public static synchronized File getCacheFolder () {
   8.231 -        if (cacheFolder == null) {
   8.232 -            final String nbUserDirProp = getNbUserDir();
   8.233 -            assert nbUserDirProp != null;
   8.234 -            final File nbUserDir = new File (nbUserDirProp);
   8.235 -            cacheFolder = FileUtil.normalizeFile(new File (nbUserDir, INDEX_DIR));
   8.236 -            if (!cacheFolder.exists()) {
   8.237 -                boolean created = cacheFolder.mkdirs();                
   8.238 -                assert created : "Cannot create cache folder";  //NOI18N
   8.239 -            }
   8.240 -            else {
   8.241 -                assert cacheFolder.isDirectory() && cacheFolder.canRead() && cacheFolder.canWrite();
   8.242 -            }
   8.243 -        }
   8.244 -        return cacheFolder;
   8.245 -    }
   8.246 -    
   8.247 -    public static boolean isTest () {
   8.248 -        return getNbUserDir() == null;
   8.249 -    }
   8.250 -    
   8.251 -    /**
   8.252 -     * Only for unit tests!
   8.253 -     *
   8.254 -     */
   8.255 -    static synchronized void setCacheFolder (final File folder) {
   8.256 -        assert folder != null && folder.exists() && folder.canRead() && folder.canWrite();
   8.257 -        cacheFolder = folder;
   8.258 -    }
   8.259 -    
   8.260 -}
     9.1 --- a/java.srclessopen/src/org/netbeans/modules/java/srclessopen/layer.xml	Fri Sep 17 18:38:20 2010 -0400
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,4 +0,0 @@
     9.4 -<?xml version="1.0" encoding="UTF-8"?>
     9.5 -<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.1//EN" "http://www.netbeans.org/dtds/filesystem-1_1.dtd">
     9.6 -<filesystem>
     9.7 -</filesystem>
    10.1 --- a/java.srclessopen/test/unit/src/org/netbeans/modules/java/srclessopen/CodeGeneratorTest.java	Fri Sep 17 18:38:20 2010 -0400
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,161 +0,0 @@
    10.4 -/*
    10.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    10.6 - *
    10.7 - * Copyright 2008-2009 Sun Microsystems, Inc. All rights reserved.
    10.8 - *
    10.9 - * The contents of this file are subject to the terms of either the GNU
   10.10 - * General Public License Version 2 only ("GPL") or the Common
   10.11 - * Development and Distribution License("CDDL") (collectively, the
   10.12 - * "License"). You may not use this file except in compliance with the
   10.13 - * License. You can obtain a copy of the License at
   10.14 - * http://www.netbeans.org/cddl-gplv2.html
   10.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
   10.16 - * specific language governing permissions and limitations under the
   10.17 - * License.  When distributing the software, include this License Header
   10.18 - * Notice in each file and include the License file at
   10.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
   10.20 - * particular file as subject to the "Classpath" exception as provided
   10.21 - * by Sun in the GPL Version 2 section of the License file that
   10.22 - * accompanied this code. If applicable, add the following below the
   10.23 - * License Header, with the fields enclosed by brackets [] replaced by
   10.24 - * your own identifying information:
   10.25 - * "Portions Copyrighted [year] [name of copyright owner]"
   10.26 - *
   10.27 - * If you wish your version of this file to be governed by only the CDDL
   10.28 - * or only the GPL Version 2, indicate your decision by adding
   10.29 - * "[Contributor] elects to include this software in this distribution
   10.30 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
   10.31 - * single choice of license, a recipient has the option to distribute
   10.32 - * your version of this file under either the CDDL, the GPL Version 2 or
   10.33 - * to extend the choice of license to its licensees as provided above.
   10.34 - * However, if you add GPL Version 2 code and therefore, elected the GPL
   10.35 - * Version 2 license, then the option applies only if the new code is
   10.36 - * made subject to such option by the copyright holder.
   10.37 - *
   10.38 - * Contributor(s):
   10.39 - *
   10.40 - * Portions Copyrighted 2008-2009 Sun Microsystems, Inc.
   10.41 - */
   10.42 -
   10.43 -package org.netbeans.modules.java.srclessopen;
   10.44 -
   10.45 -import com.sun.source.tree.CompilationUnitTree;
   10.46 -import java.io.IOException;
   10.47 -import javax.lang.model.element.TypeElement;
   10.48 -import org.netbeans.api.java.source.CompilationController;
   10.49 -import org.netbeans.api.java.source.Task;
   10.50 -import org.netbeans.api.java.source.JavaSource;
   10.51 -import org.netbeans.api.java.source.JavaSource.Phase;
   10.52 -import org.netbeans.api.java.source.ModificationResult;
   10.53 -import org.netbeans.api.java.source.SourceUtilsTestUtil;
   10.54 -import org.netbeans.api.java.source.TestUtilities;
   10.55 -import org.netbeans.api.java.source.WorkingCopy;
   10.56 -import org.netbeans.junit.NbTestCase;
   10.57 -import org.openide.filesystems.FileObject;
   10.58 -import org.openide.filesystems.FileUtil;
   10.59 -
   10.60 -/**
   10.61 - *
   10.62 - * @author Jan Lahoda
   10.63 - */
   10.64 -public class CodeGeneratorTest extends NbTestCase {
   10.65 -
   10.66 -    public CodeGeneratorTest(String name) {
   10.67 -        super(name);
   10.68 -    }
   10.69 -
   10.70 -    @Override
   10.71 -    protected void setUp() throws Exception {
   10.72 -        SourceUtilsTestUtil.prepareTest(new String[0], new Object[0]);
   10.73 -        super.setUp();
   10.74 -    }
   10.75 -
   10.76 -    public void testSimple1() throws Exception {
   10.77 -        performTest("package test; class Test { }",
   10.78 -                    "package test; class Test { } ");
   10.79 -    }
   10.80 -    
   10.81 -    public void testAnnotationDeclaration() throws Exception {
   10.82 -        performTest("package test; import test.Test.E; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; class Test {\n" +
   10.83 -                    "@Retention(RetentionPolicy.CLASS)\n" +
   10.84 -                    "@interface TT {\n" +
   10.85 -                    "    public Class test1() default Object.class;\n" +
   10.86 -                    "    public Class test2();\n" +
   10.87 -                    "    public E     test3() default E.A;\n" +
   10.88 -                    "    public E     test4();\n" +
   10.89 -                    "}\n" +
   10.90 -                    "enum E {\n" +
   10.91 -                    "    A, B;\n" +
   10.92 -                    "}\n" +
   10.93 -                    "}\n",
   10.94 -                    "package test; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import test.Test.E; class Test {\n" +
   10.95 -                    "@Retention(value = RetentionPolicy.CLASS)\n" +
   10.96 -                    "@interface TT {\n" +
   10.97 -                    "    public Class test1() default Object.class;\n" +
   10.98 -                    "    public Class test2();\n" +
   10.99 -                    "    public E     test3() default E.A;\n" +
  10.100 -                    "    public E     test4();\n" +
  10.101 -                    "}\n" +
  10.102 -                    "enum E {\n" +
  10.103 -                    "    A, B\n" +
  10.104 -                    "}\n" +
  10.105 -                    "}\n");
  10.106 -    }
  10.107 -
  10.108 -    public void testInterface() throws Exception {
  10.109 -        performTest("package test; interface Test {\n" +
  10.110 -                    "    public Class test1();\n" +
  10.111 -                    "}\n",
  10.112 -                    "package test; interface Test {\n" +
  10.113 -                    "    public Class test1();\n" +
  10.114 -                    "}\n");
  10.115 -    }
  10.116 -
  10.117 -    private void performTest(String test, final String golden) throws Exception {
  10.118 -        clearWorkDir();
  10.119 -        
  10.120 -        FileObject wd = FileUtil.toFileObject(getWorkDir());
  10.121 -
  10.122 -        assertNotNull(wd);
  10.123 -
  10.124 -        FileObject src   = FileUtil.createFolder(wd, "src");
  10.125 -        FileObject build = FileUtil.createFolder(wd, "build");
  10.126 -        FileObject cache = FileUtil.createFolder(wd, "cache");
  10.127 -        
  10.128 -        SourceUtilsTestUtil.prepareTest(src, build, cache);
  10.129 -        FileObject testFile = FileUtil.createData(src, "test/Test.java");
  10.130 -        final FileObject testOutFile = FileUtil.createData(src, "out/Test.java");
  10.131 -        TestUtilities.copyStringToFile(testFile, test);
  10.132 -        JavaSource testSource = JavaSource.forFileObject(testOutFile);
  10.133 -        Task<WorkingCopy> task = new Task<WorkingCopy>() {
  10.134 -            public void run(final WorkingCopy workingCopy) throws IOException {
  10.135 -                workingCopy.toPhase(Phase.RESOLVED);
  10.136 -
  10.137 -                CompilationUnitTree cut = workingCopy.getCompilationUnit();
  10.138 -                TypeElement t = workingCopy.getElements().getTypeElement("test.Test");
  10.139 -
  10.140 -                assertNotNull(t);
  10.141 -
  10.142 -                workingCopy.rewrite(workingCopy.getCompilationUnit(), CodeGenerator.generateCode(workingCopy, t));
  10.143 -            }
  10.144 -        };
  10.145 -        
  10.146 -        ModificationResult mr = testSource.runModificationTask(task);
  10.147 -
  10.148 -        mr.commit();
  10.149 -
  10.150 -        assertEquals(normalizeWhitespaces(golden), normalizeWhitespaces(TestUtilities.copyFileToString(FileUtil.toFile(testOutFile))));
  10.151 -
  10.152 -        testSource.runUserActionTask(new Task<CompilationController>() {
  10.153 -            public void run(CompilationController cc) throws Exception {
  10.154 -                cc.toPhase(Phase.RESOLVED);
  10.155 -                assertTrue(cc.getDiagnostics().toString(), cc.getDiagnostics().isEmpty());
  10.156 -            }
  10.157 -        }, true);
  10.158 -    }
  10.159 -
  10.160 -    private static String normalizeWhitespaces(String text) {
  10.161 -        return text.replaceAll("[ \n\t]+", " ");
  10.162 -    }
  10.163 -    
  10.164 -}