Java Code Examples for org.eclipse.jdt.internal.compiler.lookup.BlockScope#enclosingSourceType()
The following examples show how to use
org.eclipse.jdt.internal.compiler.lookup.BlockScope#enclosingSourceType() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CodeSnippetThisReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public TypeBinding resolveType(BlockScope scope) { // implicit this this.constant = Constant.NotAConstant; ReferenceBinding snippetType = scope.enclosingSourceType(); MethodScope methodScope = scope.methodScope(); if (!this.isImplicit && !checkAccess(scope, snippetType)) { return null; } this.delegateThis = scope.getField(snippetType, DELEGATE_THIS, this); if (this.delegateThis == null || !this.delegateThis.isValidBinding()) { // should not happen // if this happen we should report illegal access to this in a static context methodScope.problemReporter().errorThisSuperInStatic(this); return null; } return this.resolvedType = this.delegateThis.type; }
Example 2
Source File: LambdaExpression.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) { if (this.shouldCaptureInstance) { this.binding.modifiers &= ~ClassFileConstants.AccStatic; } else { this.binding.modifiers |= ClassFileConstants.AccStatic; } SourceTypeBinding sourceType = currentScope.enclosingSourceType(); this.binding = sourceType.addSyntheticMethod(this); int pc = codeStream.position; StringBuffer signature = new StringBuffer(); signature.append('('); if (this.shouldCaptureInstance) { codeStream.aload_0(); signature.append(sourceType.signature()); } for (int i = 0, length = this.outerLocalVariables == null ? 0 : this.outerLocalVariables.length; i < length; i++) { SyntheticArgumentBinding syntheticArgument = this.outerLocalVariables[i]; if (this.shouldCaptureInstance) { syntheticArgument.resolvedPosition++; } signature.append(syntheticArgument.type.signature()); LocalVariableBinding capturedOuterLocal = syntheticArgument.actualOuterLocalVariable; VariableBinding[] path = currentScope.getEmulationPath(capturedOuterLocal); codeStream.generateOuterAccess(path, this, capturedOuterLocal, currentScope); } signature.append(')'); if (this.expectedType instanceof IntersectionCastTypeBinding) { signature.append(((IntersectionCastTypeBinding)this.expectedType).getSAMType(currentScope).signature()); } else { signature.append(this.expectedType.signature()); } int invokeDynamicNumber = codeStream.classFile.recordBootstrapMethod(this); codeStream.invokeDynamic(invokeDynamicNumber, (this.shouldCaptureInstance ? 1 : 0) + this.outerLocalVariablesSlotSize, 1, this.descriptor.selector, signature.toString().toCharArray()); if (!valueRequired) codeStream.pop(); codeStream.recordPositionsFrom(pc, this.sourceStart); }
Example 3
Source File: ReferenceExpression.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) { this.actualMethodBinding = this.binding; // grab before synthetics come into play. // Handle some special cases up front and transform them into implicit lambdas. if (shouldGenerateImplicitLambda(currentScope)) { generateImplicitLambda(currentScope, codeStream, valueRequired); return; } SourceTypeBinding sourceType = currentScope.enclosingSourceType(); if (this.receiverType.isArrayType()) { if (isConstructorReference()) { this.actualMethodBinding = this.binding = sourceType.addSyntheticArrayMethod((ArrayBinding) this.receiverType, SyntheticMethodBinding.ArrayConstructor); } else if (CharOperation.equals(this.selector, TypeConstants.CLONE)) { this.actualMethodBinding = this.binding = sourceType.addSyntheticArrayMethod((ArrayBinding) this.receiverType, SyntheticMethodBinding.ArrayClone); } } else if (this.syntheticAccessor != null) { if (this.lhs.isSuper() || isMethodReference()) this.binding = this.syntheticAccessor; } else { // cf. MessageSend.generateCode()'s call to CodeStream.getConstantPoolDeclaringClass. We have extracted the relevant portions sans side effect here. if (this.binding != null && isMethodReference()) { if (TypeBinding.notEquals(this.binding.declaringClass, this.lhs.resolvedType.erasure())) { if (!this.binding.declaringClass.canBeSeenBy(currentScope)) { this.binding = new MethodBinding(this.binding, (ReferenceBinding) this.lhs.resolvedType.erasure()); } } } } int pc = codeStream.position; StringBuffer buffer = new StringBuffer(); int argumentsSize = 0; buffer.append('('); if (this.haveReceiver) { this.lhs.generateCode(currentScope, codeStream, true); if (this.lhs.isSuper() && !this.actualMethodBinding.isPrivate()) { if (this.lhs instanceof QualifiedSuperReference) { QualifiedSuperReference qualifiedSuperReference = (QualifiedSuperReference) this.lhs; TypeReference qualification = qualifiedSuperReference.qualification; if (qualification.resolvedType.isInterface()) { buffer.append(sourceType.signature()); } else { buffer.append(((QualifiedSuperReference) this.lhs).currentCompatibleType.signature()); } } else { buffer.append(sourceType.signature()); } } else { buffer.append(this.receiverType.signature()); } argumentsSize = 1; } else { if (this.isConstructorReference()) { ReferenceBinding[] enclosingInstances = Binding.UNINITIALIZED_REFERENCE_TYPES; if (this.receiverType.isNestedType()) { ReferenceBinding nestedType = (ReferenceBinding) this.receiverType; if ((enclosingInstances = nestedType.syntheticEnclosingInstanceTypes()) != null) { int length = enclosingInstances.length; argumentsSize = length; for (int i = 0 ; i < length; i++) { ReferenceBinding syntheticArgumentType = enclosingInstances[i]; buffer.append(syntheticArgumentType.signature()); Object[] emulationPath = currentScope.getEmulationPath( syntheticArgumentType, false /* allow compatible match */, true /* disallow instance reference in explicit constructor call */); codeStream.generateOuterAccess(emulationPath, this, syntheticArgumentType, currentScope); } } else { enclosingInstances = Binding.NO_REFERENCE_TYPES; } // Reject types that capture outer local arguments, these cannot be manufactured by the metafactory. if (nestedType.syntheticOuterLocalVariables() != null) { currentScope.problemReporter().noSuchEnclosingInstance(nestedType.enclosingType(), this, false); return; } } if (this.syntheticAccessor != null) { this.binding = sourceType.addSyntheticFactoryMethod(this.binding, this.syntheticAccessor, enclosingInstances); } } } buffer.append(')'); buffer.append('L'); buffer.append(this.resolvedType.constantPoolName()); buffer.append(';'); int invokeDynamicNumber = codeStream.classFile.recordBootstrapMethod(this); codeStream.invokeDynamic(invokeDynamicNumber, argumentsSize, 1, this.descriptor.selector, buffer.toString().toCharArray(), this.isConstructorReference(), (this.lhs instanceof TypeReference? (TypeReference) this.lhs : null), this.typeArguments); if (!valueRequired) codeStream.pop(); codeStream.recordPositionsFrom(pc, this.sourceStart); }
Example 4
Source File: SingleNameReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public TypeBinding checkFieldAccess(BlockScope scope) { FieldBinding fieldBinding = (FieldBinding) this.binding; this.constant = fieldBinding.constant(); this.bits &= ~ASTNode.RestrictiveFlagMASK; // clear bits this.bits |= Binding.FIELD; MethodScope methodScope = scope.methodScope(); if (fieldBinding.isStatic()) { // check if accessing enum static field in initializer ReferenceBinding declaringClass = fieldBinding.declaringClass; if (declaringClass.isEnum()) { SourceTypeBinding sourceType = scope.enclosingSourceType(); if (this.constant == Constant.NotAConstant && !methodScope.isStatic && (TypeBinding.equalsEquals(sourceType, declaringClass) || TypeBinding.equalsEquals(sourceType.superclass, declaringClass)) // enum constant body && methodScope.isInsideInitializerOrConstructor()) { scope.problemReporter().enumStaticFieldUsedDuringInitialization(fieldBinding, this); } } } else { if (scope.compilerOptions().getSeverity(CompilerOptions.UnqualifiedFieldAccess) != ProblemSeverities.Ignore) { scope.problemReporter().unqualifiedFieldAccess(this, fieldBinding); } // must check for the static status.... if (methodScope.isStatic) { scope.problemReporter().staticFieldAccessToNonStaticVariable(this, fieldBinding); return fieldBinding.type; } else { scope.tagAsAccessingEnclosingInstanceStateOf(fieldBinding.declaringClass, false /* type variable access */); } } if (isFieldUseDeprecated(fieldBinding, scope, this.bits)) scope.problemReporter().deprecatedField(fieldBinding, this); if ((this.bits & ASTNode.IsStrictlyAssigned) == 0 && TypeBinding.equalsEquals(methodScope.enclosingSourceType(), fieldBinding.original().declaringClass) && methodScope.lastVisibleFieldID >= 0 && fieldBinding.id >= methodScope.lastVisibleFieldID && (!fieldBinding.isStatic() || methodScope.isStatic)) { scope.problemReporter().forwardReference(this, 0, fieldBinding); this.bits |= ASTNode.IgnoreNoEffectAssignCheck; } return fieldBinding.type; }