コード例 #1
0
  /*
   * Remembers all type bindings defined in the given parsed unit, adding local/anonymous types if specified.
   */
  private void rememberAllTypes(
      CompilationUnitDeclaration parsedUnit,
      org.aspectj.org.eclipse.jdt.core.ICompilationUnit cu,
      boolean includeLocalTypes) {
    TypeDeclaration[] types = parsedUnit.types;
    if (types != null) {
      for (int i = 0, length = types.length; i < length; i++) {
        TypeDeclaration type = types[i];
        rememberWithMemberTypes(type, cu.getType(new String(type.name)));
      }
    }
    if (!includeLocalTypes
        || (parsedUnit.localTypes == null && parsedUnit.functionalExpressions == null)) return;

    HandleFactory factory = new HandleFactory();
    HashSet existingElements =
        new HashSet(parsedUnit.localTypeCount + parsedUnit.functionalExpressionsCount);
    HashMap knownScopes =
        new HashMap(parsedUnit.localTypeCount + parsedUnit.functionalExpressionsCount);

    if (parsedUnit.localTypes != null) {
      for (int i = 0; i < parsedUnit.localTypeCount; i++) {
        LocalTypeBinding localType = parsedUnit.localTypes[i];
        ClassScope classScope = localType.scope;
        TypeDeclaration typeDecl = classScope.referenceType();
        IType typeHandle =
            (IType) factory.createElement(classScope, cu, existingElements, knownScopes);
        rememberWithMemberTypes(typeDecl, typeHandle);
      }
    }
    if (parsedUnit.functionalExpressions != null) {
      for (int i = 0; i < parsedUnit.functionalExpressionsCount; i++) {
        if (parsedUnit.functionalExpressions[i] instanceof LambdaExpression) {
          final LambdaExpression expression =
              (LambdaExpression) parsedUnit.functionalExpressions[i];
          if (expression.resolvedType != null && expression.resolvedType.isValidBinding()) {
            IType typeHandle =
                (IType)
                    factory.createLambdaTypeElement(expression, cu, existingElements, knownScopes);
            remember(typeHandle, expression.getTypeBinding());
          }
        }
      }
    }
  }