org.eclipse.jdt.core.dom.ExpressionMethodReference Java Examples
The following examples show how to use
org.eclipse.jdt.core.dom.ExpressionMethodReference.
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: CompilationUnitBuilder.java From j2cl with Apache License 2.0 | 6 votes |
/** * Converts method reference expressions of the form: * * <p> * * <pre> * q::m into (par1, ..., parN) -> q.m(par1, ..., parN) or * (let $q = q, (par1, ..., parN) -> $q.m(par1, ..., parN)) * </pre> * * <p>Depending on whether the qualifier can be evaluated inside the functional expression * preserving semantics. */ private Expression convert(ExpressionMethodReference expression) { SourcePosition sourcePosition = getSourcePosition(expression); TypeDescriptor expressionTypeDescriptor = JdtUtils.createTypeDescriptor(expression.resolveTypeBinding()); // MethodDescriptor target of the method reference. MethodDescriptor referencedMethodDescriptor = resolveMethodReferenceTarget(expression); // Functional interface method that the expression implements. MethodDescriptor functionalMethodDescriptor = JdtUtils.createMethodDescriptor( expression.resolveTypeBinding().getFunctionalInterfaceMethod()); Expression qualifier = convert(expression.getExpression()); return createMethodReferenceLambda( sourcePosition, qualifier, referencedMethodDescriptor, expressionTypeDescriptor, functionalMethodDescriptor); }
Example #2
Source File: CompilationUnitBuilder.java From j2cl with Apache License 2.0 | 6 votes |
private MethodDescriptor resolveMethodReferenceTarget(ExpressionMethodReference expression) { IMethodBinding methodBinding = expression.resolveMethodBinding(); if (methodBinding == null) { // JDT did not resolve the method binding but it was not a compilation error. This situation // seems to happen only for method references on array objects. checkArgument(expression.getExpression().resolveTypeBinding().isArray()); // Array methods are provided by java.lang.Object and are matched here by name. This is safe // because there is only a handful of method in java.lang.Object and if methods are added // in the future they will be caught be the MoreCollectors.onlyElement. Resolving the target // correctly if there were many overloads is extra complexity that can be left out until // it is really needed. String targetMethodName = expression.getName().getIdentifier(); return TypeDescriptors.get().javaLangObject.getMethodDescriptors().stream() .filter(m -> m.getName().equals(targetMethodName)) .collect(MoreCollectors.onlyElement()); } return JdtUtils.createMethodDescriptor(methodBinding); }
Example #3
Source File: ChangeSignatureProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private OccurrenceUpdate<? extends ASTNode> createOccurrenceUpdate(ASTNode node, CompilationUnitRewrite cuRewrite, RefactoringStatus result) { if (BUG_89686 && node instanceof SimpleName && node.getParent() instanceof EnumConstantDeclaration) node= node.getParent(); if (Invocations.isInvocationWithArguments(node)) return new ReferenceUpdate(node, cuRewrite, result); else if (node instanceof SimpleName && node.getParent() instanceof MethodDeclaration) return new DeclarationUpdate((MethodDeclaration) node.getParent(), cuRewrite, result); else if (node instanceof MemberRef || node instanceof MethodRef) return new DocReferenceUpdate(node, cuRewrite, result); else if (ASTNodes.getParent(node, ImportDeclaration.class) != null) return new StaticImportUpdate((ImportDeclaration) ASTNodes.getParent(node, ImportDeclaration.class), cuRewrite, result); else if (node instanceof LambdaExpression) return new LambdaExpressionUpdate((LambdaExpression) node, cuRewrite, result); else if (node.getLocationInParent() == ExpressionMethodReference.NAME_PROPERTY) return new ExpressionMethodRefUpdate((ExpressionMethodReference) node.getParent(), cuRewrite, result); else return new NullOccurrenceUpdate(node, cuRewrite, result); }
Example #4
Source File: InlineConstantRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@Override public boolean visit(Name name) { StructuralPropertyDescriptor locationInParent= name.getLocationInParent(); if (locationInParent == ExpressionMethodReference.NAME_PROPERTY || locationInParent == TypeMethodReference.NAME_PROPERTY || locationInParent == SuperMethodReference.NAME_PROPERTY) { return false; } SimpleName leftmost= getLeftmost(name); IBinding leftmostBinding= leftmost.resolveBinding(); if (leftmostBinding instanceof IVariableBinding || leftmostBinding instanceof IMethodBinding || leftmostBinding instanceof ITypeBinding) { if (shouldUnqualify(leftmost)) unqualifyMemberName(leftmost); else qualifyUnqualifiedMemberNameIfNecessary(leftmost); } if (leftmostBinding instanceof ITypeBinding) { String addedImport= fNewLocationCuRewrite.getImportRewrite().addImport((ITypeBinding)leftmostBinding, fNewLocationContext); fNewLocationCuRewrite.getImportRemover().registerAddedImport(addedImport); } return false; }
Example #5
Source File: QuickAssistProcessor.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private static boolean isTypeReferenceToInstanceMethod(MethodReference methodReference) { if (methodReference instanceof TypeMethodReference) { return true; } if (methodReference instanceof ExpressionMethodReference) { Expression expression = ((ExpressionMethodReference) methodReference).getExpression(); if (expression instanceof Name) { IBinding nameBinding = ((Name) expression).resolveBinding(); if (nameBinding != null && nameBinding instanceof ITypeBinding) { return true; } } } return false; }
Example #6
Source File: QuickAssistProcessor.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private static SimpleName getMethodInvocationName(MethodReference methodReference) { SimpleName name = null; if (methodReference instanceof ExpressionMethodReference) { name = ((ExpressionMethodReference) methodReference).getName(); } else if (methodReference instanceof TypeMethodReference) { name = ((TypeMethodReference) methodReference).getName(); } else if (methodReference instanceof SuperMethodReference) { name = ((SuperMethodReference) methodReference).getName(); } return name; }
Example #7
Source File: CompilationUnitBuilder.java From j2cl with Apache License 2.0 | 4 votes |
private Expression convert(org.eclipse.jdt.core.dom.Expression expression) { switch (expression.getNodeType()) { case ASTNode.ARRAY_ACCESS: return convert((org.eclipse.jdt.core.dom.ArrayAccess) expression); case ASTNode.ARRAY_CREATION: return convert((org.eclipse.jdt.core.dom.ArrayCreation) expression); case ASTNode.ARRAY_INITIALIZER: return convert((org.eclipse.jdt.core.dom.ArrayInitializer) expression); case ASTNode.ASSIGNMENT: return convert((org.eclipse.jdt.core.dom.Assignment) expression); case ASTNode.BOOLEAN_LITERAL: return convert((org.eclipse.jdt.core.dom.BooleanLiteral) expression); case ASTNode.CAST_EXPRESSION: return convert((org.eclipse.jdt.core.dom.CastExpression) expression); case ASTNode.CHARACTER_LITERAL: return convert((org.eclipse.jdt.core.dom.CharacterLiteral) expression); case ASTNode.CLASS_INSTANCE_CREATION: return convert((org.eclipse.jdt.core.dom.ClassInstanceCreation) expression); case ASTNode.CONDITIONAL_EXPRESSION: return convert((org.eclipse.jdt.core.dom.ConditionalExpression) expression); case ASTNode.EXPRESSION_METHOD_REFERENCE: return convert((org.eclipse.jdt.core.dom.ExpressionMethodReference) expression); case ASTNode.CREATION_REFERENCE: return convert((org.eclipse.jdt.core.dom.CreationReference) expression); case ASTNode.TYPE_METHOD_REFERENCE: return convert((org.eclipse.jdt.core.dom.TypeMethodReference) expression); case ASTNode.SUPER_METHOD_REFERENCE: return convert((org.eclipse.jdt.core.dom.SuperMethodReference) expression); case ASTNode.FIELD_ACCESS: return convert((org.eclipse.jdt.core.dom.FieldAccess) expression); case ASTNode.INFIX_EXPRESSION: return convert((org.eclipse.jdt.core.dom.InfixExpression) expression); case ASTNode.INSTANCEOF_EXPRESSION: return convert((org.eclipse.jdt.core.dom.InstanceofExpression) expression); case ASTNode.LAMBDA_EXPRESSION: return convert((org.eclipse.jdt.core.dom.LambdaExpression) expression); case ASTNode.METHOD_INVOCATION: return convert((org.eclipse.jdt.core.dom.MethodInvocation) expression); case ASTNode.NULL_LITERAL: return NullLiteral.get(); case ASTNode.NUMBER_LITERAL: return convert((org.eclipse.jdt.core.dom.NumberLiteral) expression); case ASTNode.PARENTHESIZED_EXPRESSION: return convert((org.eclipse.jdt.core.dom.ParenthesizedExpression) expression); case ASTNode.POSTFIX_EXPRESSION: return convert((org.eclipse.jdt.core.dom.PostfixExpression) expression); case ASTNode.PREFIX_EXPRESSION: return convert((org.eclipse.jdt.core.dom.PrefixExpression) expression); case ASTNode.QUALIFIED_NAME: return convert((org.eclipse.jdt.core.dom.QualifiedName) expression); case ASTNode.SIMPLE_NAME: return convert((org.eclipse.jdt.core.dom.SimpleName) expression); case ASTNode.STRING_LITERAL: return convert((org.eclipse.jdt.core.dom.StringLiteral) expression); case ASTNode.SUPER_FIELD_ACCESS: return convert((org.eclipse.jdt.core.dom.SuperFieldAccess) expression); case ASTNode.SUPER_METHOD_INVOCATION: return convert((org.eclipse.jdt.core.dom.SuperMethodInvocation) expression); case ASTNode.THIS_EXPRESSION: return convert((org.eclipse.jdt.core.dom.ThisExpression) expression); case ASTNode.TYPE_LITERAL: return convert((org.eclipse.jdt.core.dom.TypeLiteral) expression); case ASTNode.VARIABLE_DECLARATION_EXPRESSION: return convert((org.eclipse.jdt.core.dom.VariableDeclarationExpression) expression); default: throw internalCompilerError( "Unexpected type for Expression: %s", expression.getClass().getName()); } }
Example #8
Source File: CodeBlock.java From SimFix with GNU General Public License v2.0 | 4 votes |
private ExpressionMethodRef visit(ExpressionMethodReference node) { int startLine = _cunit.getLineNumber(node.getStartPosition()); int endLine = _cunit.getLineNumber(node.getStartPosition() + node.getLength()); ExpressionMethodRef expressionMethodRef = new ExpressionMethodRef(startLine, endLine, node); return expressionMethodRef; }
Example #9
Source File: ExceptionAnalyzer.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
@Override public boolean visit(ExpressionMethodReference node) { return handleMethodReference(node); }
Example #10
Source File: ChangeSignatureProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
protected ExpressionMethodRefUpdate(ExpressionMethodReference decl, CompilationUnitRewrite cuRewrite, RefactoringStatus result) { super(cuRewrite, cuRewrite.createGroupDescription(RefactoringCoreMessages.ChangeSignatureRefactoring_change_signature), result); fMethodRef= decl; }
Example #11
Source File: GenericVisitor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
@Override public void endVisit(ExpressionMethodReference node) { endVisitNode(node); }
Example #12
Source File: GenericVisitor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
@Override public boolean visit(ExpressionMethodReference node) { return visitNode(node); }
Example #13
Source File: ImportReferencesCollector.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
@Override public boolean visit(ExpressionMethodReference node) { evalQualifyingExpression(node.getExpression(), node.getName()); doVisitChildren(node.typeArguments()); return false; }