This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 258248
Collapse All | Expand All

(-)a/java.source/nbproject/project.xml (+9 lines)
Lines 128-133 Link Here
128
                    </run-dependency>
128
                    </run-dependency>
129
                </dependency>
129
                </dependency>
130
                <dependency>
130
                <dependency>
131
                    <code-name-base>org.netbeans.libs.neo4j.core</code-name-base>
132
                    <build-prerequisite/>
133
                    <compile-dependency/>
134
                    <run-dependency>
135
                        <release-version>1</release-version>
136
                        <specification-version>1.0</specification-version>
137
                    </run-dependency>
138
                </dependency>
139
                <dependency>
131
                    <code-name-base>org.netbeans.modules.classfile</code-name-base>
140
                    <code-name-base>org.netbeans.modules.classfile</code-name-base>
132
                    <build-prerequisite/>
141
                    <build-prerequisite/>
133
                    <compile-dependency/>
142
                    <compile-dependency/>
(-)a/java.source/src/org/netbeans/modules/java/source/JBrowseModule.java (+8 lines)
Lines 44-49 Link Here
44
44
45
package org.netbeans.modules.java.source;
45
package org.netbeans.modules.java.source;
46
46
47
import org.netbeans.modules.java.source.indexing.neo4j.Neo4jIndex;
47
import org.netbeans.modules.java.source.usages.ClassIndexManager;
48
import org.netbeans.modules.java.source.usages.ClassIndexManager;
48
import org.openide.modules.ModuleInstall;
49
import org.openide.modules.ModuleInstall;
49
50
Lines 57-67 Link Here
57
    /** Creates a new instance of JBrowseModule */
58
    /** Creates a new instance of JBrowseModule */
58
    public JBrowseModule() {
59
    public JBrowseModule() {
59
    }
60
    }
61
62
    @Override
63
    public void restored() {
64
        super.restored();
65
        Neo4jIndex.getDefault().start();
66
    }
60
    
67
    
61
    
68
    
62
    @Override
69
    @Override
63
    public void close () {
70
    public void close () {
64
        super.close();
71
        super.close();
65
        ClassIndexManager.getDefault().close();
72
        ClassIndexManager.getDefault().close();
73
        Neo4jIndex.getDefault().stop();
66
    }        
74
    }        
67
}
75
}
(-)a/java.source/src/org/netbeans/modules/java/source/indexing/JavaParsingContext.java (-1 / +11 lines)
Lines 53-58 Link Here
53
import java.util.Collection;
53
import java.util.Collection;
54
import java.util.List;
54
import java.util.List;
55
import java.util.Set;
55
import java.util.Set;
56
import java.util.concurrent.Callable;
56
import javax.lang.model.element.TypeElement;
57
import javax.lang.model.element.TypeElement;
57
import javax.tools.JavaFileManager;
58
import javax.tools.JavaFileManager;
58
import org.netbeans.api.annotations.common.CheckForNull;
59
import org.netbeans.api.annotations.common.CheckForNull;
Lines 71-76 Link Here
71
import org.netbeans.modules.java.source.JavaFileFilterQuery;
72
import org.netbeans.modules.java.source.JavaFileFilterQuery;
72
import org.netbeans.modules.java.source.JavaSourceAccessor;
73
import org.netbeans.modules.java.source.JavaSourceAccessor;
73
import org.netbeans.modules.java.source.indexing.JavaCustomIndexer.CompileTuple;
74
import org.netbeans.modules.java.source.indexing.JavaCustomIndexer.CompileTuple;
75
import org.netbeans.modules.java.source.indexing.neo4j.Neo4jAnalyzer;
76
import org.netbeans.modules.java.source.indexing.neo4j.Neo4jIndex;
74
import org.netbeans.modules.java.source.parsing.ProcessorGenerated;
77
import org.netbeans.modules.java.source.parsing.ProcessorGenerated;
75
import org.netbeans.modules.java.source.usages.ClassIndexImpl;
78
import org.netbeans.modules.java.source.usages.ClassIndexImpl;
76
import org.netbeans.modules.java.source.usages.ClassIndexManager;
79
import org.netbeans.modules.java.source.usages.ClassIndexManager;
Lines 226-232 Link Here
226
            @NonNull /*@Out*/ final boolean[] mainMethod) throws IOException {
229
            @NonNull /*@Out*/ final boolean[] mainMethod) throws IOException {
227
        final SourceAnalyzerFactory.StorableAnalyzer analyzer = getSourceAnalyzer();
230
        final SourceAnalyzerFactory.StorableAnalyzer analyzer = getSourceAnalyzer();
228
        assert analyzer != null;
231
        assert analyzer != null;
229
        analyzer.analyse(trees, jt, fileManager, active, newTypes, mainMethod);
232
        analyzer.analyse(trees, jt, fileManager, active, newTypes, mainMethod);       
233
        Neo4jAnalyzer a = new Neo4jAnalyzer(
234
            jt,
235
            fileManager,
236
            active,
237
            newTypes,
238
            mainMethod);
239
        a.scan(trees, null);
230
        final Lookup pluginServices = getPluginServices(jt);
240
        final Lookup pluginServices = getPluginServices(jt);
231
        for (CompilationUnitTree cu : trees) {
241
        for (CompilationUnitTree cu : trees) {
232
            for (JavaIndexerPlugin plugin : getPlugins()) {
242
            for (JavaIndexerPlugin plugin : getPlugins()) {
(-)a/java.source/src/org/netbeans/modules/java/source/indexing/TransactionContext.java (-2 / +3 lines)
Lines 47-52 Link Here
47
import java.util.Map;
47
import java.util.Map;
48
import org.netbeans.api.annotations.common.CheckForNull;
48
import org.netbeans.api.annotations.common.CheckForNull;
49
import org.netbeans.api.annotations.common.NonNull;
49
import org.netbeans.api.annotations.common.NonNull;
50
import org.netbeans.modules.java.source.indexing.neo4j.Neo4jIndexTransaction;
50
import org.netbeans.modules.java.source.parsing.FileManagerTransaction;
51
import org.netbeans.modules.java.source.parsing.FileManagerTransaction;
51
import org.netbeans.modules.java.source.parsing.ProcessorGenerated;
52
import org.netbeans.modules.java.source.parsing.ProcessorGenerated;
52
import org.netbeans.modules.java.source.usages.ClassIndexEventsTransaction;
53
import org.netbeans.modules.java.source.usages.ClassIndexEventsTransaction;
Lines 230-237 Link Here
230
                PersistentIndexTransaction.create()).
231
                PersistentIndexTransaction.create()).
231
            register(
232
            register(
232
                ClassIndexEventsTransaction.class,
233
                ClassIndexEventsTransaction.class,
233
                ClassIndexEventsTransaction.create(srcIndex)
234
                ClassIndexEventsTransaction.create(srcIndex)).
234
            );
235
            register(Neo4jIndexTransaction.class, Neo4jIndexTransaction.create(root));
235
    }
236
    }
236
    
237
    
237
    /**
238
    /**
(-)a/java.source/src/org/netbeans/modules/java/source/indexing/neo4j/ClassNode.java (+130 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.java.source.indexing.neo4j;
43
44
import java.util.BitSet;
45
import javax.lang.model.element.ElementKind;
46
import org.neo4j.graphdb.Node;
47
import org.neo4j.graphdb.index.Index;
48
import org.neo4j.kernel.EmbeddedGraphDatabase;
49
import org.netbeans.api.annotations.common.CheckForNull;
50
import org.netbeans.api.annotations.common.NonNull;
51
import org.netbeans.api.annotations.common.NullAllowed;
52
53
/**
54
 *
55
 * @author Tomas Zezula
56
 */
57
class ClassNode extends ModelNode {
58
59
    private static final String PROP_BIN_NAME = "binName";       //NOI18N
60
    private static final String PROP_SIMPLE_NAME = "name";          //NOI18N
61
    private static final String PROP_KIND = "kind";                 //NOI18N
62
    private static final String PROP_RES_NAME = "resName";          //NOI18N
63
    private static final String KEY_SIMPLE_NAME ="sn";              //NOI18N
64
    private static final String KEY_CASE_INSENSITIVE_SIMPLE_NAME = "cisn";  //NOI18N
65
66
    private ClassNode(Node node) {
67
        super(node);
68
    }
69
    
70
    @NonNull
71
    String getSimpleName() {
72
        return (String) node.getProperty(PROP_SIMPLE_NAME);
73
    }
74
75
    @NonNull
76
    String getBinaryName() {
77
        return (String) node.getProperty(PROP_BIN_NAME);
78
    }
79
80
    @NonNull
81
    ElementKind getKind() {
82
        final String kn = (String) node.getProperty(PROP_KIND);
83
        return ElementKind.valueOf(kn);
84
    }
85
86
    @CheckForNull
87
    String getResourceName() {
88
        return (String) node.getProperty(PROP_RES_NAME, null);
89
    }
90
91
    void uses(
92
        @NonNull TypeReferenceNode type,
93
        @NonNull final BitSet usageTypes) {
94
        TimeLogger.start();
95
        try {
96
            for (int i = usageTypes.nextSetBit(0); i >= 0; i = usageTypes.nextSetBit(i+1)) {
97
                final RelationshipTypes rt = RelationshipTypes.fromUsageTypeOrdinal(i);
98
                node.createRelationshipTo(type.node, rt);
99
            }
100
        } finally {
101
            TimeLogger.stop();
102
        }
103
    }
104
105
    static ClassNode create(
106
            @NonNull final EmbeddedGraphDatabase db,
107
            @NonNull final Index<Node> classSimpleNames,
108
            @NonNull final String binaryName,
109
            @NonNull final String simpleName,
110
            @NonNull final PackageNode packageNode,
111
            @NonNull final ElementKind kind,
112
            @NullAllowed final String resourceName) {
113
        TimeLogger.start();
114
        try {
115
            final Node node = db.createNode();
116
            node.setProperty(PROP_BIN_NAME, binaryName);
117
            node.setProperty(PROP_SIMPLE_NAME, simpleName);
118
            node.setProperty(PROP_KIND, kind.name());
119
            if (resourceName != null) {
120
                node.setProperty(PROP_RES_NAME, resourceName);
121
            }
122
            node.createRelationshipTo(packageNode.node, RelationshipTypes.IN_PACKAGE);
123
            classSimpleNames.add(node, KEY_SIMPLE_NAME, simpleName);
124
            classSimpleNames.add(node,KEY_CASE_INSENSITIVE_SIMPLE_NAME, simpleName.toLowerCase());
125
            return new ClassNode(node);
126
        } finally {
127
            TimeLogger.stop();
128
        }
129
    }
130
}
(-)a/java.source/src/org/netbeans/modules/java/source/indexing/neo4j/ModelNode.java (+59 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.java.source.indexing.neo4j;
43
44
import org.neo4j.graphdb.Node;
45
import org.netbeans.api.annotations.common.NonNull;
46
47
/**
48
 *
49
 * @author Tomas Zezula
50
 */
51
public class ModelNode {
52
    
53
    protected final Node node;
54
55
    ModelNode(@NonNull Node node) {
56
        assert node != null;
57
        this.node = node;
58
    }
59
}
(-)a/java.source/src/org/netbeans/modules/java/source/indexing/neo4j/Neo4jAnalyzer.java (+774 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.java.source.indexing.neo4j;
43
44
import com.sun.source.tree.ClassTree;
45
import com.sun.source.tree.CompilationUnitTree;
46
import com.sun.source.tree.ErroneousTree;
47
import com.sun.source.tree.IdentifierTree;
48
import com.sun.source.tree.ImportTree;
49
import com.sun.source.tree.MemberSelectTree;
50
import com.sun.source.tree.MethodTree;
51
import com.sun.source.tree.NewClassTree;
52
import com.sun.source.tree.ParameterizedTypeTree;
53
import com.sun.source.tree.Tree;
54
import com.sun.source.tree.VariableTree;
55
import com.sun.source.util.TreeScanner;
56
import com.sun.tools.javac.api.JavacTaskImpl;
57
import com.sun.tools.javac.code.Kinds;
58
import com.sun.tools.javac.code.Symbol;
59
import com.sun.tools.javac.code.Type;
60
import com.sun.tools.javac.tree.JCTree;
61
import com.sun.tools.javac.util.Name;
62
import com.sun.tools.javac.util.Names;
63
import java.net.MalformedURLException;
64
import java.net.URI;
65
import java.net.URL;
66
import java.util.ArrayDeque;
67
import java.util.BitSet;
68
import java.util.Deque;
69
import java.util.HashMap;
70
import java.util.HashSet;
71
import java.util.List;
72
import java.util.Map;
73
import java.util.Set;
74
import java.util.Stack;
75
import java.util.logging.Level;
76
import java.util.logging.Logger;
77
import javax.lang.model.element.Element;
78
import javax.lang.model.element.ElementKind;
79
import javax.lang.model.element.ExecutableElement;
80
import javax.lang.model.element.TypeElement;
81
import javax.lang.model.type.ArrayType;
82
import javax.lang.model.type.DeclaredType;
83
import javax.lang.model.type.TypeKind;
84
import javax.lang.model.type.TypeMirror;
85
import javax.tools.JavaFileManager;
86
import javax.tools.JavaFileObject;
87
import javax.tools.StandardLocation;
88
import org.netbeans.api.annotations.common.CheckForNull;
89
import org.netbeans.api.annotations.common.NonNull;
90
import org.netbeans.api.annotations.common.NullAllowed;
91
import org.netbeans.api.java.classpath.ClassPath;
92
import org.netbeans.api.java.source.ElementHandle;
93
import org.netbeans.api.java.source.SourceUtils;
94
import org.netbeans.modules.java.source.indexing.JavaCustomIndexer;
95
import org.netbeans.modules.java.source.indexing.TransactionContext;
96
import org.netbeans.modules.java.source.parsing.FileObjects;
97
import org.netbeans.modules.java.source.usages.ClassFileUtil;
98
import org.netbeans.modules.java.source.usages.ClassIndexImpl;
99
import org.netbeans.modules.java.source.usages.Pair;
100
import org.openide.filesystems.FileObject;
101
import org.openide.filesystems.FileUtil;
102
import org.openide.filesystems.URLMapper;
103
import org.openide.util.Exceptions;
104
105
/**
106
 *
107
 * @author tom
108
 */
109
public class Neo4jAnalyzer extends TreeScanner<Void, Void> {
110
111
    private static final Logger LOG = Logger.getLogger(Neo4jAnalyzer.class.getName());
112
113
    enum State {
114
115
        EXTENDS, IMPLEMENTS, GT, OTHER, IMPORT, PACKAGE_ANN
116
    };
117
    private final Neo4jIndexTransaction neoTx;
118
    private final Stack<ClassNode> activeClass;
119
    private final Name errorName;
120
    private final Name pkgImportName;
121
    private final URL siblingUrl;
122
    private final String sourceName;
123
    private final boolean signatureFiles;
124
    private final Set<? super Pair<String, String>> topLevels;
125
    private final Set<? super ElementHandle<TypeElement>> newTypes;
126
    private final Set<Symbol> imports;
127
    private final Set<Symbol> staticImports;
128
    private final Set<Symbol> unusedPkgImports;
129
    private final Set<Pair<Symbol, ClassIndexImpl.UsageType>> packageAnnotations;
130
    private final Set<CharSequence> importIdents;
131
    private final Set<CharSequence> packageAnnotationIdents;
132
    private final boolean virtual;
133
    private final boolean[] mainMethod;
134
    private final Neo4jIndex index;
135
    private final RootNode rootNode;
136
    private boolean isStaticImport;
137
    private boolean isPkgImport;
138
    private State state;
139
    private Element enclosingElement = null;
140
    private Set<String> rsList;         //List of references from source in case when the source has more top levels or is wrongly packaged
141
    private boolean crossedTopLevel;    //True when the visitor already reached the correctly packaged top level
142
    private PackageNode packageNode;
143
    private CompilationUnitTree cu;
144
    private Map<ClassNode, Map<String, BitSet>> usages;
145
146
    public Neo4jAnalyzer(
147
            final JavacTaskImpl jt,
148
            final JavaFileManager manager,
149
            final JavaCustomIndexer.CompileTuple tuple,
150
            final Set<? super ElementHandle<TypeElement>> newTypes,
151
            final boolean[] mainMethod) throws MalformedURLException, IllegalArgumentException {
152
153
        assert jt != null;
154
        assert manager != null;
155
        assert tuple != null;
156
        assert mainMethod != null;
157
158
        this.activeClass = new Stack<ClassNode>();
159
        this.imports = new HashSet<Symbol>();
160
        this.staticImports = new HashSet<Symbol>();
161
        this.unusedPkgImports = new HashSet<Symbol>();
162
        this.importIdents = new HashSet<CharSequence>();
163
        this.packageAnnotationIdents = new HashSet<CharSequence>();
164
        this.packageAnnotations = new HashSet<Pair<Symbol, ClassIndexImpl.UsageType>>();
165
        final Names names = Names.instance(jt.getContext());
166
        this.errorName = names.error;
167
        this.pkgImportName = names.asterisk;
168
        this.state = State.OTHER;
169
        this.signatureFiles = true;
170
        this.virtual = tuple.virtual;
171
        this.siblingUrl = virtual ? tuple.indexable.getURL() : tuple.jfo.toUri().toURL();
172
        this.sourceName = inferBinaryName(manager, tuple.jfo);
173
        this.topLevels = null;
174
        this.newTypes = newTypes;
175
        this.mainMethod = mainMethod;
176
        index = Neo4jIndex.getDefault();
177
        neoTx = TransactionContext.get().get(Neo4jIndexTransaction.class);
178
        rootNode = neoTx.getRootNode();
179
        usages = new HashMap<ClassNode, Map<String, BitSet>>();
180
    }
181
182
    @Override
183
    @CheckForNull
184
    public Void scan(@NonNull final Tree node, @NullAllowed final Void nil) {
185
        if (node == null) {
186
            return null;
187
        }
188
        super.scan(node, nil);
189
        return null;
190
    }
191
192
    @Override
193
    @CheckForNull
194
    public Void visitCompilationUnit(@NonNull final CompilationUnitTree node, @NullAllowed final Void nil) {
195
        this.cu = node;
196
        State oldState = state;
197
        try {
198
            state = State.PACKAGE_ANN;
199
            scan(node.getPackageAnnotations(), nil);
200
            scan(node.getPackageName(), nil);
201
            packageNode = index.getOrCreatePackage(rootNode, node.getPackageName().toString());
202
            state = State.IMPORT;
203
            scan(node.getImports(), nil);
204
        } finally {
205
            state = oldState;
206
        }
207
        scan(node.getTypeDecls(), nil);
208
209
        ClassNode classNode = null;
210
        if (!imports.isEmpty()
211
                || !staticImports.isEmpty()
212
                || !unusedPkgImports.isEmpty()) {
213
            //Empty file
214
            String className = getResourceSimpleName(node);
215
            if (className != null) {
216
                classNode = index.createClass(
217
                        packageNode,
218
                        className,
219
                        className,
220
                        ElementKind.CLASS,
221
                        null);
222
            }
223
            addAndClearImports(classNode);
224
            addAndClearUnusedPkgImports(classNode);
225
        }
226
227
        if (!packageAnnotations.isEmpty()) {
228
            if (classNode == null) {
229
                String className = getResourceSimpleName(node);
230
                if (className != null) {
231
                    classNode = index.createClass(
232
                            packageNode,
233
                            className,
234
                            className,
235
                            ElementKind.CLASS,
236
                            null);
237
                    for (Pair<Symbol, ClassIndexImpl.UsageType> usage : packageAnnotations) {
238
                        addUsage(classNode, usage.first, usage.second);
239
                    }
240
//TODO:                        for (CharSequence ident : packageAnnotationIdents) {
241
//                            addIdent(name, ident, p, false);
242
//                        }
243
                }
244
            }
245
            packageAnnotations.clear();
246
            packageAnnotationIdents.clear();
247
        }
248
        storeUsages();
249
        return null;
250
    }
251
252
    @Override
253
    @CheckForNull
254
    public Void visitClass(@NonNull final ClassTree node, @NullAllowed final Void nil) {
255
        final Symbol.ClassSymbol sym = ((JCTree.JCClassDecl) node).sym;
256
        boolean errorInDecl = false;
257
        boolean errorIgnorSubtree = true;
258
        boolean topLevel = false;
259
        String className = null;
260
        ClassNode classNode = null;
261
262
        if (sym != null) {
263
            errorInDecl = hasErrorName(sym);
264
            if (errorInDecl) {
265
                if (!activeClass.isEmpty()) {
266
                    classNode = activeClass.get(0);
267
                } else {
268
                    topLevel = true;
269
                    className = getResourceName(this.cu);
270
                    if (className != null && !className.isEmpty()) {
271
                        final String simpleName = className.substring(className.lastIndexOf('.') + 1);  //NOI18N
272
                        classNode = index.createClass(
273
                                packageNode,
274
                                simpleName,
275
                                simpleName,
276
                                ElementKind.CLASS,
277
                                null);
278
                    } else {
279
                        LOG.log(
280
                                Level.WARNING,
281
                                "Cannot resolve {0} (class name: {1}), ignoring whole subtree.", //NOI18N
282
                                new Object[]{
283
                                    sym,
284
                                    className
285
                                });
286
                    }
287
                }
288
            } else {
289
                final StringBuilder classNameBuilder = new StringBuilder();
290
                ClassFileUtil.encodeClassName(sym, classNameBuilder, '.');  //NOI18N
291
                className = classNameBuilder.toString();
292
                if (!className.isEmpty()) {
293
                    ElementKind classType = sym.getKind();
294
                    String resourceName = null;
295
                    topLevel = activeClass.isEmpty();
296
                    if (topLevel) {
297
                        if (virtual || !className.equals(sourceName)) {
298
                            if (signatureFiles && rsList == null) {
299
                                rsList = new HashSet<String>();
300
                                if (crossedTopLevel) {
301
                                    rsList.add(sourceName);
302
                                }
303
                            }
304
                            final StringBuilder rnBuilder = new StringBuilder(FileObjects.convertPackage2Folder(sourceName));
305
                            rnBuilder.append('.');  //NOI18N
306
                            rnBuilder.append(FileObjects.getExtension(siblingUrl.getPath()));
307
                            resourceName = rnBuilder.toString();
308
                        } else {
309
                            crossedTopLevel = true;
310
                        }
311
                    } else {
312
                        resourceName = activeClass.peek().getResourceName();
313
                    }
314
                    classNode = index.createClass(
315
                            packageNode,
316
                            sym.getSimpleName().toString(),
317
                            className.substring(className.lastIndexOf('.') + 1),    //NOI18N
318
                            classType,
319
                            resourceName);
320
                } else {
321
                    LOG.log(
322
                            Level.WARNING,
323
                            "Invalid symbol {0} (source: {1}), ignoring whole subtree.", //NOI18N
324
                            new Object[]{
325
                                sym,
326
                                siblingUrl
327
                            });
328
                }
329
            }
330
        }
331
        if (classNode != null) {
332
            activeClass.push(classNode);
333
            errorIgnorSubtree = false;
334
            if (className != null) {
335
                if (topLevel) {
336
                    if (topLevels != null) {
337
                        topLevels.add(Pair.<String, String>of(className, classNode.getResourceName()));
338
                    }
339
                    addAndClearImports(classNode);
340
                }
341
                addUsage(classNode, className, ClassIndexImpl.UsageType.TYPE_REFERENCE);
342
                // index only simple name, not FQN for classes
343
//TODO:                    addIdent(classNode, simpleName, nil, true);
344
                if (newTypes != null) {
345
                    newTypes.add((ElementHandle<TypeElement>) ElementHandle.createTypeElementHandle(ElementKind.CLASS, className));
346
                }
347
            }
348
        }
349
        if (!errorIgnorSubtree) {
350
            Element old = enclosingElement;
351
            try {
352
                enclosingElement = sym;
353
                scan(node.getModifiers(), nil);
354
                scan(node.getTypeParameters(), nil);
355
                state = errorInDecl ? State.OTHER : State.EXTENDS;
356
                scan(node.getExtendsClause(), nil);
357
                state = errorInDecl ? State.OTHER : State.IMPLEMENTS;
358
                scan(node.getImplementsClause(), nil);
359
                state = State.OTHER;
360
                scan(node.getMembers(), nil);
361
                activeClass.pop();
362
            } finally {
363
                enclosingElement = old;
364
            }
365
        }
366
        if (!errorInDecl && this.rsList != null) {
367
            this.rsList.add(className);
368
        }
369
        if (topLevel) {
370
            addAndClearUnusedPkgImports(classNode);
371
        }
372
        return null;
373
    }
374
375
    @Override
376
    @CheckForNull
377
    public Void visitNewClass(@NonNull final NewClassTree node, @NullAllowed final Void nil) {
378
        final Symbol sym = ((JCTree.JCNewClass) node).constructor;
379
        if (sym != null) {
380
            final Symbol owner = sym.getEnclosingElement();
381
            if (owner != null && owner.getKind().isClass()) {
382
                addUsage(
383
                        activeClass.peek(),
384
                        owner,
385
                        ClassIndexImpl.UsageType.METHOD_REFERENCE);
386
            }
387
        }
388
        return super.visitNewClass(node, nil);
389
    }
390
391
    @Override
392
    @CheckForNull
393
    public Void visitErroneous(@NonNull final ErroneousTree tree, @NullAllowed final Void nil) {
394
        List<? extends Tree> trees = tree.getErrorTrees();
395
        for (Tree t : trees) {
396
            this.scan(t, nil);
397
        }
398
        return null;
399
    }
400
401
    @Override
402
    @CheckForNull
403
    public Void visitMethod(@NonNull final MethodTree node, @NullAllowed final Void nil) {
404
        Element old = enclosingElement;
405
        try {
406
            enclosingElement = ((JCTree.JCMethodDecl) node).sym;
407
            if (enclosingElement != null && enclosingElement.getKind() == ElementKind.METHOD) {
408
                mainMethod[0] |= SourceUtils.isMainMethod((ExecutableElement) enclosingElement);
409
                // do not add idents for constructors, they always match their class' name, which is added as an ident separately
410
//todo:                    addIdent(activeClass.peek(), node.getName(), p, true);
411
            }
412
            return super.visitMethod(node, nil);
413
        } finally {
414
            enclosingElement = old;
415
        }
416
    }
417
418
    @Override
419
    @CheckForNull
420
    public Void visitVariable(@NonNull final VariableTree node, @NullAllowed final Void nil) {
421
        Symbol s = ((JCTree.JCVariableDecl) node).sym;
422
        if (s != null && s.owner != null && (s.owner.getKind().isClass() || s.owner.getKind().isInterface())) {
423
//todo:                addIdent(activeClass.peek(), node.getName(), p, true);
424
        }
425
        return super.visitVariable(node, nil);
426
    }
427
428
    @Override
429
    @CheckForNull
430
    public Void visitMemberSelect(@NonNull final MemberSelectTree node, @NullAllowed final Void nil) {
431
        handleVisitIdentSelect(((JCTree.JCFieldAccess) node).sym, node.getIdentifier());
432
        State oldState = this.state;
433
        this.state = (this.state == State.IMPORT || state == State.PACKAGE_ANN) ? state : State.OTHER;
434
        Void ret = super.visitMemberSelect(node, nil);
435
        this.state = oldState;
436
        return ret;
437
    }
438
439
    @Override
440
    @CheckForNull
441
    public Void visitIdentifier(@NonNull final IdentifierTree node, @NonNull @NullAllowed final Void nil) {
442
        handleVisitIdentSelect(((JCTree.JCIdent) node).sym, node.getName());
443
        return super.visitIdentifier(node, nil);
444
    }
445
446
    @Override
447
    @CheckForNull
448
    public Void visitImport(@NonNull final ImportTree node, @NullAllowed final Void nil) {
449
        this.isStaticImport = node.isStatic();
450
        final Tree qit = node.getQualifiedIdentifier();
451
        isPkgImport = qit.getKind() == Tree.Kind.MEMBER_SELECT && pkgImportName == (((MemberSelectTree) qit).getIdentifier());
452
        final Void ret = super.visitImport(node, nil);
453
        isStaticImport = isPkgImport = false;
454
        return ret;
455
    }
456
457
    private void handleVisitIdentSelect(
458
            @NullAllowed final Symbol sym,
459
            @NonNull final CharSequence name) {
460
        if (!activeClass.empty()) {
461
//todo:                addIdent(activeClass.peek(), name, p, false);
462
            if (sym != null) {
463
                if (sym.kind == Kinds.ERR) {
464
                    final Symbol owner = sym.getEnclosingElement();
465
                    if (owner.getKind().isClass() || owner.getKind().isInterface()) {
466
                        addUsage(activeClass.peek(), owner, ClassIndexImpl.UsageType.TYPE_REFERENCE);
467
                    }
468
                }
469
                if (sym.getKind().isClass() || sym.getKind().isInterface()) {
470
                    switch (this.state) {
471
                        case EXTENDS:
472
                            addUsage(activeClass.peek(), sym, ClassIndexImpl.UsageType.SUPER_CLASS);
473
                            break;
474
                        case IMPLEMENTS:
475
                            addUsage(activeClass.peek(), sym, ClassIndexImpl.UsageType.SUPER_INTERFACE);
476
                            break;
477
                        case OTHER:
478
                        case GT:
479
                            addUsage(activeClass.peek(), sym, ClassIndexImpl.UsageType.TYPE_REFERENCE);
480
                            break;
481
                    }
482
                } else if (sym.getKind().isField()) {
483
                    final Symbol owner = sym.getEnclosingElement();
484
                    if (owner.getKind().isClass() || owner.getKind().isInterface()) {
485
                        addUsage(activeClass.peek(), owner, ClassIndexImpl.UsageType.FIELD_REFERENCE);
486
                    }
487
                    recordTypeUsage(sym.asType());
488
                } else if (sym.getKind() == ElementKind.CONSTRUCTOR || sym.getKind() == ElementKind.METHOD) {
489
                    final Symbol owner = sym.getEnclosingElement();
490
                    if (owner.getKind().isClass() || owner.getKind().isInterface()) {
491
                        addUsage(activeClass.peek(), owner, ClassIndexImpl.UsageType.METHOD_REFERENCE);
492
                    }
493
                    recordTypeUsage(((Symbol.MethodSymbol) sym).getReturnType());
494
                }
495
            }
496
        } else {
497
            if (state == State.IMPORT) {
498
                importIdents.add(name);
499
                if (sym != null && (sym.getKind().isClass() || sym.getKind().isInterface())) {
500
                    if (this.isStaticImport) {
501
                        this.staticImports.add(sym);
502
                    } else {
503
                        this.imports.add(sym);
504
                    }
505
                } else if (isPkgImport && sym != null && sym.getKind() == ElementKind.PACKAGE) {
506
                    unusedPkgImports.add(sym);
507
                    isPkgImport = false;
508
                }
509
            } else if (state == State.PACKAGE_ANN) {
510
                packageAnnotationIdents.add(name);
511
                if (sym != null) {
512
                    if (sym.kind == Kinds.ERR) {
513
                        final Symbol owner = sym.getEnclosingElement();
514
                        if (owner.getKind().isClass() || owner.getKind().isInterface()) {
515
                            packageAnnotations.add(Pair.of(owner, ClassIndexImpl.UsageType.TYPE_REFERENCE));
516
                        }
517
                    }
518
                    if (sym.getKind().isClass() || sym.getKind().isInterface()) {
519
                        packageAnnotations.add(Pair.of(sym, ClassIndexImpl.UsageType.TYPE_REFERENCE));
520
                    } else if (sym.getKind().isField()) {
521
                        final Symbol owner = sym.getEnclosingElement();
522
                        if (owner.getKind().isClass() || owner.getKind().isInterface()) {
523
                            packageAnnotations.add(Pair.of(owner, ClassIndexImpl.UsageType.FIELD_REFERENCE));
524
                        }
525
                    } else if (sym.getKind() == ElementKind.CONSTRUCTOR || sym.getKind() == ElementKind.METHOD) {
526
                        final Symbol owner = sym.getEnclosingElement();
527
                        if (owner.getKind().isClass() || owner.getKind().isInterface()) {
528
                            packageAnnotations.add(Pair.of(owner, ClassIndexImpl.UsageType.METHOD_REFERENCE));
529
                        }
530
                    }
531
                }
532
            }
533
        }
534
    }
535
536
    @Override
537
    @CheckForNull
538
    public Void visitParameterizedType(@NonNull final ParameterizedTypeTree node, @NullAllowed final Void nil) {
539
        scan(node.getType(), nil);
540
        State currState = this.state;
541
        this.state = State.GT;
542
        scan(node.getTypeArguments(), nil);
543
        this.state = currState;
544
        return null;
545
    }
546
547
    @NonNull
548
    private String inferBinaryName(
549
            @NonNull final JavaFileManager jfm,
550
            @NonNull final javax.tools.JavaFileObject jfo) throws IllegalArgumentException {
551
        String result = jfm.inferBinaryName(StandardLocation.SOURCE_PATH, jfo);
552
        if (result != null) {
553
            return result;
554
        }
555
        FileObject fo = null;
556
        ClassPath scp = null;
557
        try {
558
            fo = URLMapper.findFileObject(jfo.toUri().toURL());
559
            if (fo != null) {
560
                scp = ClassPath.getClassPath(fo, ClassPath.SOURCE);
561
                if (scp != null) {
562
                    result = scp.getResourceName(fo, '.', false); //NOI18N
563
                    if (result != null) {
564
                        return result;
565
                    }
566
                }
567
            }
568
        } catch (MalformedURLException e) {
569
            //pass - throws IAE
570
        }
571
        throw new IllegalArgumentException(String.format("File: %s Type: %s FileObject: %s Sourcepath: %s", //NOI18N
572
                jfo.toUri().toString(),
573
                jfo.getClass().getName(),
574
                fo == null ? "<null>" : FileUtil.getFileDisplayName(fo), //NOI18N
575
                scp == null ? "<null>" : scp.toString()));   //NOI18N
576
    }
577
578
    @CheckForNull
579
    private static String getResourceSimpleName(@NullAllowed final CompilationUnitTree cu) {
580
        final FileObject file = findFile(cu);
581
        if (file != null) {
582
            return file.getName();
583
        }
584
        return null;
585
    }
586
587
    @CheckForNull
588
    private static String getResourceName (@NullAllowed final CompilationUnitTree cu) {
589
        final FileObject file = findFile(cu);
590
        if (file != null) {
591
            final ClassPath cp = ClassPath.getClassPath(file,ClassPath.SOURCE);
592
            if (cp != null) {
593
                return cp.getResourceName(file,'.',false);
594
            }
595
        }
596
        return null;
597
    }
598
599
    @CheckForNull
600
    private static FileObject findFile(@NullAllowed final CompilationUnitTree cu) {
601
        if (cu instanceof JCTree.JCCompilationUnit) {
602
            JavaFileObject jfo = ((JCTree.JCCompilationUnit)cu).sourcefile;
603
            if (jfo != null) {
604
                URI uri = jfo.toUri();
605
                if (uri != null && uri.isAbsolute()) {
606
                    try {
607
                        FileObject fo = URLMapper.findFileObject(uri.toURL());
608
                        return fo;
609
                    } catch (MalformedURLException e) {
610
                        Exceptions.printStackTrace(e);
611
                    }
612
                }
613
            }
614
        }
615
        return null;
616
    }
617
618
    private boolean hasErrorName(@NullAllowed Symbol cs) {
619
        while (cs != null) {
620
            if (cs.name == errorName) {
621
                return true;
622
            }
623
            cs = cs.getEnclosingElement();
624
        }
625
        return false;
626
    }
627
628
    private void addAndClearImports(
629
            @NullAllowed final ClassNode classNode) {
630
        if (classNode != null) {
631
            for (Symbol s : imports) {
632
                addUsage(
633
                        classNode,
634
                        s,
635
                        ClassIndexImpl.UsageType.TYPE_REFERENCE);
636
            }
637
            for (Symbol s : staticImports) {
638
                addUsage(
639
                        classNode,
640
                        s,                        
641
                        ClassIndexImpl.UsageType.TYPE_REFERENCE,
642
                        ClassIndexImpl.UsageType.METHOD_REFERENCE,
643
                        ClassIndexImpl.UsageType.FIELD_REFERENCE);
644
            }
645
//TODO:                for (CharSequence s : importIdents) {
646
//                    addIdent(nameOfCU, s, data, false);
647
//                }
648
        }
649
        imports.clear();
650
        staticImports.clear();
651
        importIdents.clear();
652
    }
653
654
    private void addAndClearUnusedPkgImports(
655
            @NullAllowed final ClassNode classNode) {
656
        if (classNode != null) {
657
            for (Symbol s : unusedPkgImports) {
658
                final StringBuilder sb = new StringBuilder();
659
                sb.append(s.getQualifiedName());
660
                sb.append(".package-info"); //NOI18N
661
                addUsage(classNode, sb.toString(), ClassIndexImpl.UsageType.TYPE_REFERENCE);
662
            }
663
        }
664
        unusedPkgImports.clear();
665
    }
666
667
    @CheckForNull
668
    private static String encodeClassName(@NonNull final Symbol sym) {
669
        assert sym instanceof Symbol.ClassSymbol;
670
        TypeElement toEncode = null;
671
        final TypeMirror type = ((Symbol.ClassSymbol) sym).asType();
672
        if (sym.getEnclosingElement().getKind() == ElementKind.TYPE_PARAMETER) {
673
            if (type.getKind() == TypeKind.ARRAY) {
674
                TypeMirror ctype = ((ArrayType) type).getComponentType();
675
                if (ctype.getKind() == TypeKind.DECLARED) {
676
                    toEncode = (TypeElement) ((DeclaredType) ctype).asElement();
677
                }
678
            }
679
        } else {
680
            toEncode = (TypeElement) sym;
681
        }
682
        return toEncode == null ? null : ClassFileUtil.encodeClassName(toEncode);
683
    }
684
685
    private void addUsage(@NonNull final ClassNode classNode,
686
            @NullAllowed final Symbol sym,
687
            @NonNull final ClassIndexImpl.UsageType... usageTypes) {
688
        assert classNode != null;
689
        assert usageTypes != null;
690
        if (sym != null) {
691
            final String className = encodeClassName(sym);
692
            for (ClassIndexImpl.UsageType usageType : usageTypes) {
693
                addUsage(classNode, className, usageType);
694
            }
695
            final Symbol encElm = sym.getEnclosingElement();
696
            if (encElm.getKind() == ElementKind.PACKAGE) {
697
                unusedPkgImports.remove(encElm);
698
            }
699
        }
700
    }
701
702
    private void addUsage(
703
            @NonNull final ClassNode classNode,
704
            @NullAllowed final Symbol sym,
705
            @NonNull final ClassIndexImpl.UsageType usageType) {
706
        assert classNode != null;
707
        assert usageType != null;
708
        if (sym != null) {
709
            final String className = encodeClassName(sym);
710
            addUsage(classNode, className, usageType);
711
            final Symbol encElm = sym.getEnclosingElement();
712
            if (encElm.getKind() == ElementKind.PACKAGE) {
713
                unusedPkgImports.remove(encElm);
714
            }
715
        }
716
    }
717
718
    private void addUsage(
719
            @NonNull final ClassNode user,
720
            @NullAllowed final String className,
721
            @NonNull final ClassIndexImpl.UsageType type) {
722
        if (className != null) {
723
            Map<String,BitSet> usagesForClass = usages.get(user);
724
            if (usagesForClass == null) {
725
                usagesForClass = new HashMap<String, BitSet>();
726
                usages.put(user, usagesForClass);
727
            }
728
            BitSet usageTypes = usagesForClass.get(className);
729
            if (usageTypes == null) {
730
                usageTypes = new BitSet(ClassIndexImpl.UsageType.values().length);
731
                usagesForClass.put(className, usageTypes);
732
            }
733
            usageTypes.set(type.ordinal());
734
        }
735
    }
736
737
    private void storeUsages() {
738
        for (Map.Entry<ClassNode,Map<String,BitSet>> cu : usages.entrySet()) {
739
            final ClassNode user = cu.getKey();
740
            for (Map.Entry<String,BitSet> us : cu.getValue().entrySet()) {
741
                final String className = us.getKey();
742
                TypeReferenceNode reference = neoTx.getCachedTypeReference(className);
743
                if (reference == null) {
744
                    reference = index.getOrCreateTypeReference(className);
745
                    neoTx.cacheTypeReference(className, reference);
746
                }
747
                user.uses(reference, us.getValue());
748
            }
749
        }
750
    }
751
752
    private void recordTypeUsage(final TypeMirror type) {
753
        Deque<TypeMirror> types = new ArrayDeque<TypeMirror>();
754
        types.add(type);
755
        while (!types.isEmpty()) {
756
            TypeMirror currentType = types.removeFirst();
757
            if (currentType == null) {
758
                continue;
759
            }
760
            switch (currentType.getKind()) {
761
                case DECLARED:
762
                    final Symbol typeSym = ((Type) currentType).tsym;
763
                    if (typeSym != null && (typeSym.getKind().isClass() || typeSym.getKind().isInterface())) {
764
                        addUsage(activeClass.peek(), typeSym, ClassIndexImpl.UsageType.TYPE_REFERENCE);
765
                    }
766
                    types.addAll(((DeclaredType) currentType).getTypeArguments());
767
                    break;
768
                case ARRAY:
769
                    types.add(((ArrayType) currentType).getComponentType());
770
                    break;
771
            }
772
        }
773
    }
774
}
(-)a/java.source/src/org/netbeans/modules/java/source/indexing/neo4j/Neo4jIndex.java (+211 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.java.source.indexing.neo4j;
43
44
import com.sun.source.tree.ClassTree;
45
import com.sun.tools.javac.tree.JCTree;
46
import java.net.URL;
47
import javax.lang.model.element.ElementKind;
48
import org.neo4j.graphdb.Node;
49
import org.neo4j.graphdb.Transaction;
50
import org.neo4j.graphdb.index.Index;
51
import org.neo4j.kernel.EmbeddedGraphDatabase;
52
import org.netbeans.api.annotations.common.NonNull;
53
import org.netbeans.api.annotations.common.NullAllowed;
54
55
/**
56
 *
57
 * @author tom
58
 */
59
public class Neo4jIndex {
60
61
    private static final String ROOTS_INDEX = "roots";  //NOI18N
62
    private static final String PACKAGES_INDEX = "packages";  //NOI18N
63
    private static final String CLASSES_INDEX = "classes";  //NOI18N
64
    private static final String HANDLES_INDEX = "type-references";    //NOI18N
65
66
    //GuardedBy("Neo4jIndex.class")
67
    private static Neo4jIndex instance;
68
69
    //GuardedBy("this")
70
    private  EmbeddedGraphDatabase db;
71
    //GuardedBy("this")
72
    private Index<Node> roots;
73
    //GuardedBy("this")
74
    private Index<Node> packages;
75
    //GuardedBy("this")
76
    private Index<Node> classSimpleNames;
77
    //GuardedBy("this")
78
    private Index<Node> references;
79
    //GuardedBy("this")
80
    private RootNode.Factory rootFactory;
81
    //GuardedBy("this")
82
    private PackageNode.Factory packageFactory;
83
    //GuardedBy("this")
84
    private TypeReferenceNode.Factory typeReferenceFactory;
85
86
    private Neo4jIndex() {
87
    }
88
89
90
91
    public synchronized void start() {
92
        if (db == null) {
93
            db = new EmbeddedGraphDatabase("/tmp/neo");
94
            roots = db.index().forNodes(ROOTS_INDEX);
95
            packages = db.index().forNodes(PACKAGES_INDEX);
96
            classSimpleNames = db.index().forNodes(CLASSES_INDEX);
97
            references = db.index().forNodes(HANDLES_INDEX);
98
            rootFactory = new RootNode.Factory(roots);
99
            packageFactory = new PackageNode.Factory(packages);
100
            typeReferenceFactory = new TypeReferenceNode.Factory(references);
101
        }
102
    }
103
104
105
    public synchronized void stop() {
106
        if (db != null) {
107
            db.shutdown();
108
            db = null;
109
            roots = null;
110
            packages = null;
111
            classSimpleNames = null;
112
            references = null;
113
            rootFactory = null;
114
            packageFactory = null;
115
            typeReferenceFactory = null;
116
        }
117
    }
118
119
    @NonNull
120
    Transaction begin() {
121
        return db.beginTx();
122
    }
123
124
    void commit(@NonNull final Transaction tx) {
125
        try {
126
            tx.success();
127
        } finally {
128
            tx.finish();
129
        }
130
    }
131
132
    void rollBack(@NonNull final Transaction tx) {
133
        try {
134
            tx.failure();
135
        } finally {
136
            tx.finish();
137
        }
138
    }
139
140
    RootNode getOrCreateRoot(@NonNull final URL url) {
141
        return rootFactory.getOrCreate(url.toExternalForm());
142
    }
143
144
    PackageNode getOrCreatePackage(
145
            @NonNull final RootNode root,
146
            @NonNull final String packageName) {
147
        packageFactory.setRoot(root);
148
        return packageFactory.getOrCreate(packageName);
149
    }
150
151
    ClassNode createClass(
152
            @NonNull final PackageNode packageNode,
153
            @NonNull final String simpleName,
154
            @NonNull final String binaryName,
155
            @NonNull final ElementKind kind,
156
            @NullAllowed final String resourceName) {
157
        return ClassNode.create(
158
                db,
159
                classSimpleNames,
160
                binaryName,
161
                simpleName,
162
                packageNode,
163
                kind,
164
                resourceName);
165
    }
166
167
    TypeReferenceNode getOrCreateTypeReference(@NonNull final String binaryName) {
168
        return typeReferenceFactory.getOrCreate(binaryName);
169
    }
170
171
//    public Node lookupClass(ClassTree classTree) {
172
//        // determine if the class is part of the current scope, then link directly
173
//        // other lookup or create a placeholder type and link to that
174
//        return classes.get("fqn", className(classTree)).getSingle();
175
//    }
176
177
//    public Collection<String> methodNames(ClassTree className) {
178
//        // start class=node:classes(name="foo") match class-[:METHOD_OF]->method where method.name in "bar.*" return method limit 5;
179
//        final Relationship methodRel = lookupClass(className).getSingleRelationship(Direction.OUTGOING, RelTypes.METHOD_OF);
180
//        final Iterable<Relationship> methodRels = lookupClass(className).getRelationships(Direction.OUTGOING, RelTypes.METHOD_OF);
181
//        Collection<String> result=new ArrayList<String>();
182
//        for (Relationship relationship : methodRels) {
183
//            Node methodNode = relationship.getEndNode();
184
//            result.add((String)methodNode.getProperty("name"));
185
//        }
186
//        return result;
187
//    }
188
189
//    public void addMethod(ClassTree classTree, MethodTree methodTree){
190
//        Node classNode = getOrCreateClass(classTree);
191
//        Node methodNode=db.createNode();
192
//        classes.add(methodNode, "methodSignature", vmSignature);   //Indexed field
193
//        classNode.createRelationshipTo(methodNode, RelTypes.METHOD_OF);
194
//        ExecutableElement method  = ((JCTree.JCMethodDecl) methodTree).sym;
195
//        String returnType = method.getReturnType().toString();
196
//        methodNode.createRelationshipTo(getOrCreateClass(returnType), RelTypes.RETURN_TYPE);
197
//
198
//    }
199
200
    public static synchronized Neo4jIndex getDefault() {
201
        if (instance == null) {
202
            instance = new Neo4jIndex();
203
        }
204
        return instance;
205
    }
206
207
    private String className(final ClassTree classTree) {
208
        return ((JCTree.JCClassDecl)classTree).sym.fullname.toString();
209
    }
210
211
}
(-)a/java.source/src/org/netbeans/modules/java/source/indexing/neo4j/Neo4jIndexTransaction.java (+144 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.java.source.indexing.neo4j;
43
44
import java.io.IOException;
45
import java.net.URL;
46
import java.util.HashMap;
47
import java.util.Map;
48
import java.util.logging.Level;
49
import java.util.logging.Logger;
50
import org.neo4j.graphdb.Transaction;
51
import org.netbeans.api.annotations.common.CheckForNull;
52
import org.netbeans.api.annotations.common.NonNull;
53
import org.netbeans.modules.java.source.indexing.TransactionContext;
54
55
/**
56
 *
57
 * @author Tomas Zezula
58
 */
59
public class Neo4jIndexTransaction extends TransactionContext.Service {
60
61
    private static final Logger LOG = Logger.getLogger(Neo4jIndexTransaction.class.getName());
62
63
    private final URL root;
64
    private final Neo4jIndex index;
65
    private final Transaction tx;
66
    private final Map<String,PackageNode> pkgCache;
67
    private final Map<String,TypeReferenceNode> clsCache;
68
    private RootNode rootNode;
69
    
70
71
    private Neo4jIndexTransaction(@NonNull final URL root) {
72
        this.root = root;
73
        this.index = Neo4jIndex.getDefault();
74
        this.tx = index.begin();
75
        this.clsCache = new HashMap<String, TypeReferenceNode>();
76
        this.pkgCache = new HashMap<String, PackageNode>();
77
        TimeLogger.clear();
78
    }
79
80
    @Override
81
    protected void commit() throws IOException {
82
        try {
83
            freeCache();
84
        } finally {
85
            index.commit(tx);
86
            LOG.log(
87
                Level.INFO,
88
                "Time spent in neo4j: {0} ms for root: {1}.",  //NOI18N
89
                new Object[]{
90
                    TimeLogger.getMillis(),
91
                    root
92
                });
93
        }
94
    }
95
96
    @Override
97
    protected void rollBack() throws IOException {
98
        try {
99
            freeCache();
100
        } finally {
101
            index.rollBack(tx);
102
        }
103
    }
104
105
    @NonNull
106
    RootNode getRootNode() {
107
        if (rootNode == null) {
108
            rootNode = index.getOrCreateRoot(root);
109
        }
110
        return rootNode;
111
    }
112
113
    @CheckForNull
114
    PackageNode getCachedPackage(@NonNull final String fqn) {
115
        return pkgCache.get(fqn);
116
    }
117
118
    void cachePackage(
119
            @NonNull final String fqn,
120
            @NonNull final PackageNode node) {
121
        pkgCache.put(fqn,node);
122
    }
123
    
124
    @CheckForNull
125
    TypeReferenceNode getCachedTypeReference(@NonNull final String fqn) {
126
        return clsCache.get(fqn);
127
    }
128
    
129
    void cacheTypeReference(
130
            @NonNull final String fqn,
131
            @NonNull final TypeReferenceNode node) {
132
        clsCache.put(fqn,node);
133
    }
134
135
    private void freeCache() {
136
        clsCache.clear();
137
        pkgCache.clear();
138
    }
139
140
    public static Neo4jIndexTransaction create(@NonNull final URL root) {
141
        return new Neo4jIndexTransaction(root);
142
    }
143
144
}
(-)a/java.source/src/org/netbeans/modules/java/source/indexing/neo4j/PackageNode.java (+94 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.java.source.indexing.neo4j;
43
44
import java.util.Map;
45
import org.neo4j.graphdb.Node;
46
import org.neo4j.graphdb.index.Index;
47
import org.neo4j.graphdb.index.UniqueFactory;
48
import org.netbeans.api.annotations.common.NonNull;
49
50
/**
51
 *
52
 * @author Tomas Zezula
53
 */
54
class PackageNode extends ModelNode {
55
56
    private PackageNode(Node node) {
57
        super(node);
58
    }
59
60
61
    //@NotThreadSafe
62
    static class Factory extends UniqueFactory.UniqueNodeFactory {
63
64
        private static final String PROP_NAME = "name"; //NOI18N
65
66
        private RootNode root;
67
68
        Factory(
69
                @NonNull final Index<Node> packageIndex) {
70
            super(packageIndex);
71
        }
72
73
        @Override
74
        protected void initialize(
75
                @NonNull final Node t,
76
                @NonNull final Map<String, Object> map) {
77
            t.setProperty(PROP_NAME, map.get(PROP_NAME));
78
            t.createRelationshipTo(root.node, RelationshipTypes.IN_ROOT);
79
        }
80
81
        void setRoot(@NonNull final RootNode root) {
82
            this.root = root;
83
        }
84
85
        PackageNode getOrCreate(String name) {
86
            TimeLogger.start();
87
            try {
88
                return new PackageNode(getOrCreate(PROP_NAME, name));
89
            } finally {
90
                TimeLogger.stop();
91
            }
92
        }
93
    }
94
}
(-)a/java.source/src/org/netbeans/modules/java/source/indexing/neo4j/RelationshipTypes.java (+100 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.java.source.indexing.neo4j;
43
44
import org.neo4j.graphdb.RelationshipType;
45
import org.netbeans.api.annotations.common.NonNull;
46
import org.netbeans.modules.java.source.usages.ClassIndexImpl;
47
48
/**
49
 *
50
 * @author Tomas Zezula
51
 */
52
enum RelationshipTypes implements RelationshipType {
53
    IN_ROOT,
54
    IN_PACKAGE,
55
    SUPER_CLASS,
56
    SUPER_INTERFACE,
57
    FIELD_REFERENCE,
58
    METHOD_REFERENCE,
59
    TYPE_REFERENCE;
60
    
61
    private static final RelationshipTypes[] translation;
62
63
    static {
64
        final ClassIndexImpl.UsageType[] values = ClassIndexImpl.UsageType.values();
65
        translation = new RelationshipTypes[values.length];
66
        for (int i = 0; i < values.length; i++) {
67
            translation[i] = fromUsageType(values[i]);
68
        }
69
    }
70
71
    @NonNull
72
    static RelationshipTypes fromUsageType(@NonNull final ClassIndexImpl.UsageType ut) {
73
        switch (ut) {
74
            case FIELD_REFERENCE:
75
                return FIELD_REFERENCE;
76
            case METHOD_REFERENCE:
77
                return METHOD_REFERENCE;
78
            case SUPER_CLASS:
79
                return SUPER_CLASS;
80
            case SUPER_INTERFACE:
81
                return SUPER_INTERFACE;
82
            case TYPE_REFERENCE:
83
                return TYPE_REFERENCE;
84
            default:
85
                throw new IllegalArgumentException(ut.toString());
86
        }
87
    }
88
89
90
    static RelationshipTypes fromUsageTypeOrdinal(final int ordinal) {
91
        checkRange(ordinal, translation.length);
92
        return translation[ordinal];
93
    }
94
95
    private static void checkRange(int index, int len) {
96
        if (index < 0 || index >= len) {
97
            throw new IllegalArgumentException(String.format("Index: %d, Length: %d", index, len)); //NOI18N
98
        }
99
    }
100
}
(-)a/java.source/src/org/netbeans/modules/java/source/indexing/neo4j/RootNode.java (+90 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.java.source.indexing.neo4j;
43
44
import java.util.Map;
45
import org.neo4j.graphdb.Node;
46
import org.neo4j.graphdb.index.Index;
47
import org.neo4j.graphdb.index.UniqueFactory.UniqueNodeFactory;
48
import org.netbeans.api.annotations.common.NonNull;
49
50
/**
51
 *
52
 * @author Tomas Zezula
53
 */
54
class RootNode extends ModelNode {
55
56
    private static final String PROP_LOCATION = "location"; //NOI18N
57
    
58
59
    private RootNode(@NonNull Node node) {
60
        super(node);
61
    }
62
63
    String getURL() {
64
        return (String) node.getProperty(PROP_LOCATION);
65
    }
66
67
68
    static final class Factory extends UniqueNodeFactory {
69
70
        Factory(
71
                @NonNull final Index<Node> rootIndex) {
72
            super(rootIndex);
73
        }
74
75
        @Override
76
        protected void initialize(Node t, Map<String, Object> map) {
77
            t.setProperty(PROP_LOCATION, map.get(PROP_LOCATION));
78
        }
79
80
        RootNode getOrCreate(String name) {
81
            TimeLogger.start();
82
            try {
83
                return new RootNode(getOrCreate(PROP_LOCATION, name));
84
            } finally {
85
                TimeLogger.stop();
86
            }
87
        }
88
    }
89
90
}
(-)a/java.source/src/org/netbeans/modules/java/source/indexing/neo4j/TimeLogger.java (+77 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.java.source.indexing.neo4j;
43
44
/**
45
 *
46
 * @author Tomas Zezula
47
 */
48
class TimeLogger {
49
50
    private static long time = 0;
51
    private static long startTime = 0;
52
53
    static void clear() {
54
        time = 0;
55
    }
56
57
    static void start() {
58
        if (startTime != 0) {
59
            throw new IllegalStateException();
60
        }
61
        startTime = System.nanoTime();
62
    }
63
64
    static void stop() {
65
        long stopTime = System.nanoTime();
66
        if (startTime == 0) {
67
            throw new IllegalStateException();
68
        }
69
        time+=(stopTime - startTime);
70
        startTime = 0;
71
    }
72
73
    static long getMillis() {
74
        return time/1000000;
75
    }
76
77
}
(-)a/java.source/src/org/netbeans/modules/java/source/indexing/neo4j/TypeReferenceNode.java (+82 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.java.source.indexing.neo4j;
43
44
import java.util.Map;
45
import org.neo4j.graphdb.Node;
46
import org.neo4j.graphdb.index.Index;
47
import org.neo4j.graphdb.index.UniqueFactory;
48
import org.netbeans.api.annotations.common.NonNull;
49
50
/**
51
 *
52
 * @author Tomas Zezula
53
 */
54
class TypeReferenceNode extends ModelNode {
55
    private TypeReferenceNode(@NonNull final Node node) {
56
        super(node);
57
    }
58
59
    static class Factory extends UniqueFactory.UniqueNodeFactory {
60
61
        private static final String PROP_BIN_NAME = "binName";
62
63
        Factory(
64
                @NonNull final Index<Node> classIndex) {
65
            super(classIndex);
66
        }
67
68
        @Override
69
        protected void initialize(Node t, Map<String, Object> map) {
70
            t.setProperty(PROP_BIN_NAME, map.get(PROP_BIN_NAME));
71
        }
72
73
        TypeReferenceNode getOrCreate(String name) {
74
            TimeLogger.start();
75
            try {
76
                return new TypeReferenceNode(getOrCreate(PROP_BIN_NAME, name));
77
            } finally {
78
                TimeLogger.stop();
79
            }
80
        }
81
    }
82
}
(-)a/libs.neo4j.core/build.xml (+48 lines)
Line 0 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<!--
3
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
5
Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
6
7
Oracle and Java are registered trademarks of Oracle and/or its affiliates.
8
Other names may be trademarks of their respective owners.
9
10
11
The contents of this file are subject to the terms of either the GNU
12
General Public License Version 2 only ("GPL") or the Common
13
Development and Distribution License("CDDL") (collectively, the
14
"License"). You may not use this file except in compliance with the
15
License. You can obtain a copy of the License at
16
http://www.netbeans.org/cddl-gplv2.html
17
or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
18
specific language governing permissions and limitations under the
19
License.  When distributing the software, include this License Header
20
Notice in each file and include the License file at
21
nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
22
particular file as subject to the "Classpath" exception as provided
23
by Oracle in the GPL Version 2 section of the License file that
24
accompanied this code. If applicable, add the following below the
25
License Header, with the fields enclosed by brackets [] replaced by
26
your own identifying information:
27
"Portions Copyrighted [year] [name of copyright owner]"
28
29
Contributor(s):
30
31
The Original Software is NetBeans. The Initial Developer of the Original
32
Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
33
Microsystems, Inc. All Rights Reserved.
34
35
If you wish your version of this file to be governed by only the CDDL
36
or only the GPL Version 2, indicate your decision by adding
37
"[Contributor] elects to include this software in this distribution
38
under the [CDDL or GPL Version 2] license." If you do not indicate a
39
single choice of license, a recipient has the option to distribute
40
your version of this file under either the CDDL, the GPL Version 2 or
41
to extend the choice of license to its licensees as provided above.
42
However, if you add GPL Version 2 code and therefore, elected the GPL
43
Version 2 license, then the option applies only if the new code is
44
made subject to such option by the copyright holder.
45
-->
46
<project name="libs.neo4j.core" default="netbeans" basedir=".">
47
    <import file="../nbbuild/templates/projectized.xml"/>
48
</project>
(-)a/libs.neo4j.core/manifest.mf (+4 lines)
Line 0 Link Here
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.libs.neo4j.core/1
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/libs/neo4j/core/Bundle.properties
4
OpenIDE-Module-Specification-Version: 1.0
(-)a/libs.neo4j.core/nbproject/project.properties (+46 lines)
Line 0 Link Here
1
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
#
3
# Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
4
#
5
# Oracle and Java are registered trademarks of Oracle and/or its affiliates.
6
# Other names may be trademarks of their respective owners.
7
#
8
# The contents of this file are subject to the terms of either the GNU
9
# General Public License Version 2 only ("GPL") or the Common
10
# Development and Distribution License("CDDL") (collectively, the
11
# "License"). You may not use this file except in compliance with the
12
# License. You can obtain a copy of the License at
13
# http://www.netbeans.org/cddl-gplv2.html
14
# or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
15
# specific language governing permissions and limitations under the
16
# License.  When distributing the software, include this License Header
17
# Notice in each file and include the License file at
18
# nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
19
# particular file as subject to the "Classpath" exception as provided
20
# by Oracle in the GPL Version 2 section of the License file that
21
# accompanied this code. If applicable, add the following below the
22
# License Header, with the fields enclosed by brackets [] replaced by
23
# your own identifying information:
24
# "Portions Copyrighted [year] [name of copyright owner]"
25
#
26
# Contributor(s):
27
#
28
# The Original Software is NetBeans. The Initial Developer of the Original
29
# Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
30
# Microsystems, Inc. All Rights Reserved.
31
#
32
# If you wish your version of this file to be governed by only the CDDL
33
# or only the GPL Version 2, indicate your decision by adding
34
# "[Contributor] elects to include this software in this distribution
35
# under the [CDDL or GPL Version 2] license." If you do not indicate a
36
# single choice of license, a recipient has the option to distribute
37
# your version of this file under either the CDDL, the GPL Version 2 or
38
# to extend the choice of license to its licensees as provided above.
39
# However, if you add GPL Version 2 code and therefore, elected the GPL
40
# Version 2 license, then the option applies only if the new code is
41
# made subject to such option by the copyright holder.
42
43
is.autoload=true
44
release.external/neo4j-lucene-index-1.8.M07.jar=modules/ext/neo4j-lucene-index-1.8.M07.jar
45
release.external/neo4j-kernel-1.8.M07.jar=modules/ext/neo4j-kernel-1.8.M07.jar
46
release.external/geronimo-jta_1.1_spec-1.1.1.jar=modules/ext/geronimo-jta_1.1_spec-1.1.1.jar
(-)a/libs.neo4j.core/nbproject/project.xml (+80 lines)
Line 0 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<!--
3
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
5
Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
6
7
Oracle and Java are registered trademarks of Oracle and/or its affiliates.
8
Other names may be trademarks of their respective owners.
9
10
11
The contents of this file are subject to the terms of either the GNU
12
General Public License Version 2 only ("GPL") or the Common
13
Development and Distribution License("CDDL") (collectively, the
14
"License"). You may not use this file except in compliance with the
15
License. You can obtain a copy of the License at
16
http://www.netbeans.org/cddl-gplv2.html
17
or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
18
specific language governing permissions and limitations under the
19
License.  When distributing the software, include this License Header
20
Notice in each file and include the License file at
21
nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
22
particular file as subject to the "Classpath" exception as provided
23
by Oracle in the GPL Version 2 section of the License file that
24
accompanied this code. If applicable, add the following below the
25
License Header, with the fields enclosed by brackets [] replaced by
26
your own identifying information:
27
"Portions Copyrighted [year] [name of copyright owner]"
28
29
Contributor(s):
30
31
The Original Software is NetBeans. The Initial Developer of the Original
32
Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
33
Microsystems, Inc. All Rights Reserved.
34
35
If you wish your version of this file to be governed by only the CDDL
36
or only the GPL Version 2, indicate your decision by adding
37
"[Contributor] elects to include this software in this distribution
38
under the [CDDL or GPL Version 2] license." If you do not indicate a
39
single choice of license, a recipient has the option to distribute
40
your version of this file under either the CDDL, the GPL Version 2 or
41
to extend the choice of license to its licensees as provided above.
42
However, if you add GPL Version 2 code and therefore, elected the GPL
43
Version 2 license, then the option applies only if the new code is
44
made subject to such option by the copyright holder.
45
-->
46
<project xmlns="http://www.netbeans.org/ns/project/1">
47
    <type>org.netbeans.modules.apisupport.project</type>
48
    <configuration>
49
        <data xmlns="http://www.netbeans.org/ns/nb-module-project/2">
50
            <code-name-base>org.netbeans.libs.neo4j.core</code-name-base>
51
            <module-dependencies>
52
                <dependency>
53
                    <code-name-base>org.netbeans.libs.lucene</code-name-base>
54
                    <build-prerequisite/>
55
                    <compile-dependency/>
56
                    <run-dependency>
57
                        <release-version>3</release-version>
58
                        <specification-version>3.8</specification-version>
59
                    </run-dependency>
60
                </dependency>
61
            </module-dependencies>
62
            <public-packages>
63
                <subpackages>org</subpackages>
64
                <subpackages>javax</subpackages>
65
            </public-packages>
66
            <class-path-extension>
67
                <runtime-relative-path>ext/neo4j-kernel-1.8.M07.jar</runtime-relative-path>
68
                <binary-origin>external/neo4j-kernel-1.8.M07.jar</binary-origin>
69
            </class-path-extension>
70
            <class-path-extension>
71
                <runtime-relative-path>ext/neo4j-lucene-index-1.8.M07.jar</runtime-relative-path>
72
                <binary-origin>external/neo4j-lucene-index-1.8.M07.jar</binary-origin>
73
            </class-path-extension>
74
            <class-path-extension>
75
                <runtime-relative-path>ext/geronimo-jta_1.1_spec-1.1.1.jar</runtime-relative-path>
76
                <binary-origin>external/geronimo-jta_1.1_spec-1.1.1.jar</binary-origin>
77
            </class-path-extension>
78
        </data>
79
    </configuration>
80
</project>
(-)a/libs.neo4j.core/src/org/netbeans/libs/neo4j/core/Bundle.properties (+48 lines)
Line 0 Link Here
1
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
#
3
# Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
4
#
5
# Oracle and Java are registered trademarks of Oracle and/or its affiliates.
6
# Other names may be trademarks of their respective owners.
7
#
8
# The contents of this file are subject to the terms of either the GNU
9
# General Public License Version 2 only ("GPL") or the Common
10
# Development and Distribution License("CDDL") (collectively, the
11
# "License"). You may not use this file except in compliance with the
12
# License. You can obtain a copy of the License at
13
# http://www.netbeans.org/cddl-gplv2.html
14
# or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
15
# specific language governing permissions and limitations under the
16
# License.  When distributing the software, include this License Header
17
# Notice in each file and include the License file at
18
# nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
19
# particular file as subject to the "Classpath" exception as provided
20
# by Oracle in the GPL Version 2 section of the License file that
21
# accompanied this code. If applicable, add the following below the
22
# License Header, with the fields enclosed by brackets [] replaced by
23
# your own identifying information:
24
# "Portions Copyrighted [year] [name of copyright owner]"
25
#
26
# Contributor(s):
27
#
28
# The Original Software is NetBeans. The Initial Developer of the Original
29
# Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
30
# Microsystems, Inc. All Rights Reserved.
31
#
32
# If you wish your version of this file to be governed by only the CDDL
33
# or only the GPL Version 2, indicate your decision by adding
34
# "[Contributor] elects to include this software in this distribution
35
# under the [CDDL or GPL Version 2] license." If you do not indicate a
36
# single choice of license, a recipient has the option to distribute
37
# your version of this file under either the CDDL, the GPL Version 2 or
38
# to extend the choice of license to its licensees as provided above.
39
# However, if you add GPL Version 2 code and therefore, elected the GPL
40
# Version 2 license, then the option applies only if the new code is
41
# made subject to such option by the copyright holder.
42
43
## libs/lucene/manifest.mf
44
OpenIDE-Module-Name=Neo4J Integration
45
OpenIDE-Module-Display-Category=Libraries
46
OpenIDE-Module-Short-Description=Bundles Neo4J Graph Database.
47
OpenIDE-Module-Long-Description=\
48
    This module bundles Neo4J Graph Database.
(-)a/nbbuild/cluster.properties (+1 lines)
Lines 328-333 Link Here
328
        libs.jvyamlb,\
328
        libs.jvyamlb,\
329
        libs.lucene,\
329
        libs.lucene,\
330
        libs.nashorn,\
330
        libs.nashorn,\
331
        libs.neo4j.core,\
331
        libs.smack,\
332
        libs.smack,\
332
        libs.svnClientAdapter,\
333
        libs.svnClientAdapter,\
333
        libs.svnClientAdapter.javahl,\
334
        libs.svnClientAdapter.javahl,\

Return to bug 258248