/** * This method performs checks on the constant name which are quick enough to be performed every * time the ui input component contents are changed. * * @return return the resulting status * @throws JavaScriptModelException thrown when the operation could not be executed */ public RefactoringStatus checkConstantNameOnChange() throws JavaScriptModelException { if (Arrays.asList(getExcludedVariableNames()).contains(fConstantName)) return RefactoringStatus.createErrorStatus( Messages.format( RefactoringCoreMessages.ExtractConstantRefactoring_another_variable, getConstantName())); return Checks.checkConstantName(getConstantName()); }
/* * @see ICompletionProposal#getDisplayString() */ public String getDisplayString() { String shortCutString = CorrectionCommandHandler.getShortCutString(getCommandId()); if (shortCutString != null) { return Messages.format( CorrectionMessages.ChangeCorrectionProposal_name_with_shortcut, new String[] {getName(), shortCutString}); } return getName(); }
public void setText(String text) { if (text == null || text.length() == 0) { getShell().setText(fTitle); } else { getShell() .setText( Messages.format( JavaUIMessages.TypeSelectionDialog2_title_format, new String[] {fTitle, text})); } }
protected void handleWidgetSelected(TypeNameMatch[] selection) { IStatus status = null; if (selection.length == 0) { status = new Status( IStatus.ERROR, JavaScriptPlugin.getPluginId(), IStatus.ERROR, "", null); //$NON-NLS-1$ } else { if (fValidator != null) { List jElements = new ArrayList(); for (int i = 0; i < selection.length; i++) { IType type = selection[i].getType(); if (type != null) { jElements.add(type); } else { status = new Status( IStatus.ERROR, JavaScriptPlugin.getPluginId(), IStatus.ERROR, Messages.format( JavaUIMessages.TypeSelectionDialog_error_type_doesnot_exist, selection[i].getFullyQualifiedName()), null); break; } } if (status == null) { status = fValidator.validate(jElements.toArray()); } } else { status = new Status( IStatus.OK, JavaScriptPlugin.getPluginId(), IStatus.OK, "", null); // $NON-NLS-1$ } } updateStatus(status); }
protected void computeResult() { TypeNameMatch[] selected = fContent.getSelection(); if (selected == null || selected.length == 0) { setResult(null); return; } // If the scope is null then it got computed by the type selection component. if (fScope == null) { fScope = fContent.getScope(); } OpenTypeHistory history = OpenTypeHistory.getInstance(); List result = new ArrayList(selected.length); for (int i = 0; i < selected.length; i++) { TypeNameMatch typeInfo = selected[i]; IType type = typeInfo.getType(); if (!type.exists()) { String title = JavaUIMessages.TypeSelectionDialog_errorTitle; IPackageFragmentRoot root = typeInfo.getPackageFragmentRoot(); String containerName = JavaScriptElementLabels.getElementLabel(root, JavaScriptElementLabels.ROOT_QUALIFIED); String message = Messages.format( JavaUIMessages.TypeSelectionDialog_dialogMessage, new String[] {typeInfo.getFullyQualifiedName(), containerName}); MessageDialog.openError(getShell(), title, message); history.remove(typeInfo); setResult(null); } else { history.accessed(typeInfo); result.add(type); } } setResult(result); }
public RefactoringStatus initialize(final RefactoringArguments arguments) { if (arguments instanceof JavaRefactoringArguments) { final JavaRefactoringArguments extended = (JavaRefactoringArguments) arguments; final String selection = extended.getAttribute(JDTRefactoringDescriptor.ATTRIBUTE_SELECTION); if (selection != null) { int offset = -1; int length = -1; final StringTokenizer tokenizer = new StringTokenizer(selection); if (tokenizer.hasMoreTokens()) offset = Integer.valueOf(tokenizer.nextToken()).intValue(); if (tokenizer.hasMoreTokens()) length = Integer.valueOf(tokenizer.nextToken()).intValue(); if (offset >= 0 && length >= 0) { fSelectionStart = offset; fSelectionLength = length; } else return RefactoringStatus.createFatalErrorStatus( Messages.format( RefactoringCoreMessages.InitializableRefactoring_illegal_argument, new Object[] {selection, JDTRefactoringDescriptor.ATTRIBUTE_SELECTION})); } else return RefactoringStatus.createFatalErrorStatus( Messages.format( RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, JDTRefactoringDescriptor.ATTRIBUTE_SELECTION)); final String handle = extended.getAttribute(JDTRefactoringDescriptor.ATTRIBUTE_INPUT); if (handle != null) { final IJavaScriptElement element = JDTRefactoringDescriptor.handleToElement(extended.getProject(), handle, false); if (element == null || !element.exists() || element.getElementType() != IJavaScriptElement.JAVASCRIPT_UNIT) return createInputFatalStatus(element, IJavaScriptRefactorings.EXTRACT_CONSTANT); else fCu = (IJavaScriptUnit) element; } else return RefactoringStatus.createFatalErrorStatus( Messages.format( RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, JDTRefactoringDescriptor.ATTRIBUTE_INPUT)); final String visibility = extended.getAttribute(ATTRIBUTE_VISIBILITY); if (visibility != null && !"".equals(visibility)) { // $NON-NLS-1$ int flag = 0; try { flag = Integer.parseInt(visibility); } catch (NumberFormatException exception) { return RefactoringStatus.createFatalErrorStatus( Messages.format( RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, ATTRIBUTE_VISIBILITY)); } fVisibility = JdtFlags.getVisibilityString(flag); } final String name = extended.getAttribute(JDTRefactoringDescriptor.ATTRIBUTE_NAME); if (name != null && !"".equals(name)) // $NON-NLS-1$ fConstantName = name; else return RefactoringStatus.createFatalErrorStatus( Messages.format( RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, JDTRefactoringDescriptor.ATTRIBUTE_NAME)); final String replace = extended.getAttribute(ATTRIBUTE_REPLACE); if (replace != null) { fReplaceAllOccurrences = Boolean.valueOf(replace).booleanValue(); } else return RefactoringStatus.createFatalErrorStatus( Messages.format( RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, ATTRIBUTE_REPLACE)); final String declareFinal = extended.getAttribute(ATTRIBUTE_QUALIFY); if (declareFinal != null) { fQualifyReferencesWithDeclaringClassName = Boolean.valueOf(declareFinal).booleanValue(); } else return RefactoringStatus.createFatalErrorStatus( Messages.format( RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, ATTRIBUTE_QUALIFY)); } else return RefactoringStatus.createFatalErrorStatus( RefactoringCoreMessages.InitializableRefactoring_inacceptable_arguments); return new RefactoringStatus(); }
public Change createChange(IProgressMonitor monitor) throws CoreException { final Map arguments = new HashMap(); String project = null; IJavaScriptProject javaProject = fCu.getJavaScriptProject(); if (javaProject != null) project = javaProject.getElementName(); int flags = JavaScriptRefactoringDescriptor.JAR_REFACTORING | JavaScriptRefactoringDescriptor.JAR_SOURCE_ATTACHMENT; if (JdtFlags.getVisibilityCode(fVisibility) != Modifier.PRIVATE) flags |= RefactoringDescriptor.STRUCTURAL_CHANGE; String pattern = ""; // $NON-NLS-1$ try { pattern = BindingLabelProvider.getBindingLabel( getContainingTypeBinding(), JavaScriptElementLabels.ALL_FULLY_QUALIFIED) + "."; //$NON-NLS-1$ } catch (JavaScriptModelException exception) { JavaScriptPlugin.log(exception); } final String expression = ASTNodes.asString(fSelectedExpression.getAssociatedExpression()); final String description = Messages.format( RefactoringCoreMessages.ExtractConstantRefactoring_descriptor_description_short, fConstantName); final String header = Messages.format( RefactoringCoreMessages.ExtractConstantRefactoring_descriptor_description, new String[] {pattern + fConstantName, expression}); final JDTRefactoringDescriptorComment comment = new JDTRefactoringDescriptorComment(project, this, header); comment.addSetting( Messages.format( RefactoringCoreMessages.ExtractConstantRefactoring_constant_name_pattern, fConstantName)); comment.addSetting( Messages.format( RefactoringCoreMessages.ExtractConstantRefactoring_constant_expression_pattern, expression)); String visibility = fVisibility; if ("".equals(visibility)) // $NON-NLS-1$ visibility = RefactoringCoreMessages.ExtractConstantRefactoring_default_visibility; comment.addSetting( Messages.format( RefactoringCoreMessages.ExtractConstantRefactoring_visibility_pattern, visibility)); if (fReplaceAllOccurrences) comment.addSetting(RefactoringCoreMessages.ExtractConstantRefactoring_replace_occurrences); if (fQualifyReferencesWithDeclaringClassName) comment.addSetting(RefactoringCoreMessages.ExtractConstantRefactoring_qualify_references); final JDTRefactoringDescriptor descriptor = new JDTRefactoringDescriptor( IJavaScriptRefactorings.EXTRACT_CONSTANT, project, description, comment.asString(), arguments, flags); arguments.put(JDTRefactoringDescriptor.ATTRIBUTE_INPUT, descriptor.elementToHandle(fCu)); arguments.put(JDTRefactoringDescriptor.ATTRIBUTE_NAME, fConstantName); arguments.put( JDTRefactoringDescriptor.ATTRIBUTE_SELECTION, new Integer(fSelectionStart).toString() + " " + new Integer(fSelectionLength).toString()); // $NON-NLS-1$ arguments.put(ATTRIBUTE_REPLACE, Boolean.valueOf(fReplaceAllOccurrences).toString()); arguments.put( ATTRIBUTE_QUALIFY, Boolean.valueOf(fQualifyReferencesWithDeclaringClassName).toString()); arguments.put( ATTRIBUTE_VISIBILITY, new Integer(JdtFlags.getVisibilityCode(fVisibility)).toString()); return new RefactoringDescriptorChange( descriptor, RefactoringCoreMessages.ExtractConstantRefactoring_name, new Change[] {fChange}); }
public String getName() { return Messages.format(RefactoringCoreMessages.DeleteFolderChange_0, fPath.lastSegment()); }