Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

read source code by using ADT SDK

0 Likes
918

Hi experts,

I am currently creating an ADT plugin for eclipse.

My aim is to read abap source code of current frame program / class, parse it and display some extracts in my own view.

But how can I read source code via ADT SDK?

Maybe I can use AdtSourceFileRetrievalServiceFactory/IAdtSourceFileRetrievalService, but I have to pass IFile. How do I get IFile when all I have is program name?


Are there any existing code samples / template projects?


Any hints appreciated.


Thank you

Peter

Message was edited by: Peter Herweg P. S.: Of course I can read content of current editor (see below). But when coding contains INCLUDEs, I have to read content of these includes additionally.     public Object execute(ExecutionEvent event) throws ExecutionException {         IWorkbenchWindow window = HandlerUtil                 .getActiveWorkbenchWindowChecked(event);         try {                     IEditorPart editorPart = window.getActivePage().getActiveEditor();                         ITextEditor editor = (ITextEditor) editorPart                     .getAdapter(ITextEditor.class);                         if (editor != null) {                 IDocumentProvider provider = editor.getDocumentProvider();                 IDocument document = provider.getDocument(editor.getEditorInput());                     try {                     String code = document.get();                         code = AbapSource.getCleanCode(code);                                     document.set(code);                 } catch (Exception ex) {                     //TODO                                    }             }         } catch (java.lang.Exception ex) {             //TODO         }         return null;     }

1 REPLY 1
Read only

0 Likes
755

Hello,

I found it by myself.

Using this coding I get access to InputStream:

IWorkspace workspace = ResourcesPlugin.getWorkspace();

IWorkspaceRoot root = workspace.getRoot();

IProject project  = root.getProject("my_project");

IFolder folder = project.getFolder(".adt").getFolder("programs").getFolder("programs").getFolder("zsd_0010");

IFile file = folder.getFile("zsd_0010.asprog");

//download to semantic file system

IAdtSfsUtil sfs = AdtSfsUtilFactory.createAdtSfsUtil();

sfs.synchronizeDevelopmentObject(file, false, null);

//open stream

InputStream is = file.getContents();

Best regards

Peter