本文整理汇总了Java中org.eclipse.jdt.internal.compiler.lookup.TypeIds.UNBOXING属性的典型用法代码示例。如果您正苦于以下问题:Java TypeIds.UNBOXING属性的具体用法?Java TypeIds.UNBOXING怎么用?Java TypeIds.UNBOXING使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.eclipse.jdt.internal.compiler.lookup.TypeIds
的用法示例。
在下文中一共展示了TypeIds.UNBOXING属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: reportOnlyUselesslyReadPrivateField
void reportOnlyUselesslyReadPrivateField(BlockScope currentScope, FieldBinding fieldBinding, boolean valueRequired) {
if (valueRequired) {
// access is relevant, turn compound use into real use:
fieldBinding.compoundUseFlag = 0;
fieldBinding.modifiers |= ExtraCompilerModifiers.AccLocallyUsed;
} else {
if (fieldBinding.isUsedOnlyInCompound()) {
fieldBinding.compoundUseFlag--; // consume one
if (fieldBinding.compoundUseFlag == 0 // report only the last usage
&& fieldBinding.isOrEnclosedByPrivateType()
&& (this.implicitConversion & TypeIds.UNBOXING) == 0) // don't report if unboxing is involved (might cause NPE)
{
// compoundAssignment/postIncrement is the only usage of this field
currentScope.problemReporter().unusedPrivateField(fieldBinding.sourceField());
fieldBinding.modifiers |= ExtraCompilerModifiers.AccLocallyUsed; // don't report again
}
}
}
}
示例2: localVariableNullReference
public void localVariableNullReference(LocalVariableBinding local, ASTNode location) {
if (location instanceof Expression && (((Expression)location).implicitConversion & TypeIds.UNBOXING) != 0) {
nullUnboxing(location, local.type);
return;
}
int severity = computeSeverity(IProblem.NullLocalVariableReference);
if (severity == ProblemSeverities.Ignore) return;
String[] arguments = new String[] {new String(local.name) };
this.handle(
IProblem.NullLocalVariableReference,
arguments,
arguments,
severity,
nodeSourceStart(local, location),
nodeSourceEnd(local, location));
}
示例3: localVariablePotentialNullReference
public void localVariablePotentialNullReference(LocalVariableBinding local, ASTNode location) {
if (location instanceof Expression && (((Expression)location).implicitConversion & TypeIds.UNBOXING) != 0) {
potentialNullUnboxing(location, local.type);
return;
}
if ((local.type.tagBits & TagBits.AnnotationNullable) != 0 && location instanceof Expression) {
dereferencingNullableExpression((Expression) location);
return;
}
int severity = computeSeverity(IProblem.PotentialNullLocalVariableReference);
if (severity == ProblemSeverities.Ignore) return;
String[] arguments = new String[] {new String(local.name)};
this.handle(
IProblem.PotentialNullLocalVariableReference,
arguments,
arguments,
severity,
nodeSourceStart(local, location),
nodeSourceEnd(local, location));
}
示例4: resolveUnboxing
boolean resolveUnboxing(Expression expression) {
org.eclipse.jdt.internal.compiler.ast.ASTNode node = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(expression);
if (node instanceof org.eclipse.jdt.internal.compiler.ast.Expression) {
org.eclipse.jdt.internal.compiler.ast.Expression compilerExpression = (org.eclipse.jdt.internal.compiler.ast.Expression) node;
return (compilerExpression.implicitConversion & TypeIds.UNBOXING) != 0;
}
return false;
}
示例5: generateCode
/**
* Code generation for a array reference
*/
public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {
int pc = codeStream.position;
this.receiver.generateCode(currentScope, codeStream, true);
if (this.receiver instanceof CastExpression // ((type[])null)[0]
&& ((CastExpression)this.receiver).innermostCastedExpression().resolvedType == TypeBinding.NULL){
codeStream.checkcast(this.receiver.resolvedType);
}
this.position.generateCode(currentScope, codeStream, true);
codeStream.arrayAt(this.resolvedType.id);
// Generating code for the potential runtime type checking
if (valueRequired) {
codeStream.generateImplicitConversion(this.implicitConversion);
} else {
boolean isUnboxing = (this.implicitConversion & TypeIds.UNBOXING) != 0;
// conversion only generated if unboxing
if (isUnboxing) codeStream.generateImplicitConversion(this.implicitConversion);
switch (isUnboxing ? postConversionType(currentScope).id : this.resolvedType.id) {
case T_long :
case T_double :
codeStream.pop2();
break;
default :
codeStream.pop();
}
}
codeStream.recordPositionsFrom(pc, this.sourceStart);
}
示例6: analyseCode
public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) {
FlowInfo result = this.expression
.analyseCode(currentScope, flowContext, flowInfo)
.unconditionalInits();
if ((this.expression.implicitConversion & TypeIds.UNBOXING) != 0) {
this.expression.checkNPE(currentScope, flowContext, flowInfo);
}
return result;
}
示例7: generateCode
public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {
int pc = codeStream.position;
if ((this.bits & Binding.VARIABLE) == 0) { // nothing to do if type ref
codeStream.recordPositionsFrom(pc, this.sourceStart);
return;
}
FieldBinding lastFieldBinding = this.otherBindings == null ? (FieldBinding) this.binding : this.otherBindings[this.otherBindings.length-1];
if (lastFieldBinding.canBeSeenBy(getFinalReceiverType(), this, currentScope)) {
super.generateCode(currentScope, codeStream, valueRequired);
return;
}
lastFieldBinding = generateReadSequence(currentScope, codeStream);
if (lastFieldBinding != null) {
boolean isStatic = lastFieldBinding.isStatic();
Constant fieldConstant = lastFieldBinding.constant();
if (fieldConstant != Constant.NotAConstant) {
if (!isStatic){
codeStream.invokeObjectGetClass();
codeStream.pop();
}
if (valueRequired) { // inline the last field constant
codeStream.generateConstant(fieldConstant, this.implicitConversion);
}
} else {
boolean isFirst = lastFieldBinding == this.binding
&& (this.indexOfFirstFieldBinding == 1 || TypeBinding.equalsEquals(lastFieldBinding.declaringClass, currentScope.enclosingReceiverType()))
&& this.otherBindings == null; // could be dup: next.next.next
TypeBinding requiredGenericCast = getGenericCast(this.otherBindings == null ? 0 : this.otherBindings.length);
if (valueRequired
|| (!isFirst && currentScope.compilerOptions().complianceLevel >= ClassFileConstants.JDK1_4)
|| ((this.implicitConversion & TypeIds.UNBOXING) != 0)
|| requiredGenericCast != null) {
int lastFieldPc = codeStream.position;
if (lastFieldBinding.declaringClass == null) { // array length
codeStream.arraylength();
if (valueRequired) {
codeStream.generateImplicitConversion(this.implicitConversion);
} else {
// could occur if !valueRequired but compliance >= 1.4
codeStream.pop();
}
} else {
codeStream.generateEmulatedReadAccessForField(lastFieldBinding);
if (requiredGenericCast != null) codeStream.checkcast(requiredGenericCast);
if (valueRequired) {
codeStream.generateImplicitConversion(this.implicitConversion);
} else {
boolean isUnboxing = (this.implicitConversion & TypeIds.UNBOXING) != 0;
// conversion only generated if unboxing
if (isUnboxing) codeStream.generateImplicitConversion(this.implicitConversion);
switch (isUnboxing ? postConversionType(currentScope).id : lastFieldBinding.type.id) {
case T_long :
case T_double :
codeStream.pop2();
break;
default :
codeStream.pop();
}
}
}
int fieldPosition = (int) (this.sourcePositions[this.sourcePositions.length - 1] >>> 32);
codeStream.recordPositionsFrom(lastFieldPc, fieldPosition);
} else {
if (!isStatic){
codeStream.invokeObjectGetClass(); // perform null check
codeStream.pop();
}
}
}
}
codeStream.recordPositionsFrom(pc, this.sourceStart);
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:73,代码来源:CodeSnippetQualifiedNameReference.java
示例8: generateCode
/**
* MessageSend code generation
*
* @param currentScope org.eclipse.jdt.internal.compiler.lookup.BlockScope
* @param codeStream org.eclipse.jdt.internal.compiler.codegen.CodeStream
* @param valueRequired boolean
*/
public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {
int pc = codeStream.position;
// generate receiver/enclosing instance access
MethodBinding codegenBinding = this.binding instanceof PolymorphicMethodBinding ? this.binding : this.binding.original();
boolean isStatic = codegenBinding.isStatic();
if (isStatic) {
this.receiver.generateCode(currentScope, codeStream, false);
} else if ((this.bits & ASTNode.DepthMASK) != 0 && this.receiver.isImplicitThis()) { // outer access ?
// outer method can be reached through emulation if implicit access
ReferenceBinding targetType = currentScope.enclosingSourceType().enclosingTypeAt((this.bits & ASTNode.DepthMASK) >> ASTNode.DepthSHIFT);
Object[] path = currentScope.getEmulationPath(targetType, true /*only exact match*/, false/*consider enclosing arg*/);
codeStream.generateOuterAccess(path, this, targetType, currentScope);
} else {
this.receiver.generateCode(currentScope, codeStream, true);
if ((this.bits & NeedReceiverGenericCast) != 0) {
codeStream.checkcast(this.actualReceiverType);
}
}
codeStream.recordPositionsFrom(pc, this.sourceStart);
// generate arguments
generateArguments(this.binding, this.arguments, currentScope, codeStream);
pc = codeStream.position;
// actual message invocation
if (this.syntheticAccessor == null){
TypeBinding constantPoolDeclaringClass = CodeStream.getConstantPoolDeclaringClass(currentScope, codegenBinding, this.actualReceiverType, this.receiver.isImplicitThis());
if (isStatic){
codeStream.invoke(Opcodes.OPC_invokestatic, codegenBinding, constantPoolDeclaringClass);
} else if((this.receiver.isSuper()) || codegenBinding.isPrivate()){
codeStream.invoke(Opcodes.OPC_invokespecial, codegenBinding, constantPoolDeclaringClass);
} else if (constantPoolDeclaringClass.isInterface()) { // interface or annotation type
codeStream.invoke(Opcodes.OPC_invokeinterface, codegenBinding, constantPoolDeclaringClass);
} else {
codeStream.invoke(Opcodes.OPC_invokevirtual, codegenBinding, constantPoolDeclaringClass);
}
} else {
codeStream.invoke(Opcodes.OPC_invokestatic, this.syntheticAccessor, null /* default declaringClass */);
}
// required cast must occur even if no value is required
if (this.valueCast != null) codeStream.checkcast(this.valueCast);
if (valueRequired){
// implicit conversion if necessary
codeStream.generateImplicitConversion(this.implicitConversion);
} else {
boolean isUnboxing = (this.implicitConversion & TypeIds.UNBOXING) != 0;
// conversion only generated if unboxing
if (isUnboxing) codeStream.generateImplicitConversion(this.implicitConversion);
switch (isUnboxing ? postConversionType(currentScope).id : codegenBinding.returnType.id) {
case T_long :
case T_double :
codeStream.pop2();
break;
case T_void :
break;
default :
codeStream.pop();
}
}
codeStream.recordPositionsFrom(pc, (int)(this.nameSourcePosition >>> 32)); // highlight selector
}
示例9: computeConversion
/**
* Base types need that the widening is explicitly done by the compiler using some bytecode like i2f.
* Also check unsafe type operations.
*/
public void computeConversion(Scope scope, TypeBinding runtimeType, TypeBinding compileTimeType) {
if (runtimeType == null || compileTimeType == null)
return;
if (this.implicitConversion != 0) return; // already set independently
// it is possible for a Byte to be unboxed to a byte & then converted to an int
// but it is not possible for a byte to become Byte & then assigned to an Integer,
// or to become an int before boxed into an Integer
if (runtimeType != TypeBinding.NULL && runtimeType.isBaseType()) {
if (!compileTimeType.isBaseType()) {
TypeBinding unboxedType = scope.environment().computeBoxingType(compileTimeType);
this.implicitConversion = TypeIds.UNBOXING;
scope.problemReporter().autoboxing(this, compileTimeType, runtimeType);
compileTimeType = unboxedType;
}
} else if (compileTimeType != TypeBinding.NULL && compileTimeType.isBaseType()) {
TypeBinding boxedType = scope.environment().computeBoxingType(runtimeType);
if (TypeBinding.equalsEquals(boxedType, runtimeType)) // Object o = 12;
boxedType = compileTimeType;
this.implicitConversion = TypeIds.BOXING | (boxedType.id << 4) + compileTimeType.id;
scope.problemReporter().autoboxing(this, compileTimeType, scope.environment().computeBoxingType(boxedType));
return;
} else if (this.constant != Constant.NotAConstant && this.constant.typeID() != TypeIds.T_JavaLangString) {
this.implicitConversion = TypeIds.BOXING;
return;
}
int compileTimeTypeID, runtimeTypeID;
if ((compileTimeTypeID = compileTimeType.id) >= TypeIds.T_LastWellKnownTypeId) { // e.g. ? extends String ==> String (103227); >= TypeIds.T_LastWellKnownTypeId implies TypeIds.NoId
compileTimeTypeID = compileTimeType.erasure().id == TypeIds.T_JavaLangString ? TypeIds.T_JavaLangString : TypeIds.T_JavaLangObject;
} else if (runtimeType.isPrimitiveType() && compileTimeType instanceof ReferenceBinding && !compileTimeType.isBoxedPrimitiveType()) {
compileTimeTypeID = TypeIds.T_JavaLangObject; // treatment is the same as for jlO.
}
switch (runtimeTypeID = runtimeType.id) {
case T_byte :
case T_short :
case T_char :
if (compileTimeTypeID == TypeIds.T_JavaLangObject) {
this.implicitConversion |= (runtimeTypeID << 4) + compileTimeTypeID;
} else {
this.implicitConversion |= (TypeIds.T_int << 4) + compileTimeTypeID;
}
break;
case T_JavaLangString :
case T_float :
case T_boolean :
case T_double :
case T_int : //implicitConversion may result in i2i which will result in NO code gen
case T_long :
this.implicitConversion |= (runtimeTypeID << 4) + compileTimeTypeID;
break;
default : // regular object ref
// if (compileTimeType.isRawType() && runtimeTimeType.isBoundParameterizedType()) {
// scope.problemReporter().unsafeRawExpression(this, compileTimeType, runtimeTimeType);
// }
}
}
示例10: generateCode
public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {
if (!valueRequired)
currentScope.problemReporter().unusedObjectAllocation(this);
int pc = codeStream.position;
MethodBinding codegenBinding = this.binding.original();
ReferenceBinding allocatedType = codegenBinding.declaringClass;
codeStream.new_(this.type, allocatedType);
boolean isUnboxing = (this.implicitConversion & TypeIds.UNBOXING) != 0;
if (valueRequired || isUnboxing) {
codeStream.dup();
}
// better highlight for allocation: display the type individually
if (this.type != null) { // null for enum constant body
codeStream.recordPositionsFrom(pc, this.type.sourceStart);
} else {
// push enum constant name and ordinal
codeStream.ldc(String.valueOf(this.enumConstant.name));
codeStream.generateInlinedValue(this.enumConstant.binding.id);
}
// handling innerclass instance allocation - enclosing instance arguments
if (allocatedType.isNestedType()) {
codeStream.generateSyntheticEnclosingInstanceValues(
currentScope,
allocatedType,
enclosingInstance(),
this);
}
// generate the arguments for constructor
generateArguments(this.binding, this.arguments, currentScope, codeStream);
// handling innerclass instance allocation - outer local arguments
if (allocatedType.isNestedType()) {
codeStream.generateSyntheticOuterArgumentValues(
currentScope,
allocatedType,
this);
}
// invoke constructor
if (this.syntheticAccessor == null) {
codeStream.invoke(Opcodes.OPC_invokespecial, codegenBinding, null /* default declaringClass */, this.typeArguments);
} else {
// synthetic accessor got some extra arguments appended to its signature, which need values
for (int i = 0,
max = this.syntheticAccessor.parameters.length - codegenBinding.parameters.length;
i < max;
i++) {
codeStream.aconst_null();
}
codeStream.invoke(Opcodes.OPC_invokespecial, this.syntheticAccessor, null /* default declaringClass */, this.typeArguments);
}
if (valueRequired) {
codeStream.generateImplicitConversion(this.implicitConversion);
} else if (isUnboxing) {
// conversion only generated if unboxing
codeStream.generateImplicitConversion(this.implicitConversion);
switch (postConversionType(currentScope).id) {
case T_long :
case T_double :
codeStream.pop2();
break;
default :
codeStream.pop();
}
}
codeStream.recordPositionsFrom(pc, this.sourceStart);
if (this.anonymousType != null) {
this.anonymousType.generateCode(currentScope, codeStream);
}
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:70,代码来源:QualifiedAllocationExpression.java
示例11: generateCode
public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {
int pc = codeStream.position;
if (this.constant != Constant.NotAConstant) {
if (valueRequired) {
codeStream.generateConstant(this.constant, this.implicitConversion);
}
} else {
FieldBinding lastFieldBinding = generateReadSequence(currentScope, codeStream);
if (lastFieldBinding != null) {
boolean isStatic = lastFieldBinding.isStatic();
Constant fieldConstant = lastFieldBinding.constant();
if (fieldConstant != Constant.NotAConstant) {
if (!isStatic){
codeStream.invokeObjectGetClass();
codeStream.pop();
}
if (valueRequired) { // inline the last field constant
codeStream.generateConstant(fieldConstant, this.implicitConversion);
}
} else {
boolean isFirst = lastFieldBinding == this.binding
&& (this.indexOfFirstFieldBinding == 1 || lastFieldBinding.declaringClass == currentScope.enclosingReceiverType())
&& this.otherBindings == null; // could be dup: next.next.next
TypeBinding requiredGenericCast = getGenericCast(this.otherBindings == null ? 0 : this.otherBindings.length);
if (valueRequired
|| (!isFirst && currentScope.compilerOptions().complianceLevel >= ClassFileConstants.JDK1_4)
|| ((this.implicitConversion & TypeIds.UNBOXING) != 0)
|| requiredGenericCast != null) {
int lastFieldPc = codeStream.position;
if (lastFieldBinding.declaringClass == null) { // array length
codeStream.arraylength();
if (valueRequired) {
codeStream.generateImplicitConversion(this.implicitConversion);
} else {
// could occur if !valueRequired but compliance >= 1.4
codeStream.pop();
}
} else {
SyntheticMethodBinding accessor = this.syntheticReadAccessors == null ? null : this.syntheticReadAccessors[this.syntheticReadAccessors.length - 1];
if (accessor == null) {
TypeBinding constantPoolDeclaringClass = CodeStream.getConstantPoolDeclaringClass(currentScope, lastFieldBinding, getFinalReceiverType(), isFirst);
if (isStatic) {
codeStream.fieldAccess(Opcodes.OPC_getstatic, lastFieldBinding, constantPoolDeclaringClass);
} else {
codeStream.fieldAccess(Opcodes.OPC_getfield, lastFieldBinding, constantPoolDeclaringClass);
}
} else {
codeStream.invoke(Opcodes.OPC_invokestatic, accessor, null /* default declaringClass */);
}
if (requiredGenericCast != null) codeStream.checkcast(requiredGenericCast);
if (valueRequired) {
codeStream.generateImplicitConversion(this.implicitConversion);
} else {
boolean isUnboxing = (this.implicitConversion & TypeIds.UNBOXING) != 0;
// conversion only generated if unboxing
if (isUnboxing) codeStream.generateImplicitConversion(this.implicitConversion);
switch (isUnboxing ? postConversionType(currentScope).id : lastFieldBinding.type.id) {
case T_long :
case T_double :
codeStream.pop2();
break;
default :
codeStream.pop();
break;
}
}
}
int fieldPosition = (int) (this.sourcePositions[this.sourcePositions.length - 1] >>> 32);
codeStream.recordPositionsFrom(lastFieldPc, fieldPosition);
} else {
if (!isStatic){
codeStream.invokeObjectGetClass(); // perform null check
codeStream.pop();
}
}
}
}
}
codeStream.recordPositionsFrom(pc, this.sourceStart);
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:81,代码来源:QualifiedNameReference.java
示例12: generateCode
/**
* MessageSend code generation
*
* @param currentScope org.eclipse.jdt.internal.compiler.lookup.BlockScope
* @param codeStream org.eclipse.jdt.internal.compiler.codegen.CodeStream
* @param valueRequired boolean
*/
public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {
int pc = codeStream.position;
// generate receiver/enclosing instance access
MethodBinding codegenBinding = this.binding instanceof PolymorphicMethodBinding ? this.binding : this.binding.original();
boolean isStatic = codegenBinding.isStatic();
if (isStatic) {
this.receiver.generateCode(currentScope, codeStream, false);
} else if ((this.bits & ASTNode.DepthMASK) != 0 && this.receiver.isImplicitThis()) { // outer access ?
// outer method can be reached through emulation if implicit access
ReferenceBinding targetType = currentScope.enclosingSourceType().enclosingTypeAt((this.bits & ASTNode.DepthMASK) >> ASTNode.DepthSHIFT);
Object[] path = currentScope.getEmulationPath(targetType, true /*only exact match*/, false/*consider enclosing arg*/);
codeStream.generateOuterAccess(path, this, targetType, currentScope);
} else {
this.receiver.generateCode(currentScope, codeStream, true);
if ((this.bits & NeedReceiverGenericCast) != 0) {
codeStream.checkcast(this.actualReceiverType);
}
}
codeStream.recordPositionsFrom(pc, this.sourceStart);
// generate arguments
generateArguments(this.binding, this.arguments, currentScope, codeStream);
pc = codeStream.position;
// actual message invocation
if (this.syntheticAccessor == null){
TypeBinding constantPoolDeclaringClass = CodeStream.getConstantPoolDeclaringClass(currentScope, codegenBinding, this.actualReceiverType, this.receiver.isImplicitThis());
if (isStatic){
codeStream.invoke(Opcodes.OPC_invokestatic, codegenBinding, constantPoolDeclaringClass, this.typeArguments);
} else if((this.receiver.isSuper()) || codegenBinding.isPrivate()){
codeStream.invoke(Opcodes.OPC_invokespecial, codegenBinding, constantPoolDeclaringClass, this.typeArguments);
} else if (constantPoolDeclaringClass.isInterface()) { // interface or annotation type
codeStream.invoke(Opcodes.OPC_invokeinterface, codegenBinding, constantPoolDeclaringClass, this.typeArguments);
} else {
codeStream.invoke(Opcodes.OPC_invokevirtual, codegenBinding, constantPoolDeclaringClass, this.typeArguments);
}
} else {
codeStream.invoke(Opcodes.OPC_invokestatic, this.syntheticAccessor, null /* default declaringClass */, this.typeArguments);
}
// required cast must occur even if no value is required
if (this.valueCast != null) codeStream.checkcast(this.valueCast);
if (valueRequired){
// implicit conversion if necessary
codeStream.generateImplicitConversion(this.implicitConversion);
} else {
boolean isUnboxing = (this.implicitConversion & TypeIds.UNBOXING) != 0;
// conversion only generated if unboxing
if (isUnboxing) codeStream.generateImplicitConversion(this.implicitConversion);
switch (isUnboxing ? postConversionType(currentScope).id : codegenBinding.returnType.id) {
case T_long :
case T_double :
codeStream.pop2();
break;
case T_void :
break;
default :
codeStream.pop();
}
}
codeStream.recordPositionsFrom(pc, (int)(this.nameSourcePosition >>> 32)); // highlight selector
}
示例13: generateCode
public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {
int pc = codeStream.position;
if ((this.bits & Binding.VARIABLE) == 0) { // nothing to do if type ref
codeStream.recordPositionsFrom(pc, this.sourceStart);
return;
}
FieldBinding lastFieldBinding = this.otherBindings == null ? (FieldBinding) this.binding : this.otherBindings[this.otherBindings.length-1];
if (lastFieldBinding.canBeSeenBy(getFinalReceiverType(), this, currentScope)) {
super.generateCode(currentScope, codeStream, valueRequired);
return;
}
lastFieldBinding = generateReadSequence(currentScope, codeStream);
if (lastFieldBinding != null) {
boolean isStatic = lastFieldBinding.isStatic();
Constant fieldConstant = lastFieldBinding.constant();
if (fieldConstant != Constant.NotAConstant) {
if (!isStatic){
codeStream.invokeObjectGetClass();
codeStream.pop();
}
if (valueRequired) { // inline the last field constant
codeStream.generateConstant(fieldConstant, this.implicitConversion);
}
} else {
boolean isFirst = lastFieldBinding == this.binding
&& (this.indexOfFirstFieldBinding == 1 || lastFieldBinding.declaringClass == currentScope.enclosingReceiverType())
&& this.otherBindings == null; // could be dup: next.next.next
TypeBinding requiredGenericCast = getGenericCast(this.otherBindings == null ? 0 : this.otherBindings.length);
if (valueRequired
|| (!isFirst && currentScope.compilerOptions().complianceLevel >= ClassFileConstants.JDK1_4)
|| ((this.implicitConversion & TypeIds.UNBOXING) != 0)
|| requiredGenericCast != null) {
int lastFieldPc = codeStream.position;
if (lastFieldBinding.declaringClass == null) { // array length
codeStream.arraylength();
if (valueRequired) {
codeStream.generateImplicitConversion(this.implicitConversion);
} else {
// could occur if !valueRequired but compliance >= 1.4
codeStream.pop();
}
} else {
codeStream.generateEmulatedReadAccessForField(lastFieldBinding);
if (requiredGenericCast != null) codeStream.checkcast(requiredGenericCast);
if (valueRequired) {
codeStream.generateImplicitConversion(this.implicitConversion);
} else {
boolean isUnboxing = (this.implicitConversion & TypeIds.UNBOXING) != 0;
// conversion only generated if unboxing
if (isUnboxing) codeStream.generateImplicitConversion(this.implicitConversion);
switch (isUnboxing ? postConversionType(currentScope).id : lastFieldBinding.type.id) {
case T_long :
case T_double :
codeStream.pop2();
break;
default :
codeStream.pop();
}
}
}
int fieldPosition = (int) (this.sourcePositions[this.sourcePositions.length - 1] >>> 32);
codeStream.recordPositionsFrom(lastFieldPc, fieldPosition);
} else {
if (!isStatic){
codeStream.invokeObjectGetClass(); // perform null check
codeStream.pop();
}
}
}
}
codeStream.recordPositionsFrom(pc, this.sourceStart);
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:73,代码来源:CodeSnippetQualifiedNameReference.java
示例14: computeConversion
/**
* Base types need that the widening is explicitly done by the compiler using some bytecode like i2f.
* Also check unsafe type operations.
*/
public void computeConversion(Scope scope, TypeBinding runtimeType, TypeBinding compileTimeType) {
if (runtimeType == null || compileTimeType == null)
return;
if (this.implicitConversion != 0) return; // already set independantly
// it is possible for a Byte to be unboxed to a byte & then converted to an int
// but it is not possible for a byte to become Byte & then assigned to an Integer,
// or to become an int before boxed into an Integer
if (runtimeType != TypeBinding.NULL && runtimeType.isBaseType()) {
if (!compileTimeType.isBaseType()) {
TypeBinding unboxedType = scope.environment().computeBoxingType(compileTimeType);
this.implicitConversion = TypeIds.UNBOXING;
scope.problemReporter().autoboxing(this, compileTimeType, runtimeType);
compileTimeType = unboxedType;
}
} else if (compileTimeType != TypeBinding.NULL && compileTimeType.isBaseType()) {
TypeBinding boxedType = scope.environment().computeBoxingType(runtimeType);
if (boxedType == runtimeType) // Object o = 12;
boxedType = compileTimeType;
this.implicitConversion = TypeIds.BOXING | (boxedType.id << 4) + compileTimeType.id;
scope.problemReporter().autoboxing(this, compileTimeType, scope.environment().computeBoxingType(boxedType));
return;
} else if (this.constant != Constant.NotAConstant && this.constant.typeID() != TypeIds.T_JavaLangString) {
this.implicitConversion = TypeIds.BOXING;
return;
}
int compileTimeTypeID, runtimeTypeID;
if ((compileTimeTypeID = compileTimeType.id) == TypeIds.NoId) { // e.g. ? extends String ==> String (103227)
compileTimeTypeID = compileTimeType.erasure().id == TypeIds.T_JavaLangString ? TypeIds.T_JavaLangString : TypeIds.T_JavaLangObject;
}
switch (runtimeTypeID = runtimeType.id) {
case T_byte :
case T_short :
case T_char :
if (compileTimeTypeID == TypeIds.T_JavaLangObject) {
this.implicitConversion |= (runtimeTypeID << 4) + compileTimeTypeID;
} else {
this.implicitConversion |= (TypeIds.T_int << 4) + compileTimeTypeID;
}
break;
case T_JavaLangString :
case T_float :
case T_boolean :
case T_double :
case T_int : //implicitConversion may result in i2i which will result in NO code gen
case T_long :
this.implicitConversion |= (runtimeTypeID << 4) + compileTimeTypeID;
break;
default : // regular object ref
// if (compileTimeType.isRawType() && runtimeTimeType.isBoundParameterizedType()) {
// scope.problemReporter().unsafeRawExpression(this, compileTimeType, runtimeTimeType);
// }
}
}
示例15: analyseCode
public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) {
// must verify that exceptions potentially thrown by this expression are caught in the method.
try {
((MethodScope) currentScope).isConstructorCall = true;
// process enclosing instance
if (this.qualification != null) {
flowInfo =
this.qualification
.analyseCode(currentScope, flowContext, flowInfo)
.unconditionalInits();
}
// process arguments
if (this.arguments != null) {
boolean analyseResources = currentScope.compilerOptions().analyseResourceLeaks;
for (int i = 0, max = this.arguments.length; i < max; i++) {
flowInfo =
this.arguments[i]
.analyseCode(currentScope, flowContext, flowInfo)
.unconditionalInits();
if (analyseResources) {
// if argument is an AutoCloseable insert info that it *may* be closed (by the target constructor, i.e.)
flowInfo = FakedTrackingVariable.markPassedToOutside(currentScope, this.arguments[i], flowInfo, false);
}
if ((this.arguments[i].implicitConversion & TypeIds.UNBOXING) != 0) {
this.arguments[i].checkNPE(currentScope, flowContext, flowInfo);
}
}
analyseArguments(currentScope, flowContext, flowInfo, this.binding, this.arguments);
}
ReferenceBinding[] thrownExceptions;
if ((thrownExceptions = this.binding.thrownExceptions) != Binding.NO_EXCEPTIONS) {
if ((this.bits & ASTNode.Unchecked) != 0 && this.genericTypeArguments == null) {
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=277643, align with javac on JLS 15.12.2.6
thrownExceptions = currentScope.environment().convertToRawTypes(this.binding.thrownExceptions, true, true);
}
// check exceptions
flowContext.checkExceptionHandlers(
thrownExceptions,
(this.accessMode == ExplicitConstructorCall.ImplicitSuper)
? (ASTNode) currentScope.methodScope().referenceContext
: (ASTNode) this,
flowInfo,
currentScope);
}
manageEnclosingInstanceAccessIfNecessary(currentScope, flowInfo);
manageSyntheticAccessIfNecessary(currentScope, flowInfo);
return flowInfo;
} finally {
((MethodScope) currentScope).isConstructorCall = false;
}
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:54,代码来源:ExplicitConstructorCall.java