当前位置: 首页>>代码示例>>Java>>正文


Java JavaContext.getCompilationUnit方法代码示例

本文整理汇总了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;
    }
  });
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:LombokPsiParser.java

示例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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:33,代码来源:EcjParser.java

示例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);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:9,代码来源:LombokPsiParser.java

示例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();
}
 
开发者ID:vincetreur,项目名称:Ristretto,代码行数:7,代码来源:ImportFinder.java


注:本文中的com.android.tools.lint.detector.api.JavaContext.getCompilationUnit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。