private void configureWizardPage(NewTypeWizardPage page) { fillInWizardPageName(page); fillInWizardPageSuperTypes(page); }
break; nameToHTML(fTypeNameWithParameters, buf); ITypeBinding superclass= getPossibleSuperTypeBinding(fNode); if (superclass != null) { if (superclass.isClass()) { if (fTypeKind == K_CLASS) { buf.append("</b> extends <b>"); //$NON-NLS-1$ nameToHTML(BindingLabelProvider.getBindingLabel(superclass, BindingLabelProvider.DEFAULT_TEXTFLAGS), buf); buf.append("</b> implements <b>"); //$NON-NLS-1$ nameToHTML(BindingLabelProvider.getBindingLabel(superclass, BindingLabelProvider.DEFAULT_TEXTFLAGS), buf);
fTypeKind= typeKind; fTypeContainer= typeContainer; fTypeNameWithParameters= getTypeName(typeKind, node); switch (typeKind) { case K_CLASS: setImage(JavaPluginImages.get(JavaPluginImages.IMG_OBJS_CLASS)); if (isInnerType) { if (containerName.length() == 0) { setDisplayName(Messages.format(CorrectionMessages.NewCUCompletionUsingWizardProposal_createinnerclass_description, typeLabel)); } else { setDisplayName(Messages.format(CorrectionMessages.NewCUCompletionUsingWizardProposal_createinnerclass_intype_description, new String[] { typeLabel, containerLabel })); setDisplayName(Messages.format(CorrectionMessages.NewCUCompletionUsingWizardProposal_createclass_description, typeLabel)); } else { setDisplayName(Messages.format(CorrectionMessages.NewCUCompletionUsingWizardProposal_createclass_inpackage_description, new String[] { typeLabel, containerLabel })); setImage(JavaPluginImages.get(JavaPluginImages.IMG_OBJS_INTERFACE)); if (isInnerType) { if (containerName.length() == 0) { setDisplayName(Messages.format(CorrectionMessages.NewCUCompletionUsingWizardProposal_createinnerinterface_description, typeLabel)); } else { setDisplayName(Messages.format(CorrectionMessages.NewCUCompletionUsingWizardProposal_createinnerinterface_intype_description, new String[] { typeLabel, containerLabel })); setDisplayName(Messages.format(CorrectionMessages.NewCUCompletionUsingWizardProposal_createinterface_description, typeLabel)); } else { setDisplayName(Messages.format(CorrectionMessages.NewCUCompletionUsingWizardProposal_createinterface_inpackage_description, new String[] { typeLabel, containerLabel })); setImage(JavaPluginImages.get(JavaPluginImages.IMG_OBJS_ENUM));
@Override public void apply(IDocument document) { StructuredSelection selection= new StructuredSelection(fCompilationUnit); NewElementWizard wizard= createWizard(selection); wizard.init(JavaPlugin.getDefault().getWorkbench(), selection); wizard.addPages(); try { NewTypeWizardPage page= getPage(wizard); page.createType(null); createdType= page.getCreatedType();
public static void getPackageDoesNotExistProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) throws CoreException { ICompilationUnit cu= context.getCompilationUnit(); ASTNode selectedNode= problem.getCoveringNode(context.getASTRoot()); if (selectedNode == null) { return; } Name node= null; if (selectedNode instanceof Name) { node= (Name) selectedNode; } else { return; } IJavaProject javaProject= cu.getJavaProject(); IModuleDescription moduleDescription= cu.getModule(); if (moduleDescription != null && moduleDescription.exists() && javaProject != null && JavaModelUtil.is9OrHigher(javaProject)) { ICompilationUnit moduleCompilationUnit= moduleDescription.getCompilationUnit(); if (cu.equals(moduleCompilationUnit)) { IPackageFragmentRoot root= (IPackageFragmentRoot) moduleDescription.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); if (root != null) { String name= node.getFullyQualifiedName(); IPackageFragment pack= root.getPackageFragment(name); proposals.add(new NewCUUsingWizardProposal(cu, null, NewCUUsingWizardProposal.K_CLASS, pack, IProposalRelevance.NEW_TYPE)); proposals.add(new NewCUUsingWizardProposal(cu, null, NewCUUsingWizardProposal.K_INTERFACE, pack, IProposalRelevance.NEW_TYPE)); proposals.add(new NewCUUsingWizardProposal(cu, null, NewCUUsingWizardProposal.K_ENUM, pack, IProposalRelevance.NEW_TYPE)); proposals.add(new NewCUUsingWizardProposal(cu, null, NewCUUsingWizardProposal.K_ANNOTATION, pack, IProposalRelevance.NEW_TYPE)); } } } }
/** * Fill-in the "Super Class" and "Super Interfaces" fields. * @param page the wizard page. */ private void fillInWizardPageSuperTypes(NewTypeWizardPage page) { ITypeBinding type= getPossibleSuperTypeBinding(fNode); type= Bindings.normalizeTypeBinding(type); if (type != null) { if (type.isArray()) { type= type.getElementType(); } if (type.isTopLevel() || type.isMember()) { if (type.isClass() && (fTypeKind == K_CLASS)) { page.setSuperClass(type.getQualifiedName(), true); } else if (type.isInterface()) { List<String> superInterfaces= new ArrayList<>(); superInterfaces.add(type.getQualifiedName()); page.setSuperInterfaces(superInterfaces, true); } } } }
private NewElementWizard createWizard(StructuredSelection selection) { switch (fTypeKind) { case K_CLASS: { NewClassWizardPage page= new NewClassWizardPage(); page.init(selection); configureWizardPage(page); return new NewClassCreationWizard(page, true); } case K_INTERFACE: { NewInterfaceWizardPage page= new NewInterfaceWizardPage(); page.init(selection); configureWizardPage(page); return new NewInterfaceCreationWizard(page, true); } case K_ENUM: { NewEnumWizardPage page= new NewEnumWizardPage(); page.init(selection); configureWizardPage(page); return new NewEnumCreationWizard(page, true); } case K_ANNOTATION: { NewAnnotationWizardPage page= new NewAnnotationWizardPage(); page.init(selection); configureWizardPage(page); return new NewAnnotationCreationWizard(page, true); } } throw new IllegalArgumentException(); }
fTypeContainer= typeContainer; if (fNode != null) { fTypeNameWithParameters= getTypeName(typeKind, node); switch (typeKind) { case K_CLASS: setImage(JavaPluginImages.get(JavaPluginImages.IMG_OBJS_CLASS)); if (fNode != null) { if (isInnerType) { if (containerName.length() == 0) { setDisplayName(Messages.format(CorrectionMessages.NewCUCompletionUsingWizardProposal_createinnerclass_description, typeLabel)); } else { setDisplayName(Messages.format(CorrectionMessages.NewCUCompletionUsingWizardProposal_createinnerclass_intype_description, new String[] { typeLabel, containerLabel })); setDisplayName(Messages.format(CorrectionMessages.NewCUCompletionUsingWizardProposal_createclass_description, typeLabel)); } else { setDisplayName(Messages.format(CorrectionMessages.NewCUCompletionUsingWizardProposal_createclass_inpackage_description, new String[] { typeLabel, containerLabel })); setDisplayName(Messages.format(CorrectionMessages.NewCUCompletionUsingWizardProposal_createnewclass_inpackage_description, containerLabel)); setImage(JavaPluginImages.get(JavaPluginImages.IMG_OBJS_INTERFACE)); if (fNode != null) { if (isInnerType) { if (containerName.length() == 0) { setDisplayName(Messages.format(CorrectionMessages.NewCUCompletionUsingWizardProposal_createinnerinterface_description, typeLabel)); } else { setDisplayName(Messages.format(CorrectionMessages.NewCUCompletionUsingWizardProposal_createinnerinterface_intype_description, new String[] { typeLabel, containerLabel })); setDisplayName(Messages.format(CorrectionMessages.NewCUCompletionUsingWizardProposal_createinterface_description, typeLabel));
@Override public void apply(IDocument document) { StructuredSelection selection= new StructuredSelection(fCompilationUnit); NewElementWizard wizard= createWizard(selection); wizard.init(JavaPlugin.getDefault().getWorkbench(), selection); wizard.addPages(); try { NewTypeWizardPage page= getPage(wizard); page.createType(null); createdType= page.getCreatedType();
proposals.add(new NewCUUsingWizardProposal(cu, node, NewCUUsingWizardProposal.K_CLASS, enclosing, rel+3)); proposals.add(new NewCUUsingWizardProposal(cu, node, NewCUUsingWizardProposal.K_INTERFACE, enclosing, rel+2)); proposals.add(new NewCUUsingWizardProposal(cu, node, NewCUUsingWizardProposal.K_ENUM, enclosing, rel)); proposals.add(new NewCUUsingWizardProposal(cu, node, NewCUUsingWizardProposal.K_ANNOTATION, enclosing, rel + 1)); addNullityAnnotationTypesProposals(cu, node, proposals);
/** * Fill-in the "Super Class" and "Super Interfaces" fields. * @param page the wizard page. */ private void fillInWizardPageSuperTypes(NewTypeWizardPage page) { if (fNode != null) { ITypeBinding type= getPossibleSuperTypeBinding(fNode); type= Bindings.normalizeTypeBinding(type); if (type != null) { if (type.isArray()) { type= type.getElementType(); } if (type.isTopLevel() || type.isMember()) { if (type.isClass() && (fTypeKind == K_CLASS)) { page.setSuperClass(type.getQualifiedName(), true); } else if (type.isInterface()) { List<String> superInterfaces= new ArrayList<>(); superInterfaces.add(type.getQualifiedName()); page.setSuperInterfaces(superInterfaces, true); } } } } }
private NewElementWizard createWizard(StructuredSelection selection) { switch (fTypeKind) { case K_CLASS: { NewClassWizardPage page= new NewClassWizardPage(); page.init(selection); configureWizardPage(page); return new NewClassCreationWizard(page, true); } case K_INTERFACE: { NewInterfaceWizardPage page= new NewInterfaceWizardPage(); page.init(selection); configureWizardPage(page); return new NewInterfaceCreationWizard(page, true); } case K_ENUM: { NewEnumWizardPage page= new NewEnumWizardPage(); page.init(selection); configureWizardPage(page); return new NewEnumCreationWizard(page, true); } case K_ANNOTATION: { NewAnnotationWizardPage page= new NewAnnotationWizardPage(); page.init(selection); configureWizardPage(page); return new NewAnnotationCreationWizard(page, true); } } throw new IllegalArgumentException(); }
private void configureWizardPage(NewTypeWizardPage page) { fillInWizardPageName(page); fillInWizardPageSuperTypes(page); }
nameToHTML(fTypeNameWithParameters, buf); ITypeBinding superclass= getPossibleSuperTypeBinding(fNode); if (superclass != null) { if (superclass.isClass()) { if (fTypeKind == K_CLASS) { buf.append("</b> extends <b>"); //$NON-NLS-1$ nameToHTML(BindingLabelProvider.getBindingLabel(superclass, BindingLabelProvider.DEFAULT_TEXTFLAGS), buf); buf.append("</b> implements <b>"); //$NON-NLS-1$ nameToHTML(BindingLabelProvider.getBindingLabel(superclass, BindingLabelProvider.DEFAULT_TEXTFLAGS), buf);
proposals.add(new NewCUUsingWizardProposal(cu, node, NewCUUsingWizardProposal.K_CLASS, enclosing, rel+3)); proposals.add(new NewCUUsingWizardProposal(cu, node, NewCUUsingWizardProposal.K_INTERFACE, enclosing, rel+2)); proposals.add(new NewCUUsingWizardProposal(cu, node, NewCUUsingWizardProposal.K_ENUM, enclosing, rel)); proposals.add(new NewCUUsingWizardProposal(cu, node, NewCUUsingWizardProposal.K_ANNOTATION, enclosing, rel + 1)); addNullityAnnotationTypesProposals(cu, node, proposals);