Package org.eclipse.jdt.core

Examples of org.eclipse.jdt.core.IClassFile


            IJavaElement ref = workingCopy.getElementAt(selection.getOffset());
            if (ref != null) {
                return ref;
            }
        } else if (input instanceof IClassFile) {
            IClassFile iClass = (IClassFile) input;
            IJavaElement ref = iClass.getElementAt(selection.getOffset());
            if (ref != null) {
                // If we are in the inner class, try to refine search result now
                if(ref instanceof IType){
                    IType type = (IType) ref;
                    IClassFile classFile = type.getClassFile();
                    if(classFile != iClass){
                        /*
                         * WORKAROUND it seems that source range for constructors from
                         * bytecode with source attached from zip files is not computed
                         * in Eclipse (SourceMapper returns nothing useful).
                         * Example: HashMap$Entry class with constructor
                         * <init>(ILjava/lang/Object;Ljava/lang/Object;Ljava/util/HashMap$Entry;)V
                         * We will get here at least the inner class...
                         * see https://bugs.eclipse.org/bugs/show_bug.cgi?id=137847
                         */
                        ref = classFile.getElementAt(selection.getOffset());
                    }
                }
                return ref;
            }
        }
View Full Code Here


     * @param javaElement
     * @return new generated input stream for given element bytecode class file, or null
     * if class file cannot be found or this element is not from java source path
     */
    public static InputStream createInputStream(IJavaElement javaElement) {
        IClassFile classFile = (IClassFile) javaElement
            .getAncestor(IJavaElement.CLASS_FILE);
        InputStream is = null;

        // existing read-only class files
        if (classFile != null) {
            IJavaElement jarParent = classFile.getParent();
            // TODO dirty hack to be sure, that package is from jar -
            // because JarPackageFragment is not public class, we cannot
            // use instanceof here
            boolean isJar = jarParent != null
                && jarParent.getClass().getName()
View Full Code Here

     */
    protected boolean setDocumentContent(IDocument document,
        IEditorInput editorInput, String encoding) throws CoreException {

        if (editorInput instanceof IClassFileEditorInput) {
            IClassFile classFile = ((IClassFileEditorInput) editorInput)
                .getClassFile();

            String source = null;
            try {
                source = classFile.getSource();
            } catch (JavaModelException e) {
                // ignore, this may happen if *class* file is not on class path but inside
                // of source tree without associated source
            }
            if (source == null) {
View Full Code Here

        }
        boolean abstractOrInterface = false;
        try {
            switch (javaEl.getElementType()) {
                case IJavaElement.CLASS_FILE :
                    IClassFile classFile = (IClassFile) javaEl;
                    if(isOnClasspath(javaEl)) {
                        abstractOrInterface = classFile.isInterface();
                    } /*else {
                       this is the case for eclipse-generated class files.
                       if we do not perform the check in if, then we will have java model
                       exception on classFile.isInterface() call.
                    }*/
 
View Full Code Here

        return decompiled;
    }

    private IEditorInput doOpenBuffer(IJavaReferenceType type,
        IClassFile parent, boolean externalClass) {
        IClassFile classFile = null;
        try {
            classFile = JdtUtils.getInnerType(parent, getSourceMapper()
                .getDecompiledClass(parent), type.getSignature());
        } catch (DebugException e) {
            BytecodeOutlinePlugin.log(e, IStatus.ERROR);
View Full Code Here

    }

    private IEditorInput doOpenBuffer(IEditorInput input, boolean force,
        boolean reuseSource) {
        if (input instanceof IClassFileEditorInput) {
            IClassFile cf = ((IClassFileEditorInput) input).getClassFile();
            String origSrc = getAttachedJavaSource(cf, force);
            if (origSrc != null && !hasMappedSource) {
                // remember, that the JDT knows where the real source is and can show it
                setHasMappedSource(true);
            }

            if (origSrc == null || (force && !reuseSource)) {
                setDecompiled(true);
                char[] src;
                if (input instanceof ExternalClassFileEditorInput) {
                    ExternalClassFileEditorInput extInput = (ExternalClassFileEditorInput) input;
                    src = getSourceMapper().getSource(
                        extInput.getFile(), cf, decompilerFlags);
                } else {
                    src = getSourceMapper().getSource(cf, decompilerFlags);
                }
                changeBufferContent(cf, src);
            } else {
                setDecompiled(false);
            }
        } else if (input instanceof FileEditorInput) {
            FileEditorInput fileEditorInput = (FileEditorInput) input;
            // make class file from that
            IClassFileEditorInput cfi = (IClassFileEditorInput) transformEditorInput(input);
            // return changed reference
            input = cfi;
            setDecompiled(true);
            IClassFile cf = cfi.getClassFile();
            char[] src = getSourceMapper().getSource(
                fileEditorInput.getFile(), cf, decompilerFlags);
            changeBufferContent(cf, src);
        }
        return input;
View Full Code Here

    /*
     * @see JavaEditor#getElementAt(int)
     */
    protected IJavaElement getElementAt(int offset) {

        IClassFile classFile = getClassFile();
        if (classFile == null) {
            return null;
        }
        IJavaElement result = null;
        if (isDecompiled()) {
            IDocument document = getDocumentProvider().getDocument(
                getEditorInput());
            try {
                // XXX have test if the requested line is from bytecode or sourcecode?!?
                if(document.getLength() > offset){
                    int lineAtOffset = document.getLineOfOffset(offset);
                    // get DecompiledMethod from line, then get JavaElement with same
                    // signature, because we do not have offsets or lines in the class file,
                    // only java elements...
                    result = getSourceMapper().findElement(classFile, lineAtOffset);
                }
            } catch (BadLocationException e) {
                BytecodeOutlinePlugin.log(e, IStatus.ERROR);
            }
        } else {
            try {
                result = classFile.getElementAt(offset);
            } catch (JavaModelException e) {
                BytecodeOutlinePlugin.log(e, IStatus.ERROR);
            }
        }

View Full Code Here

    /*
     * @see JavaEditor#getCorrespondingElement(IJavaElement)
     */
    protected IJavaElement getCorrespondingElement(IJavaElement element) {
        IClassFile classFile = getClassFile();
        if (classFile == null) {
            return super.getCorrespondingElement(element);
        }
        if (classFile.equals(element.getAncestor(IJavaElement.CLASS_FILE))) {
            return element;
        }
        return super.getCorrespondingElement(element);
    }
View Full Code Here

     */
    public void inputChanged(final IClassFileEditorInput input) {
        Runnable updateInput = new Runnable() {
            public void run() {
                fInputUpdater.post(input);
                IClassFile cf = input.getClassFile();
                try {
                    String source = cf.getSource();
                    setDecompiled(source != null && source.startsWith(MARK));
                } catch (JavaModelException e) {
                    BytecodeOutlinePlugin.log(e, IStatus.ERROR);
                }

View Full Code Here

        if (documentProvider instanceof ClassFileDocumentProvider) {
            ((ClassFileDocumentProvider) documentProvider)
                .removeInputChangeListener(this);
        }

        IClassFile classFile = getClassFile();
        BytecodeBufferManager.removeBuffer(BytecodeBufferManager
            .getBuffer(classFile));
        super.dispose();
    }
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.core.IClassFile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.