Package org.dyno.visual.swing.parser.listener

Source Code of org.dyno.visual.swing.parser.listener.OuterClassModel

/************************************************************************************
* Copyright (c) 2008 William Chen.                                                 *
*                                                                                  *
* All rights reserved. This program and the accompanying materials are made        *
* available under the terms of the Eclipse Public License v1.0 which accompanies   *
* this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html *
*                                                                                  *
* Use is subject to the terms of Eclipse Public License v1.0.                      *
*                                                                                  *
* Contributors:                                                                    *
*     William Chen - initial API and implementation.                               *
************************************************************************************/

package org.dyno.visual.swing.parser.listener;

import java.beans.MethodDescriptor;
import java.util.List;

import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IMember;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.Signature;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.eclipse.jdt.ui.JavaUI;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IFileEditorInput;

@SuppressWarnings("unchecked")
public class OuterClassModel extends BaseClassModel {
 
  public void editMethod(IEditorPart editor, MethodDescriptor methodDesc) {
    Class<?>[] pd = methodDesc.getMethod().getParameterTypes();
    if (pd.length > 0) {
      String pname = pd[0].getName();
      int dot = pname.lastIndexOf('.');
      if (dot != -1)
        pname = pname.substring(dot + 1);
     
      String eventTypeSig = Signature.createTypeSignature(pname, false);
     
      IFileEditorInput file = (IFileEditorInput) editor.getEditorInput();
      ICompilationUnit unit = JavaCore.createCompilationUnitFrom(file.getFile());
      IType meType = unit.getType(className);
      IMember member = meType.getMethod(methodDesc.getName(),new String[] {eventTypeSig });
      JavaUI.revealInEditor(editor, (IJavaElement) member);
    }   
  }
 
  protected TypeDeclaration[] getInnerTypes(TypeDeclaration type) {
    List innerTypes = ((CompilationUnit)type.getParent()).types();   
    if(innerTypes!=null){
      TypeDeclaration[]types=new TypeDeclaration[innerTypes.size()];
      innerTypes.toArray(types);
      return types;
    }
    return null;
  }
}

TOP

Related Classes of org.dyno.visual.swing.parser.listener.OuterClassModel

TOP
Copyright © 2018 www.massapi.com. 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.