com.intellij.psi.PsiImportStatement Java Examples

The following examples show how to use com.intellij.psi.PsiImportStatement. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ComponentsMethodDeclarationHandler.java    From litho with Apache License 2.0 6 votes vote down vote up
@Override
public PsiElement[] getGotoDeclarationTargets(
    @Nullable PsiElement sourceElement, int offset, Editor editor) {
  // Exclusions
  if (sourceElement == null
      || PsiTreeUtil.getParentOfType(sourceElement, PsiImportStatement.class) != null) {
    return PsiElement.EMPTY_ARRAY;
  }
  final Project project = sourceElement.getProject();
  return BaseLithoComponentsDeclarationHandler.resolve(sourceElement)
      // Filter Methods
      .filter(PsiMethod.class::isInstance)
      .map(PsiMethod.class::cast)
      .map(method -> findSpecMethods(method, project))
      .findFirst()
      .map(
          result -> {
            final Map<String, String> data = new HashMap<>();
            data.put(EventLogger.KEY_TARGET, "method");
            data.put(EventLogger.KEY_TYPE, EventLogger.VALUE_NAVIGATION_TYPE_GOTO);
            LOGGER.log(EventLogger.EVENT_NAVIGATION, data);
            return result;
          })
      .orElse(PsiMethod.EMPTY_ARRAY);
}
 
Example #2
Source File: JavaImportsUtil.java    From KodeBeagle with Apache License 2.0 6 votes vote down vote up
private Map<String, Set<String>> getFullyQualifiedImportsWithMethods(
        final PsiJavaFile javaFile, final Map<String, Set<String>> importVsMethods) {
    Map<String, Set<String>> fullyQualifiedImportsWithMethods = new HashMap<>();
    PsiImportList importList = javaFile.getImportList();
    Collection<PsiImportStatement> importStatements =
            PsiTreeUtil.findChildrenOfType(importList, PsiImportStatement.class);
    for (PsiImportStatement importStatement : importStatements) {
        if (!importStatement.isOnDemand()) {
            String qualifiedName = importStatement.getQualifiedName();
            if (importVsMethods.containsKey(qualifiedName)) {
                fullyQualifiedImportsWithMethods.put(qualifiedName,
                        importVsMethods.get(qualifiedName));
            }
        }
    }
    return fullyQualifiedImportsWithMethods;
}
 
Example #3
Source File: PolygeneFacetType.java    From attic-polygene-java with Apache License 2.0 6 votes vote down vote up
public final boolean value( PsiFile psiFile )
{
    final boolean[] hasPolygeneImportPackage = new boolean[]{ false };

    psiFile.accept( new JavaElementVisitor()
    {
        @Override
        public final void visitImportStatement( PsiImportStatement statement )
        {
            String packageName = statement.getQualifiedName();
            if( packageName != null && packageName.startsWith( "org.apache.polygene" ) )
            {
                hasPolygeneImportPackage[ 0 ] = true;
            }
        }

        @Override
        public void visitReferenceExpression( PsiReferenceExpression expression )
        {
            // Ignore
        }
    } );
    return hasPolygeneImportPackage[ 0 ];
}
 
Example #4
Source File: BaseLithoComponentsDeclarationHandler.java    From litho with Apache License 2.0 5 votes vote down vote up
/**
 * @param sourceElement component to find declaration for
 * @param isComponentClass filters component type
 * @param hasComponentSpecAnnotation filters resolved componentSpec type
 * @param tag event tag for logging
 * @return declaration target for the provided sourceElement or null if it wasn't found
 */
@Nullable
static PsiElement getGotoDeclarationTarget(
    @Nullable PsiElement sourceElement,
    Predicate<PsiClass> isComponentClass,
    Predicate<PsiClass> hasComponentSpecAnnotation,
    String tag) {
  // Exclusions
  if (sourceElement == null
      || PsiTreeUtil.getParentOfType(sourceElement, PsiImportStatement.class) != null) {
    return null;
  }
  final Project project = sourceElement.getProject();

  return resolve(sourceElement)
      // Filter Component classes
      .filter(PsiClass.class::isInstance)
      .map(PsiClass.class::cast)
      .filter(isComponentClass)
      // Find Spec classes by name
      .map(PsiClass::getQualifiedName)
      .filter(Objects::nonNull)
      .map(LithoPluginUtils::getLithoComponentSpecNameFromComponent)
      .map(specName -> PsiSearchUtils.findOriginalClass(project, specName))
      .filter(Objects::nonNull)
      // Filter Spec classes by implementation
      .filter(hasComponentSpecAnnotation)
      .limit(1)
      .peek(
          psiClass -> {
            final Map<String, String> data = new HashMap<>();
            data.put(EventLogger.KEY_TARGET, "class");
            data.put(EventLogger.KEY_CLASS, tag);
            data.put(EventLogger.KEY_TYPE, EventLogger.VALUE_NAVIGATION_TYPE_GOTO);
            logger.log(EventLogger.EVENT_NAVIGATION, data);
          })
      .findFirst()
      .orElse(null);
}