Java Code Examples for org.eclipse.jdt.internal.corext.util.Messages#format()

The following examples show how to use org.eclipse.jdt.internal.corext.util.Messages#format() . 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: AccessRulesDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private String getDescriptionString() {
	String desc;
	String name= BasicElementLabels.getResourceName(fCurrElement.getPath().lastSegment());
	switch (fCurrElement.getEntryKind()) {
		case IClasspathEntry.CPE_CONTAINER:
			try {
				name= JavaElementLabels.getContainerEntryLabel(fCurrElement.getPath(), fCurrElement.getJavaProject());
			} catch (JavaModelException e) {
			}
			desc= NewWizardMessages.AccessRulesDialog_container_description;
			break;
		case IClasspathEntry.CPE_PROJECT:
			desc=  NewWizardMessages.AccessRulesDialog_project_description;
			break;
		default:
			desc=  NewWizardMessages.AccessRulesDialog_description;
	}

	return Messages.format(desc, name);
}
 
Example 2
Source File: JarWriter3.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Writes the passed resource to the current archive.
 *
 * @param resource
 *            the file to be written
 * @param destinationPath
 *            the path for the file inside the archive
 * @throws CoreException
 *             to signal any other unusual termination. This can also be
 *             used to return information in the status object.
 */
public void write(IFile resource, IPath destinationPath) throws CoreException {
	try {
		if (fJarPackage.areDirectoryEntriesIncluded())
			addDirectories(resource, destinationPath);
		addFile(resource, destinationPath);
	} catch (IOException ex) {
		// Ensure full path is visible
		String message= null;
		if (ex.getLocalizedMessage() != null)
			message= Messages.format(JarPackagerMessages.JarWriter_writeProblemWithMessage, new Object[] {BasicElementLabels.getPathLabel(resource.getFullPath(), false), ex.getLocalizedMessage()});
		else
			message= Messages.format(JarPackagerMessages.JarWriter_writeProblem, BasicElementLabels.getPathLabel(resource.getFullPath(), false));
		throw JarPackagerUtil.createCoreException(message, ex);
	}
}
 
Example 3
Source File: NLSPropertyFileModifier.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static Change removeKeys(IPath propertyFilePath, List<String> keys) throws CoreException {

		String name= Messages.format(NLSMessages.NLSPropertyFileModifier_remove_from_property_file, BasicElementLabels.getPathLabel(propertyFilePath, false));
		TextChange textChange= new TextFileChange(name, getPropertyFile(propertyFilePath));
		textChange.setTextType("properties"); //$NON-NLS-1$

		PropertyFileDocumentModel model= new PropertyFileDocumentModel(textChange.getCurrentDocument(new NullProgressMonitor()));

		for (Iterator<String> iterator= keys.iterator(); iterator.hasNext();) {
			String key= iterator.next();
			TextEdit edit= model.remove(key);
			if (edit != null) {
				TextChangeCompatibility.addTextEdit(textChange, Messages.format(NLSMessages.NLSPropertyFileModifier_remove_entry, BasicElementLabels.getJavaElementName(key)), edit);
			}

		}
		return textChange;
	}
 
Example 4
Source File: ConstructorFromSuperclassProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public String getName() {
	StringBuffer buf= new StringBuffer();
	buf.append(fTypeNode.getName().getIdentifier());
	buf.append('(');
	if (fSuperConstructor != null) {
		ITypeBinding[] paramTypes= fSuperConstructor.getParameterTypes();
		for (int i= 0; i < paramTypes.length; i++) {
			if (i > 0) {
				buf.append(',');
			}
			buf.append(paramTypes[i].getName());
		}
	}
	buf.append(')');
	return Messages.format(CorrectionMessages.ConstructorFromSuperclassProposal_description, BasicElementLabels.getJavaElementName(buf.toString()));
}
 
Example 5
Source File: RenameFieldProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private RefactoringStatus checkEnclosingHierarchy() {
	IType current= fField.getDeclaringType();
	if (Checks.isTopLevel(current))
		return null;
	RefactoringStatus result= new RefactoringStatus();
	while (current != null){
		IField otherField= current.getField(getNewElementName());
		if (otherField.exists()){
			String msg= Messages.format(RefactoringCoreMessages.RenameFieldRefactoring_hiding2,
			 	new String[]{ BasicElementLabels.getJavaElementName(getNewElementName()), BasicElementLabels.getJavaElementName(current.getFullyQualifiedName('.')), BasicElementLabels.getJavaElementName(otherField.getElementName())});
			result.addWarning(msg, JavaStatusContext.create(otherField));
		}
		current= current.getDeclaringType();
	}
	return result;
}
 
Example 6
Source File: ExcludeFromBuildpathAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public String getDetailedDescription() {
	if (!isEnabled())
		return null;

	if (getSelectedElements().size() != 1)
		return NewWizardMessages.PackageExplorerActionGroup_FormText_Default_Exclude;

	IJavaElement elem= (IJavaElement) getSelectedElements().get(0);
       String name= ClasspathModifier.escapeSpecialChars(JavaElementLabels.getElementLabel(elem, JavaElementLabels.ALL_DEFAULT));
       if (elem instanceof IPackageFragment) {
       	return Messages.format(NewWizardMessages.PackageExplorerActionGroup_FormText_ExcludePackage, name);
       } else if (elem instanceof ICompilationUnit) {
       	return Messages.format(NewWizardMessages.PackageExplorerActionGroup_FormText_ExcludeFile, name);
       }

       return null;
}
 
Example 7
Source File: CPListLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public String getText(Object element) {
	if (element instanceof CPListElement) {
		return getCPListElementText((CPListElement) element);
	} else if (element instanceof CPListElementAttribute) {
		CPListElementAttribute attribute= (CPListElementAttribute) element;
		String text= getCPListElementAttributeText(attribute);
		if (attribute.isNonModifiable()) {
			return Messages.format(NewWizardMessages.CPListLabelProvider_non_modifiable_attribute, text);
		}
		return text;
	} else if (element instanceof CPUserLibraryElement) {
		return getCPUserLibraryText((CPUserLibraryElement) element);
	} else if (element instanceof IAccessRule) {
		IAccessRule rule= (IAccessRule) element;
		return Messages.format(NewWizardMessages.CPListLabelProvider_access_rules_label, new String[] { AccessRulesLabelProvider.getResolutionLabel(rule.getKind()), BasicElementLabels.getPathLabel(rule.getPattern(), false)});
	}
	return super.getText(element);
}
 
Example 8
Source File: RenameSourceFolderProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Change createChange(IProgressMonitor monitor) throws CoreException {
	monitor.beginTask(RefactoringCoreMessages.RenameTypeRefactoring_creating_change, 1);
	try {
		final IResource resource= fSourceFolder.getResource();
		final String project= resource.getProject().getName();
		final String newName= getNewElementName();
		final String description= Messages.format(RefactoringCoreMessages.RenameSourceFolderChange_descriptor_description_short, JavaElementLabels.getElementLabel(fSourceFolder, JavaElementLabels.ALL_DEFAULT));
		final String header= Messages.format(RefactoringCoreMessages.RenameSourceFolderChange_descriptor_description, new String[] { BasicElementLabels.getPathLabel(resource.getFullPath(), false), BasicElementLabels.getJavaElementName(newName)});
		final String comment= new JDTRefactoringDescriptorComment(project, this, header).asString();
		final RenameJavaElementDescriptor descriptor= RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_SOURCE_FOLDER);
		descriptor.setProject(project);
		descriptor.setDescription(description);
		descriptor.setComment(comment);
		descriptor.setFlags(RefactoringDescriptor.NONE);
		descriptor.setJavaElement(fSourceFolder);
		descriptor.setNewName(newName);
		return new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.RenameSourceFolderRefactoring_rename, new Change[] { new RenameSourceFolderChange(fSourceFolder, newName)});
	} finally {
		monitor.done();
	}
}
 
Example 9
Source File: PushDownWizard.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void updateStatusLine() {
	if (fStatusLine == null)
		return;
	Object[] selectedMembers= fTableViewer.getCheckedElements();
	final int selected= selectedMembers.length;
	final String msg= selected == 1 ? Messages.format(RefactoringMessages.PushDownInputPage_status_line_singular, JavaElementLabels.getElementLabel(
			((MemberActionInfo)selectedMembers[0]).getMember(), JavaElementLabels.M_PARAMETER_TYPES)) : Messages.format(RefactoringMessages.PushDownInputPage_status_line_plural, String
			.valueOf(selected));
	fStatusLine.setText(msg);
}
 
Example 10
Source File: CPListLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public String getCPUserLibraryText(CPUserLibraryElement element) {
	String name= element.getName();
	if (element.isSystemLibrary()) {
		name= Messages.format(NewWizardMessages.CPListLabelProvider_systemlibrary, name);
	}
	return name;
}
 
Example 11
Source File: RenameJavaProjectProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected RefactoringStatus doCheckFinalConditions(IProgressMonitor pm, CheckConditionsContext context) throws CoreException {
	pm.beginTask("", 1); //$NON-NLS-1$
	try{
		if (isReadOnly()){
			String message= Messages.format(RefactoringCoreMessages.RenameJavaProjectRefactoring_read_only,
					BasicElementLabels.getJavaElementName(fProject.getElementName()));
			return RefactoringStatus.createErrorStatus(message);
		}
		return new RefactoringStatus();
	} finally{
		pm.done();
	}
}
 
Example 12
Source File: MoveInnerToTopRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Change createChange(final IProgressMonitor monitor) throws CoreException {
	monitor.beginTask(RefactoringCoreMessages.MoveInnerToTopRefactoring_creating_change, 1);
	final Map<String, String> arguments= new HashMap<String, String>();
	String project= null;
	IJavaProject javaProject= fType.getJavaProject();
	if (javaProject != null)
		project= javaProject.getElementName();
	final String description= Messages.format(RefactoringCoreMessages.MoveInnerToTopRefactoring_descriptor_description_short, BasicElementLabels.getJavaElementName(fType.getElementName()));
	final String header= Messages.format(RefactoringCoreMessages.MoveInnerToTopRefactoring_descriptor_description, new String[] { JavaElementLabels.getElementLabel(fType, JavaElementLabels.ALL_FULLY_QUALIFIED), JavaElementLabels.getElementLabel(fType.getParent(), JavaElementLabels.ALL_FULLY_QUALIFIED)});
	final JDTRefactoringDescriptorComment comment= new JDTRefactoringDescriptorComment(project, this, header);
	comment.addSetting(Messages.format(RefactoringCoreMessages.MoveInnerToTopRefactoring_original_pattern, JavaElementLabels.getElementLabel(fType, JavaElementLabels.ALL_FULLY_QUALIFIED)));
	final boolean enclosing= fEnclosingInstanceFieldName != null && !"".equals(fEnclosingInstanceFieldName); //$NON-NLS-1$
	if (enclosing)
		comment.addSetting(Messages.format(RefactoringCoreMessages.MoveInnerToTopRefactoring_field_pattern, BasicElementLabels.getJavaElementName(fEnclosingInstanceFieldName)));
	if (fNameForEnclosingInstanceConstructorParameter != null && !"".equals(fNameForEnclosingInstanceConstructorParameter)) //$NON-NLS-1$
		comment.addSetting(Messages.format(RefactoringCoreMessages.MoveInnerToTopRefactoring_parameter_pattern, BasicElementLabels.getJavaElementName(fNameForEnclosingInstanceConstructorParameter)));
	if (enclosing && fMarkInstanceFieldAsFinal)
		comment.addSetting(RefactoringCoreMessages.MoveInnerToTopRefactoring_declare_final);
	final ConvertMemberTypeDescriptor descriptor= RefactoringSignatureDescriptorFactory.createConvertMemberTypeDescriptor(project, description, comment.asString(), arguments, RefactoringDescriptor.MULTI_CHANGE | RefactoringDescriptor.STRUCTURAL_CHANGE | JavaRefactoringDescriptor.JAR_REFACTORING | JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT);
	arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(project, fType));
	if (enclosing)
		arguments.put(ATTRIBUTE_FIELD_NAME, fEnclosingInstanceFieldName);
	if (fNameForEnclosingInstanceConstructorParameter != null && !"".equals(fNameForEnclosingInstanceConstructorParameter)) //$NON-NLS-1$
		arguments.put(ATTRIBUTE_PARAMETER_NAME, fNameForEnclosingInstanceConstructorParameter);
	arguments.put(ATTRIBUTE_FIELD, Boolean.valueOf(fCreateInstanceField).toString());
	arguments.put(ATTRIBUTE_FINAL, Boolean.valueOf(fMarkInstanceFieldAsFinal).toString());
	arguments.put(ATTRIBUTE_POSSIBLE, Boolean.valueOf(fIsInstanceFieldCreationPossible).toString());
	arguments.put(ATTRIBUTE_MANDATORY, Boolean.valueOf(fIsInstanceFieldCreationMandatory).toString());
	final DynamicValidationRefactoringChange result= new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.MoveInnerToTopRefactoring_move_to_Top);
	result.addAll(fChangeManager.getAllChanges());
	result.add(createCompilationUnitForMovedType(new SubProgressMonitor(monitor, 1)));
	return result;
}
 
Example 13
Source File: MethodChecks.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static RefactoringStatus checkIfOverridesAnother(IMethod method, ITypeHierarchy hierarchy) throws JavaModelException {
	IMethod overrides= MethodChecks.overridesAnotherMethod(method, hierarchy);
	if (overrides == null)
		return null;

	RefactoringStatusContext context= JavaStatusContext.create(overrides);
	String message= Messages.format(RefactoringCoreMessages.MethodChecks_overrides,
			new String[]{JavaElementUtil.createMethodSignature(overrides), JavaElementLabels.getElementLabel(overrides.getDeclaringType(), JavaElementLabels.ALL_FULLY_QUALIFIED)});
	return RefactoringStatus.createStatus(RefactoringStatus.FATAL, message, context, Corext.getPluginId(), RefactoringStatusCodes.OVERRIDES_ANOTHER_METHOD, overrides);
}
 
Example 14
Source File: ParameterEditDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IStatus validateDefaultValue() {
	if (fDefaultValue == null)
		return null;
	String defaultValue= fDefaultValue.getText();
	if (defaultValue.length() == 0)
		return createErrorStatus(RefactoringMessages.ParameterEditDialog_defaultValue_error);
	if (ChangeSignatureProcessor.isValidExpression(defaultValue))
		return Status.OK_STATUS;
	String msg= Messages.format(RefactoringMessages.ParameterEditDialog_defaultValue_invalid, new String[]{defaultValue});
	return createErrorStatus(msg);

}
 
Example 15
Source File: PushDownRefactoringProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private RefactoringStatus checkPossibleSubclasses(IProgressMonitor pm) throws JavaModelException {
	IType[] modifiableSubclasses= getAbstractDestinations(pm);
	if (modifiableSubclasses.length == 0) {
		String msg= Messages.format(RefactoringCoreMessages.PushDownRefactoring_no_subclasses, new String[] { JavaElementLabels.getTextLabel(getDeclaringType(), JavaElementLabels.ALL_FULLY_QUALIFIED) });
		return RefactoringStatus.createFatalErrorStatus(msg);
	}
	return new RefactoringStatus();
}
 
Example 16
Source File: LineWrappingTabPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private String getGroupLabel(Category category) {
    if (fSelection.size() == 1) {
	    if (fSelectionState.getElements().size() == 1)
	        return Messages.format(FormatterMessages.LineWrappingTabPage_group, category.name.toLowerCase());
	    return Messages.format(FormatterMessages.LineWrappingTabPage_multi_group, new String[] {category.name.toLowerCase(), Integer.toString(fSelectionState.getElements().size())});
    }
	return Messages.format(FormatterMessages.LineWrappingTabPage_multiple_selections, new String[] {Integer.toString(fSelectionState.getElements().size())});
}
 
Example 17
Source File: PullUpRefactoringProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected RefactoringStatus checkDeclaringSuperTypes(final IProgressMonitor monitor) throws JavaModelException {
	final RefactoringStatus result= new RefactoringStatus();
	if (getCandidateTypes(result, monitor).length == 0 && !result.hasFatalError()) {
		final String msg= Messages.format(RefactoringCoreMessages.PullUpRefactoring_not_this_type, new String[] { JavaElementLabels.getTextLabel(getDeclaringType(), JavaElementLabels.ALL_FULLY_QUALIFIED)});
		return RefactoringStatus.createFatalErrorStatus(msg);
	}
	return result;
}
 
Example 18
Source File: TypeContextChecker.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private ITypeBinding[] resolveBindings(String[] types, RefactoringStatus[] results, boolean firstPass) throws CoreException {
	//TODO: split types into parameterTypes and returnType
	int parameterCount= types.length - 1;
	ITypeBinding[] typeBindings= new ITypeBinding[types.length];

	StringBuffer cuString= new StringBuffer();
	cuString.append(fStubTypeContext.getBeforeString());
	int offsetBeforeMethodName= appendMethodDeclaration(cuString, types, parameterCount);
	cuString.append(fStubTypeContext.getAfterString());

	// need a working copy to tell the parser where to resolve (package visible) types
	ICompilationUnit wc= fMethod.getCompilationUnit().getWorkingCopy(new WorkingCopyOwner() {/*subclass*/}, new NullProgressMonitor());
	try {
		wc.getBuffer().setContents(cuString.toString());
		CompilationUnit compilationUnit= new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL).parse(wc, true);
		ASTNode method= NodeFinder.perform(compilationUnit, offsetBeforeMethodName, METHOD_NAME.length()).getParent();
		Type[] typeNodes= new Type[types.length];
		if (method instanceof MethodDeclaration) {
			MethodDeclaration methodDeclaration= (MethodDeclaration) method;
			typeNodes[parameterCount]= methodDeclaration.getReturnType2();
			List<SingleVariableDeclaration> parameters= methodDeclaration.parameters();
			for (int i= 0; i < parameterCount; i++)
				typeNodes[i]= parameters.get(i).getType();

		} else if (method instanceof AnnotationTypeMemberDeclaration) {
			typeNodes[0]= ((AnnotationTypeMemberDeclaration) method).getType();
		}

		for (int i= 0; i < types.length; i++) {
			Type type= typeNodes[i];
			if (type == null) {
				String msg= Messages.format(RefactoringCoreMessages.TypeContextChecker_couldNotResolveType, BasicElementLabels.getJavaElementName(types[i]));
				results[i]= RefactoringStatus.createErrorStatus(msg);
				continue;
			}
			results[i]= new RefactoringStatus();
			IProblem[] problems= ASTNodes.getProblems(type, ASTNodes.NODE_ONLY, ASTNodes.PROBLEMS);
			if (problems.length > 0) {
				for (int p= 0; p < problems.length; p++)
					if (isError(problems[p], type))
						results[i].addError(problems[p].getMessage());
			}
			ITypeBinding binding= handleBug84585(type.resolveBinding());
			if (firstPass && (binding == null || binding.isRecovered())) {
				types[i]= qualifyTypes(type, results[i]);
			}
			typeBindings[i]= binding;
		}
		return typeBindings;
	} finally {
		wc.discardWorkingCopy();
	}
}
 
Example 19
Source File: MoveCompilationUnitChange.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public String getName() {
	return Messages.format(RefactoringCoreMessages.MoveCompilationUnitChange_name,
	new String[]{BasicElementLabels.getFileName(getCu()), getPackageName(getDestinationPackage())});
}
 
Example 20
Source File: UserLibraryMarkerResolutionGenerator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public String getDescription() {
	return Messages.format(CorrectionMessages.ReorgCorrectionsSubProcessor_configure_buildpath_description, BasicElementLabels.getResourceName(fProject.getElementName()));
}