本文整理匯總了Java中org.netbeans.api.java.source.ui.ElementOpen類的典型用法代碼示例。如果您正苦於以下問題:Java ElementOpen類的具體用法?Java ElementOpen怎麽用?Java ElementOpen使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ElementOpen類屬於org.netbeans.api.java.source.ui包,在下文中一共展示了ElementOpen類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: findAndOpenJavaClass
import org.netbeans.api.java.source.ui.ElementOpen; //導入依賴的package包/類
public static void findAndOpenJavaClass(final String classBinaryName, Document doc) {
final JavaSource js = getJavaSource(doc);
if (js != null) {
try {
js.runUserActionTask(new Task<CompilationController>() {
public void run(CompilationController cc) throws Exception {
boolean opened = false;
TypeElement element = findClassElementByBinaryName(classBinaryName, cc);
if (element != null) {
opened = ElementOpen.open(js.getClasspathInfo(), element);
}
if (!opened) {
String msg = NbBundle.getMessage(JPAEditorUtil.class, "LBL_SourceNotFound", classBinaryName);
StatusDisplayer.getDefault().setStatusText(msg);
}
}
}, false);
} catch (IOException ex) {
Logger.getLogger("global").log(Level.SEVERE, ex.getMessage(), ex);
}
}
}
示例2: run
import org.netbeans.api.java.source.ui.ElementOpen; //導入依賴的package包/類
@Override
public void run(CompilationController controller) throws Exception {
if (cancel.get()) { return; }
boolean opened = false;
if (classBinaryName == null) {
return;
}
TypeElement element = JavaUtils.findClassElementByBinaryName(classBinaryName, controller);
if (element != null) {
elementFound.set(true);
if (cancel.get()) { return; }
opened = ElementOpen.open(javaSource.getClasspathInfo(), element);
}
if (!opened) {
String msg = NbBundle.getMessage(JavaUtils.class, "LBL_SourceNotFound", classBinaryName); //NOI18N
StatusDisplayer.getDefault().setStatusText(msg);
}
}
示例3: openable
import org.netbeans.api.java.source.ui.ElementOpen; //導入依賴的package包/類
@NonNull
public static Openable openable(
@NonNull final ElementHandle<?> handle,
@NonNull final FileObject fileObject,
@NonNull final String displayName) {
return () -> {
checkFile(fileObject, displayName);
FileObject file = fileObject;
if (isClassFile(file)) {
final FileObject src = findSource(file, handle);
if (src != null) {
file = src;
}
}
if (!ElementOpen.open(file, handle)) {
noSource(displayName);
}
};
}
示例4: findAndOpenJavaClass
import org.netbeans.api.java.source.ui.ElementOpen; //導入依賴的package包/類
public static void findAndOpenJavaClass(final String classBinaryName, Document doc) {
final JavaSource js = getJavaSource(doc);
if (js != null) {
try {
js.runUserActionTask(new Task<CompilationController>() {
public void run(CompilationController cc) throws Exception {
boolean opened = false;
TypeElement element = findClassElementByBinaryName(classBinaryName, cc);
if (element != null) {
opened = ElementOpen.open(js.getClasspathInfo(), element);
}
if (!opened) {
String msg = NbBundle.getMessage(HibernateEditorUtil.class, "LBL_SourceNotFound", classBinaryName);
StatusDisplayer.getDefault().setStatusText(msg);
}
}
}, false);
} catch (IOException ex) {
Logger.getLogger("global").log(Level.SEVERE, ex.getMessage(), ex);
}
}
}
示例5: open
import org.netbeans.api.java.source.ui.ElementOpen; //導入依賴的package包/類
private void open(FileObject fileObject, String classHandle) {
FileObject pkg = SourceGroupSupport.findSourceGroupForFile(modelerFile.getFileObject()).getRootFolder();
try {
JavaSource javaSource = JavaSource.create(ClasspathInfo.create(pkg));
javaSource.runUserActionTask(controller -> {
try {
controller.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
TypeElement element = controller.getElements().getTypeElement(classHandle);
VariableElement variableElement = getField(element, attribute);
EntityMappings entityMappings = (EntityMappings) modelerFile.getDefinitionElement();
ElementHandle<Element> elementHandle = ElementHandle.create(variableElement == null ? element : variableElement);
if (element != null) {
ElementOpen.open(fileObject, elementHandle);
}
} catch (IOException t) {
ExceptionUtils.printStackTrace(t);
}
}, true);
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
示例6: open
import org.netbeans.api.java.source.ui.ElementOpen; //導入依賴的package包/類
@Override
public void open() {
FileObject file = getFileObject();
if (file != null) {
ClasspathInfo cpInfo = ClasspathInfo.create(file);
ElementOpen.open(cpInfo, me);
}
}
示例7: openMethodInEditor
import org.netbeans.api.java.source.ui.ElementOpen; //導入依賴的package包/類
/**
* Open the specified method of the specified class in the editor
*
* @param doc The document on from which the java model context is to be created
* @param classBinName binary name of the class whose method is to be opened in the editor
* @param methodName name of the method
* @param argCount number of arguments that the method has (-1 if caller doesn't care)
* @param publicFlag YES if the method is public, NO if not, DONT_CARE if caller doesn't care
* @param staticFlag YES if the method is static, NO if not, DONT_CARE if caller doesn't care
*/
public static void openMethodInEditor(FileObject fileObject, final String classBinName,
final String methodName, int argCount, Public publicFlag, Static staticFlag) {
if (classBinName == null || methodName == null || fileObject == null) {
return;
}
final JavaSource js = JavaUtils.getJavaSource(fileObject);
if (js == null) {
return;
}
final ElementHandle<ExecutableElement> eh = JavaUtils.findMethod(fileObject, classBinName, methodName, argCount, publicFlag, staticFlag);
if (eh != null) {
try {
js.runUserActionTask(new Task<CompilationController>() {
@Override
public void run(CompilationController cc) throws Exception {
ExecutableElement ee = eh.resolve(cc);
ElementOpen.open(js.getClasspathInfo(), ee);
}
}, true);
} catch (IOException ex) {
Logger.getLogger("global").log(Level.SEVERE, ex.getMessage(), ex);
}
}
}
示例8: run
import org.netbeans.api.java.source.ui.ElementOpen; //導入依賴的package包/類
@Override
public void run(CompilationController cc) throws Exception {
TypeElement type = JavaUtils.findClassElementByBinaryName(className, cc);
if (type == null) {
return;
}
elementFound.set(true);
Property[] props = new PropertyFinder(
type.asType(), propName, cc.getElementUtilities(), MatchType.PREFIX).findProperties();
if (props.length > 0 && props[0].getSetter() != null) {
ElementOpen.open(cc.getClasspathInfo(), props[0].getSetter());
}
}
示例9: actionPerformed
import org.netbeans.api.java.source.ui.ElementOpen; //導入依賴的package包/類
@NbBundle.Messages({"MSG_NoSource=Source not available for {0}"})
@Override
public void actionPerformed(ActionEvent e) {
if (!ElementOpen.open(
description.getClasspathInfo(),
description.getHandle())) {
Toolkit.getDefaultToolkit().beep();
StatusDisplayer.getDefault().setStatusText(
Bundle.MSG_NoSource(description.getHandle().getQualifiedName()));
}
}
示例10: openOriginatingElement
import org.netbeans.api.java.source.ui.ElementOpen; //導入依賴的package包/類
private static boolean openOriginatingElement(FileObject layer, final String origEl) throws Exception {
final Project prj = FileOwnerQuery.getOwner(layer);
if (prj == null) {
StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(OpenLayerFilesAction.class, "OpenLayerFilesAction.msg.no_project", FileUtil.getFileDisplayName(layer)), 1);
return false;
}
final String prjName = ProjectUtils.getInformation(prj).getDisplayName();
NbModuleProvider nbm = prj.getLookup().lookup(NbModuleProvider.class);
if (nbm == null) {
StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(OpenLayerFilesAction.class, "OpenLayerFilesAction.msg.not_module", prjName), 1);
return false;
}
FileObject src = nbm.getSourceDirectory();
if (src == null) {
StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(OpenLayerFilesAction.class, "OpenLayerFilesAction.msg.no_src_dir", prjName), 1);
return false;
}
final AtomicBoolean success = new AtomicBoolean();
JavaSource.create(ClasspathInfo.create(src)).runWhenScanFinished(new Task<CompilationController>() {
public @Override void run(CompilationController cc) throws Exception {
cc.toPhase(JavaSource.Phase.RESOLVED);
Element el;
TypeElement type = cc.getElements().getTypeElement(origEl);
if (type != null) {
el = type;
} else {
PackageElement pkg = cc.getElements().getPackageElement(origEl);
if (pkg != null) {
el = pkg;
} else {
int dot = origEl.lastIndexOf('.');
String clazz = origEl.substring(0, dot);
type = cc.getElements().getTypeElement(clazz);
if (type == null) {
StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(OpenLayerFilesAction.class, "OpenLayerFilesAction.msg.class_not_found", origEl, prjName), 1);
return;
}
String member = origEl.substring(dot + 1);
el = null;
for (Element nested : type.getEnclosedElements()) {
if (nested.toString().equals(member)) {
el = nested;
break;
}
}
if (el == null) {
StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(OpenLayerFilesAction.class, "OpenLayerFilesAction.msg.member_not_found", member, clazz), 1);
return;
}
}
}
if (ElementOpen.open(cc.getClasspathInfo(), el)) {
success.set(true);
} else {
StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(OpenLayerFilesAction.class, "OpenLayerFilesAction.msg.could_not_open", origEl), 1);
}
}
}, true).get();
return success.get();
}
示例11: run
import org.netbeans.api.java.source.ui.ElementOpen; //導入依賴的package包/類
@Override
public void run(CompilationController cc) throws Exception {
cc.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
int dotIndex = propChain.lastIndexOf("."); //NOI18N
if (className == null) {
return;
}
TypeElement te = JavaUtils.findClassElementByBinaryName(className, cc);
if (te == null) {
return;
}
TypeMirror startType = te.asType();
ElementUtilities eu = cc.getElementUtilities();
// property chain
if (dotIndex != -1) {
String getterChain = propChain.substring(0, dotIndex);
StringTokenizer tokenizer = new StringTokenizer(getterChain, "."); //NOI18N
while (tokenizer.hasMoreTokens() && startType != null) {
String propertyName = tokenizer.nextToken();
Property[] props = new PropertyFinder(startType, propertyName, eu, MatchType.PREFIX).findProperties();
// no matching element found
if (props.length == 0 || props[0].getGetter() == null) {
startType = null;
break;
}
TypeMirror retType = props[0].getGetter().getReturnType();
if (retType.getKind() == TypeKind.DECLARED) {
startType = retType;
} else {
startType = null;
}
}
}
if (startType == null) {
return;
}
elementFound.set(true);
String setterProp = propChain.substring(dotIndex + 1);
Property[] sProps = new PropertyFinder(startType, setterProp, eu, MatchType.PREFIX).findProperties();
if (sProps.length > 0) {
ExecutableElement element = jumpToGetter ? sProps[0].getGetter() : sProps[0].getSetter();
if (element != null) {
ElementOpen.open(cc.getClasspathInfo(), element);
}
}
}
示例12: run
import org.netbeans.api.java.source.ui.ElementOpen; //導入依賴的package包/類
@Override
public void run() {
SourceClassInfo ci = ProfilerTypeUtils.resolveClass(className, project);
FileObject sourceFile = ci != null ? ci.getFile() : null;
if (sourceFile == null) {
return;
}
final JavaSource js = JavaSource.forFileObject(sourceFile);
if (js != null) {
ScanSensitiveTask<CompilationController> t = new ScanSensitiveTask<CompilationController>() {
public void run(CompilationController controller) throws Exception {
if (!controller.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED).equals(JavaSource.Phase.ELEMENTS_RESOLVED)) {
return;
}
TypeElement parentClass = ElementUtilitiesEx.resolveClassByName(className, controller, true);
if (cancelled != null && cancelled.get()) return;
if (ElementOpen.open(controller.getClasspathInfo(), parentClass)) {
Document doc = controller.getDocument();
if (doc != null && doc instanceof StyledDocument) {
if (openAtLine(controller, doc, methodName, line)) {
result.set(true);
return;
}
if (methodName != null) {
ExecutableElement methodElement = ElementUtilitiesEx.resolveMethodByName(controller, parentClass, methodName, signature);
if (methodElement != null && ElementOpen.open(controller.getClasspathInfo(), methodElement)) {
result.set(true);
return;
}
}
}
result.set(true);
}
}
@Override
public boolean shouldRetry() {
return !result.get();
}
};
ParsingUtils.invokeScanSensitiveTask(js, t);
}
}
示例13: open
import org.netbeans.api.java.source.ui.ElementOpen; //導入依賴的package包/類
@Override
public void open() {
if (elementHandle != null) {
ElementOpen.open(element.getFileObject(), elementHandle);
}
}
示例14: open
import org.netbeans.api.java.source.ui.ElementOpen; //導入依賴的package包/類
@Override
public void open() {
if(fileObject != null && handle != null && fileObject.isValid()) {
ElementOpen.open(fileObject, handle);
}
}
示例15: open
import org.netbeans.api.java.source.ui.ElementOpen; //導入依賴的package包/類
@Override
public void open() {
if (elementHandle!=null) {
ElementOpen.open(handle.getFileObject(), elementHandle);
}
}