Java 类org.eclipse.jdt.internal.compiler.ast.UnionTypeReference 实例源码

项目:Eclipse-Postfix-Code-Completion    文件:Parser.java   
protected void consumeCatchType() {
    // CatchType ::= UnionType
    int length = this.astLengthStack[this.astLengthPtr--];
    if (length != 1) {
        TypeReference[] typeReferences;
        System.arraycopy(
                this.astStack,
                (this.astPtr -= length) + 1,
                (typeReferences = new TypeReference[length]),
                0,
                length);
        UnionTypeReference typeReference = new UnionTypeReference(typeReferences);
        pushOnAstStack(typeReference);
        if (this.options.sourceLevel < ClassFileConstants.JDK1_7) {
            problemReporter().multiCatchNotBelow17(typeReference);
        }
    } else {
        // push back the type reference
        pushOnAstLengthStack(1);
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:CodeFormatterVisitor.java   
/**
 * @see org.eclipse.jdt.internal.compiler.ASTVisitor#visit(org.eclipse.jdt.internal.compiler.ast.UnionTypeReference, org.eclipse.jdt.internal.compiler.lookup.BlockScope)
 */
public boolean visit(
    UnionTypeReference unionTypeReference,
    BlockScope scope) {

    TypeReference[] typeReferences = unionTypeReference.typeReferences;
    for (int i = 0, max = typeReferences.length; i < max; i++) {
        if (i != 0) {
            this.scribe.printNextToken(TerminalTokens.TokenNameOR, true);
            this.scribe.space();
        }
        typeReferences[i].traverse(this, scope);
    }
    return false;
}
项目:Eclipse-Postfix-Code-Completion    文件:CodeFormatterVisitor.java   
/**
 * @see org.eclipse.jdt.internal.compiler.ASTVisitor#visit(org.eclipse.jdt.internal.compiler.ast.UnionTypeReference, org.eclipse.jdt.internal.compiler.lookup.BlockScope)
 */
public boolean visit(
    UnionTypeReference unionTypeReference,
    ClassScope scope) {

    TypeReference[] typeReferences = unionTypeReference.typeReferences;
    for (int i = 0, max = typeReferences.length; i < max; i++) {
        if (i != 0) {
            this.scribe.printNextToken(TerminalTokens.TokenNameOR, true);
            this.scribe.space();
        }
        typeReferences[i].traverse(this, scope);
    }
    return false;
}
项目:Eclipse-Postfix-Code-Completion    文件:ExceptionHandlingFlowContext.java   
private ASTNode getExceptionType(int index) {   
    if (this.exceptionToCatchBlockMap == null) {
        return this.catchArguments[index].type;
    }
    int catchBlock = this.exceptionToCatchBlockMap[index];
    ASTNode node = this.catchArguments[catchBlock].type;
    if (node instanceof UnionTypeReference) {
        TypeReference[] typeRefs = ((UnionTypeReference)node).typeReferences;
        for (int i = 0, len = typeRefs.length; i < len; i++) {
            TypeReference typeRef = typeRefs[i];
            if (TypeBinding.equalsEquals(typeRef.resolvedType, this.handledExceptions[index])) return typeRef;
        }   
    } 
    return node;
}
项目:Eclipse-Postfix-Code-Completion    文件:MultiCatchExceptionLabel.java   
public void initialize(UnionTypeReference typeReference, Annotation [] annotations) {
    TypeReference[] typeReferences = typeReference.typeReferences;
    int length = typeReferences.length;
    this.exceptionLabels = new ExceptionLabel[length];
    for (int i = 0; i < length; i++) {
        this.exceptionLabels[i] = new ExceptionLabel(this.codeStream, typeReferences[i].resolvedType, typeReferences[i], i == 0 ? annotations : null);
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:CodeFormatterVisitor.java   
/**
 * @see org.eclipse.jdt.internal.compiler.ASTVisitor#visit(org.eclipse.jdt.internal.compiler.ast.UnionTypeReference, org.eclipse.jdt.internal.compiler.lookup.BlockScope)
 */
public boolean visit(
    UnionTypeReference unionTypeReference,
    BlockScope scope) {

    TypeReference[] typeReferences = unionTypeReference.typeReferences;
    for (int i = 0, max = typeReferences.length; i < max; i++) {
        if (i != 0) {
            this.scribe.printNextToken(TerminalTokens.TokenNameOR, true);
            this.scribe.space();
        }
        typeReferences[i].traverse(this, scope);
    }
    return false;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:CodeFormatterVisitor.java   
/**
 * @see org.eclipse.jdt.internal.compiler.ASTVisitor#visit(org.eclipse.jdt.internal.compiler.ast.UnionTypeReference, org.eclipse.jdt.internal.compiler.lookup.BlockScope)
 */
public boolean visit(
    UnionTypeReference unionTypeReference,
    ClassScope scope) {

    TypeReference[] typeReferences = unionTypeReference.typeReferences;
    for (int i = 0, max = typeReferences.length; i < max; i++) {
        if (i != 0) {
            this.scribe.printNextToken(TerminalTokens.TokenNameOR, true);
            this.scribe.space();
        }
        typeReferences[i].traverse(this, scope);
    }
    return false;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ExceptionHandlingFlowContext.java   
private ASTNode getExceptionType(int index) {   
    if (this.exceptionToCatchBlockMap == null) {
        return this.catchArguments[index].type;
    }
    int catchBlock = this.exceptionToCatchBlockMap[index];
    ASTNode node = this.catchArguments[catchBlock].type;
    if (node instanceof UnionTypeReference) {
        TypeReference[] typeRefs = ((UnionTypeReference)node).typeReferences;
        for (int i = 0, len = typeRefs.length; i < len; i++) {
            TypeReference typeRef = typeRefs[i];
            if (typeRef.resolvedType == this.handledExceptions[index]) return typeRef;
        }   
    } 
    return node;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:MultiCatchExceptionLabel.java   
public void initialize(UnionTypeReference typeReference) {
    TypeReference[] typeReferences = typeReference.typeReferences;
    int length = typeReferences.length;
    this.exceptionLabels = new ExceptionLabel[length];
    for (int i = 0; i < length; i++) {
        this.exceptionLabels[i] = new ExceptionLabel(this.codeStream, typeReferences[i].resolvedType);
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:ThrownExceptionFinder.java   
private void removeCaughtExceptions(TryStatement tryStatement, boolean recordUncheckedCaughtExceptions) {
    Argument[] catchArguments = tryStatement.catchArguments;
    int length = catchArguments == null ? 0 : catchArguments.length;
    for (int i = 0; i < length; i++) {
        if (catchArguments[i].type instanceof UnionTypeReference) {
            UnionTypeReference unionTypeReference = (UnionTypeReference) catchArguments[i].type;
            TypeBinding caughtException;
            for (int j = 0; j < unionTypeReference.typeReferences.length; j++) {
                caughtException = unionTypeReference.typeReferences[j].resolvedType;
                if ((caughtException instanceof ReferenceBinding) && caughtException.isValidBinding()) {    // might be null when its the completion node
                    if (recordUncheckedCaughtExceptions) {
                        // is in outermost try-catch. Remove all caught exceptions, unchecked or checked
                        removeCaughtException((ReferenceBinding)caughtException);
                        this.caughtExceptions.add(caughtException);
                    } else {
                        // is in some inner try-catch. Discourage already caught checked exceptions
                        // from being proposed in an outer catch.
                        if (!caughtException.isUncheckedException(true)) {
                            this.discouragedExceptions.add(caughtException);
                        }
                    }
                }
            }
        } else {
            TypeBinding exception = catchArguments[i].type.resolvedType;
            if ((exception instanceof ReferenceBinding) && exception.isValidBinding()) {
                if (recordUncheckedCaughtExceptions) {
                    // is in outermost try-catch. Remove all caught exceptions, unchecked or checked
                    removeCaughtException((ReferenceBinding)exception);
                    this.caughtExceptions.add(exception);
                } else {
                    // is in some inner try-catch. Discourage already caught checked exceptions
                    // from being proposed in an outer catch
                    if (!exception.isUncheckedException(true)) {
                        this.discouragedExceptions.add(exception);
                    }
                }
            }
        }
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:CodeFormatterVisitor.java   
/**
 * @see org.eclipse.jdt.internal.compiler.ASTVisitor#visit(org.eclipse.jdt.internal.compiler.ast.Argument, org.eclipse.jdt.internal.compiler.lookup.BlockScope)
 */
public boolean visit(Argument argument, BlockScope scope) {

    if (argument.modifiers != NO_MODIFIERS || argument.annotations != null) {
        this.scribe.printComment();
        this.scribe.printModifiers(argument.annotations, this, ICodeFormatterConstants.ANNOTATION_ON_PARAMETER, !hasNonAnnotationModifiers());
        this.scribe.space();
    }

    /*
     * Argument type
     */
    TypeReference argumentType = argument.type;
    if (argumentType != null) {
        if (argumentType instanceof UnionTypeReference) {
            formatMultiCatchArguments(
                    argument, 
                    this.preferences.insert_space_before_binary_operator, 
                    this.preferences.insert_space_after_binary_operator,
                    this.preferences.alignment_for_union_type_in_multicatch,
                    scope);
        } else {
            argumentType.traverse(this, scope);
        }
    }

    if (argument.isVarArgs()) {
        Annotation [][] annotationsOnDimensions = argumentType.getAnnotationsOnDimensions(true);
        if (annotationsOnDimensions != null) {
            Annotation [] varargAnnotations = annotationsOnDimensions[annotationsOnDimensions.length - 1];
            if (varargAnnotations != null) {
                formatInlineAnnotations(varargAnnotations, true);
            }
        }
        this.scribe.printNextToken(TerminalTokens.TokenNameELLIPSIS, this.preferences.insert_space_before_ellipsis);
        if (this.preferences.insert_space_after_ellipsis) {
            this.scribe.space();
        }
        this.scribe.printNextToken(TerminalTokens.TokenNameIdentifier, false);
    } else {
        if (argument.isReceiver()) {
            this.scribe.space();
            NameReference qualifyingName = ((Receiver) argument).qualifyingName;
            if (qualifyingName != null) {
                qualifyingName.traverse(this, scope);
                this.scribe.printNextToken(TerminalTokens.TokenNameDOT, false);
            }
            this.scribe.printNextToken(TerminalTokens.TokenNamethis, false);
        } else {
            /*
             * Print the argument name
             */
            this.scribe.printNextToken(TerminalTokens.TokenNameIdentifier, argument.type != null);
        }
    }

    formatExtraDimensions(argumentType);
    return false;
}
项目:Eclipse-Postfix-Code-Completion    文件:CodeFormatterVisitor.java   
private void formatMultiCatchArguments(Argument argument,
        boolean spaceBeforePipe,
        boolean spaceAfterPipe,
        int multiCatchAlignment,
        BlockScope scope) {
    UnionTypeReference unionType = (UnionTypeReference) argument.type;
    int length = unionType.typeReferences != null ? unionType.typeReferences.length : 0;
    if (length > 0) {
        Alignment argumentsAlignment = this.scribe.createAlignment(
                Alignment.MULTI_CATCH,
                multiCatchAlignment,
                length,
                this.scribe.scanner.currentPosition);
        this.scribe.enterAlignment(argumentsAlignment);
        boolean ok = false;
        do {
            switch (multiCatchAlignment & Alignment.SPLIT_MASK) {
                case Alignment.M_COMPACT_SPLIT:
                case Alignment.M_NEXT_PER_LINE_SPLIT:
                    argumentsAlignment.startingColumn = this.scribe.column;
                    break;
            }
            try {
                for (int i = 0; i < length; i++) {
                    if (i > 0) {
                        if (this.preferences.wrap_before_or_operator_multicatch) {
                            this.scribe.alignFragment(argumentsAlignment, i);
                        }
                        this.scribe.printNextToken(TerminalTokens.TokenNameOR, spaceBeforePipe);
                        this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
                        if (this.scribe.lastNumberOfNewLines == 1) {
                            // a new line has been inserted while printing the comment
                            // hence we need to use the break indentation level before printing next token...
                            this.scribe.indentationLevel = argumentsAlignment.breakIndentationLevel;
                        }
                        if (!this.preferences.wrap_before_or_operator_multicatch) {
                            this.scribe.alignFragment(argumentsAlignment, i);
                        }
                    }
                    if (i == 0) {
                        this.scribe.alignFragment(argumentsAlignment, i);
                        int fragmentIndentation = argumentsAlignment.fragmentIndentations[0];
                        if ((argumentsAlignment.mode & Alignment.M_INDENT_ON_COLUMN) != 0 && fragmentIndentation > 0) {
                            this.scribe.indentationLevel = fragmentIndentation;
                        }
                    } else if (spaceAfterPipe) {
                        this.scribe.space();
                    }
                    unionType.typeReferences[i].traverse(this, scope);
                    argumentsAlignment.startingColumn = -1;
                }
                ok = true;
            } catch (AlignmentException e) {
                this.scribe.redoAlignment(e);
            }
        } while (!ok);

        this.scribe.exitAlignment(argumentsAlignment, true);
    }

}
项目:Eclipse-Postfix-Code-Completion    文件:Parser.java   
protected void consumeCatchFormalParameter() {
    // CatchFormalParameter ::= Modifiersopt CatchType VariableDeclaratorId
    this.identifierLengthPtr--;
    char[] identifierName = this.identifierStack[this.identifierPtr];
    long namePositions = this.identifierPositionStack[this.identifierPtr--];
    int extendedDimensions = this.intStack[this.intPtr--]; // https://bugs.eclipse.org/bugs/show_bug.cgi?id=348369
    TypeReference type = (TypeReference) this.astStack[this.astPtr--];
    if (extendedDimensions > 0) {
        type = augmentTypeWithAdditionalDimensions(type, extendedDimensions, null, false);
        type.sourceEnd = this.endPosition;
        // https://bugs.eclipse.org/bugs/show_bug.cgi?id=391092
        if (type instanceof UnionTypeReference) {
            this.problemReporter().illegalArrayOfUnionType(identifierName, type);       
        }
    }
    this.astLengthPtr--;
    int modifierPositions = this.intStack[this.intPtr--];
    this.intPtr--;
    Argument arg =
        new Argument(
            identifierName,
            namePositions,
            type,
            this.intStack[this.intPtr + 1] & ~ClassFileConstants.AccDeprecated); // modifiers
    arg.bits &= ~ASTNode.IsArgument;
    arg.declarationSourceStart = modifierPositions;
    // consume annotations
    int length;
    if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
        System.arraycopy(
            this.expressionStack,
            (this.expressionPtr -= length) + 1,
            arg.annotations = new Annotation[length],
            0,
            length);
    }
    pushOnAstStack(arg);
    /* if incomplete method header, this.listLength counter will not have been reset,
        indicating that some arguments are available on the stack */
    this.listLength++;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ThrownExceptionFinder.java   
private void removeCaughtExceptions(TryStatement tryStatement, boolean recordUncheckedCaughtExceptions) {
    Argument[] catchArguments = tryStatement.catchArguments;
    int length = catchArguments == null ? 0 : catchArguments.length;
    for (int i = 0; i < length; i++) {
        if (catchArguments[i].type instanceof UnionTypeReference) {
            UnionTypeReference unionTypeReference = (UnionTypeReference) catchArguments[i].type;
            TypeBinding caughtException;
            for (int j = 0; j < unionTypeReference.typeReferences.length; j++) {
                caughtException = unionTypeReference.typeReferences[j].resolvedType;
                if ((caughtException instanceof ReferenceBinding) && caughtException.isValidBinding()) {    // might be null when its the completion node
                    if (recordUncheckedCaughtExceptions) {
                        // is in outermost try-catch. Remove all caught exceptions, unchecked or checked
                        removeCaughtException((ReferenceBinding)caughtException);
                        this.caughtExceptions.add(caughtException);
                    } else {
                        // is in some inner try-catch. Discourage already caught checked exceptions
                        // from being proposed in an outer catch.
                        if (!caughtException.isUncheckedException(true)) {
                            this.discouragedExceptions.add(caughtException);
                        }
                    }
                }
            }
        } else {
            TypeBinding exception = catchArguments[i].type.resolvedType;
            if ((exception instanceof ReferenceBinding) && exception.isValidBinding()) {
                if (recordUncheckedCaughtExceptions) {
                    // is in outermost try-catch. Remove all caught exceptions, unchecked or checked
                    removeCaughtException((ReferenceBinding)exception);
                    this.caughtExceptions.add(exception);
                } else {
                    // is in some inner try-catch. Discourage already caught checked exceptions
                    // from being proposed in an outer catch
                    if (!exception.isUncheckedException(true)) {
                        this.discouragedExceptions.add(exception);
                    }
                }
            }
        }
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:CodeFormatterVisitor.java   
/**
 * @see org.eclipse.jdt.internal.compiler.ASTVisitor#visit(org.eclipse.jdt.internal.compiler.ast.Argument, org.eclipse.jdt.internal.compiler.lookup.BlockScope)
 */
public boolean visit(Argument argument, BlockScope scope) {

    if (argument.modifiers != NO_MODIFIERS || argument.annotations != null) {
        this.scribe.printComment();
        this.scribe.printModifiers(argument.annotations, this, ICodeFormatterConstants.ANNOTATION_ON_PARAMETER);
        this.scribe.space();
    }

    /*
     * Argument type
     */
    if (argument.type != null) {
        if (argument.type instanceof UnionTypeReference) {
            formatMultiCatchArguments(
                    argument, 
                    this.preferences.insert_space_before_binary_operator, 
                    this.preferences.insert_space_after_binary_operator,
                    this.preferences.alignment_for_union_type_in_multicatch,
                    scope);
        } else {
            argument.type.traverse(this, scope);
        }
    }

    if (argument.isVarArgs()) {
        this.scribe.printNextToken(TerminalTokens.TokenNameELLIPSIS, this.preferences.insert_space_before_ellipsis);
        if (this.preferences.insert_space_after_ellipsis) {
            this.scribe.space();
        }
        this.scribe.printNextToken(TerminalTokens.TokenNameIdentifier, false);
    } else {
        /*
         * Print the argument name
         */
        this.scribe.printNextToken(TerminalTokens.TokenNameIdentifier, true);
    }


    /*
     * Check for extra dimensions
     */
    int extraDimensions = getDimensions();
    if (extraDimensions != 0) {
         for (int i = 0; i < extraDimensions; i++) {
            this.scribe.printNextToken(TerminalTokens.TokenNameLBRACKET);
            this.scribe.printNextToken(TerminalTokens.TokenNameRBRACKET);
         }
    }

    return false;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:CodeFormatterVisitor.java   
private void formatMultiCatchArguments(Argument argument,
        boolean spaceBeforePipe,
        boolean spaceAfterPipe,
        int multiCatchAlignment,
        BlockScope scope) {
    UnionTypeReference unionType = (UnionTypeReference) argument.type;
    int length = unionType.typeReferences != null ? unionType.typeReferences.length : 0;
    if (length > 0) {
        Alignment argumentsAlignment = this.scribe.createAlignment(
                Alignment.MULTI_CATCH,
                multiCatchAlignment,
                length,
                this.scribe.scanner.currentPosition);
        this.scribe.enterAlignment(argumentsAlignment);
        boolean ok = false;
        do {
            switch (multiCatchAlignment & Alignment.SPLIT_MASK) {
                case Alignment.M_COMPACT_SPLIT:
                case Alignment.M_NEXT_PER_LINE_SPLIT:
                    argumentsAlignment.startingColumn = this.scribe.column;
                    break;
            }
            try {
                for (int i = 0; i < length; i++) {
                    if (i > 0) {
                        if (this.preferences.wrap_before_or_operator_multicatch) {
                            this.scribe.alignFragment(argumentsAlignment, i);
                        }
                        this.scribe.printNextToken(TerminalTokens.TokenNameOR, spaceBeforePipe);
                        this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT);
                        if (this.scribe.lastNumberOfNewLines == 1) {
                            // a new line has been inserted while printing the comment
                            // hence we need to use the break indentation level before printing next token...
                            this.scribe.indentationLevel = argumentsAlignment.breakIndentationLevel;
                        }
                        if (!this.preferences.wrap_before_or_operator_multicatch) {
                            this.scribe.alignFragment(argumentsAlignment, i);
                        }
                    }
                    if (i == 0) {
                        this.scribe.alignFragment(argumentsAlignment, i);
                        int fragmentIndentation = argumentsAlignment.fragmentIndentations[0];
                        if ((argumentsAlignment.mode & Alignment.M_INDENT_ON_COLUMN) != 0 && fragmentIndentation > 0) {
                            this.scribe.indentationLevel = fragmentIndentation;
                        }
                    } else if (spaceAfterPipe) {
                        this.scribe.space();
                    }
                    unionType.typeReferences[i].traverse(this, scope);
                    argumentsAlignment.startingColumn = -1;
                }
                ok = true;
            } catch (AlignmentException e) {
                this.scribe.redoAlignment(e);
            }
        } while (!ok);

        this.scribe.exitAlignment(argumentsAlignment, true);
    }

}