예제 #1
0
 private static void addForClassType(
     ArrayList<String> result, JetType jetType, JetNameValidator validator) {
   ClassDescriptor classDescriptor = TypeUtils.getClassDescriptor(jetType);
   if (classDescriptor != null) {
     Name className = classDescriptor.getName();
     addCamelNames(result, className.getName(), validator);
   }
 }
예제 #2
0
  @Test
  public void pathSegments() {
    Assert.assertEquals(Lists.newArrayList(), new FqName("").pathSegments());

    for (String name : new String[] {"com", "com.jetbrains", "com.jetbrains.jet"}) {
      List<Name> segments = new FqName(name).pathSegments();
      List<String> segmentsStrings = new ArrayList<String>();
      for (Name segment : segments) {
        segmentsStrings.add(segment.getName());
      }
      Assert.assertEquals(Arrays.asList(name.split("\\.")), segmentsStrings);
    }
  }
예제 #3
0
 private TypeParameterDescriptorImpl(
     @NotNull DeclarationDescriptor containingDeclaration,
     @NotNull List<AnnotationDescriptor> annotations,
     boolean reified,
     @NotNull Variance variance,
     @NotNull Name name,
     int index) {
   super(containingDeclaration, annotations, name);
   this.index = index;
   this.variance = variance;
   this.upperBounds = Sets.newLinkedHashSet();
   this.reified = reified;
   // TODO: Should we actually pass the annotations on to the type constructor?
   this.typeConstructor =
       new TypeConstructorImpl(
           this,
           annotations,
           false,
           name.getName(),
           Collections.<TypeParameterDescriptor>emptyList(),
           upperBounds);
 }
예제 #4
0
 private static void addNamesForType(
     ArrayList<String> result, JetType jetType, JetNameValidator validator) {
   JetStandardLibrary standardLibrary = JetStandardLibrary.getInstance();
   JetTypeChecker typeChecker = JetTypeChecker.INSTANCE;
   if (ErrorUtils.containsErrorType(jetType)) return;
   if (typeChecker.equalTypes(standardLibrary.getBooleanType(), jetType)) {
     addName(result, "b", validator);
   } else if (typeChecker.equalTypes(standardLibrary.getIntType(), jetType)) {
     addName(result, "i", validator);
   } else if (typeChecker.equalTypes(standardLibrary.getByteType(), jetType)) {
     addName(result, "byte", validator);
   } else if (typeChecker.equalTypes(standardLibrary.getLongType(), jetType)) {
     addName(result, "l", validator);
   } else if (typeChecker.equalTypes(standardLibrary.getFloatType(), jetType)) {
     addName(result, "fl", validator);
   } else if (typeChecker.equalTypes(standardLibrary.getDoubleType(), jetType)) {
     addName(result, "d", validator);
   } else if (typeChecker.equalTypes(standardLibrary.getShortType(), jetType)) {
     addName(result, "sh", validator);
   } else if (typeChecker.equalTypes(standardLibrary.getCharType(), jetType)) {
     addName(result, "c", validator);
   } else if (typeChecker.equalTypes(standardLibrary.getStringType(), jetType)) {
     addName(result, "s", validator);
   } else {
     if (jetType.getArguments().size() == 1) {
       JetType argument = jetType.getArguments().get(0).getType();
       if (typeChecker.equalTypes(standardLibrary.getArrayType(argument), jetType)) {
         if (typeChecker.equalTypes(standardLibrary.getBooleanType(), argument)) {
           addName(result, "booleans", validator);
         } else if (typeChecker.equalTypes(standardLibrary.getIntType(), argument)) {
           addName(result, "ints", validator);
         } else if (typeChecker.equalTypes(standardLibrary.getByteType(), argument)) {
           addName(result, "bytes", validator);
         } else if (typeChecker.equalTypes(standardLibrary.getLongType(), argument)) {
           addName(result, "longs", validator);
         } else if (typeChecker.equalTypes(standardLibrary.getFloatType(), argument)) {
           addName(result, "floats", validator);
         } else if (typeChecker.equalTypes(standardLibrary.getDoubleType(), argument)) {
           addName(result, "doubles", validator);
         } else if (typeChecker.equalTypes(standardLibrary.getShortType(), argument)) {
           addName(result, "shorts", validator);
         } else if (typeChecker.equalTypes(standardLibrary.getCharType(), argument)) {
           addName(result, "chars", validator);
         } else if (typeChecker.equalTypes(standardLibrary.getStringType(), argument)) {
           addName(result, "strings", validator);
         } else {
           ClassDescriptor classDescriptor = TypeUtils.getClassDescriptor(argument);
           if (classDescriptor != null) {
             Name className = classDescriptor.getName();
             addName(
                 result, "arrayOf" + StringUtil.capitalize(className.getName()) + "s", validator);
           }
         }
       } else {
         addForClassType(result, jetType, validator);
       }
     } else {
       addForClassType(result, jetType, validator);
     }
   }
 }
예제 #5
0
  @NotNull
  public Collection<FunctionDescriptor> getTopLevelFunctionDescriptorsByName(
      @NotNull String name,
      @NotNull JetSimpleNameExpression expression,
      @NotNull ResolveSession resolveSession,
      @NotNull GlobalSearchScope scope) {
    // name parameter can differ from expression.getReferenceName() when expression contains
    // completion suffix
    Name referenceName =
        expression.getIdentifier() == null
            ? JetPsiUtil.getConventionName(expression)
            : Name.identifier(name);
    if (referenceName == null || referenceName.toString().isEmpty()) {
      return Collections.emptyList();
    }

    BindingContext context = ResolveSessionUtils.resolveToExpression(resolveSession, expression);
    JetScope jetScope = context.get(BindingContext.RESOLUTION_SCOPE, expression);

    if (jetScope == null) {
      return Collections.emptyList();
    }

    Set<FunctionDescriptor> result = Sets.newHashSet();

    Collection<PsiMethod> topLevelFunctionPrototypes =
        JetFromJavaDescriptorHelper.getTopLevelFunctionPrototypesByName(
            referenceName.getName(), project, scope);
    for (PsiMethod method : topLevelFunctionPrototypes) {
      FqName functionFQN = JetFromJavaDescriptorHelper.getJetTopLevelDeclarationFQN(method);
      if (functionFQN != null) {
        JetImportDirective importDirective =
            JetPsiFactory.createImportDirective(project, new ImportPath(functionFQN, false));
        Collection<? extends DeclarationDescriptor> declarationDescriptors =
            new QualifiedExpressionResolver()
                .analyseImportReference(
                    importDirective,
                    jetScope,
                    new BindingTraceContext(),
                    resolveSession.getModuleConfiguration());
        for (DeclarationDescriptor declarationDescriptor : declarationDescriptors) {
          if (declarationDescriptor instanceof FunctionDescriptor) {
            result.add((FunctionDescriptor) declarationDescriptor);
          }
        }
      }
    }

    Set<FqName> affectedPackages = Sets.newHashSet();
    Collection<JetNamedFunction> jetNamedFunctions =
        JetShortFunctionNameIndex.getInstance().get(referenceName.getName(), project, scope);
    for (JetNamedFunction jetNamedFunction : jetNamedFunctions) {
      PsiFile containingFile = jetNamedFunction.getContainingFile();
      if (containingFile instanceof JetFile) {
        JetFile jetFile = (JetFile) containingFile;
        String packageName = jetFile.getPackageName();
        if (packageName != null) {
          affectedPackages.add(new FqName(packageName));
        }
      }
    }

    for (FqName affectedPackage : affectedPackages) {
      NamespaceDescriptor packageDescriptor =
          resolveSession.getPackageDescriptorByFqName(affectedPackage);
      assert packageDescriptor != null
          : "There's a function in stub index with invalid package: " + affectedPackage;
      JetScope memberScope = packageDescriptor.getMemberScope();
      result.addAll(memberScope.getFunctions(referenceName));
    }

    return result;
  }