static TypeBinding getFirstParameterType(TypeDeclaration decl, CompletionProposalCollector completionProposalCollector) { TypeBinding firstParameterType = null; ASTNode node = getAssistNode(completionProposalCollector); if (node == null) return null; if (!(node instanceof CompletionOnQualifiedNameReference) && !(node instanceof CompletionOnSingleNameReference) && !(node instanceof CompletionOnMemberAccess)) return null; // Never offer on 'super.<autocomplete>'. if (node instanceof FieldReference && ((FieldReference)node).receiver instanceof SuperReference) return null; if (node instanceof NameReference) { Binding binding = ((NameReference) node).binding; // Unremark next block to allow a 'blank' autocomplete to list any extensions that apply to the current scope, but make sure we're not in a static context first, which this doesn't do. // Lacking good use cases, and having this particular concept be a little tricky on javac, means for now we don't support extension methods like this. this.X() will be fine, though. /* if ((node instanceof SingleNameReference) && (((SingleNameReference) node).token.length == 0)) { firstParameterType = decl.binding; } else */if (binding instanceof VariableBinding) { firstParameterType = ((VariableBinding) binding).type; } } else if (node instanceof FieldReference) { firstParameterType = ((FieldReference) node).actualReceiverType; } return firstParameterType; }
protected void consumeFieldAccess(boolean isSuperAccess) { // FieldAccess ::= Primary '.' 'Identifier' // FieldAccess ::= 'super' '.' 'Identifier' FieldReference fr = new FieldReference( this.identifierStack[this.identifierPtr], this.identifierPositionStack[this.identifierPtr--]); this.identifierLengthPtr--; if (isSuperAccess) { //considers the fieldReference beginning at the 'super' .... fr.sourceStart = this.intStack[this.intPtr--]; fr.receiver = new SuperReference(fr.sourceStart, this.endPosition); pushOnExpressionStack(fr); } else { //optimize push/pop fr.receiver = this.expressionStack[this.expressionPtr]; //field reference begins at the receiver fr.sourceStart = fr.receiver.sourceStart; this.expressionStack[this.expressionPtr] = fr; } }
protected void consumeMethodInvocationSuperWithTypeArguments() { // MethodInvocation ::= 'super' '.' TypeArguments 'Identifier' '(' ArgumentListopt ')' MessageSend m = newMessageSendWithTypeArguments(); this.intPtr--; // start position of the typeArguments m.sourceEnd = this.rParenPos; m.nameSourcePosition = this.identifierPositionStack[this.identifierPtr]; m.selector = this.identifierStack[this.identifierPtr--]; this.identifierLengthPtr--; // handle type arguments int length = this.genericsLengthStack[this.genericsLengthPtr--]; this.genericsPtr -= length; System.arraycopy(this.genericsStack, this.genericsPtr + 1, m.typeArguments = new TypeReference[length], 0, length); m.sourceStart = this.intStack[this.intPtr--]; // start position of the super keyword m.receiver = new SuperReference(m.sourceStart, this.endPosition); pushOnExpressionStack(m); consumeInvocationExpression(); }
protected void consumeReferenceExpressionSuperForm() { // ReferenceExpression ::= 'super' '::' NonWildTypeArgumentsopt Identifier ReferenceExpression referenceExpression = newReferenceExpression(); TypeReference [] typeArguments = null; char [] selector; int sourceEnd; sourceEnd = (int) this.identifierPositionStack[this.identifierPtr]; referenceExpression.nameSourceStart = (int) (this.identifierPositionStack[this.identifierPtr] >>> 32); selector = this.identifierStack[this.identifierPtr--]; this.identifierLengthPtr--; int length = this.genericsLengthStack[this.genericsLengthPtr--]; if (length > 0) { this.genericsPtr -= length; System.arraycopy(this.genericsStack, this.genericsPtr + 1, typeArguments = new TypeReference[length], 0, length); this.intPtr--; // pop type arguments source start. } SuperReference superReference = new SuperReference(this.intStack[this.intPtr--], this.endPosition); referenceExpression.initialize(this.compilationUnit.compilationResult, superReference, typeArguments, selector, sourceEnd); consumeReferenceExpression(referenceExpression); }
protected void consumeFieldAccess(boolean isSuperAccess) { // FieldAccess ::= Primary '.' 'Identifier' // FieldAccess ::= 'super' '.' 'Identifier' if (this.indexOfAssistIdentifier() < 0) { super.consumeFieldAccess(isSuperAccess); return; } FieldReference fieldReference = new SelectionOnFieldReference( this.identifierStack[this.identifierPtr], this.identifierPositionStack[this.identifierPtr--]); this.identifierLengthPtr--; if (isSuperAccess) { //considerates the fieldReferenceerence beginning at the 'super' .... fieldReference.sourceStart = this.intStack[this.intPtr--]; fieldReference.receiver = new SuperReference(fieldReference.sourceStart, this.endPosition); pushOnExpressionStack(fieldReference); } else { //optimize push/pop if ((fieldReference.receiver = this.expressionStack[this.expressionPtr]).isThis()) { //fieldReferenceerence begins at the this fieldReference.sourceStart = fieldReference.receiver.sourceStart; } this.expressionStack[this.expressionPtr] = fieldReference; } this.assistNode = fieldReference; this.lastCheckPoint = fieldReference.sourceEnd + 1; if (!this.diet){ this.restartRecovery = true; // force to restart in recovery mode this.lastIgnoredToken = -1; } this.isOrphanCompletionNode = true; }
/** * @see org.eclipse.jdt.internal.compiler.ASTVisitor#visit(org.eclipse.jdt.internal.compiler.ast.SuperReference, org.eclipse.jdt.internal.compiler.lookup.BlockScope) */ public boolean visit(SuperReference superReference, BlockScope scope) { final int numberOfParens = (superReference.bits & ASTNode.ParenthesizedMASK) >> ASTNode.ParenthesizedSHIFT; if (numberOfParens > 0) { manageOpeningParenthesizedExpression(superReference, numberOfParens); } this.scribe.printNextToken(TerminalTokens.TokenNamesuper); if (numberOfParens > 0) { manageClosingParenthesizedExpression(superReference, numberOfParens); } return false; }
protected void consumeMethodInvocationSuper() { // MethodInvocation ::= 'super' '.' 'Identifier' '(' ArgumentListopt ')' MessageSend m = newMessageSend(); m.sourceStart = this.intStack[this.intPtr--]; // start position of the super keyword m.sourceEnd = this.rParenPos; m.nameSourcePosition = this.identifierPositionStack[this.identifierPtr]; m.selector = this.identifierStack[this.identifierPtr--]; this.identifierLengthPtr--; m.receiver = new SuperReference(m.sourceStart, this.endPosition); pushOnExpressionStack(m); consumeInvocationExpression(); }
@Override public void endVisit(SuperReference x, BlockScope scope) { try { assert (typeMap.get(x.resolvedType) == curClass.classType.getSuperClass()); // Super refs can be modeled as a this ref. push(makeThisRef(makeSourceInfo(x))); } catch (Throwable e) { throw translateException(x, e); } }
@Override public boolean visit(SuperReference node, BlockScope scope) { fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); }
/** * Parse the block statements inside the given constructor declaration and try to complete at the * cursor location. */ public void parseBlockStatements(ConstructorDeclaration cd, CompilationUnitDeclaration unit) { //only parse the method body of cd //fill out its statements //convert bugs into parse error initialize(); // set the lastModifiers to reflect the modifiers of the constructor whose // block statements are being parsed // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=202634 this.lastModifiers = cd.modifiers; this.lastModifiersStart = cd.modifiersSourceStart; // simulate goForConstructorBody except that we don't want to balance brackets because they are not going to be balanced goForBlockStatementsopt(); this.referenceContext = cd; this.compilationUnit = unit; this.scanner.resetTo(cd.bodyStart, bodyEnd(cd)); consumeNestedMethod(); try { parse(); } catch (AbortCompilation ex) { this.lastAct = ERROR_ACTION; } if (this.lastAct == ERROR_ACTION) { cd.bits |= ASTNode.HasSyntaxErrors; return; } // attach the statements as we might be searching for a reference to a local type cd.explicitDeclarations = this.realBlockStack[this.realBlockPtr--]; int length; if ((length = this.astLengthStack[this.astLengthPtr--]) != 0) { this.astPtr -= length; if (this.astStack[this.astPtr + 1] instanceof ExplicitConstructorCall) //avoid a isSomeThing that would only be used here BUT what is faster between two alternatives ? { System.arraycopy( this.astStack, this.astPtr + 2, cd.statements = new Statement[length - 1], 0, length - 1); cd.constructorCall = (ExplicitConstructorCall) this.astStack[this.astPtr + 1]; } else { //need to add explicitly the super(); System.arraycopy( this.astStack, this.astPtr + 1, cd.statements = new Statement[length], 0, length); cd.constructorCall = SuperReference.implicitSuperConstructorCall(); } } else { cd.constructorCall = SuperReference.implicitSuperConstructorCall(); if (!containsComment(cd.bodyStart, cd.bodyEnd)) { cd.bits |= ASTNode.UndocumentedEmptyBlock; } } if (cd.constructorCall.sourceEnd == 0) { cd.constructorCall.sourceEnd = cd.sourceEnd; cd.constructorCall.sourceStart = cd.sourceStart; } }
public boolean visit(SuperReference superReference, BlockScope scope) { addRealFragment(superReference); return false; }
@Override public void endVisit(MessageSend x, BlockScope scope) { try { SourceInfo info = makeSourceInfo(x); JMethod method = typeMap.get(x.binding); List<JExpression> arguments = popCallArgs(info, x.arguments, x.binding); JExpression receiver = pop(x.receiver); if (x.receiver instanceof ThisReference) { if (method.isStatic()) { // don't bother qualifying it, it's a no-op receiver = null; } else if ((x.bits & ASTNode.DepthMASK) != 0) { // outer method can be reached through emulation if implicit access ReferenceBinding targetType = scope.enclosingSourceType().enclosingTypeAt( (x.bits & ASTNode.DepthMASK) >> ASTNode.DepthSHIFT); receiver = makeThisReference(info, targetType, true, scope); } else if (x.receiver.sourceStart == 0) { // Synthetic this ref with bad source info; fix the info. JThisRef oldRef = (JThisRef) receiver; receiver = new JThisRef(info, oldRef.getClassType()); } } JMethodCall call = new JMethodCall(info, receiver, method); // On a super ref, don't allow polymorphic dispatch. Oddly enough, // QualifiedSuperReference not derived from SuperReference! boolean isSuperRef = x.receiver instanceof SuperReference || x.receiver instanceof QualifiedSuperReference; if (isSuperRef) { call.setStaticDispatchOnly(); } // The arguments come first... call.addArgs(arguments); if (x.valueCast != null) { JType castType = typeMap.get(x.valueCast); push(maybeCast(castType, call)); } else { push(call); } } catch (Throwable e) { throw translateException(x, e); } }
@Override public boolean visit(SuperReference node, BlockScope scope) { setGeneratedBy(node, source); applyOffsetExpression(node); return super.visit(node, scope); }