Java Code Examples for org.eclipse.jdt.core.dom.Expression#resolveTypeBinding()
The following examples show how to use
org.eclipse.jdt.core.dom.Expression#resolveTypeBinding() .
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: EnhancedForLoop.java From JDeodorant with MIT License | 6 votes |
private static AbstractControlVariable generateConditionControlVariable(Expression dataStructure) { // initialize startValue VariableValue startValue = new VariableValue(0); // initialize endValue VariableValue endValue = null; ITypeBinding dataStructureBinding = dataStructure.resolveTypeBinding(); // if the dataStructure is an array or a mehtodInvocation returning and array (both covered by the first expression) OR // the data structure is a collection or the data structure is a methodInvocation returning a collection (both covered by the second expression) // These are the only cases supported by the JAVA enhanced for loop if (dataStructureBinding.isArray() || AbstractLoopUtilities.isCollection(dataStructureBinding)) { endValue = new VariableValue(VariableValue.ValueType.DATA_STRUCTURE_SIZE); } // initialize variableUpdaters List<VariableUpdater> variableUpdaters = new ArrayList<VariableUpdater>(); variableUpdaters.add(new VariableUpdater(1)); if (endValue == null) { return null; } return new AbstractControlVariable(startValue, endValue, variableUpdaters, dataStructure); }
Example 2
Source File: Checks.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * @param e * @return int * Checks.IS_RVALUE if e is an rvalue * Checks.IS_RVALUE_GUESSED if e is guessed as an rvalue * Checks.NOT_RVALUE_VOID if e is not an rvalue because its type is void * Checks.NOT_RVALUE_MISC if e is not an rvalue for some other reason */ public static int checkExpressionIsRValue(Expression e) { if (e instanceof Name) { if(!(((Name) e).resolveBinding() instanceof IVariableBinding)) { return NOT_RVALUE_MISC; } } if (e instanceof Annotation) return NOT_RVALUE_MISC; ITypeBinding tb= e.resolveTypeBinding(); boolean guessingRequired= false; if (tb == null) { guessingRequired= true; tb= ASTResolving.guessBindingForReference(e); } if (tb == null) return NOT_RVALUE_MISC; else if (tb.getName().equals("void")) //$NON-NLS-1$ return NOT_RVALUE_VOID; return guessingRequired ? IS_RVALUE_GUESSED : IS_RVALUE; }
Example 3
Source File: UnresolvedElementsSubProcessor.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
private static ITypeBinding[] getArgumentTypes(List<Expression> arguments) { ITypeBinding[] res= new ITypeBinding[arguments.size()]; for (int i= 0; i < res.length; i++) { Expression expression= arguments.get(i); ITypeBinding curr= expression.resolveTypeBinding(); if (curr == null) { return null; } if (!curr.isNullType()) { // don't normalize null type curr= Bindings.normalizeTypeBinding(curr); if (curr == null) { curr= expression.getAST().resolveWellKnownType("java.lang.Object"); //$NON-NLS-1$ } } res[i]= curr; } return res; }
Example 4
Source File: IntroduceIndirectionRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private ITypeBinding getExpressionType(MethodInvocation invocation) { Expression expression= invocation.getExpression(); ITypeBinding typeBinding= null; if (expression == null) { typeBinding= invocation.resolveMethodBinding().getDeclaringClass(); } else { typeBinding= expression.resolveTypeBinding(); } if (typeBinding != null && typeBinding.isTypeVariable()) { ITypeBinding[] typeBounds= typeBinding.getTypeBounds(); if (typeBounds.length > 0) { for (ITypeBinding typeBound : typeBounds) { ITypeBinding expressionType= getExpressionType(invocation, typeBound); if (expressionType != null) { return expressionType; } } typeBinding= typeBounds[0].getTypeDeclaration(); } else { typeBinding= invocation.getAST().resolveWellKnownType("java.lang.Object"); //$NON-NLS-1$ } } Assert.isNotNull(typeBinding, "Type binding of target expression may not be null"); //$NON-NLS-1$ return typeBinding; }
Example 5
Source File: CallContext.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public ITypeBinding getReceiverType() { Expression expression= Invocations.getExpression(invocation); if (expression != null) { return expression.resolveTypeBinding(); } IMethodBinding method= Invocations.resolveBinding(invocation); if (method != null) { return method.getDeclaringClass(); } return null; }
Example 6
Source File: RefactorProposalUtility.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
public static CUCorrectionProposal getAssignVariableProposal(CodeActionParams params, IInvocationContext context, boolean problemsAtLocation, Map formatterOptions, boolean returnAsCommand, IProblemLocationCore[] locations) throws CoreException { ASTNode node = context.getCoveringNode(); Statement statement = ASTResolving.findParentStatement(node); if (!(statement instanceof ExpressionStatement)) { return null; } ExpressionStatement expressionStatement = (ExpressionStatement) statement; Expression expression = expressionStatement.getExpression(); if (expression.getNodeType() == ASTNode.ASSIGNMENT) { return null; } ITypeBinding typeBinding = expression.resolveTypeBinding(); typeBinding = Bindings.normalizeTypeBinding(typeBinding); if (typeBinding == null) { return null; } if (containsMatchingProblem(locations, IProblem.UnusedObjectAllocation)) { return null; } final ICompilationUnit cu = context.getCompilationUnit(); int relevance; if (context.getSelectionLength() == 0) { relevance = IProposalRelevance.EXTRACT_LOCAL_ZERO_SELECTION; } else if (problemsAtLocation) { relevance = IProposalRelevance.EXTRACT_LOCAL_ERROR; } else { relevance = IProposalRelevance.EXTRACT_LOCAL; } if (returnAsCommand) { return new AssignToVariableAssistCommandProposal(cu, JavaCodeActionKind.REFACTOR_ASSIGN_VARIABLE, AssignToVariableAssistProposal.LOCAL, expressionStatement, typeBinding, relevance, APPLY_REFACTORING_COMMAND_ID, Arrays.asList(ASSIGN_VARIABLE_COMMAND, params)); } else { return new AssignToVariableAssistProposal(cu, JavaCodeActionKind.REFACTOR_ASSIGN_VARIABLE, AssignToVariableAssistProposal.LOCAL, expressionStatement, typeBinding, relevance); } }
Example 7
Source File: RefactorProposalUtility.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
public static CUCorrectionProposal getAssignFieldProposal(CodeActionParams params, IInvocationContext context, boolean problemsAtLocation, Map formatterOptions, boolean returnAsCommand, IProblemLocationCore[] locations) throws CoreException { ASTNode node = context.getCoveringNode(); Statement statement = ASTResolving.findParentStatement(node); if (!(statement instanceof ExpressionStatement)) { return null; } ExpressionStatement expressionStatement = (ExpressionStatement) statement; Expression expression = expressionStatement.getExpression(); if (expression.getNodeType() == ASTNode.ASSIGNMENT) { return null; } ITypeBinding typeBinding = expression.resolveTypeBinding(); typeBinding = Bindings.normalizeTypeBinding(typeBinding); if (typeBinding == null) { return null; } if (containsMatchingProblem(locations, IProblem.UnusedObjectAllocation)) { return null; } final ICompilationUnit cu = context.getCompilationUnit(); ASTNode type = ASTResolving.findParentType(expression); if (type != null) { int relevance; if (context.getSelectionLength() == 0) { relevance = IProposalRelevance.EXTRACT_LOCAL_ZERO_SELECTION; } else if (problemsAtLocation) { relevance = IProposalRelevance.EXTRACT_LOCAL_ERROR; } else { relevance = IProposalRelevance.EXTRACT_LOCAL; } if (returnAsCommand) { return new AssignToVariableAssistCommandProposal(cu, JavaCodeActionKind.REFACTOR_ASSIGN_FIELD, AssignToVariableAssistProposal.FIELD, expressionStatement, typeBinding, relevance, APPLY_REFACTORING_COMMAND_ID, Arrays.asList(ASSIGN_FIELD_COMMAND, params)); } else { return new AssignToVariableAssistProposal(cu, JavaCodeActionKind.REFACTOR_ASSIGN_FIELD, AssignToVariableAssistProposal.FIELD, expressionStatement, typeBinding, relevance); } } return null; }
Example 8
Source File: ExtractTempRefactoring.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private ITypeBinding guessBindingForReference(Expression expression) { ITypeBinding binding = expression.resolveTypeBinding(); if (binding == null) { binding = ASTResolving.guessBindingForReference(expression); } return binding; }
Example 9
Source File: ExtractFieldRefactoring.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private RefactoringStatus checkTempTypeForLocalTypeUsage() throws JavaModelException { Expression expression = getSelectedExpression().getAssociatedExpression(); Type resultingType = null; ITypeBinding typeBinding = expression.resolveTypeBinding(); AST ast = fCURewrite.getAST(); if (expression instanceof ClassInstanceCreation && (typeBinding == null || typeBinding.getTypeArguments().length == 0)) { resultingType = ((ClassInstanceCreation) expression).getType(); } else if (expression instanceof CastExpression) { resultingType = ((CastExpression) expression).getType(); } else { if (typeBinding == null) { typeBinding = ASTResolving.guessBindingForReference(expression); } if (typeBinding != null) { typeBinding = Bindings.normalizeForDeclarationUse(typeBinding, ast); ImportRewrite importRewrite = fCURewrite.getImportRewrite(); ImportRewriteContext context = new ContextSensitiveImportRewriteContext(expression, importRewrite); resultingType = importRewrite.addImport(typeBinding, ast, context, TypeLocation.LOCAL_VARIABLE); } else { resultingType = ast.newSimpleType(ast.newSimpleName("Object")); //$NON-NLS-1$ } } IMethodBinding declaringMethodBinding = getMethodDeclaration().resolveBinding(); ITypeBinding[] methodTypeParameters = declaringMethodBinding == null ? new ITypeBinding[0] : declaringMethodBinding.getTypeParameters(); LocalTypeAndVariableUsageAnalyzer analyzer = new LocalTypeAndVariableUsageAnalyzer(methodTypeParameters); resultingType.accept(analyzer); boolean usesLocalTypes = !analyzer.getUsageOfEnclosingNodes().isEmpty(); if (usesLocalTypes) { return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractFieldRefactoring_uses_type_declared_locally); } return null; }
Example 10
Source File: AbstractLoopUtilities.java From JDeodorant with MIT License | 5 votes |
public static boolean isLengthFieldAccess(Expression expression) { SimpleName name = null; ITypeBinding typeBinding = null; if (expression instanceof QualifiedName) { QualifiedName qualifiedName = (QualifiedName) expression; name = qualifiedName.getName(); Name qualifier = qualifiedName.getQualifier(); typeBinding = qualifier.resolveTypeBinding(); } else if (expression instanceof FieldAccess) { FieldAccess fieldAccess = (FieldAccess)expression; name = fieldAccess.getName(); Expression fieldAsccessExpression = fieldAccess.getExpression(); typeBinding = fieldAsccessExpression.resolveTypeBinding(); } if (name != null && typeBinding != null) { IBinding nameBinding = name.resolveBinding(); if (nameBinding != null && nameBinding.getKind() == IBinding.VARIABLE && typeBinding != null) { IVariableBinding nameVariableBinding = (IVariableBinding) nameBinding; return (nameVariableBinding.getName().equals("length") && typeBinding.isArray()); } } return false; }
Example 11
Source File: UnresolvedElementsSubProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static boolean useExistingParentCastProposal(ICompilationUnit cu, CastExpression expression, Expression accessExpression, SimpleName accessSelector, ITypeBinding[] paramTypes, Collection<ICommandAccess> proposals) { ITypeBinding castType= expression.getType().resolveBinding(); if (castType == null) { return false; } if (paramTypes != null) { if (Bindings.findMethodInHierarchy(castType, accessSelector.getIdentifier(), paramTypes) == null) { return false; } } else if (Bindings.findFieldInHierarchy(castType, accessSelector.getIdentifier()) == null) { return false; } ITypeBinding bindingToCast= accessExpression.resolveTypeBinding(); if (bindingToCast != null && !bindingToCast.isCastCompatible(castType)) { return false; } IMethodBinding res= Bindings.findMethodInHierarchy(castType, accessSelector.getIdentifier(), paramTypes); if (res != null) { AST ast= expression.getAST(); ASTRewrite rewrite= ASTRewrite.create(ast); CastExpression newCast= ast.newCastExpression(); newCast.setType((Type) ASTNode.copySubtree(ast, expression.getType())); newCast.setExpression((Expression) rewrite.createCopyTarget(accessExpression)); ParenthesizedExpression parents= ast.newParenthesizedExpression(); parents.setExpression(newCast); ASTNode node= rewrite.createCopyTarget(expression.getExpression()); rewrite.replace(expression, node, null); rewrite.replace(accessExpression, parents, null); String label= CorrectionMessages.UnresolvedElementsSubProcessor_missingcastbrackets_description; Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CAST); ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, cu, rewrite, IProposalRelevance.ADD_PARENTHESES_AROUND_CAST, image); proposals.add(proposal); return true; } return false; }
Example 12
Source File: StructCache.java From junion with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static Entry get(Expression type) { ITypeBinding ib = type.resolveTypeBinding(); if(ib == null) { if(type instanceof MethodInvocation) { IMethodBinding mi = ((MethodInvocation)type).resolveMethodBinding(); if(mi != null) ib = mi.getReturnType(); } } if(ib == null) { CompilerError.exec(CompilerError.TYPE_NOT_FOUND, type.toString() + ", " + type.getClass()); return null; } else return get(ib); }
Example 13
Source File: QuickAssistProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static ITypeBinding extractExpressionType(ExpressionStatement statement) { Expression expression= statement.getExpression(); if (expression.getNodeType() == ASTNode.METHOD_INVOCATION || expression.getNodeType() == ASTNode.FIELD_ACCESS) { return expression.resolveTypeBinding(); } return null; }
Example 14
Source File: QuickAssistProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static boolean getAssignToVariableProposals(IInvocationContext context, ASTNode node, IProblemLocation[] locations, Collection<ICommandAccess> resultingCollections) { Statement statement= ASTResolving.findParentStatement(node); if (!(statement instanceof ExpressionStatement)) { return false; } ExpressionStatement expressionStatement= (ExpressionStatement) statement; Expression expression= expressionStatement.getExpression(); if (expression.getNodeType() == ASTNode.ASSIGNMENT) { return false; // too confusing and not helpful } ITypeBinding typeBinding= expression.resolveTypeBinding(); typeBinding= Bindings.normalizeTypeBinding(typeBinding); if (typeBinding == null) { return false; } if (resultingCollections == null) { return true; } // don't add if already added as quick fix if (containsMatchingProblem(locations, IProblem.UnusedObjectAllocation)) return false; ICompilationUnit cu= context.getCompilationUnit(); AssignToVariableAssistProposal localProposal= new AssignToVariableAssistProposal(cu, AssignToVariableAssistProposal.LOCAL, expressionStatement, typeBinding, IProposalRelevance.ASSIGN_TO_LOCAL); localProposal.setCommandId(ASSIGN_TO_LOCAL_ID); resultingCollections.add(localProposal); ASTNode type= ASTResolving.findParentType(expression); if (type != null) { AssignToVariableAssistProposal fieldProposal= new AssignToVariableAssistProposal(cu, AssignToVariableAssistProposal.FIELD, expressionStatement, typeBinding, IProposalRelevance.ASSIGN_TO_FIELD); fieldProposal.setCommandId(ASSIGN_TO_FIELD_ID); resultingCollections.add(fieldProposal); } return true; }
Example 15
Source File: InvertBooleanUtility.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
private static boolean isBoolean(Expression expression) { ITypeBinding typeBinding = expression.resolveTypeBinding(); AST ast = expression.getAST(); return typeBinding == ast.resolveWellKnownType("boolean") //$NON-NLS-1$ || typeBinding == ast.resolveWellKnownType("java.lang.Boolean"); //$NON-NLS-1$ }
Example 16
Source File: ExtractMethodAnalyzer.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private void initReturnType(ImportRewrite rewriter) { AST ast= fEnclosingBodyDeclaration.getAST(); fReturnType= null; fReturnTypeBinding= null; switch (fReturnKind) { case ACCESS_TO_LOCAL: VariableDeclaration declaration= ASTNodes.findVariableDeclaration(fReturnValue, fEnclosingBodyDeclaration); fReturnType= ASTNodeFactory.newType(ast, declaration, rewriter, new ContextSensitiveImportRewriteContext(declaration, rewriter)); if (declaration.resolveBinding() != null) { fReturnTypeBinding= declaration.resolveBinding().getType(); } break; case EXPRESSION: Expression expression= (Expression)getFirstSelectedNode(); if (expression.getNodeType() == ASTNode.CLASS_INSTANCE_CREATION) { fExpressionBinding= ((ClassInstanceCreation)expression).getType().resolveBinding(); } else { fExpressionBinding= expression.resolveTypeBinding(); } if (fExpressionBinding != null) { if (fExpressionBinding.isNullType()) { getStatus().addFatalError(RefactoringCoreMessages.ExtractMethodAnalyzer_cannot_extract_null_type, JavaStatusContext.create(fCUnit, expression)); } else { ITypeBinding normalizedBinding= Bindings.normalizeForDeclarationUse(fExpressionBinding, ast); if (normalizedBinding != null) { ImportRewriteContext context= new ContextSensitiveImportRewriteContext(fEnclosingBodyDeclaration, rewriter); fReturnType= rewriter.addImport(normalizedBinding, ast, context); fReturnTypeBinding= normalizedBinding; } } } else { fReturnType= ast.newPrimitiveType(PrimitiveType.VOID); fReturnTypeBinding= ast.resolveWellKnownType("void"); //$NON-NLS-1$ getStatus().addError(RefactoringCoreMessages.ExtractMethodAnalyzer_cannot_determine_return_type, JavaStatusContext.create(fCUnit, expression)); } break; case RETURN_STATEMENT_VALUE: LambdaExpression enclosingLambdaExpr= ASTResolving.findEnclosingLambdaExpression(getFirstSelectedNode()); if (enclosingLambdaExpr != null) { fReturnType= ASTNodeFactory.newReturnType(enclosingLambdaExpr, ast, rewriter, null); IMethodBinding methodBinding= enclosingLambdaExpr.resolveMethodBinding(); fReturnTypeBinding= methodBinding != null ? methodBinding.getReturnType() : null; } else if (fEnclosingBodyDeclaration.getNodeType() == ASTNode.METHOD_DECLARATION) { fReturnType= ((MethodDeclaration) fEnclosingBodyDeclaration).getReturnType2(); fReturnTypeBinding= fReturnType != null ? fReturnType.resolveBinding() : null; } break; default: fReturnType= ast.newPrimitiveType(PrimitiveType.VOID); fReturnTypeBinding= ast.resolveWellKnownType("void"); //$NON-NLS-1$ } if (fReturnType == null) { fReturnType= ast.newPrimitiveType(PrimitiveType.VOID); fReturnTypeBinding= ast.resolveWellKnownType("void"); //$NON-NLS-1$ } }
Example 17
Source File: ImplementationCollector.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
private List<T> findMethodImplementations(IProgressMonitor monitor) throws CoreException { IMethod method = (IMethod) javaElement; try { if (cannotBeOverriddenMethod(method)) { return null; } } catch (JavaModelException e) { JavaLanguageServerPlugin.logException("Find method implementations failure ", e); return null; } CompilationUnit ast = CoreASTProvider.getInstance().getAST(typeRoot, CoreASTProvider.WAIT_YES, monitor); if (ast == null) { return null; } ASTNode node = NodeFinder.perform(ast, region.getOffset(), region.getLength()); ITypeBinding parentTypeBinding = null; if (node instanceof SimpleName) { ASTNode parent = node.getParent(); if (parent instanceof MethodInvocation) { Expression expression = ((MethodInvocation) parent).getExpression(); if (expression == null) { parentTypeBinding= Bindings.getBindingOfParentType(node); } else { parentTypeBinding = expression.resolveTypeBinding(); } } else if (parent instanceof SuperMethodInvocation) { // Directly go to the super method definition return Collections.singletonList(mapper.convert(method, 0, 0)); } else if (parent instanceof MethodDeclaration) { parentTypeBinding = Bindings.getBindingOfParentType(node); } } final IType receiverType = getType(parentTypeBinding); if (receiverType == null) { return null; } final List<T> results = new ArrayList<>(); try { String methodLabel = JavaElementLabelsCore.getElementLabel(method, JavaElementLabelsCore.DEFAULT_QUALIFIED); monitor.beginTask(Messages.format(JavaElementImplementationHyperlink_search_method_implementors, methodLabel), 10); SearchRequestor requestor = new SearchRequestor() { @Override public void acceptSearchMatch(SearchMatch match) throws CoreException { if (match.getAccuracy() == SearchMatch.A_ACCURATE) { Object element = match.getElement(); if (element instanceof IMethod) { IMethod methodFound = (IMethod) element; if (!JdtFlags.isAbstract(methodFound)) { T result = mapper.convert(methodFound, match.getOffset(), match.getLength()); if (result != null) { results.add(result); } } } } } }; IJavaSearchScope hierarchyScope; if (receiverType.isInterface()) { hierarchyScope = SearchEngine.createHierarchyScope(method.getDeclaringType()); } else { if (isFullHierarchyNeeded(new SubProgressMonitor(monitor, 3), method, receiverType)) { hierarchyScope = SearchEngine.createHierarchyScope(receiverType); } else { boolean isMethodAbstract = JdtFlags.isAbstract(method); hierarchyScope = SearchEngine.createStrictHierarchyScope(null, receiverType, true, isMethodAbstract, null); } } int limitTo = IJavaSearchConstants.DECLARATIONS | IJavaSearchConstants.IGNORE_DECLARING_TYPE | IJavaSearchConstants.IGNORE_RETURN_TYPE; SearchPattern pattern = SearchPattern.createPattern(method, limitTo); Assert.isNotNull(pattern); SearchParticipant[] participants = new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }; SearchEngine engine = new SearchEngine(); engine.search(pattern, participants, hierarchyScope, requestor, new SubProgressMonitor(monitor, 7)); if (monitor.isCanceled()) { throw new OperationCanceledException(); } } finally { monitor.done(); } return results; }
Example 18
Source File: ScopeAnalyzer.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private static ITypeBinding getBinding(Expression node) { if (node != null) { return node.resolveTypeBinding(); } return null; }
Example 19
Source File: ASTNodes.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Returns the type to which an inlined variable initializer should be cast, or * <code>null</code> if no cast is necessary. * * @param initializer the initializer expression of the variable to inline * @param reference the reference to the variable (which is to be inlined) * @return a type binding to which the initializer should be cast, or <code>null</code> iff no cast is necessary * @since 3.6 */ public static ITypeBinding getExplicitCast(Expression initializer, Expression reference) { ITypeBinding initializerType= initializer.resolveTypeBinding(); ITypeBinding referenceType= reference.resolveTypeBinding(); if (initializerType == null || referenceType == null) return null; if (initializerType.isPrimitive() && referenceType.isPrimitive() && ! referenceType.isEqualTo(initializerType)) { return referenceType; } else if (initializerType.isPrimitive() && ! referenceType.isPrimitive()) { // initializer is autoboxed ITypeBinding unboxedReferenceType= Bindings.getUnboxedTypeBinding(referenceType, reference.getAST()); if (!unboxedReferenceType.isEqualTo(initializerType)) return unboxedReferenceType; else if (needsExplicitBoxing(reference)) return referenceType; } else if (! initializerType.isPrimitive() && referenceType.isPrimitive()) { // initializer is autounboxed ITypeBinding unboxedInitializerType= Bindings.getUnboxedTypeBinding(initializerType, reference.getAST()); if (!unboxedInitializerType.isEqualTo(referenceType)) return referenceType; } else if (initializerType.isRawType() && referenceType.isParameterizedType()) { return referenceType; // don't lose the unchecked conversion } else if (initializer instanceof LambdaExpression || initializer instanceof MethodReference) { if (isTargetAmbiguous(reference, isExplicitlyTypedLambda(initializer))) { return referenceType; } else { ITypeBinding targetType= getTargetType(reference); if (targetType == null || targetType != referenceType) { return referenceType; } } } else if (! TypeRules.canAssign(initializerType, referenceType)) { if (!Bindings.containsTypeVariables(referenceType)) return referenceType; } return null; }
Example 20
Source File: ReturnFlowInfo.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private static int getReturnFlag(ReturnStatement node) { Expression expression= node.getExpression(); if (expression == null || expression.resolveTypeBinding() == node.getAST().resolveWellKnownType("void")) //$NON-NLS-1$ return VOID_RETURN; return VALUE_RETURN; }