Java 类org.eclipse.jdt.internal.compiler.ast.LambdaExpression 实例源码
项目:Eclipse-Postfix-Code-Completion
文件:RecoveredBlock.java
public RecoveredElement add(Statement stmt, int bracketBalanceValue, boolean delegatedByParent) {
if (stmt instanceof LambdaExpression) // lambdas are recovered up to the containing statement anyways.
return this;
resetPendingModifiers();
/* do not consider a nested block starting passed the block end (if set)
it must be belonging to an enclosing block */
if (this.blockDeclaration.sourceEnd != 0
&& stmt.sourceStart > this.blockDeclaration.sourceEnd){
if (delegatedByParent) return this; //ignore
return this.parent.add(stmt, bracketBalanceValue);
}
RecoveredStatement element = new RecoveredStatement(stmt, this, bracketBalanceValue);
attach(element);
if (stmt.sourceEnd == 0) return element;
return this;
}
项目:Eclipse-Postfix-Code-Completion
文件:ProblemReporter.java
public void missingTypeInLambda(LambdaExpression lambda, MethodBinding method) {
int nameSourceStart = lambda.sourceStart();
int nameSourceEnd = lambda.diagnosticsSourceEnd();
List missingTypes = method.collectMissingTypes(null);
if (missingTypes == null) {
System.err.println("The lambda expression " + method + " is wrongly tagged as containing missing types"); //$NON-NLS-1$ //$NON-NLS-2$
return;
}
TypeBinding missingType = (TypeBinding) missingTypes.get(0);
this.handle(
IProblem.MissingTypeInLambda,
new String[] {
new String(missingType.readableName()),
},
new String[] {
new String(missingType.shortReadableName()),
},
nameSourceStart,
nameSourceEnd);
}
项目:Eclipse-Postfix-Code-Completion
文件:InferenceContext18.java
/**
* 18.5.3 Functional Interface Parameterization Inference
*/
public ReferenceBinding inferFunctionalInterfaceParameterization(LambdaExpression lambda, BlockScope blockScope,
ParameterizedTypeBinding targetTypeWithWildCards)
{
TypeBinding[] q = createBoundsForFunctionalInterfaceParameterizationInference(targetTypeWithWildCards);
if (q == null || q.length != lambda.arguments().length) {
// fail TODO: can this still happen here?
} else {
if (reduceWithEqualityConstraints(lambda.argumentTypes(), q)) {
ReferenceBinding genericType = targetTypeWithWildCards.genericType();
TypeBinding[] a = targetTypeWithWildCards.arguments; // a is not-null by construction of parameterizedWithWildcard()
TypeBinding[] aprime = getFunctionInterfaceArgumentSolutions(a);
// TODO If F<A'1, ..., A'm> is a well-formed type, ...
return blockScope.environment().createParameterizedType(genericType, aprime, genericType.enclosingType());
}
}
return targetTypeWithWildCards;
}
项目:Eclipse-Postfix-Code-Completion
文件:CodeStream.java
public void reset(LambdaExpression lambda, ClassFile targetClassFile) {
init(targetClassFile);
this.lambdaExpression = lambda;
this.methodDeclaration = null;
int[] lineSeparatorPositions2 = this.lineSeparatorPositions;
if (lineSeparatorPositions2 != null) {
int length = lineSeparatorPositions2.length;
int lineSeparatorPositionsEnd = length - 1;
int start = Util.getLineNumber(lambda.body().sourceStart, lineSeparatorPositions2, 0, lineSeparatorPositionsEnd);
this.lineNumberStart = start;
if (start > lineSeparatorPositionsEnd) {
this.lineNumberEnd = start;
} else {
int end = Util.getLineNumber(lambda.body().sourceEnd, lineSeparatorPositions2, start - 1, lineSeparatorPositionsEnd);
if (end >= lineSeparatorPositionsEnd) {
end = length;
}
this.lineNumberEnd = end == 0 ? 1 : end;
}
}
this.preserveUnusedLocals = lambda.scope.compilerOptions().preserveAllLocalVariables;
initializeMaxLocals(lambda.binding);
}
项目:che
文件:HandleFactory.java
/** Returns a handle denoting the lambda type identified by its scope. */
public IJavaElement createLambdaTypeElement(
LambdaExpression expression,
ICompilationUnit unit,
HashSet existingElements,
HashMap knownScopes) {
return createElement(
expression.scope, expression.sourceStart(), unit, existingElements, knownScopes)
.getParent();
}
项目:Eclipse-Postfix-Code-Completion
文件:SelectionParser.java
@Override
protected void consumeLambdaExpression() {
super.consumeLambdaExpression();
LambdaExpression expression = (LambdaExpression) this.expressionStack[this.expressionPtr];
int arrowEnd = expression.arrowPosition();
int arrowStart = arrowEnd - 1;
if (this.selectionStart == arrowStart || this.selectionStart == arrowEnd) {
if (this.selectionEnd == arrowStart || this.selectionEnd == arrowEnd) {
this.expressionStack[this.expressionPtr] = new SelectionOnLambdaExpression(expression);
}
}
}
项目:Eclipse-Postfix-Code-Completion
文件:SelectionOnLambdaExpression.java
public SelectionOnLambdaExpression(LambdaExpression expression) {
// Where is object derivation when I need it ???
super(expression.compilationResult(), true);
// copy all state created by the parser.
this.sourceStart = expression.sourceStart;
this.sourceEnd = expression.sourceEnd;
this.hasParentheses = expression.hasParentheses;
this.statementEnd = expression.statementEnd;
this.setBody(expression.body());
this.setArguments(expression.arguments());
this.setArrowPosition(expression.arrowPosition());
}
项目:Eclipse-Postfix-Code-Completion
文件:CodeFormatterVisitor.java
/**
* @see org.eclipse.jdt.internal.compiler.ASTVisitor#visit(org.eclipse.jdt.internal.compiler.ast.LambdaExpression, org.eclipse.jdt.internal.compiler.lookup.BlockScope)
*/
public boolean visit(LambdaExpression lambdaExpression, BlockScope scope) {
final int numberOfParens = (lambdaExpression.bits & ASTNode.ParenthesizedMASK) >> ASTNode.ParenthesizedSHIFT;
if (numberOfParens > 0) {
manageOpeningParenthesizedExpression(lambdaExpression, numberOfParens);
}
if (isNextToken(TerminalTokens.TokenNameLPAREN)) {
// Format arguments
formatMethodArguments(
null,
lambdaExpression.arguments(),
lambdaExpression.getScope(),
this.preferences.insert_space_before_opening_paren_in_method_declaration,
this.preferences.insert_space_between_empty_parens_in_method_declaration,
this.preferences.insert_space_before_closing_paren_in_method_declaration,
this.preferences.insert_space_after_opening_paren_in_method_declaration,
this.preferences.insert_space_before_comma_in_method_declaration_parameters,
this.preferences.insert_space_after_comma_in_method_declaration_parameters,
this.preferences.alignment_for_parameters_in_method_declaration);
} else {
// This MUST be a single, untyped parameter
this.scribe.printNextToken(TerminalTokens.TokenNameIdentifier);
}
if (this.preferences.insert_space_before_lambda_arrow) this.scribe.space();
this.scribe.printNextToken(TerminalTokens.TokenNameARROW);
if (this.preferences.insert_space_after_lambda_arrow) this.scribe.space();
final Statement body = lambdaExpression.body();
if (body instanceof Block) {
formatBlock((Block) body, scope, this.preferences.brace_position_for_lambda_body, this.preferences.insert_space_before_opening_brace_in_block);
} else {
body.traverse(this, scope);
}
if (numberOfParens > 0) {
manageClosingParenthesizedExpression(lambdaExpression, numberOfParens);
}
return false;
}
项目:Eclipse-Postfix-Code-Completion
文件:OrLocator.java
public int match(LambdaExpression node, MatchingNodeSet nodeSet) {
int level = IMPOSSIBLE_MATCH;
for (int i = 0, length = this.patternLocators.length; i < length; i++) {
int newLevel = this.patternLocators[i].match(node, nodeSet);
if (newLevel > level) {
if (newLevel == ACCURATE_MATCH) return ACCURATE_MATCH;
level = newLevel;
}
}
return level;
}
项目:Eclipse-Postfix-Code-Completion
文件:AndLocator.java
public int match(LambdaExpression node, MatchingNodeSet nodeSet) {
int level = IMPOSSIBLE_MATCH;
for (int i = 0, length = this.patternLocators.length; i < length; i++) {
int newLevel = this.patternLocators[i].match(node, nodeSet);
if (newLevel > level) {
if (newLevel == ACCURATE_MATCH) return ACCURATE_MATCH;
level = newLevel;
}
}
return level;
}
项目:Eclipse-Postfix-Code-Completion
文件:SelectionRequestor.java
protected IJavaElement findLocalElement(int pos, MethodScope scope) {
if (scope != null && scope.isLambdaScope()) {
IJavaElement parent = findLocalElement(pos, scope.enclosingMethodScope());
LambdaExpression expression = (LambdaExpression) scope.originalReferenceContext();
if (expression != null && expression.resolvedType != null && expression.resolvedType.isValidBinding()) {
org.eclipse.jdt.internal.core.LambdaExpression lambdaElement = LambdaFactory.createLambdaExpression((JavaElement) parent, expression);
return lambdaElement.getMethod();
}
return parent;
}
return findLocalElement(pos);
}
项目:Eclipse-Postfix-Code-Completion
文件:Parser.java
protected void consumeNestedLambda() {
// NestedLambda ::= $empty - we get here just after the type+parenthesis elided singleton parameter or just before the '(' of the parameter list.
consumeNestedType();
this.nestedMethod[this.nestedType] ++;
LambdaExpression lambda = new LambdaExpression(this.compilationUnit.compilationResult, isAssistParser());
pushOnAstStack(lambda);
this.processingLambdaParameterList = true;
}
项目:Eclipse-Postfix-Code-Completion
文件:Parser.java
protected void consumeLambdaHeader() {
// LambdaHeader ::= LambdaParameters '->' Synthetic/fake production with a synthetic non-terminal. Body not seen yet.
int arrowPosition = this.scanner.currentPosition - 1;
Argument [] arguments = null;
int length = this.astLengthStack[this.astLengthPtr--];
this.astPtr -= length;
//arguments
if (length != 0) {
System.arraycopy(
this.astStack,
this.astPtr + 1,
arguments = new Argument[length],
0,
length);
}
for (int i = 0; i < length; i++) {
final Argument argument = arguments[i];
if (argument.isReceiver()) {
problemReporter().illegalThis(argument);
}
if (argument.name.length == 1 && argument.name[0] == '_')
problemReporter().illegalUseOfUnderscoreAsAnIdentifier(argument.sourceStart, argument.sourceEnd, true); // true == lambdaParameter
}
LambdaExpression lexp = (LambdaExpression) this.astStack[this.astPtr];
lexp.setArguments(arguments);
lexp.setArrowPosition(arrowPosition);
lexp.sourceEnd = this.intStack[this.intPtr--]; // ')' position or identifier position.
lexp.sourceStart = this.intStack[this.intPtr--]; // '(' position or identifier position.
lexp.hasParentheses = (this.scanner.getSource()[lexp.sourceStart] == '(');
this.listLength -= arguments == null ? 0 : arguments.length; // not necessary really.
this.processingLambdaParameterList = false;
if (this.currentElement != null) {
this.lastCheckPoint = arrowPosition + 1; // we don't want the typed formal parameters to be processed by recovery.
}
}
项目:Eclipse-Postfix-Code-Completion
文件:ProblemReporter.java
public void bytecodeExceeds64KLimit(LambdaExpression location) {
MethodBinding method = location.binding;
this.handle(
IProblem.BytecodeExceeds64KLimit,
new String[] {new String(method.selector), typesAsString(method, false)},
new String[] {new String(method.selector), typesAsString(method, true)},
ProblemSeverities.Error | ProblemSeverities.Abort | ProblemSeverities.Fatal,
location.sourceStart,
location.diagnosticsSourceEnd());
}
项目:Eclipse-Postfix-Code-Completion
文件:ProblemReporter.java
public void lambdaSignatureMismatched(LambdaExpression target) {
this.handle(
IProblem.lambdaSignatureMismatched,
new String[] { new String(target.descriptor.readableName()) },
new String[] { new String(target.descriptor.shortReadableName()) },
target.sourceStart,
target.diagnosticsSourceEnd());
}
项目:Eclipse-Postfix-Code-Completion
文件:ProblemReporter.java
public void lambdaExpressionCannotImplementGenericMethod(LambdaExpression lambda, MethodBinding sam) {
final String selector = new String(sam.selector);
this.handle(
IProblem.NoGenericLambda,
new String[] { selector, new String(sam.declaringClass.readableName())},
new String[] { selector, new String(sam.declaringClass.shortReadableName())},
lambda.sourceStart,
lambda.diagnosticsSourceEnd());
}
项目:Eclipse-Postfix-Code-Completion
文件:ProblemReporter.java
public void lambdaExpressionsNotBelow18(LambdaExpression lexp) {
this.handle(
IProblem.LambdaExpressionNotBelow18,
NoArgument,
NoArgument,
lexp.sourceStart,
lexp.diagnosticsSourceEnd());
}
项目:Eclipse-Postfix-Code-Completion
文件:ProblemReporter.java
public void shouldReturn(TypeBinding returnType, ASTNode location) {
int sourceStart = location.sourceStart;
int sourceEnd = location.sourceEnd;
if (location instanceof LambdaExpression) {
LambdaExpression exp = (LambdaExpression) location;
sourceStart = exp.sourceStart;
sourceEnd = exp.diagnosticsSourceEnd();
}
this.handle(
methodHasMissingSwitchDefault() ? IProblem.ShouldReturnValueHintMissingDefault : IProblem.ShouldReturnValue,
new String[] { new String (returnType.readableName())},
new String[] { new String (returnType.shortReadableName())},
sourceStart,
sourceEnd);
}
项目:Eclipse-Postfix-Code-Completion
文件:ProblemReporter.java
public void lambdaShapeComputationError(LambdaExpression expression) {
this.handle(
IProblem.LambdaShapeComputationError,
NoArgument,
NoArgument,
expression.sourceStart,
expression.diagnosticsSourceEnd());
}
项目:Eclipse-Postfix-Code-Completion
文件:InferenceContext18.java
public SuspendedInferenceRecord enterLambda(LambdaExpression lambda) {
SuspendedInferenceRecord record = new SuspendedInferenceRecord(this.currentInvocation, this.invocationArguments, this.inferenceVariables, this.inferenceKind);
this.inferenceVariables = null;
this.invocationArguments = null;
this.currentInvocation = null;
return record;
}
项目:Eclipse-Postfix-Code-Completion
文件:SourceTypeBinding.java
public SyntheticMethodBinding addSyntheticMethod(LambdaExpression lambda) {
if (!isPrototype()) throw new IllegalStateException();
if (this.synthetics == null)
this.synthetics = new HashMap[MAX_SYNTHETICS];
if (this.synthetics[SourceTypeBinding.METHOD_EMUL] == null)
this.synthetics[SourceTypeBinding.METHOD_EMUL] = new HashMap(5);
SyntheticMethodBinding lambdaMethod = null;
SyntheticMethodBinding[] lambdaMethods = (SyntheticMethodBinding[]) this.synthetics[SourceTypeBinding.METHOD_EMUL].get(lambda);
if (lambdaMethods == null) {
lambdaMethod = new SyntheticMethodBinding(lambda, CharOperation.concat(TypeConstants.ANONYMOUS_METHOD, Integer.toString(this.lambdaOrdinal++).toCharArray()), this);
this.synthetics[SourceTypeBinding.METHOD_EMUL].put(lambda, lambdaMethods = new SyntheticMethodBinding[1]);
lambdaMethods[0] = lambdaMethod;
} else {
lambdaMethod = lambdaMethods[0];
}
// Create a $deserializeLambda$ method if necessary, one is shared amongst all lambdas
if (lambda.isSerializable) {
SyntheticMethodBinding[] deserializeLambdaMethods = (SyntheticMethodBinding[]) this.synthetics[SourceTypeBinding.METHOD_EMUL].get(TypeConstants.DESERIALIZE_LAMBDA);
if (deserializeLambdaMethods == null) {
SyntheticMethodBinding deserializeLambdaMethod = new SyntheticMethodBinding(this);
this.synthetics[SourceTypeBinding.METHOD_EMUL].put(TypeConstants.DESERIALIZE_LAMBDA,deserializeLambdaMethods = new SyntheticMethodBinding[1]);
deserializeLambdaMethods[0] = deserializeLambdaMethod;
}
}
return lambdaMethod;
}
项目:Eclipse-Postfix-Code-Completion
文件:ConstraintExpressionFormula.java
public ReferenceBinding findGroundTargetType(InferenceContext18 inferenceContext, BlockScope scope,
LambdaExpression lambda, ParameterizedTypeBinding targetTypeWithWildCards)
{
if (lambda.argumentsTypeElided()) {
return lambda.findGroundTargetTypeForElidedLambda(scope, targetTypeWithWildCards);
} else {
SuspendedInferenceRecord previous = inferenceContext.enterLambda(lambda);
try {
return inferenceContext.inferFunctionalInterfaceParameterization(lambda, scope, targetTypeWithWildCards);
} finally {
inferenceContext.resumeSuspendedInference(previous);
}
}
}
项目:Eclipse-Postfix-Code-Completion
文件:SyntheticMethodBinding.java
public SyntheticMethodBinding(LambdaExpression lambda, char [] lambdaName, SourceTypeBinding declaringClass) {
this.lambda = lambda;
this.declaringClass = declaringClass;
this.selector = lambdaName;
this.modifiers = lambda.binding.modifiers;
this.tagBits |= (TagBits.AnnotationResolved | TagBits.DeprecatedAnnotationResolved) | (lambda.binding.tagBits & TagBits.HasParameterAnnotations);
this.returnType = lambda.binding.returnType;
this.parameters = lambda.binding.parameters;
this.thrownExceptions = lambda.binding.thrownExceptions;
this.purpose = SyntheticMethodBinding.LambdaMethod;
SyntheticMethodBinding[] knownAccessMethods = declaringClass.syntheticMethods();
int methodId = knownAccessMethods == null ? 0 : knownAccessMethods.length;
this.index = methodId;
}
项目:Eclipse-Postfix-Code-Completion
文件:InternalExtendedCompletionContext.java
private void computeVisibleElementBindings() {
CompilationUnitDeclaration previousUnitBeingCompleted = this.lookupEnvironment.unitBeingCompleted;
this.lookupEnvironment.unitBeingCompleted = this.compilationUnitDeclaration;
try {
this.hasComputedVisibleElementBindings = true;
Scope scope = this.assistScope;
ASTNode astNode = this.assistNode;
boolean notInJavadoc = this.completionContext.javadoc == 0;
this.visibleLocalVariables = new ObjectVector();
this.visibleFields = new ObjectVector();
this.visibleMethods = new ObjectVector();
ReferenceContext referenceContext = scope.referenceContext();
if (referenceContext instanceof AbstractMethodDeclaration || referenceContext instanceof LambdaExpression) {
// completion is inside a method body
searchVisibleVariablesAndMethods(scope, this.visibleLocalVariables, this.visibleFields, this.visibleMethods, notInJavadoc);
} else if (referenceContext instanceof TypeDeclaration) {
TypeDeclaration typeDeclaration = (TypeDeclaration) referenceContext;
FieldDeclaration[] fields = typeDeclaration.fields;
if (fields != null) {
done : for (int i = 0; i < fields.length; i++) {
if (fields[i] instanceof Initializer) {
Initializer initializer = (Initializer) fields[i];
if (initializer.block.sourceStart <= astNode.sourceStart &&
astNode.sourceStart < initializer.bodyEnd) {
// completion is inside an initializer
searchVisibleVariablesAndMethods(scope, this.visibleLocalVariables, this.visibleFields, this.visibleMethods, notInJavadoc);
break done;
}
} else {
FieldDeclaration fieldDeclaration = fields[i];
if (fieldDeclaration.initialization != null && fieldDeclaration.binding != null) {
boolean isInsideInitializer = false;
if (fieldDeclaration.initialization.sourceEnd > 0) {
if (fieldDeclaration.initialization.sourceStart <= astNode.sourceStart &&
astNode.sourceEnd <= fieldDeclaration.initialization.sourceEnd) {
// completion is inside a field initializer
isInsideInitializer = true;
}
} else { // The sourceEnd may not yet be set
CompletionNodeDetector detector = new CompletionNodeDetector(this.assistNode, fieldDeclaration.initialization);
if (detector.containsCompletionNode()) {
// completion is inside a field initializer
isInsideInitializer = true;
}
}
if (isInsideInitializer) {
searchVisibleVariablesAndMethods(scope, this.visibleLocalVariables, this.visibleFields, this.visibleMethods, notInJavadoc);
// remove this field from visibleFields list because completion is being asked in its
// intialization and so this has not yet been declared successfully.
if (this.visibleFields.size > 0 && this.visibleFields.contains(fieldDeclaration.binding)) {
this.visibleFields.remove(fieldDeclaration.binding);
}
int count = 0;
while (count < this.visibleFields.size) {
FieldBinding visibleField = (FieldBinding)this.visibleFields.elementAt(count);
if (visibleField.id > fieldDeclaration.binding.id) {
this.visibleFields.remove(visibleField);
continue;
}
count++;
}
break done;
}
}
}
}
}
}
} finally {
this.lookupEnvironment.unitBeingCompleted = previousUnitBeingCompleted;
}
}
项目: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;
}
项目:Eclipse-Postfix-Code-Completion
文件:AssistParser.java
@Override
protected void consumeNestedLambda() {
super.consumeNestedLambda();
LambdaExpression lexp = (LambdaExpression) this.astStack[this.astPtr];
pushOnElementStack(K_LAMBDA_EXPRESSION_DELIMITER, EXPRESSION_BODY, lexp);
}
项目:Eclipse-Postfix-Code-Completion
文件:HandleFactory.java
/**
* Returns a handle denoting the lambda type identified by its scope.
*/
public IJavaElement createLambdaTypeElement(LambdaExpression expression, ICompilationUnit unit, HashSet existingElements, HashMap knownScopes) {
return createElement(expression.scope, expression.sourceStart(), unit, existingElements, knownScopes).getParent();
}
项目:Eclipse-Postfix-Code-Completion
文件:FlowContext.java
/**
* Answer the parent flow context but be careful not to cross the boundary of a nested type,
* or null if no such parent exists.
*/
public FlowContext getLocalParent() {
if (this.associatedNode instanceof AbstractMethodDeclaration || this.associatedNode instanceof TypeDeclaration || this.associatedNode instanceof LambdaExpression)
return null;
return this.parent;
}
项目:Eclipse-Postfix-Code-Completion
文件:InferenceContext18.java
private boolean checkExpression(Expression expri, TypeBinding[] u, TypeBinding r1, TypeBinding[] v, TypeBinding r2)
throws InferenceFailureException {
if (expri instanceof LambdaExpression && !((LambdaExpression)expri).argumentsTypeElided()) {
if (r2.id == TypeIds.T_void)
return true;
LambdaExpression lambda = (LambdaExpression) expri;
Expression[] results = lambda.resultExpressions();
if (r1.isFunctionalInterface(this.scope) && r2.isFunctionalInterface(this.scope)
&& !(r1.isCompatibleWith(r2) || r2.isCompatibleWith(r1))) {
// "these rules are applied recursively to R1 and R2, for each result expression in expi."
// (what does "applied .. to R1 and R2" mean? Why mention R1/R2 and not U/V?)
for (int i = 0; i < results.length; i++) {
if (!checkExpression(results[i], u, r1, v, r2))
return false;
}
return true;
}
checkPrimitive1: if (r1.isPrimitiveType() && !r2.isPrimitiveType()) {
// check: each result expression is a standalone expression of a primitive type
for (int i = 0; i < results.length; i++) {
if (results[i].isPolyExpression() || (results[i].resolvedType != null && !results[i].resolvedType.isPrimitiveType()))
break checkPrimitive1;
}
return true;
}
checkPrimitive2: if (r2.isPrimitiveType() && !r1.isPrimitiveType()) {
for (int i = 0; i < results.length; i++) {
// for all expressions (not for any expression not)
if (!(
(!results[i].isPolyExpression() && (results[i].resolvedType != null && !results[i].resolvedType.isPrimitiveType())) // standalone of a referencetype
|| results[i].isPolyExpression())) // or a poly
break checkPrimitive2;
}
return true;
}
return reduceAndIncorporate(ConstraintTypeFormula.create(r1, r2, ReductionResult.SUBTYPE));
} else if (expri instanceof ReferenceExpression && ((ReferenceExpression)expri).isExactMethodReference()) {
for (int i = 0; i < u.length; i++) {
ReferenceExpression reference = (ReferenceExpression) expri;
if (!reduceAndIncorporate(ConstraintTypeFormula.create(u[i], v[i], ReductionResult.SAME)))
return false;
if (r2.id == TypeIds.T_void)
return true;
MethodBinding method = reference.findCompileTimeMethodTargeting(null, this.scope); // TODO directly access exactMethodBinding!
TypeBinding returnType = method.isConstructor() ? method.declaringClass : method.returnType;
if (r1.isPrimitiveType() && !r2.isPrimitiveType() && returnType.isPrimitiveType())
return true;
if (r2.isPrimitiveType() && !r1.isPrimitiveType() && !returnType.isPrimitiveType())
return true;
}
return reduceAndIncorporate(ConstraintTypeFormula.create(r1, r2, ReductionResult.SUBTYPE));
} else if (expri instanceof ConditionalExpression) {
ConditionalExpression cond = (ConditionalExpression) expri;
return checkExpression(cond.valueIfTrue, u, r1, v, r2) && checkExpression(cond.valueIfFalse, u, r1, v, r2);
} else {
return false;
}
}
项目:Eclipse-Postfix-Code-Completion
文件:PolyTypeBinding.java
public char[] shortReadableName() {
return this.expression instanceof LambdaExpression ?
((LambdaExpression) this.expression).printExpression(0, new StringBuffer(), true).toString().toCharArray() : readableName();
}
项目:Eclipse-Postfix-Code-Completion
文件:MethodBinding.java
public LambdaExpression sourceLambda() {
return null;
}
项目:Eclipse-Postfix-Code-Completion
文件:SyntheticMethodBinding.java
public LambdaExpression sourceLambda() {
return this.lambda;
}