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

项目:Eclipse-Postfix-Code-Completion    文件:DefaultBindingResolver.java   
synchronized IVariableBinding resolveVariable(VariableDeclaration variable) {
    final Object node = this.newAstToOldAst.get(variable);
    if (node instanceof AbstractVariableDeclaration) {
        AbstractVariableDeclaration abstractVariableDeclaration = (AbstractVariableDeclaration) node;
        IVariableBinding variableBinding = null;
        if (abstractVariableDeclaration instanceof org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) {
            org.eclipse.jdt.internal.compiler.ast.FieldDeclaration fieldDeclaration = (org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) abstractVariableDeclaration;
            variableBinding = this.getVariableBinding(fieldDeclaration.binding, variable);
        } else {
            variableBinding = this.getVariableBinding(((LocalDeclaration) abstractVariableDeclaration).binding, variable);
        }
        if (variableBinding == null) {
            return null;
        }
        this.bindingsToAstNodes.put(variableBinding, variable);
        String key = variableBinding.getKey();
        if (key != null) {
            this.bindingTables.bindingKeysToBindings.put(key, variableBinding);
        }
        return variableBinding;
    }
    return null;
}
项目:Eclipse-Postfix-Code-Completion    文件:RecoveredField.java   
public RecoveredElement updateOnClosingBrace(int braceStart, int braceEnd){
    if (this.bracketBalance > 0){ // was an array initializer
        this.bracketBalance--;
        if (this.bracketBalance == 0) {
            if(this.fieldDeclaration.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT) {
                updateSourceEndIfNecessary(braceEnd - 1);
                return this.parent;
            } else {
                if (this.fieldDeclaration.declarationSourceEnd > 0)
                    this.alreadyCompletedFieldInitialization = true;
            }
        }
        return this;
    } else if (this.bracketBalance == 0) {
        this.alreadyCompletedFieldInitialization = true;
        updateSourceEndIfNecessary(braceEnd - 1);
    }
    if (this.parent != null){
        return this.parent.updateOnClosingBrace(braceStart, braceEnd);
    }
    return this;
}
项目:Eclipse-Postfix-Code-Completion    文件:RecoveredField.java   
public RecoveredElement updateOnOpeningBrace(int braceStart, int braceEnd){
    if (this.fieldDeclaration.declarationSourceEnd == 0) {
        if (this.fieldDeclaration.type instanceof ArrayTypeReference || this.fieldDeclaration.type instanceof ArrayQualifiedTypeReference) {
            if (!this.alreadyCompletedFieldInitialization) {
                this.bracketBalance++;
                return null; // no update is necessary  (array initializer)
            }
        } else {  // https://bugs.eclipse.org/bugs/show_bug.cgi?id=308980
            // in case an initializer bracket is opened in a non-array field
            // e.g. int field = {..
            this.bracketBalance++;
            return null; // no update is necessary  (array initializer)
        }
    }
    if (this.fieldDeclaration.declarationSourceEnd == 0
        && this.fieldDeclaration.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT){
        this.bracketBalance++;
        return null; // no update is necessary  (enum constant)
    }
    // might be an array initializer
    this.updateSourceEndIfNecessary(braceStart - 1, braceEnd - 1);
    return this.parent.updateOnOpeningBrace(braceStart, braceEnd);
}
项目:Eclipse-Postfix-Code-Completion    文件:ProblemReporter.java   
public void assignmentHasNoEffect(AbstractVariableDeclaration location, char[] name){
    int severity = computeSeverity(IProblem.AssignmentHasNoEffect);
    if (severity == ProblemSeverities.Ignore) return;
    String[] arguments = new String[] { new String(name) };
    int start = location.sourceStart;
    int end = location.sourceEnd;
    if (location.initialization != null) {
        end = location.initialization.sourceEnd;
    }
    this.handle(
            IProblem.AssignmentHasNoEffect,
            arguments,
            arguments,
            severity,
            start,
            end);
}
项目:Eclipse-Postfix-Code-Completion    文件:CodeStream.java   
public void generateSyntheticBodyForEnumInitializationMethod(SyntheticMethodBinding methodBinding) {
    // no local used
    this.maxLocals = 0;
    // generate all enum constants
    SourceTypeBinding sourceTypeBinding = (SourceTypeBinding) methodBinding.declaringClass;
    TypeDeclaration typeDeclaration = sourceTypeBinding.scope.referenceContext;
    BlockScope staticInitializerScope = typeDeclaration.staticInitializerScope;
    FieldDeclaration[] fieldDeclarations = typeDeclaration.fields;
    for (int i = methodBinding.startIndex, max = methodBinding.endIndex; i < max; i++) {
        FieldDeclaration fieldDecl = fieldDeclarations[i];
        if (fieldDecl.isStatic()) {
            if (fieldDecl.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT) {
                fieldDecl.generateCode(staticInitializerScope, this);
            }
        }
    }
    return_();
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:SelectionRequestor.java   
public void acceptLocalVariable(LocalVariableBinding binding) {
    LocalDeclaration local = binding.declaration;
    IJavaElement parent = findLocalElement(local.sourceStart); // findLocalElement() cannot find local variable
    LocalVariable localVar = null;
    if(parent != null) {
        localVar = new LocalVariable(
                (JavaElement)parent,
                new String(local.name),
                local.declarationSourceStart,
                local.declarationSourceEnd,
                local.sourceStart,
                local.sourceEnd,
                Util.typeSignature(local.type),
                local.annotations,
                local.modifiers,
                local.getKind() == AbstractVariableDeclaration.PARAMETER);
    }
    if (localVar != null) {
        addElement(localVar);
        if(SelectionEngine.DEBUG){
            System.out.print("SELECTION - accept local variable("); //$NON-NLS-1$
            System.out.print(localVar.toString());
            System.out.println(")"); //$NON-NLS-1$
        }
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:DefaultBindingResolver.java   
synchronized IVariableBinding resolveVariable(VariableDeclaration variable) {
    final Object node = this.newAstToOldAst.get(variable);
    if (node instanceof AbstractVariableDeclaration) {
        AbstractVariableDeclaration abstractVariableDeclaration = (AbstractVariableDeclaration) node;
        IVariableBinding variableBinding = null;
        if (abstractVariableDeclaration instanceof org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) {
            org.eclipse.jdt.internal.compiler.ast.FieldDeclaration fieldDeclaration = (org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) abstractVariableDeclaration;
            variableBinding = this.getVariableBinding(fieldDeclaration.binding, variable);
        } else {
            variableBinding = this.getVariableBinding(((LocalDeclaration) abstractVariableDeclaration).binding, variable);
        }
        if (variableBinding == null) {
            return null;
        }
        this.bindingsToAstNodes.put(variableBinding, variable);
        String key = variableBinding.getKey();
        if (key != null) {
            this.bindingTables.bindingKeysToBindings.put(key, variableBinding);
        }
        return variableBinding;
    }
    return null;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:RecoveredField.java   
public RecoveredElement updateOnClosingBrace(int braceStart, int braceEnd){
    if (this.bracketBalance > 0){ // was an array initializer
        this.bracketBalance--;
        if (this.bracketBalance == 0) {
            if(this.fieldDeclaration.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT) {
                updateSourceEndIfNecessary(braceEnd - 1);
                return this.parent;
            } else {
                if (this.fieldDeclaration.declarationSourceEnd > 0)
                    this.alreadyCompletedFieldInitialization = true;
            }
        }
        return this;
    } else if (this.bracketBalance == 0) {
        this.alreadyCompletedFieldInitialization = true;
        updateSourceEndIfNecessary(braceEnd - 1);
    }
    if (this.parent != null){
        return this.parent.updateOnClosingBrace(braceStart, braceEnd);
    }
    return this;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:RecoveredField.java   
public RecoveredElement updateOnOpeningBrace(int braceStart, int braceEnd){
    if (this.fieldDeclaration.declarationSourceEnd == 0) {
        if (this.fieldDeclaration.type instanceof ArrayTypeReference || this.fieldDeclaration.type instanceof ArrayQualifiedTypeReference) {
            if (!this.alreadyCompletedFieldInitialization) {
                this.bracketBalance++;
                return null; // no update is necessary  (array initializer)
            }
        } else {  // https://bugs.eclipse.org/bugs/show_bug.cgi?id=308980
            // in case an initializer bracket is opened in a non-array field
            // e.g. int field = {..
            this.bracketBalance++;
            return null; // no update is necessary  (array initializer)
        }
    }
    if (this.fieldDeclaration.declarationSourceEnd == 0
        && this.fieldDeclaration.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT){
        this.bracketBalance++;
        return null; // no update is necessary  (enum constant)
    }
    // might be an array initializer
    this.updateSourceEndIfNecessary(braceStart - 1, braceEnd - 1);
    return this.parent.updateOnOpeningBrace(braceStart, braceEnd);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ProblemReporter.java   
public void assignmentHasNoEffect(AbstractVariableDeclaration location, char[] name){
    int severity = computeSeverity(IProblem.AssignmentHasNoEffect);
    if (severity == ProblemSeverities.Ignore) return;
    String[] arguments = new String[] { new String(name) };
    int start = location.sourceStart;
    int end = location.sourceEnd;
    if (location.initialization != null) {
        end = location.initialization.sourceEnd;
    }
    this.handle(
            IProblem.AssignmentHasNoEffect,
            arguments,
            arguments,
            severity,
            start,
            end);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:CodeStream.java   
public void generateSyntheticBodyForEnumInitializationMethod(SyntheticMethodBinding methodBinding) {
    // no local used
    this.maxLocals = 0;
    // generate all enum constants
    SourceTypeBinding sourceTypeBinding = (SourceTypeBinding) methodBinding.declaringClass;
    TypeDeclaration typeDeclaration = sourceTypeBinding.scope.referenceContext;
    BlockScope staticInitializerScope = typeDeclaration.staticInitializerScope;
    FieldDeclaration[] fieldDeclarations = typeDeclaration.fields;
    for (int i = methodBinding.startIndex, max = methodBinding.endIndex; i < max; i++) {
        FieldDeclaration fieldDecl = fieldDeclarations[i];
        if (fieldDecl.isStatic()) {
            if (fieldDecl.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT) {
                fieldDecl.generateCode(staticInitializerScope, this);
            }
        }
    }
    return_();
}
项目:lombok    文件:EclipseHandlerUtil.java   
/**
 * Generates a new statement that checks if the given variable is null, and if so, throws a {@code NullPointerException} with the
 * variable name as message.
 */
public static Statement generateNullCheck(AbstractVariableDeclaration variable, ASTNode source) {
    int pS = source.sourceStart, pE = source.sourceEnd;
    long p = (long)pS << 32 | pE;

    if (isPrimitive(variable.type)) return null;
    AllocationExpression exception = new AllocationExpression();
    setGeneratedBy(exception, source);
    exception.type = new QualifiedTypeReference(fromQualifiedName("java.lang.NullPointerException"), new long[]{p, p, p});
    setGeneratedBy(exception.type, source);
    exception.arguments = new Expression[] { new StringLiteral(variable.name, pS, pE, 0)};
    setGeneratedBy(exception.arguments[0], source);
    ThrowStatement throwStatement = new ThrowStatement(exception, pS, pE);
    setGeneratedBy(throwStatement, source);

    SingleNameReference varName = new SingleNameReference(variable.name, p);
    setGeneratedBy(varName, source);
    NullLiteral nullLiteral = new NullLiteral(pS, pE);
    setGeneratedBy(nullLiteral, source);
    EqualExpression equalExpression = new EqualExpression(varName, nullLiteral, OperatorIds.EQUAL_EQUAL);
    equalExpression.sourceStart = pS; equalExpression.statementEnd = equalExpression.sourceEnd = pE;
    setGeneratedBy(equalExpression, source);
    IfStatement ifStatement = new IfStatement(equalExpression, throwStatement, 0, 0);
    setGeneratedBy(ifStatement, source);
    return ifStatement;
}
项目:lombok-ianchiu    文件:SetGeneratedByVisitor.java   
private void fixPositions(AbstractVariableDeclaration node) {
    node.sourceEnd = sourceEnd;
    node.sourceStart = sourceStart;
    node.declarationEnd = sourceEnd;
    node.declarationSourceEnd = sourceEnd;
    node.declarationSourceStart = sourceStart;
    node.modifiersSourceStart = sourceStart;
}
项目:intellij-ce-playground    文件:EcjParser.java   
@Override
@Nullable
public ResolvedNode resolve(@NonNull JavaContext context, @NonNull Node node) {
    Object nativeNode = getNativeNode(node);
    if (nativeNode == null) {
        return null;
    }

    if (nativeNode instanceof NameReference) {
        return resolve(((NameReference) nativeNode).binding);
    } else if (nativeNode instanceof TypeReference) {
        return resolve(((TypeReference) nativeNode).resolvedType);
    } else if (nativeNode instanceof MessageSend) {
        return resolve(((MessageSend) nativeNode).binding);
    } else if (nativeNode instanceof AllocationExpression) {
        return resolve(((AllocationExpression) nativeNode).binding);
    } else if (nativeNode instanceof TypeDeclaration) {
        return resolve(((TypeDeclaration) nativeNode).binding);
    } else if (nativeNode instanceof ExplicitConstructorCall) {
        return resolve(((ExplicitConstructorCall) nativeNode).binding);
    } else if (nativeNode instanceof Annotation) {
        return resolve(((Annotation) nativeNode).resolvedType);
    } else if (nativeNode instanceof AbstractMethodDeclaration) {
        return resolve(((AbstractMethodDeclaration) nativeNode).binding);
    } else if (nativeNode instanceof AbstractVariableDeclaration) {
        if (nativeNode instanceof LocalDeclaration) {
            return resolve(((LocalDeclaration) nativeNode).binding);
        } else if (nativeNode instanceof FieldDeclaration) {
            return resolve(((FieldDeclaration) nativeNode).binding);
        }
    }

    // TODO: Handle org.eclipse.jdt.internal.compiler.ast.SuperReference. It
    // doesn't contain an actual method binding; the parent node call should contain
    // it, but is missing a native node reference; investigate the ECJ bridge's super
    // handling.

    return null;
}
项目:EasyMPermission    文件:SetGeneratedByVisitor.java   
private void fixPositions(AbstractVariableDeclaration node) {
    node.sourceEnd = sourceEnd;
    node.sourceStart = sourceStart;
    node.declarationEnd = sourceEnd;
    node.declarationSourceEnd = sourceEnd;
    node.declarationSourceStart = sourceStart;
    node.modifiersSourceStart = sourceStart;
}
项目:Eclipse-Postfix-Code-Completion    文件:InternalExtendedCompletionContext.java   
private JavaElement getJavaElement(LocalVariableBinding binding) {
    LocalDeclaration local = binding.declaration;

    JavaElement parent = null;
    ReferenceContext referenceContext = binding.declaringScope.referenceContext();
    if (referenceContext instanceof AbstractMethodDeclaration) {
        AbstractMethodDeclaration methodDeclaration = (AbstractMethodDeclaration) referenceContext;
        parent = this.getJavaElementOfCompilationUnit(methodDeclaration, methodDeclaration.binding);
    } else if (referenceContext instanceof TypeDeclaration){
        // Local variable is declared inside an initializer
        TypeDeclaration typeDeclaration = (TypeDeclaration) referenceContext;

        JavaElement type = this.getJavaElementOfCompilationUnit(typeDeclaration, typeDeclaration.binding);
        parent = Util.getUnresolvedJavaElement(local.sourceStart, local.sourceEnd, type);
    }
    if (parent == null) return null;

    return new LocalVariable(
            parent,
            new String(local.name),
            local.declarationSourceStart,
            local.declarationSourceEnd,
            local.sourceStart,
            local.sourceEnd,
            Util.typeSignature(local.type),
            binding.declaration.annotations,
            local.modifiers,
            local.getKind() == AbstractVariableDeclaration.PARAMETER);
}
项目:Eclipse-Postfix-Code-Completion    文件:SelectionParser.java   
protected void consumeEnterVariable() {
    // EnterVariable ::= $empty
    // do nothing by default

    super.consumeEnterVariable();

    AbstractVariableDeclaration variable = (AbstractVariableDeclaration) this.astStack[this.astPtr];
    if (variable.type == this.assistNode){
        if (!this.diet){
            this.restartRecovery    = true; // force to restart in recovery mode
            this.lastIgnoredToken = -1;
        }
        this.isOrphanCompletionNode = false; // already attached inside variable decl
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:SelectionParser.java   
protected void consumeExitVariableWithInitialization() {
    super.consumeExitVariableWithInitialization();

    // does not keep the initialization if selection is not inside
    AbstractVariableDeclaration variable = (AbstractVariableDeclaration) this.astStack[this.astPtr];
    int start = variable.initialization.sourceStart;
    int end =  variable.initialization.sourceEnd;
    if ((this.selectionStart < start) &&  (this.selectionEnd < start) ||
            (this.selectionStart > end) && (this.selectionEnd > end)) {
            variable.initialization = null;
    }
    triggerRecoveryUponLambdaClosure(variable, false);
}
项目:Eclipse-Postfix-Code-Completion    文件:SelectionRequestor.java   
public void acceptLocalVariable(LocalVariableBinding binding, org.eclipse.jdt.internal.compiler.env.ICompilationUnit unit) {
    LocalDeclaration local = binding.declaration;
    IJavaElement parent = null;
    if (binding.declaringScope.isLambdaSubscope() && unit instanceof ICompilationUnit) {
        HashSet existingElements = new HashSet();
        HashMap knownScopes = new HashMap();
        parent = this.handleFactory.createElement(binding.declaringScope, local.sourceStart, (ICompilationUnit) unit, existingElements, knownScopes);
    } else {        
        parent = findLocalElement(local.sourceStart, binding.declaringScope.methodScope()); // findLocalElement() cannot find local variable
    }
    LocalVariable localVar = null;
    if(parent != null) {
        localVar = new LocalVariable(
                (JavaElement)parent,
                new String(local.name),
                local.declarationSourceStart,
                local.declarationSourceEnd,
                local.sourceStart,
                local.sourceEnd,
                local.type == null ? Signature.createTypeSignature(binding.type.readableName(), true) : Util.typeSignature(local.type),
                local.annotations,
                local.modifiers,
                local.getKind() == AbstractVariableDeclaration.PARAMETER);
    }
    if (localVar != null) {
        addElement(localVar);
        if(SelectionEngine.DEBUG){
            System.out.print("SELECTION - accept local variable("); //$NON-NLS-1$
            System.out.print(localVar.toString());
            System.out.println(")"); //$NON-NLS-1$
        }
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:DefaultBindingResolver.java   
IMethodBinding resolveConstructor(EnumConstantDeclaration enumConstantDeclaration) {
    org.eclipse.jdt.internal.compiler.ast.ASTNode node = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(enumConstantDeclaration);
    if (node instanceof org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) {
        org.eclipse.jdt.internal.compiler.ast.FieldDeclaration fieldDeclaration = (org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) node;
        if (fieldDeclaration.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT && fieldDeclaration.initialization != null) {
            AllocationExpression allocationExpression = (AllocationExpression) fieldDeclaration.initialization;
            return getMethodBinding(allocationExpression.binding);
        }
    }
    return null;
}
项目:Eclipse-Postfix-Code-Completion    文件:Parser.java   
protected void consumeExitVariableWithInitialization() {
    // ExitVariableWithInitialization ::= $empty
    // do nothing by default
    this.expressionLengthPtr--;
    AbstractVariableDeclaration variableDecl = (AbstractVariableDeclaration) this.astStack[this.astPtr];
    variableDecl.initialization = this.expressionStack[this.expressionPtr--];
    // we need to update the declarationSourceEnd of the local variable declaration to the
    // source end position of the initialization expression
    variableDecl.declarationSourceEnd = variableDecl.initialization.sourceEnd;
    variableDecl.declarationEnd = variableDecl.initialization.sourceEnd;

    recoveryExitFromVariable();
}
项目:Eclipse-Postfix-Code-Completion    文件:Parser.java   
protected void consumeExitVariableWithoutInitialization() {
    // ExitVariableWithoutInitialization ::= $empty
    // do nothing by default

    AbstractVariableDeclaration variableDecl = (AbstractVariableDeclaration) this.astStack[this.astPtr];
    variableDecl.declarationSourceEnd = variableDecl.declarationEnd;
    if(this.currentElement != null && this.currentElement instanceof RecoveredField) {
        if(this.endStatementPosition > variableDecl.sourceEnd) {
            this.currentElement.updateSourceEndIfNecessary(this.endStatementPosition);
        }
    }
    recoveryExitFromVariable();
}
项目:Eclipse-Postfix-Code-Completion    文件:ProblemReporter.java   
public void possibleHeapPollutionFromVararg(AbstractVariableDeclaration vararg) {
    String[] arguments = new String[] {new String(vararg.name)};
    this.handle(
        IProblem.PotentialHeapPollutionFromVararg,
        arguments,
        arguments,
        vararg.sourceStart,
        vararg.sourceEnd);
}
项目:Eclipse-Postfix-Code-Completion    文件:ProblemReporter.java   
public void variableTypeCannotBeVoid(AbstractVariableDeclaration varDecl) {
    String[] arguments = new String[] {new String(varDecl.name)};
    this.handle(
        IProblem.VariableTypeCannotBeVoid,
        arguments,
        arguments,
        varDecl.sourceStart,
        varDecl.sourceEnd);
}
项目:Eclipse-Postfix-Code-Completion    文件:ProblemReporter.java   
public void variableTypeCannotBeVoidArray(AbstractVariableDeclaration varDecl) {
    this.handle(
        IProblem.CannotAllocateVoidArray,
        NoArgument,
        NoArgument,
        varDecl.type.sourceStart,
        varDecl.type.sourceEnd);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:InternalExtendedCompletionContext.java   
private JavaElement getJavaElement(LocalVariableBinding binding) {
    LocalDeclaration local = binding.declaration;

    JavaElement parent = null;
    ReferenceContext referenceContext = binding.declaringScope.referenceContext();
    if (referenceContext instanceof AbstractMethodDeclaration) {
        AbstractMethodDeclaration methodDeclaration = (AbstractMethodDeclaration) referenceContext;
        parent = this.getJavaElementOfCompilationUnit(methodDeclaration, methodDeclaration.binding);
    } else if (referenceContext instanceof TypeDeclaration){
        // Local variable is declared inside an initializer
        TypeDeclaration typeDeclaration = (TypeDeclaration) referenceContext;

        JavaElement type = this.getJavaElementOfCompilationUnit(typeDeclaration, typeDeclaration.binding);
        parent = Util.getUnresolvedJavaElement(local.sourceStart, local.sourceEnd, type);
    }
    if (parent == null) return null;

    return new LocalVariable(
            parent,
            new String(local.name),
            local.declarationSourceStart,
            local.declarationSourceEnd,
            local.sourceStart,
            local.sourceEnd,
            Util.typeSignature(local.type),
            binding.declaration.annotations,
            local.modifiers,
            local.getKind() == AbstractVariableDeclaration.PARAMETER);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:DefaultBindingResolver.java   
IMethodBinding resolveConstructor(EnumConstantDeclaration enumConstantDeclaration) {
    org.eclipse.jdt.internal.compiler.ast.ASTNode node = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(enumConstantDeclaration);
    if (node instanceof org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) {
        org.eclipse.jdt.internal.compiler.ast.FieldDeclaration fieldDeclaration = (org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) node;
        if (fieldDeclaration.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT && fieldDeclaration.initialization != null) {
            AllocationExpression allocationExpression = (AllocationExpression) fieldDeclaration.initialization;
            return getMethodBinding(allocationExpression.binding);
        }
    }
    return null;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ProblemReporter.java   
public void possibleHeapPollutionFromVararg(AbstractVariableDeclaration vararg) {
    String[] arguments = new String[] {new String(vararg.name)};
    this.handle(
        IProblem.PotentialHeapPollutionFromVararg,
        arguments,
        arguments,
        vararg.sourceStart,
        vararg.sourceEnd);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ProblemReporter.java   
public void variableTypeCannotBeVoid(AbstractVariableDeclaration varDecl) {
    String[] arguments = new String[] {new String(varDecl.name)};
    this.handle(
        IProblem.VariableTypeCannotBeVoid,
        arguments,
        arguments,
        varDecl.sourceStart,
        varDecl.sourceEnd);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ProblemReporter.java   
public void variableTypeCannotBeVoidArray(AbstractVariableDeclaration varDecl) {
    this.handle(
        IProblem.CannotAllocateVoidArray,
        NoArgument,
        NoArgument,
        varDecl.type.sourceStart,
        varDecl.type.sourceEnd);
}
项目:lombok    文件:SetGeneratedByVisitor.java   
private void applyOffsetVariable(AbstractVariableDeclaration node) {
    applyOffsetASTNode(node);
    node.declarationEnd = newSourceEnd;
    node.declarationSourceEnd = newSourceEnd;
    node.declarationSourceStart = newSourceStart;
    node.modifiersSourceStart = newSourceStart;
}
项目:lombok-ianchiu    文件:EclipseHandlerUtil.java   
/**
 * Generates a new statement that checks if the given variable is null, and if so, throws a specified exception with the
 * variable name as message.
 * 
 * @param exName The name of the exception to throw; normally {@code java.lang.NullPointerException}.
 */
public static Statement generateNullCheck(AbstractVariableDeclaration variable, EclipseNode sourceNode) {
    NullCheckExceptionType exceptionType = sourceNode.getAst().readConfiguration(ConfigurationKeys.NON_NULL_EXCEPTION_TYPE);
    if (exceptionType == null) exceptionType = NullCheckExceptionType.NULL_POINTER_EXCEPTION;

    ASTNode source = sourceNode.get();

    int pS = source.sourceStart, pE = source.sourceEnd;
    long p = (long)pS << 32 | pE;

    if (isPrimitive(variable.type)) return null;
    AllocationExpression exception = new AllocationExpression();
    setGeneratedBy(exception, source);
    int partCount = 1;
    String exceptionTypeStr = exceptionType.getExceptionType();
    for (int i = 0; i < exceptionTypeStr.length(); i++) if (exceptionTypeStr.charAt(i) == '.') partCount++;
    long[] ps = new long[partCount];
    Arrays.fill(ps, 0L);
    exception.type = new QualifiedTypeReference(fromQualifiedName(exceptionTypeStr), ps);
    setGeneratedBy(exception.type, source);
    exception.arguments = new Expression[] {
            new StringLiteral(exceptionType.toExceptionMessage(new String(variable.name)).toCharArray(), pS, pE, 0)
    };
    setGeneratedBy(exception.arguments[0], source);
    ThrowStatement throwStatement = new ThrowStatement(exception, pS, pE);
    setGeneratedBy(throwStatement, source);

    SingleNameReference varName = new SingleNameReference(variable.name, p);
    setGeneratedBy(varName, source);
    NullLiteral nullLiteral = new NullLiteral(pS, pE);
    setGeneratedBy(nullLiteral, source);
    EqualExpression equalExpression = new EqualExpression(varName, nullLiteral, OperatorIds.EQUAL_EQUAL);
    equalExpression.sourceStart = pS; equalExpression.statementEnd = equalExpression.sourceEnd = pE;
    setGeneratedBy(equalExpression, source);
    Block throwBlock = new Block(0);
    throwBlock.statements = new Statement[] {throwStatement};
    throwBlock.sourceStart = pS; throwBlock.sourceEnd = pE;
    setGeneratedBy(throwBlock, source);
    IfStatement ifStatement = new IfStatement(equalExpression, throwBlock, 0, 0);
    setGeneratedBy(ifStatement, source);
    return ifStatement;
}
项目:lombok-ianchiu    文件:HandleBuilder.java   
/**
 * Returns the explicitly requested singular annotation on this node (field
 * or parameter), or null if there's no {@code @Singular} annotation on it.
 * 
 * @param node The node (field or method param) to inspect for its name and potential {@code @Singular} annotation.
 */
private SingularData getSingularData(EclipseNode node, ASTNode source) {
    for (EclipseNode child : node.down()) {
        if (!annotationTypeMatches(Singular.class, child)) continue;
        char[] pluralName = node.getKind() == Kind.FIELD ? removePrefixFromField(node) : ((AbstractVariableDeclaration) node.get()).name;
        AnnotationValues<Singular> ann = createAnnotation(Singular.class, child);
        String explicitSingular = ann.getInstance().value();
        if (explicitSingular.isEmpty()) {
            if (Boolean.FALSE.equals(node.getAst().readConfiguration(ConfigurationKeys.SINGULAR_AUTO))) {
                node.addError("The singular must be specified explicitly (e.g. @Singular(\"task\")) because auto singularization is disabled.");
                explicitSingular = new String(pluralName);
            } else {
                explicitSingular = autoSingularize(new String(pluralName));
                if (explicitSingular == null) {
                    node.addError("Can't singularize this name; please specify the singular explicitly (i.e. @Singular(\"sheep\"))");
                    explicitSingular = new String(pluralName);
                }
            }
        }
        char[] singularName = explicitSingular.toCharArray();

        TypeReference type = ((AbstractVariableDeclaration) node.get()).type;
        TypeReference[] typeArgs = null;
        String typeName;
        if (type instanceof ParameterizedSingleTypeReference) {
            typeArgs = ((ParameterizedSingleTypeReference) type).typeArguments;
            typeName = new String(((ParameterizedSingleTypeReference) type).token);
        } else if (type instanceof ParameterizedQualifiedTypeReference) {
            TypeReference[][] tr = ((ParameterizedQualifiedTypeReference) type).typeArguments;
            if (tr != null) typeArgs = tr[tr.length - 1];
            char[][] tokens = ((ParameterizedQualifiedTypeReference) type).tokens;
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < tokens.length; i++) {
                if (i > 0) sb.append(".");
                sb.append(tokens[i]);
            }
            typeName = sb.toString();
        } else {
            typeName = type.toString();
        }

        String targetFqn = EclipseSingularsRecipes.get().toQualified(typeName);
        EclipseSingularizer singularizer = EclipseSingularsRecipes.get().getSingularizer(targetFqn);
        if (singularizer == null) {
            node.addError("Lombok does not know how to create the singular-form builder methods for type '" + typeName + "'; they won't be generated.");
            return null;
        }

        return new SingularData(child, singularName, pluralName, typeArgs == null ? Collections.<TypeReference>emptyList() : Arrays.asList(typeArgs), targetFqn, singularizer, source);
    }

    return null;
}
项目:EasyMPermission    文件:EclipseHandlerUtil.java   
/**
 * Generates a new statement that checks if the given variable is null, and if so, throws a specified exception with the
 * variable name as message.
 * 
 * @param exName The name of the exception to throw; normally {@code java.lang.NullPointerException}.
 */
public static Statement generateNullCheck(AbstractVariableDeclaration variable, EclipseNode sourceNode) {
    NullCheckExceptionType exceptionType = sourceNode.getAst().readConfiguration(ConfigurationKeys.NON_NULL_EXCEPTION_TYPE);
    if (exceptionType == null) exceptionType = NullCheckExceptionType.NULL_POINTER_EXCEPTION;

    ASTNode source = sourceNode.get();

    int pS = source.sourceStart, pE = source.sourceEnd;
    long p = (long)pS << 32 | pE;

    if (isPrimitive(variable.type)) return null;
    AllocationExpression exception = new AllocationExpression();
    setGeneratedBy(exception, source);
    int partCount = 1;
    String exceptionTypeStr = exceptionType.getExceptionType();
    for (int i = 0; i < exceptionTypeStr.length(); i++) if (exceptionTypeStr.charAt(i) == '.') partCount++;
    long[] ps = new long[partCount];
    Arrays.fill(ps, 0L);
    exception.type = new QualifiedTypeReference(fromQualifiedName(exceptionTypeStr), ps);
    setGeneratedBy(exception.type, source);
    exception.arguments = new Expression[] {
            new StringLiteral(exceptionType.toExceptionMessage(new String(variable.name)).toCharArray(), pS, pE, 0)
    };
    setGeneratedBy(exception.arguments[0], source);
    ThrowStatement throwStatement = new ThrowStatement(exception, pS, pE);
    setGeneratedBy(throwStatement, source);

    SingleNameReference varName = new SingleNameReference(variable.name, p);
    setGeneratedBy(varName, source);
    NullLiteral nullLiteral = new NullLiteral(pS, pE);
    setGeneratedBy(nullLiteral, source);
    EqualExpression equalExpression = new EqualExpression(varName, nullLiteral, OperatorIds.EQUAL_EQUAL);
    equalExpression.sourceStart = pS; equalExpression.statementEnd = equalExpression.sourceEnd = pE;
    setGeneratedBy(equalExpression, source);
    Block throwBlock = new Block(0);
    throwBlock.statements = new Statement[] {throwStatement};
    throwBlock.sourceStart = pS; throwBlock.sourceEnd = pE;
    setGeneratedBy(throwBlock, source);
    IfStatement ifStatement = new IfStatement(equalExpression, throwBlock, 0, 0);
    setGeneratedBy(ifStatement, source);
    return ifStatement;
}
项目:EasyMPermission    文件:HandleBuilder.java   
/**
 * Returns the explicitly requested singular annotation on this node (field
 * or parameter), or null if there's no {@code @Singular} annotation on it.
 * 
 * @param node The node (field or method param) to inspect for its name and potential {@code @Singular} annotation.
 */
private SingularData getSingularData(EclipseNode node, ASTNode source) {
    for (EclipseNode child : node.down()) {
        if (child.getKind() == Kind.ANNOTATION && annotationTypeMatches(Singular.class, child)) {
            char[] pluralName = node.getKind() == Kind.FIELD ? removePrefixFromField(node) : ((AbstractVariableDeclaration) node.get()).name;
            AnnotationValues<Singular> ann = createAnnotation(Singular.class, child);
            String explicitSingular = ann.getInstance().value();
            if (explicitSingular.isEmpty()) {
                if (Boolean.FALSE.equals(node.getAst().readConfiguration(ConfigurationKeys.SINGULAR_AUTO))) {
                    node.addError("The singular must be specified explicitly (e.g. @Singular(\"task\")) because auto singularization is disabled.");
                    explicitSingular = new String(pluralName);
                } else {
                    explicitSingular = autoSingularize(node.getName());
                    if (explicitSingular == null) {
                        node.addError("Can't singularize this name; please specify the singular explicitly (i.e. @Singular(\"sheep\"))");
                        explicitSingular = new String(pluralName);
                    }
                }
            }
            char[] singularName = explicitSingular.toCharArray();

            TypeReference type = ((AbstractVariableDeclaration) node.get()).type;
            TypeReference[] typeArgs = null;
            String typeName;
            if (type instanceof ParameterizedSingleTypeReference) {
                typeArgs = ((ParameterizedSingleTypeReference) type).typeArguments;
                typeName = new String(((ParameterizedSingleTypeReference) type).token);
            } else if (type instanceof ParameterizedQualifiedTypeReference) {
                TypeReference[][] tr = ((ParameterizedQualifiedTypeReference) type).typeArguments;
                if (tr != null) typeArgs = tr[tr.length - 1];
                char[][] tokens = ((ParameterizedQualifiedTypeReference) type).tokens;
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < tokens.length; i++) {
                    if (i > 0) sb.append(".");
                    sb.append(tokens[i]);
                }
                typeName = sb.toString();
            } else {
                typeName = type.toString();
            }

            String targetFqn = EclipseSingularsRecipes.get().toQualified(typeName);
            EclipseSingularizer singularizer = EclipseSingularsRecipes.get().getSingularizer(targetFqn);
            if (singularizer == null) {
                node.addError("Lombok does not know how to create the singular-form builder methods for type '" + typeName + "'; they won't be generated.");
                return null;
            }

            return new SingularData(child, singularName, pluralName, typeArgs == null ? Collections.<TypeReference>emptyList() : Arrays.asList(typeArgs), targetFqn, singularizer, source);
        }
    }

    return null;
}
项目:android-retrolambda-lombok    文件:EcjTreeBuilder.java   
AbstractVariableDeclaration create() {
    throw new UnsupportedOperationException(); 
}
项目:android-retrolambda-lombok    文件:EcjTreeBuilder.java   
AbstractVariableDeclaration create() {
    return new FieldDeclaration(); 
}
项目:android-retrolambda-lombok    文件:EcjTreeBuilder.java   
AbstractVariableDeclaration create() {
    return new LocalDeclaration(null, 0, 0); 
}
项目:android-retrolambda-lombok    文件:EcjTreeBuilder.java   
AbstractVariableDeclaration create() {
    return new Argument(null, 0, null, 0);
}
项目:Eclipse-Postfix-Code-Completion    文件:AssistParser.java   
protected boolean triggerRecoveryUponLambdaClosure(Statement statement, boolean shouldCommit) {
    // Last block statement reduced is required to be on the AST stack top.
    boolean lambdaClosed = false;
    int statementStart, statementEnd;
    statementStart = statement.sourceStart;
    statementEnd = statement instanceof AbstractVariableDeclaration ? ((AbstractVariableDeclaration)statement).declarationSourceEnd : statement.sourceEnd;
    for (int i = this.elementPtr; i >= 0; --i) {
        if (this.elementKindStack[i] != K_LAMBDA_EXPRESSION_DELIMITER)
            continue;
        LambdaExpression expression = (LambdaExpression) this.elementObjectInfoStack[i];
        if (expression.sourceStart >= statementStart && expression.sourceEnd <= statementEnd) {
            this.elementPtr = i - 1;
            lambdaClosed = true;
        } else {
            if (shouldCommit) {
                int stackLength = this.stack.length;
                if (++this.stateStackTop >= stackLength) {
                    System.arraycopy(
                            this.stack, 0,
                            this.stack = new int[stackLength + StackIncrement], 0,
                            stackLength);
                }
                this.stack[this.stateStackTop] = this.unstackedAct;
                commit();
                this.stateStackTop --;
            }
            return false;
        }
    }

    if (lambdaClosed && this.currentElement != null) {
        this.restartRecovery = true;
        if (!(statement instanceof AbstractVariableDeclaration)) { // added already as part of standard recovery since these contribute a name to the scope prevailing at the cursor.
            /* See if CompletionParser.attachOrphanCompletionNode has already added bits and pieces of AST to the recovery tree. If so, we want to
               replace those fragments with the fuller statement that provides target type for the lambda that got closed just now. There is prior
               art/precedent in the Java 7 world to this: Search for recoveredBlock.statements[--recoveredBlock.statementCount] = null;
               See also that this concern does not arise in the case of field/local initialization since the initializer is replaced with full tree by consumeExitVariableWithInitialization.
            */
            ASTNode assistNodeParent = this.assistNodeParent();
            ASTNode enclosingNode = this.enclosingNode();
            if (assistNodeParent != null || enclosingNode != null) {
                RecoveredBlock recoveredBlock = (RecoveredBlock) (this.currentElement instanceof RecoveredBlock ? this.currentElement : 
                                                    (this.currentElement.parent instanceof RecoveredBlock) ? this.currentElement.parent : null);
                if (recoveredBlock != null) {
                    RecoveredStatement recoveredStatement = recoveredBlock.statementCount > 0 ? recoveredBlock.statements[recoveredBlock.statementCount - 1] : null;
                    ASTNode parseTree = recoveredStatement != null ? recoveredStatement.updatedStatement(0, new HashSet()) : null;
                    if (parseTree != null && (parseTree == assistNodeParent || parseTree == enclosingNode)) {
                        recoveredBlock.statements[--recoveredBlock.statementCount] = null;
                        this.currentElement = recoveredBlock;
                    }
                }
            }
            this.currentElement.add(statement, 0);
        }
    }
    this.snapShot = null;
    return lambdaClosed;
}