blob: 60d91e4bb4a717a1819d82dd378100657dd71480 [file] [log] [blame]
//
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//
= DevFaqObtainSourcesOfAJavaClass
:jbake-type: wiki
:jbake-tags: wiki, devfaq, needsreview
:jbake-status: published
:keywords: Apache NetBeans wiki DevFaqObtainSourcesOfAJavaClass
:description: Apache NetBeans wiki DevFaqObtainSourcesOfAJavaClass
:toc: left
:toc-title:
:syntax: true
=== How do I obtain a source file for a Java class and open it in the editor?
Sometimes it is necessary to open source code for a Java file from your NetBeans plug-in.
The source code may be located in the currently open projects, in a library or in the platform JRE.
It is assumed that libraries and platform JRE have associated sources in your environment.
The associations are configured from the *Tools > Libraries* and
*Tools > Java Platform* menu items.
Here is an example of how to find a `FileObject` corresponding to the class `javax.swing.JComponent`:
[source,java]
----
String classResource = "javax/swing/JComponent.java";
for (FileObject curRoot : GlobalPathRegistry.getDefault().getSourceRoots()) {
FileObject fileObject = curRoot.getFileObject(classResource);
if (fileObject != null) {
// source file object found
// do something, e.g. openEditor(fileObject, lineNumber);
return;
}
}
----
In the `if` block you can do something with the source file you found.
For example, you can open it in the Java editor.
link:DevFaqOpenFileAtLine.asciidoc[DevFaqOpenFileAtLine] describes how.
=== Apache Migration Information
The content in this page was kindly donated by Oracle Corp. to the
Apache Software Foundation.
This page was exported from link:http://wiki.netbeans.org/DevFaqObtainSourcesOfAJavaClass[http://wiki.netbeans.org/DevFaqObtainSourcesOfAJavaClass] ,
that was last modified by NetBeans user Admin
on 2009-11-06T15:57:14Z.
*NOTE:* This document was automatically converted to the AsciiDoc format on 2018-02-07, and needs to be reviewed.