本文整理汇总了Java中com.android.tools.lint.detector.api.JavaContext.getCompilationUnit方法的典型用法代码示例。如果您正苦于以下问题:Java JavaContext.getCompilationUnit方法的具体用法?Java JavaContext.getCompilationUnit怎么用?Java JavaContext.getCompilationUnit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.android.tools.lint.detector.api.JavaContext
的用法示例。
在下文中一共展示了JavaContext.getCompilationUnit方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findClass
import com.android.tools.lint.detector.api.JavaContext; //导入方法依赖的package包/类
@Nullable
@Override
public ResolvedClass findClass(@NonNull JavaContext context, @NonNull final String fullyQualifiedName) {
Node compilationUnit = context.getCompilationUnit();
if (compilationUnit == null) {
return null;
}
final PsiElement element = getPsiElement(compilationUnit);
if (element == null) {
return null;
}
return ApplicationManager.getApplication().runReadAction(new Computable<ResolvedClass>() {
@Nullable
@Override
public ResolvedClass compute() {
PsiClass aClass = JavaPsiFacade.getInstance(element.getProject()).findClass(fullyQualifiedName, element.getResolveScope());
if (aClass != null) {
return new ResolvedPsiClass(aClass);
}
return null;
}
});
}
示例2: findClass
import com.android.tools.lint.detector.api.JavaContext; //导入方法依赖的package包/类
@Nullable
@Override
public ResolvedClass findClass(@NonNull JavaContext context,
@NonNull String fullyQualifiedName) {
Node compilationUnit = context.getCompilationUnit();
if (compilationUnit == null) {
return null;
}
Object nativeObj = getNativeNode(compilationUnit);
if (!(nativeObj instanceof CompilationUnitDeclaration)) {
return null;
}
CompilationUnitDeclaration ecjUnit = (CompilationUnitDeclaration) nativeObj;
// Convert "foo.bar.Baz" into char[][] 'foo','bar','Baz' as required for
// ECJ name lookup
List<char[]> arrays = Lists.newArrayList();
for (String segment : Splitter.on('.').split(fullyQualifiedName)) {
arrays.add(segment.toCharArray());
}
char[][] compoundName = new char[arrays.size()][];
for (int i = 0, n = arrays.size(); i < n; i++) {
compoundName[i] = arrays.get(i);
}
Binding typeOrPackage = ecjUnit.scope.getTypeOrPackage(compoundName);
if (typeOrPackage instanceof TypeBinding && !(typeOrPackage instanceof ProblemReferenceBinding)) {
return new EcjResolvedClass((TypeBinding)typeOrPackage);
}
return null;
}
示例3: dispose
import com.android.tools.lint.detector.api.JavaContext; //导入方法依赖的package包/类
@Override
public void dispose(@NonNull JavaContext context, @NonNull Node compilationUnit) {
if (context.getCompilationUnit() != null) {
myLock.finish();
myLock = null;
context.setCompilationUnit(null);
}
}
示例4: hasImport
import com.android.tools.lint.detector.api.JavaContext; //导入方法依赖的package包/类
public static boolean hasImport(JavaContext context, MethodDefinition aMethodCall) {
ImportFinder finder = new ImportFinder(aMethodCall);
Node surroundingClass = context.getCompilationUnit();
surroundingClass.accept(finder);
return finder.isImportFound();
}