if (declaringClass == null) { return null; }
	private TextEdit evaluateEdits(CompilationUnit root, ImportRewrite importRewrite, int offset, int length, IProgressMonitor monitor) throws BadLocationException, JavaModelException {		SimpleName nameNode= null;		if (root != null) { // got an AST			ASTNode node= NodeFinder.perform(root, offset, length);			if (node instanceof MarkerAnnotation) {				node= ((Annotation) node).getTypeName();			}			if (node instanceof QualifiedName) {				nameNode= ((QualifiedName) node).getName();			} else if (node instanceof SimpleName) {				nameNode= (SimpleName) node;			}		}				String name, simpleName, containerName;		int qualifierStart;		int simpleNameStart;		if (nameNode != null) {			simpleName= nameNode.getIdentifier();			simpleNameStart= nameNode.getStartPosition();			if (nameNode.getLocationInParent() == QualifiedName.NAME_PROPERTY) {				Name qualifier= ((QualifiedName) nameNode.getParent()).getQualifier();				containerName= qualifier.getFullyQualifiedName();				name= JavaModelUtil.concatenateName(containerName, simpleName);				qualifierStart= qualifier.getStartPosition();			} else if (nameNode.getParent().getLocationInParent() == QualifiedType.NAME_PROPERTY) {				Type qualifier= ((QualifiedType) nameNode.getParent().getParent()).getQualifier();				containerName= ASTNodes.asString(qualifier);				name= JavaModelUtil.concatenateName(containerName, simpleName);				qualifierStart= qualifier.getStartPosition();			} else if (nameNode.getLocationInParent() == MethodInvocation.NAME_PROPERTY) {				ASTNode qualifier= ((MethodInvocation) nameNode.getParent()).getExpression();				if (qualifier instanceof Name) {					containerName= ASTNodes.asString(qualifier);					name= JavaModelUtil.concatenateName(containerName, simpleName);					qualifierStart= qualifier.getStartPosition();				} else {					return null;				}			} else {				containerName= ""; //$NON-NLS-1$				name= simpleName;				qualifierStart= simpleNameStart;			}						IBinding binding= nameNode.resolveBinding();			if (binding != null) {				if (binding instanceof ITypeBinding) {					ITypeBinding typeBinding= (ITypeBinding) binding;					String qualifiedBindingName= typeBinding.getQualifiedName();					if (containerName.length() > 0 && !qualifiedBindingName.equals(name)) {						return null;					}										String res= importRewrite.addImport(typeBinding);					if (containerName.length() > 0 && !res.equals(simpleName)) {						// adding import failed						return null;					}					return new ReplaceEdit(qualifierStart, simpleNameStart - qualifierStart, ""); //$NON-NLS-1$				} else if (binding instanceof IVariableBinding || binding instanceof IMethodBinding) {					boolean isField= binding instanceof IVariableBinding;					ITypeBinding declaringClass= isField ? ((IVariableBinding) binding).getDeclaringClass() : ((IMethodBinding) binding).getDeclaringClass();					if (Modifier.isStatic(binding.getModifiers())) {						if (containerName.length() > 0) { 							if (containerName.equals(declaringClass.getName()) || containerName.equals(declaringClass.getQualifiedName()) ) {								String res= importRewrite.addStaticImport(declaringClass.getQualifiedName(), binding.getName(), isField);								if (!res.equals(simpleName)) {									// adding import failed									return null;								}								return new ReplaceEdit(qualifierStart, simpleNameStart - qualifierStart, ""); //$NON-NLS-1$							}						}					}					return null; // no static imports for packages				} else {					return null;				}			}					} else {			qualifierStart= getNameStart(fDocument, offset);			int nameEnd= getNameEnd(fDocument, offset + length);			int len= nameEnd - qualifierStart;						name= fDocument.get(qualifierStart, len).trim();			simpleName= Signature.getSimpleName(name);			containerName= Signature.getQualifier(name);						simpleNameStart= getSimpleNameStart(fDocument, qualifierStart, containerName);						int res= importRewrite.getDefaultImportRewriteContext().findInContext(containerName, simpleName, ImportRewriteContext.KIND_TYPE);			if (res == ImportRewriteContext.RES_NAME_CONFLICT) {				fStatus= JavaUIStatus.createError(IStatus.ERROR, CodeGenerationMessages.AddImportsOperation_error_importclash, null); 				return null;			} else if (res == ImportRewriteContext.RES_NAME_FOUND) {				return new ReplaceEdit(qualifierStart, simpleNameStart - qualifierStart, ""); //$NON-NLS-1$			}		}		IJavaSearchScope searchScope= SearchEngine.createJavaSearchScope(new IJavaElement[] { fCompilationUnit.getJavaProject() });				TypeInfo[] types= findAllTypes(simpleName, searchScope, nameNode, new SubProgressMonitor(monitor, 1));		if (types.length == 0) {			fStatus= JavaUIStatus.createError(IStatus.ERROR, Messages.format(CodeGenerationMessages.AddImportsOperation_error_notresolved_message, simpleName), null); 			return null;		}				if (monitor.isCanceled()) {			throw new OperationCanceledException();		}		TypeInfo chosen;		if (types.length > 1 && fQuery != null) {			chosen= fQuery.chooseImport(types, containerName);			if (chosen == null) {				throw new OperationCanceledException();			}		} else {			chosen= types[0];		}		importRewrite.addImport(chosen.getFullyQualifiedName());		return new ReplaceEdit(qualifierStart, simpleNameStart - qualifierStart, ""); //$NON-NLS-1$	}