String addedCUName= typeName + ".java"; if (!JavaConventions.validateCompilationUnitName(addedCUName).matches(IStatus.ERROR)) { IPackageFragment pack= (IPackageFragment) cu.getParent(); final ICompilationUnit addedCU= pack.getCompilationUnit(addedCUName); if (!addedCU.exists()) { if ((kind & SimilarElementsRequestor.CLASSES) != 0) { String label= CorrectionMessages.getFormattedString("UnresolvedElementsSubProcessor.createclassusingwizard.description", typeName); proposals.add(new NewCUCompletionUsingWizardProposal(label, typeName, cu, true, problemPos, 0)); } if ((kind & SimilarElementsRequestor.INTERFACES) != 0) { String label= CorrectionMessages.getFormattedString("UnresolvedElementsSubProcessor.createinterfaceusingwizard.description", typeName); proposals.add(new NewCUCompletionUsingWizardProposal(label, typeName, cu, false, problemPos, 0)); } } }
addNewTypeProposals(typeName, problemPos, kind, proposals);
	public static void getTypeProposals(ProblemPosition problemPos, int kind, ArrayList proposals) throws CoreException {				ICompilationUnit cu= problemPos.getCompilationUnit();				// corrections		String typeName= cu.getBuffer().getText(problemPos.getOffset(), problemPos.getLength());		int bracketIndex= typeName.indexOf('[');		if (bracketIndex != -1) {			typeName= typeName.substring(0, bracketIndex);		}				CodeGenerationSettings settings= JavaPreferencesSettings.getCodeGenerationSettings();				SimilarElement[] elements= SimilarElementsRequestor.findSimilarElement(cu, problemPos.getOffset(), typeName, kind);		for (int i= 0; i < elements.length; i++) {			String curr= elements[i].getName();			String simpleName= Signature.getSimpleName(curr);						String replaceName= simpleName;						ImportEdit importEdit= new ImportEdit(cu, settings);									IImportDeclaration existingImport= JavaModelUtil.findImport(cu, simpleName);			if (existingImport != null) {				if (!existingImport.getElementName().equals(curr)) {					// import for otehr type already exists -> use qualified					replaceName= curr;				}			} else {				importEdit.addImport(curr);			}									replaceName= importEdit.addImport(curr);									boolean importOnly= replaceName.equals(typeName);						CUCorrectionProposal proposal= new CUCorrectionProposal("", cu, 0); //$NON-NLS-1$			proposals.add(proposal);						TextEdit root= proposal.getRootTextEdit();						if (!importEdit.isEmpty()) {				root.add(importEdit); //$NON-NLS-1$			}			if (!importOnly) {				root.add(SimpleTextEdit.createReplace(problemPos.getOffset(), typeName.length(), replaceName)); //$NON-NLS-1$				proposal.setDisplayName(CorrectionMessages.getFormattedString("UnresolvedElementsSubProcessor.changetype.description", replaceName)); //$NON-NLS-1$				proposal.setRelevance(3);			} else {				proposal.setImage(JavaPluginImages.get(JavaPluginImages.IMG_OBJS_IMPDECL));				proposal.setDisplayName(CorrectionMessages.getFormattedString("UnresolvedElementsSubProcessor.importtype.description", curr)); //$NON-NLS-1$				proposal.setRelevance(5);			}		}				// add type		String addedCUName= typeName + ".java"; //$NON-NLS-1$		if (!JavaConventions.validateCompilationUnitName(addedCUName).matches(IStatus.ERROR)) {			IPackageFragment pack= (IPackageFragment) cu.getParent();			final ICompilationUnit addedCU= pack.getCompilationUnit(addedCUName);			if (!addedCU.exists()) {				if ((kind & SimilarElementsRequestor.CLASSES) != 0) {					String label= CorrectionMessages.getFormattedString("UnresolvedElementsSubProcessor.createclassusingwizard.description", typeName); //$NON-NLS-1$                    proposals.add(new NewCUCompletionUsingWizardProposal(label, typeName, cu, true, problemPos, 0));				}				if ((kind & SimilarElementsRequestor.INTERFACES) != 0) {					String label= CorrectionMessages.getFormattedString("UnresolvedElementsSubProcessor.createinterfaceusingwizard.description", typeName); //$NON-NLS-1$                    proposals.add(new NewCUCompletionUsingWizardProposal(label, typeName, cu, false, problemPos, 0));				}							}		}	}