当前位置: 首页>>代码示例>>Java>>正文


Java ElementOpen类代码示例

本文整理汇总了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);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:JPAEditorUtil.java

示例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);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:JavaUtils.java

示例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);
        }
    };
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:OpenAction.java

示例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);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:HibernateEditorUtil.java

示例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);
    }
}
 
开发者ID:jeddict,项目名称:jeddict,代码行数:23,代码来源:OpenSourceCodeAction.java

示例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);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:ResolvedJavaSymbolDescriptor.java

示例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);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:37,代码来源:JavaUtils.java

示例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());
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:PHyperlinkProcessor.java

示例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()));
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:Nodes.java

示例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();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:61,代码来源:OpenLayerFilesAction.java

示例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);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:52,代码来源:PropertyHyperlinkProcessor.java

示例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);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:50,代码来源:GoToJavaSourceProvider.java

示例13: open

import org.netbeans.api.java.source.ui.ElementOpen; //导入依赖的package包/类
@Override
public void open() {
    if (elementHandle != null) {
        ElementOpen.open(element.getFileObject(), elementHandle);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:7,代码来源:WhereUsedQueryUI.java

示例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);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:7,代码来源:ElementGrip.java

示例15: open

import org.netbeans.api.java.source.ui.ElementOpen; //导入依赖的package包/类
@Override
public void open() {
    if (elementHandle!=null) {
        ElementOpen.open(handle.getFileObject(), elementHandle);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:7,代码来源:RenameRefactoringUI.java


注:本文中的org.netbeans.api.java.source.ui.ElementOpen类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。