Eclipse插件:解析Android Project源代码以获取所用方法的名称

时间:2014-02-22 05:16:08

标签: java android parsing eclipse-plugin

我正在开发一个eclipse插件,我想要Android Project源代码中使用的所有方法(存在于Android API中)的名称。有谁知道我应该如何解析代码?

假设我的源代码是:

package com.example.androidsample;

import android.content.Context;
import android.location.Location;
import android.location.LocationManager;
import android.telephony.SmsManager;


public class MockLocationProvider {
  String providerName;
  Context ctx;

  public MockLocationProvider(String name, Context ctx) {
    this.providerName = name;
    this.ctx = ctx;
    LocationManager lm = (LocationManager) ctx.getSystemService(
    Context.LOCATION_SERVICE);
    lm.addTestProvider(providerName, false, false, false, false, false, true, true, 0, 5);
    SmsManager smsManager =     SmsManager.getDefault();
    smsManager.sendTextMessage("Phone Number", null, "Message", null, null);
    lm.setTestProviderEnabled(providerName, true);
  }

  public void pushLocation(double lat, double lon) {
    LocationManager lm = (LocationManager) ctx.getSystemService(
      Context.LOCATION_SERVICE);

    Location mockLocation = new Location(providerName);
    mockLocation.setLatitude(lat);
    mockLocation.setLongitude(lon); 
    mockLocation.setAltitude(0); 
    mockLocation.setTime(System.currentTimeMillis()); 
    lm.setTestProviderLocation(providerName, mockLocation);
  }

  public void shutdown() {
    LocationManager lm = (LocationManager) ctx.getSystemService(
      Context.LOCATION_SERVICE);
    lm.removeTestProvider(providerName);
  }
}

然后我要求的清单就像:

[
getSystemService,
addTestProvider,
getDefault,
sendTextMessage,
setTestProviderEnabled,
setLatitude,
setLongitude,
setAltitude,
setTime,
setTestProviderLocation,
removeTestProvider
]

对此方向的任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:0)

我有类似的任务。 我使用ASTParser来获取类中每个方法的MethodDeclaration。 然后我使用getBody并将每个方法更深入地解析为语句。