org.eclipse.jdt.internal.corext.dom.Bindings Java Examples

The following examples show how to use org.eclipse.jdt.internal.corext.dom.Bindings. 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: GenerateHashCodeEqualsOperation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 7 votes vote down vote up
private Statement createAddArrayHashCode(IVariableBinding binding) {
	MethodInvocation invoc= fAst.newMethodInvocation();
	if (JavaModelUtil.is50OrHigher(fRewrite.getCu().getJavaProject())) {
		invoc.setName(fAst.newSimpleName(METHODNAME_HASH_CODE));
		invoc.setExpression(getQualifiedName(JAVA_UTIL_ARRAYS));
		invoc.arguments().add(getThisAccessForHashCode(binding.getName()));
	} else {
		invoc.setName(fAst.newSimpleName(METHODNAME_HASH_CODE));
		final IJavaElement element= fType.getJavaElement();
		if (element != null && !"".equals(element.getElementName())) //$NON-NLS-1$
			invoc.setExpression(fAst.newSimpleName(element.getElementName()));
		invoc.arguments().add(getThisAccessForHashCode(binding.getName()));
		ITypeBinding type= binding.getType().getElementType();
		if (!Bindings.isVoidType(type)) {
			if (!type.isPrimitive() || binding.getType().getDimensions() >= 2)
				type= fAst.resolveWellKnownType(JAVA_LANG_OBJECT);
			if (!fCustomHashCodeTypes.contains(type))
				fCustomHashCodeTypes.add(type);
		}
	}
	return prepareAssignment(invoc);
}
 
Example #2
Source File: InferTypeArgumentsTCModel.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public ParameterTypeVariable2 makeParameterTypeVariable(IMethodBinding methodBinding, int parameterIndex) {
	if (methodBinding == null)
		return null;
	TType type= getBoxedType(methodBinding.getParameterTypes() [parameterIndex], /*no boxing*/null);
	if (type == null)
		return null;

	ParameterTypeVariable2 cv= new ParameterTypeVariable2(type, parameterIndex, methodBinding);
	ParameterTypeVariable2 storedCv= (ParameterTypeVariable2) storedCv(cv);
	if (storedCv == cv) {
		if (methodBinding.getDeclaringClass().isLocal() || Modifier.isPrivate(methodBinding.getModifiers()))
			fCuScopedConstraintVariables.add(cv);
		makeElementVariables(storedCv, type);
		makeArrayElementVariable(storedCv);
		if (fStoreToString)
			storedCv.setData(ConstraintVariable2.TO_STRING, "[Parameter(" + parameterIndex + "," + Bindings.asString(methodBinding) + ")]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
	}
	return storedCv;
}
 
Example #3
Source File: MissingReturnTypeInLambdaCorrectionProposal.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected Expression computeProposals(AST ast, ITypeBinding returnBinding, int returnOffset, CompilationUnit root, Expression result) {
	ScopeAnalyzer analyzer= new ScopeAnalyzer(root);
	IBinding[] bindings= analyzer.getDeclarationsInScope(returnOffset, ScopeAnalyzer.VARIABLES | ScopeAnalyzer.CHECK_VISIBILITY);

	org.eclipse.jdt.core.dom.NodeFinder finder= new org.eclipse.jdt.core.dom.NodeFinder(root, returnOffset, 0);
	ASTNode varDeclFrag= ASTResolving.findAncestor(finder.getCoveringNode(), ASTNode.VARIABLE_DECLARATION_FRAGMENT);
	IVariableBinding varDeclFragBinding= null;
	if (varDeclFrag != null) {
		varDeclFragBinding= ((VariableDeclarationFragment) varDeclFrag).resolveBinding();
	}
	for (int i= 0; i < bindings.length; i++) {
		IVariableBinding curr= (IVariableBinding) bindings[i];
		ITypeBinding type= curr.getType();
		// Bindings are compared to make sure that a lambda does not return a variable which is yet to be initialised.
		if (type != null && type.isAssignmentCompatible(returnBinding) && testModifier(curr) && !Bindings.equals(curr, varDeclFragBinding)) {
			if (result == null) {
				result= ast.newSimpleName(curr.getName());
			}
			addLinkedPositionProposal(RETURN_EXPRESSION_KEY, curr.getName());
		}
	}
	return result;
}
 
Example #4
Source File: MoveInnerToTopRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean visit(final ThisExpression node) {
	Assert.isNotNull(node);
	Name name= node.getQualifier();
	if (fCreateInstanceField && name != null) {
		ITypeBinding binding= node.resolveTypeBinding();
		if (binding != null && Bindings.equals(binding, fTypeBinding.getDeclaringClass())) {
			AST ast= node.getAST();
			Expression expression= null;
			if (fCodeGenerationSettings.useKeywordThis || fEnclosingInstanceFieldName.equals(fNameForEnclosingInstanceConstructorParameter)) {
				FieldAccess access= ast.newFieldAccess();
				access.setExpression(ast.newThisExpression());
				access.setName(ast.newSimpleName(fEnclosingInstanceFieldName));
				expression= access;
			} else {
				expression= ast.newSimpleName(fEnclosingInstanceFieldName);
			}
			fSourceRewrite.getASTRewrite().replace(node, expression, null);
		}
	}
	return super.visit(node);
}
 
Example #5
Source File: NewAsyncRemoteServiceInterfaceCreationWizardPage.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
public static List<IMethodBinding> computeSyncMethodsThatNeedAsyncVersions(
    ITypeBinding syncTypeBinding, ITypeBinding asyncTypeBinding) {
  // Compute all overridable methods on the sync interface
  List<IMethodBinding> overridableSyncMethods = computeOverridableMethodsForInterface(syncTypeBinding);

  // Remove sync methods that would override existing methods in the
  // async hierarchy
  List<IMethodBinding> remainingMethods = new ArrayList<IMethodBinding>();
  for (IMethodBinding overridableSyncMethod : overridableSyncMethods) {
    IMethod syncMethod = (IMethod) overridableSyncMethod.getJavaElement();
    String[] asyncParameterTypes = RemoteServiceUtilities.computeAsyncParameterTypes(overridableSyncMethod);
    if (Bindings.findMethodInHierarchy(asyncTypeBinding,
        syncMethod.getElementName(), asyncParameterTypes) != null) {
      // Don't add method that appear in the type hierarchy
      continue;
    }

    remainingMethods.add(overridableSyncMethod);
  }

  return remainingMethods;
}
 
Example #6
Source File: ModifierCorrectionSubProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static int getNeededVisibility(ASTNode currNode, ITypeBinding targetType, IBinding binding) {
	ITypeBinding currNodeBinding= Bindings.getBindingOfParentType(currNode);
	if (currNodeBinding == null) { // import
		return Modifier.PUBLIC;
	}

	if (Bindings.isSuperType(targetType, currNodeBinding)) {
		if (binding != null && (JdtFlags.isProtected(binding) || binding.getKind() == IBinding.TYPE)) {
			return Modifier.PUBLIC;
		}
		return Modifier.PROTECTED;
	}

	if (currNodeBinding.getPackage().getKey().equals(targetType.getPackage().getKey())) {
		return 0;
	}
	return Modifier.PUBLIC;
}
 
Example #7
Source File: AsynchronousInterfaceValidator.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected List<CategorizedProblem> doValidateMethodOnDependentInterface(
    IMethodBinding methodBinding, TypeDeclaration changedInterface,
    ITypeBinding dependentInterfaceBinding) {
  String[] parameters = RemoteServiceUtilities.computeAsyncParameterTypes(methodBinding);
  String methodName = methodBinding.getName();
  if (Bindings.findMethodInHierarchy(changedInterface.resolveBinding(),
      methodName, parameters) == null) {
    CategorizedProblem problem = RemoteServiceProblemFactory.newMissingAsyncMethodOnAsync(
        methodBinding, changedInterface);
    if (problem != null) {
      return Collections.singletonList(problem);
    }
  }

  return Collections.emptyList();
}
 
Example #8
Source File: SemanticHighlightings.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean consumes(final SemanticToken token) {
	final SimpleName node= token.getNode();
	if (node.isDeclaration()) {
		return false;
	}

	final IBinding binding= token.getBinding();
	if (binding == null || binding.getKind() != IBinding.VARIABLE) {
		return false;
	}

	ITypeBinding currentType= Bindings.getBindingOfParentType(node);
	ITypeBinding declaringType= ((IVariableBinding) binding).getDeclaringClass();
	if (declaringType == null || currentType == declaringType)
		return false;

	return Bindings.isSuperType(declaringType, currentType);
}
 
Example #9
Source File: AccessAnalyzer.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private boolean considerBinding(IBinding binding, ASTNode node) {
	if (!(binding instanceof IVariableBinding)) {
		return false;
	}
	boolean result = Bindings.equals(fFieldBinding, ((IVariableBinding) binding).getVariableDeclaration());
	if (!result || fEncapsulateDeclaringClass) {
		return result;
	}

	if (binding instanceof IVariableBinding) {
		AbstractTypeDeclaration type = ASTNodes.getParent(node, AbstractTypeDeclaration.class);
		if (type != null) {
			ITypeBinding declaringType = type.resolveBinding();
			return !Bindings.equals(fDeclaringClassBinding, declaringType);
		}
	}
	return true;
}
 
Example #10
Source File: ConstructorFromSuperclassProposal.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private ITypeBinding getEnclosingInstance() {
	ITypeBinding currBinding= fTypeNode.resolveBinding();
	if (currBinding == null || Modifier.isStatic(currBinding.getModifiers())) {
		return null;
	}
	ITypeBinding superBinding= currBinding.getSuperclass();
	if (superBinding == null || superBinding.getDeclaringClass() == null || Modifier.isStatic(superBinding.getModifiers())) {
		return null;
	}
	ITypeBinding enclosing= superBinding.getDeclaringClass();

	while (currBinding != null) {
		if (Bindings.isSuperType(enclosing, currBinding)) {
			return null; // enclosing in scope
		}
		if (Modifier.isStatic(currBinding.getModifiers())) {
			return null; // no more enclosing instances
		}
		currBinding= currBinding.getDeclaringClass();
	}
	return enclosing;
}
 
Example #11
Source File: ReturnTypeSubProcessor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
public ITypeBinding getTypeBinding(AST ast) {
	boolean couldBeObject= false;
	for (int i= 0; i < fResult.size(); i++) {
		ReturnStatement node= fResult.get(i);
		Expression expr= node.getExpression();
		if (expr != null) {
			ITypeBinding binding= Bindings.normalizeTypeBinding(expr.resolveTypeBinding());
			if (binding != null) {
				return binding;
			} else {
				couldBeObject= true;
			}
		} else {
			return ast.resolveWellKnownType("void"); //$NON-NLS-1$
		}
	}
	if (couldBeObject) {
		return ast.resolveWellKnownType("java.lang.Object"); //$NON-NLS-1$
	}
	return ast.resolveWellKnownType("void"); //$NON-NLS-1$
}
 
Example #12
Source File: MoveInstanceMethodProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public final boolean visit(final QualifiedName node) {
	Assert.isNotNull(node);
	IBinding binding= node.resolveBinding();
	if (binding instanceof ITypeBinding) {
		final ITypeBinding type= (ITypeBinding) binding;
		if (type.isClass() && type.getDeclaringClass() != null) {
			final Type newType= fTargetRewrite.getImportRewrite().addImport(type, node.getAST());
			fRewrite.replace(node, newType, null);
			return false;
		}
	}
	binding= node.getQualifier().resolveBinding();
	if (Bindings.equals(fTarget, binding)) {
		fRewrite.replace(node, getFieldReference(node.getName(), fRewrite), null);
		return false;
	}
	node.getQualifier().accept(this);
	return false;
}
 
Example #13
Source File: RefactorProposalUtility.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private static boolean supportsExtractVariable(IInvocationContext context) {
	ASTNode node = context.getCoveredNode();
	if (!(node instanceof Expression)) {
		if (context.getSelectionLength() != 0) {
			return false;
		}

		node = context.getCoveringNode();
		if (!(node instanceof Expression)) {
			return false;
		}
	}

	final Expression expression = (Expression) node;
	ITypeBinding binding = expression.resolveTypeBinding();
	if (binding == null || Bindings.isVoidType(binding)) {
		return false;
	}

	return true;
}
 
Example #14
Source File: StubUtility2.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static IMethodBinding[] getDelegateCandidates(ITypeBinding binding, ITypeBinding hierarchy) {
	List<IMethodBinding> allMethods= new ArrayList<IMethodBinding>();
	boolean isInterface= binding.isInterface();
	IMethodBinding[] typeMethods= binding.getDeclaredMethods();
	for (int index= 0; index < typeMethods.length; index++) {
		final int modifiers= typeMethods[index].getModifiers();
		if (!typeMethods[index].isConstructor() && !Modifier.isStatic(modifiers) && (isInterface || Modifier.isPublic(modifiers))) {
			IMethodBinding result= Bindings.findOverriddenMethodInHierarchy(hierarchy, typeMethods[index]);
			if (result != null && Flags.isFinal(result.getModifiers()))
				continue;
			ITypeBinding[] parameterBindings= typeMethods[index].getParameterTypes();
			boolean upper= false;
			for (int offset= 0; offset < parameterBindings.length; offset++) {
				if (parameterBindings[offset].isWildcardType() && parameterBindings[offset].isUpperbound())
					upper= true;
			}
			if (!upper)
				allMethods.add(typeMethods[index]);
		}
	}
	return allMethods.toArray(new IMethodBinding[allMethods.size()]);
}
 
Example #15
Source File: OverrideIndicatorManager.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Opens and reveals the defining method.
 */
public void open() {
	CompilationUnit ast= SharedASTProvider.getAST(fJavaElement, SharedASTProvider.WAIT_ACTIVE_ONLY, null);
	if (ast != null) {
		ASTNode node= ast.findDeclaringNode(fAstNodeKey);
		if (node instanceof MethodDeclaration) {
			try {
				IMethodBinding methodBinding= ((MethodDeclaration)node).resolveBinding();
				IMethodBinding definingMethodBinding= Bindings.findOverriddenMethod(methodBinding, true);
				if (definingMethodBinding != null) {
					IJavaElement definingMethod= definingMethodBinding.getJavaElement();
					if (definingMethod != null) {
						JavaUI.openInEditor(definingMethod, true, true);
						return;
					}
				}
			} catch (CoreException e) {
				ExceptionHandler.handle(e, JavaEditorMessages.OverrideIndicatorManager_open_error_title, JavaEditorMessages.OverrideIndicatorManager_open_error_messageHasLogEntry);
				return;
			}
		}
	}
	String title= JavaEditorMessages.OverrideIndicatorManager_open_error_title;
	String message= JavaEditorMessages.OverrideIndicatorManager_open_error_message;
	MessageDialog.openError(JavaPlugin.getActiveWorkbenchShell(), title, message);
}
 
Example #16
Source File: Checks.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Checks if the new method is already used in the given type.
 * @param type
 * @param methodName
 * @param parameters
 * @return the status
 */
public static RefactoringStatus checkMethodInType(ITypeBinding type, String methodName, ITypeBinding[] parameters) {
	RefactoringStatus result= new RefactoringStatus();
	IMethodBinding method= org.eclipse.jdt.internal.corext.dom.Bindings.findMethodInType(type, methodName, parameters);
	if (method != null) {
		if (method.isConstructor()) {
			result.addWarning(Messages.format(RefactoringCoreMessages.Checks_methodName_constructor,
					new Object[] { BasicElementLabels.getJavaElementName(type.getName()) }));
		} else {
			result.addError(Messages.format(RefactoringCoreMessages.Checks_methodName_exists,
					new Object[] { BasicElementLabels.getJavaElementName(methodName), BasicElementLabels.getJavaElementName(type.getName()) }),
					JavaStatusContext.create(method));
		}
	}
	return result;
}
 
Example #17
Source File: SemanticHighlightings.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean consumes(SemanticToken token) {
	SimpleName node= token.getNode();
	if (node.isDeclaration())
		return false;

	IBinding binding= token.getBinding();
	if (binding == null || binding.getKind() != IBinding.METHOD)
		return false;

	ITypeBinding currentType= Bindings.getBindingOfParentType(node);
	ITypeBinding declaringType= ((IMethodBinding) binding).getDeclaringClass();
	if (currentType == declaringType || currentType == null)
		return false;

	return Bindings.isSuperType(declaringType, currentType);
}
 
Example #18
Source File: UnresolvedElementsSubProcessor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private static String getExpressionBaseName(Expression expr) {
	IBinding argBinding= Bindings.resolveExpressionBinding(expr, true);
	if (argBinding instanceof IVariableBinding) {
		IJavaProject project= null;
		ASTNode root= expr.getRoot();
		if (root instanceof CompilationUnit) {
			ITypeRoot typeRoot= ((CompilationUnit) root).getTypeRoot();
			if (typeRoot != null) {
				project= typeRoot.getJavaProject();
			}
		}
		return StubUtility.getBaseName((IVariableBinding)argBinding, project);
	}
	if (expr instanceof SimpleName) {
		return ((SimpleName) expr).getIdentifier();
	}
	return null;
}
 
Example #19
Source File: IntroduceParameterRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private List<String> guessTempNamesFromExpression(Expression selectedExpression, String[] excluded) {
	ITypeBinding expressionBinding= Bindings.normalizeForDeclarationUse(
		selectedExpression.resolveTypeBinding(),
		selectedExpression.getAST());
	String typeName= getQualifiedName(expressionBinding);
	if (typeName.length() == 0)
		typeName= expressionBinding.getName();
	if (typeName.length() == 0)
		return Collections.emptyList();
	int typeParamStart= typeName.indexOf("<"); //$NON-NLS-1$
	if (typeParamStart != -1)
		typeName= typeName.substring(0, typeParamStart);
	String[] proposals= StubUtility.getLocalNameSuggestions(fSourceCU.getJavaProject(), typeName, expressionBinding.getDimensions(), excluded);
	return Arrays.asList(proposals);
}
 
Example #20
Source File: NewAsyncRemoteServiceInterfaceCreationWizardPage.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * NOTE: This method comes from StubUtility2.
 */
@SuppressWarnings("deprecation")
private static IMethodBinding findOverridingMethod(IMethodBinding method,
    List<IMethodBinding> allMethods) {
  for (IMethodBinding cur : allMethods) {
    if (Bindings.areOverriddenMethods(cur, method)
        || Bindings.isSubsignature(cur, method)) {
      return cur;
    }
  }
  return null;
}
 
Example #21
Source File: MoveInstanceMethodProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public final boolean visit(final FieldAccess node) {
	Assert.isNotNull(node);
	final Expression expression= node.getExpression();
	final IVariableBinding variable= node.resolveFieldBinding();
	final AST ast= fRewrite.getAST();
	if (expression instanceof ThisExpression) {
		if (Bindings.equals(fTarget, variable)) {
			if (fAnonymousClass > 0) {
				final ThisExpression target= ast.newThisExpression();
				target.setQualifier(ast.newSimpleName(fTargetType.getElementName()));
				fRewrite.replace(node, target, null);
			} else
				fRewrite.replace(node, ast.newThisExpression(), null);
			return false;
		} else {
			expression.accept(this);
			return false;
		}
	} else if (expression instanceof FieldAccess) {
		final FieldAccess access= (FieldAccess) expression;
		final IBinding binding= access.getName().resolveBinding();
		if (access.getExpression() instanceof ThisExpression && Bindings.equals(fTarget, binding)) {
			ASTNode newFieldAccess= getFieldReference(node.getName(), fRewrite);
			fRewrite.replace(node, newFieldAccess, null);
			return false;
		}
	} else if (expression != null) {
		expression.accept(this);
		return false;
	}
	return true;
}
 
Example #22
Source File: ASTResolving.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static IMethodBinding findAnnotationMember(Annotation annotation, String name) {
	ITypeBinding annotBinding= annotation.resolveTypeBinding();
	if (annotBinding != null) {
		return Bindings.findMethodInType(annotBinding, name, (String[]) null);
	}
	return null;
}
 
Example #23
Source File: MoveInstanceMethodProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public final boolean visit(final MethodInvocation node) {
	Assert.isNotNull(node);
	final Expression expression= node.getExpression();
	final IMethodBinding binding= node.resolveMethodBinding();
	if (binding == null || !Modifier.isStatic(binding.getModifiers()) && Bindings.equals(binding, fBinding) && (expression == null || expression instanceof ThisExpression)) {
		fStatus.merge(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.MoveInstanceMethodProcessor_potentially_recursive, JavaStatusContext.create(fMethod.getCompilationUnit(), node)));
		fResult.add(node);
		return false;
	}
	return true;
}
 
Example #24
Source File: ASTResolving.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static ITypeBinding guessVariableType(List<VariableDeclarationFragment> fragments) {
	for (Iterator<VariableDeclarationFragment> iter= fragments.iterator(); iter.hasNext();) {
		VariableDeclarationFragment frag= iter.next();
		if (frag.getInitializer() != null) {
			return Bindings.normalizeTypeBinding(frag.getInitializer().resolveTypeBinding());
		}
	}
	return null;
}
 
Example #25
Source File: StubUtility2.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static IMethodBinding findOverridingMethod(IMethodBinding method, List<IMethodBinding> allMethods) {
	for (int i= 0; i < allMethods.size(); i++) {
		IMethodBinding curr= allMethods.get(i);
		if (Bindings.areOverriddenMethods(curr, method) || Bindings.isSubsignature(curr, method))
			return curr;
	}
	return null;
}
 
Example #26
Source File: NewMethodCorrectionProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private Type evaluateParameterType(AST ast, Expression elem, String key, ImportRewriteContext context) {
	ITypeBinding binding= Bindings.normalizeTypeBinding(elem.resolveTypeBinding());
	if (binding != null && binding.isWildcardType()) {
		binding= ASTResolving.normalizeWildcardType(binding, true, ast);
	}
	if (binding != null) {
		ITypeBinding[] typeProposals= ASTResolving.getRelaxingTypes(ast, binding);
		for (int i= 0; i < typeProposals.length; i++) {
			addLinkedPositionProposal(key, typeProposals[i]);
		}
		return getImportRewrite().addImport(binding, ast, context);
	}
	return ast.newSimpleType(ast.newSimpleName("Object")); //$NON-NLS-1$
}
 
Example #27
Source File: IntroduceFactoryRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @param methodName
 * @return a <code>RefactoringStatus</code> that identifies whether the
 * the name <code>newMethodName</code> is available to use as the name of
 * the new factory method within the factory-owner class (either a to-be-
 * created factory class or the constructor-owning class, depending on the
 * user options).
 */
private RefactoringStatus isUniqueMethodName(String methodName) {
	ITypeBinding declaringClass= fCtorBinding.getDeclaringClass();
	if (Bindings.findMethodInType(declaringClass, methodName, fCtorBinding.getParameterTypes()) != null) {
		String format= Messages.format(RefactoringCoreMessages.IntroduceFactory_duplicateMethodName, BasicElementLabels.getJavaElementName(methodName));
		return RefactoringStatus.createErrorStatus(format);
	}
		return new RefactoringStatus();
}
 
Example #28
Source File: StubUtility2.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static IMethodBinding findMethodBinding(IMethodBinding method, List<IMethodBinding> allMethods) {
	for (int i= 0; i < allMethods.size(); i++) {
		IMethodBinding curr= allMethods.get(i);
		if (Bindings.isSubsignature(method, curr)) {
			return curr;
		}
	}
	return null;
}
 
Example #29
Source File: CalleeAnalyzerVisitor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static IMethod findIncludingSupertypes(IMethodBinding method, IType type, IProgressMonitor pm) throws JavaModelException {
	IMethod inThisType= Bindings.findMethod(method, type);
	if (inThisType != null)
		return inThisType;
	IType[] superTypes= JavaModelUtil.getAllSuperTypes(type, pm);
	for (int i= 0; i < superTypes.length; i++) {
		IMethod m= Bindings.findMethod(method, superTypes[i]);
		if (m != null)
			return m;
	}
	return null;
}
 
Example #30
Source File: OccurrencesFinder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean addUsage(Name node, IBinding binding) {
	if (binding != null && Bindings.equals(getBindingDeclaration(binding), fTarget)) {
		int flag= 0;
		String description= fReadDescription;
		if (fTarget instanceof IVariableBinding) {
			boolean isWrite= fWriteUsages.remove(node);
			flag= isWrite ? F_WRITE_OCCURRENCE : F_READ_OCCURRENCE;
			if (isWrite)
				description= fWriteDescription;
		}
		fResult.add(new OccurrenceLocation(node.getStartPosition(), node.getLength(), flag, description));
		return true;
	}
	return false;
}