org.eclipse.jdt.internal.corext.util.Messages Java Examples

The following examples show how to use org.eclipse.jdt.internal.corext.util.Messages. 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: ChangeSignatureProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
protected void checkIfDeletedParametersUsed() {
	for (Iterator<ParameterInfo> iter= getDeletedInfos().iterator(); iter.hasNext();) {
		ParameterInfo info= iter.next();
		VariableDeclaration paramDecl= getParameter(info.getOldIndex());
		TempOccurrenceAnalyzer analyzer= new TempOccurrenceAnalyzer(paramDecl, false);
		analyzer.perform();
		SimpleName[] paramRefs= analyzer.getReferenceNodes();

		if (paramRefs.length > 0) {
			RefactoringStatusContext context= JavaStatusContext.create(fCuRewrite.getCu(), paramRefs[0]);
			String typeName= getFullTypeName();
			Object[] keys= new String[] { BasicElementLabels.getJavaElementName(paramDecl.getName().getIdentifier()),
					BasicElementLabels.getJavaElementName(getMethod().getElementName()),
					BasicElementLabels.getJavaElementName(typeName) };
			String msg= Messages.format(RefactoringCoreMessages.ChangeSignatureRefactoring_parameter_used, keys);
			fResult.addError(msg, context);
		}
	}
}
 
Example #2
Source File: PullUpMemberPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void editSelectedMembers() {
	if (!fEditButton.isEnabled())
		return;

	final ISelection preserved= fTableViewer.getSelection();
	try {
		MemberActionInfo[] selectedMembers= getSelectedMembers();
		final String shellTitle= RefactoringMessages.PullUpInputPage1_Edit_members;
		final String labelText= selectedMembers.length == 1
				? Messages.format(RefactoringMessages.PullUpInputPage1_Mark_selected_members_singular, JavaElementLabels.getElementLabel(selectedMembers[0].getMember(),
						JavaElementLabels.M_PARAMETER_TYPES))
				: Messages.format(RefactoringMessages.PullUpInputPage1_Mark_selected_members_plural, String.valueOf(selectedMembers.length));
		final Map<String, Integer> stringMapping= createStringMappingForSelectedMembers();
		final String[] keys= stringMapping.keySet().toArray(new String[stringMapping.keySet().size()]);
		Arrays.sort(keys);
		final int initialSelectionIndex= getInitialSelectionIndexForEditDialog(stringMapping, keys);
		final ComboSelectionDialog dialog= new ComboSelectionDialog(getShell(), shellTitle, labelText, keys, initialSelectionIndex);
		dialog.setBlockOnOpen(true);
		if (dialog.open() == Window.CANCEL)
			return;
		final int action= stringMapping.get(dialog.getSelectedString()).intValue();
		setActionForInfos(selectedMembers, action);
	} finally {
		updateWizardPage(preserved, true);
	}
}
 
Example #3
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 #4
Source File: FatJarPackageWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @param classpathEntries the path to the package fragment roots
 * @param projectName the root of the project dependency tree
 * @param status a status to report problems to
 * @return all package fragment roots corresponding to each classpath entry start the search at project with projectName
 */
private static IPackageFragmentRoot[] getRequiredPackageFragmentRoots(IPath[] classpathEntries, final String projectName, MultiStatus status) {
	ArrayList<IPackageFragmentRoot> result= new ArrayList<IPackageFragmentRoot>();

	IJavaProject[] searchOrder= getProjectSearchOrder(projectName);

	for (int i= 0; i < classpathEntries.length; i++) {
		IPath entry= classpathEntries[i];
		IPackageFragmentRoot[] elements= findRootsForClasspath(entry, searchOrder);
		if (elements == null) {
			status.add(new Status(IStatus.WARNING, JavaUI.ID_PLUGIN, Messages.format(FatJarPackagerMessages.FatJarPackageWizardPage_error_missingClassFile, BasicElementLabels.getPathLabel(entry, false))));
		} else {
			for (int j= 0; j < elements.length; j++) {
				result.add(elements[j]);
			}
		}
	}

	return result.toArray(new IPackageFragmentRoot[result.size()]);
}
 
Example #5
Source File: RenamePackageProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private RefactoringStatus checkPackageName(String newName) throws CoreException {
	RefactoringStatus status= new RefactoringStatus();
	IPackageFragmentRoot[] roots= fPackage.getJavaProject().getPackageFragmentRoots();
	Set<String> topLevelTypeNames= getTopLevelTypeNames();
	for (int i= 0; i < roots.length; i++) {
		IPackageFragmentRoot root= roots[i];
		if (! isPackageNameOkInRoot(newName, root)) {
			String rootLabel = JavaElementLabels.getElementLabel(root, JavaElementLabels.ALL_DEFAULT);
			String newPackageName= BasicElementLabels.getJavaElementName(getNewElementName());
			String message= Messages.format(RefactoringCoreMessages.RenamePackageRefactoring_aleady_exists, new Object[]{ newPackageName, rootLabel});
			status.merge(RefactoringStatus.createWarningStatus(message));
			status.merge(checkTypeNameConflicts(root, newName, topLevelTypeNames));
		}
	}
	return status;
}
 
Example #6
Source File: TodoTaskConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public String getColumnText(Object element, int columnIndex) {
	TodoTask task= (TodoTask) element;
	if (columnIndex == 0) {
		String name= task.name;
		if (isDefaultTask(task)) {
			name=Messages.format(PreferencesMessages.TodoTaskConfigurationBlock_tasks_default, name);
		}
		return name;
	} else {
		if (PRIORITY_HIGH.equals(task.priority)) {
			return PreferencesMessages.TodoTaskConfigurationBlock_markers_tasks_high_priority;
		} else if (PRIORITY_NORMAL.equals(task.priority)) {
			return PreferencesMessages.TodoTaskConfigurationBlock_markers_tasks_normal_priority;
		} else if (PRIORITY_LOW.equals(task.priority)) {
			return PreferencesMessages.TodoTaskConfigurationBlock_markers_tasks_low_priority;
		}
		return ""; //$NON-NLS-1$
	}
}
 
Example #7
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 #8
Source File: ResourceTransferDragAdapter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void handleFinishedDropMove(DragSourceEvent event) {
	MultiStatus status= new MultiStatus(
		JavaPlugin.getPluginId(),
		IJavaStatusConstants.INTERNAL_ERROR,
		JavaUIMessages.ResourceTransferDragAdapter_cannot_delete_resource,
		null);
	List<IResource> resources= convertSelection();
	for (Iterator<IResource> iter= resources.iterator(); iter.hasNext();) {
		IResource resource= iter.next();
		try {
			resource.delete(true, null);
		} catch (CoreException e) {
			status.add(e.getStatus());
		}
	}
	int childrenCount= status.getChildren().length;
	if (childrenCount > 0) {
		Shell parent= SWTUtil.getShell(event.widget);
		ErrorDialog error= new ErrorDialog(parent,
				JavaUIMessages.ResourceTransferDragAdapter_moving_resource,
				childrenCount == 1 ? JavaUIMessages.ResourceTransferDragAdapter_cannot_delete_files_singular : Messages.format(
						JavaUIMessages.ResourceTransferDragAdapter_cannot_delete_files_plural, String.valueOf(childrenCount)), status, IStatus.ERROR);
		error.open();
	}
}
 
Example #9
Source File: RenameFieldProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private RefactoringStatus checkNestedHierarchy(IType type) throws CoreException {
	IType[] nestedTypes= type.getTypes();
	if (nestedTypes == null)
		return null;
	RefactoringStatus result= new RefactoringStatus();
	for (int i= 0; i < nestedTypes.length; i++){
		IField otherField= nestedTypes[i].getField(getNewElementName());
		if (otherField.exists()){
			String msg= Messages.format(
				RefactoringCoreMessages.RenameFieldRefactoring_hiding,
				new String[]{ BasicElementLabels.getJavaElementName(fField.getElementName()), BasicElementLabels.getJavaElementName(getNewElementName()), BasicElementLabels.getJavaElementName(nestedTypes[i].getFullyQualifiedName('.'))});
			result.addWarning(msg, JavaStatusContext.create(otherField));
		}
		result.merge(checkNestedHierarchy(nestedTypes[i]));
	}
	return result;
}
 
Example #10
Source File: JavaElementLinks.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected String getSimpleTypeName(IJavaElement enclosingElement, String typeSig) {
	String typeName= super.getSimpleTypeName(enclosingElement, typeSig);
	
	String title= ""; //$NON-NLS-1$
	String qualifiedName= Signature.toString(Signature.getTypeErasure(typeSig));
	int qualifierLength= qualifiedName.length() - typeName.length() - 1;
	if (qualifierLength > 0) {
		if (qualifiedName.endsWith(typeName)) {
			title= qualifiedName.substring(0, qualifierLength);
			title= Messages.format(JavaUIMessages.JavaElementLinks_title, title);
		} else {
			title= qualifiedName; // Not expected. Just show the whole qualifiedName.
		}
	}
	
	try {
		String uri= createURI(JAVADOC_SCHEME, enclosingElement, qualifiedName, null, null);
		return createHeaderLink(uri, typeName, title);
	} catch (URISyntaxException e) {
		JavaPlugin.log(e);
		return typeName;
	}
}
 
Example #11
Source File: AddFolderToBuildpathAction.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_toBuildpath;

	Object obj= getSelectedElements().get(0);
	String elementLabel= JavaElementLabels.getTextLabel(obj, JavaElementLabels.ALL_DEFAULT);
	if (obj instanceof IJavaProject) {
		return Messages.format(NewWizardMessages.PackageExplorerActionGroup_FormText_ProjectToBuildpath, elementLabel);
	} else if (obj instanceof IPackageFragment) {
		return Messages.format(NewWizardMessages.PackageExplorerActionGroup_FormText_PackageToBuildpath, elementLabel);
	} else if (obj instanceof IResource) {
		return Messages.format(NewWizardMessages.PackageExplorerActionGroup_FormText_FolderToBuildpath, elementLabel);
	}

	return null;
}
 
Example #12
Source File: ReorgPolicyFactory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public String createNewName(ICompilationUnit cu, IPackageFragment destination) {
	if (isNewNameOk(destination, cu.getElementName()))
		return null;
	if (!ReorgUtils.isParentInWorkspaceOrOnDisk(cu, destination))
		return null;
	int i= 1;
	while (true) {
		String newName;
		if (i == 1)
			newName= Messages.format(RefactoringCoreMessages.CopyRefactoring_cu_copyOf1, cu.getElementName()); // Don't use BasicElementLabels! No RTL!
		else
			newName= Messages.format(RefactoringCoreMessages.CopyRefactoring_cu_copyOfMore, new String[] { String.valueOf(i), cu.getElementName()}); // Don't use BasicElementLabels! No RTL!
		if (isNewNameOk(destination, newName) && !fAutoGeneratedNewNames.contains(newName)) {
			fAutoGeneratedNewNames.add(newName);
			return JavaCore.removeJavaLikeExtension(newName);
		}
		i++;
	}
}
 
Example #13
Source File: UnresolvedElementsSubProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static void getAmbiguosTypeReferenceProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) throws CoreException {
	final ICompilationUnit cu= context.getCompilationUnit();
	int offset= problem.getOffset();
	int len= problem.getLength();

	IJavaElement[] elements= cu.codeSelect(offset, len);
	for (int i= 0; i < elements.length; i++) {
		IJavaElement curr= elements[i];
		if (curr instanceof IType && !TypeFilter.isFiltered((IType) curr)) {
			String qualifiedTypeName= ((IType) curr).getFullyQualifiedName('.');

			CompilationUnit root= context.getASTRoot();

			String label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_importexplicit_description, BasicElementLabels.getJavaElementName(qualifiedTypeName));
			Image image= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_IMPDECL);
			ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, cu, ASTRewrite.create(root.getAST()), IProposalRelevance.IMPORT_EXPLICIT, image);

			ImportRewrite imports= proposal.createImportRewrite(root);
			imports.addImport(qualifiedTypeName);

			proposals.add(proposal);
		}
	}
}
 
Example #14
Source File: FilterDescriptor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates a new <code>ViewerFilter</code>.
 * This method is only valid for viewer filters.
 * @return a new <code>ViewerFilter</code>
 */
public ViewerFilter createViewerFilter() {
	if (!isCustomFilter())
		return null;

	final ViewerFilter[] result= new ViewerFilter[1];
	String message= Messages.format(FilterMessages.FilterDescriptor_filterCreationError_message, getId());
	ISafeRunnable code= new SafeRunnable(message) {
		/*
		 * @see org.eclipse.core.runtime.ISafeRunnable#run()
		 */
		public void run() throws Exception {
			result[0]= (ViewerFilter)fElement.createExecutableExtension(CLASS_ATTRIBUTE);
		}

	};
	SafeRunner.run(code);
	return result[0];
}
 
Example #15
Source File: ChangeSignatureProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private RefactoringStatus checkParameterNamesInRippleMethods() throws JavaModelException {
	RefactoringStatus result= new RefactoringStatus();
	Set<String> newParameterNames= getNewParameterNamesList();
	for (int i= 0; i < fRippleMethods.length; i++) {
		String[] paramNames= fRippleMethods[i].getParameterNames();
		for (int j= 0; j < paramNames.length; j++) {
			if (newParameterNames.contains(paramNames[j])){
				String[] args= new String[]{ JavaElementUtil.createMethodSignature(fRippleMethods[i]), BasicElementLabels.getJavaElementName(paramNames[j])};
				String msg= Messages.format(RefactoringCoreMessages.ChangeSignatureRefactoring_already_has, args);
				RefactoringStatusContext context= JavaStatusContext.create(fRippleMethods[i].getCompilationUnit(), fRippleMethods[i].getNameRange());
				result.addError(msg, context);
			}
		}
	}
	return result;
}
 
Example #16
Source File: NLSRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static RefactoringStatus checkKey(String key) {
	RefactoringStatus result= new RefactoringStatus();

	if (key == null)
		result.addFatalError(NLSMessages.NLSRefactoring_null);

	if (key.startsWith("!") || key.startsWith("#")) { //$NON-NLS-1$ //$NON-NLS-2$
		RefactoringStatusContext context= new JavaStringStatusContext(key, new SourceRange(0, 0));
		result.addWarning(NLSMessages.NLSRefactoring_warning, context);
	}

	if ("".equals(key.trim())) //$NON-NLS-1$
		result.addFatalError(NLSMessages.NLSRefactoring_empty);

	final String[] UNWANTED_STRINGS= {" ", ":", "\"", "\\", "'", "?", "="}; //$NON-NLS-7$ //$NON-NLS-6$ //$NON-NLS-5$ //$NON-NLS-4$ //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-1$
	//feature in resource bundle - does not work properly if keys have ":"
	for (int i= 0; i < UNWANTED_STRINGS.length; i++) {
		if (key.indexOf(UNWANTED_STRINGS[i]) != -1) {
			String[] args= {key, UNWANTED_STRINGS[i]};
			String msg= Messages.format(NLSMessages.NLSRefactoring_should_not_contain, args);
			result.addError(msg);
		}
	}
	return result;
}
 
Example #17
Source File: ChangeSignatureProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private RefactoringStatus checkOriginalVarargs() throws JavaModelException {
	if (JdtFlags.isVarargs(fMethod))
		fOldVarargIndex= fMethod.getNumberOfParameters() - 1;
	List<ParameterInfo> notDeletedInfos= getNotDeletedInfos();
	for (int i= 0; i < notDeletedInfos.size(); i++) {
		ParameterInfo info= notDeletedInfos.get(i);
		if (info.isOldVarargs() && ! info.isNewVarargs())
			return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.ChangeSignatureRefactoring_cannot_convert_vararg, BasicElementLabels.getJavaElementName(info.getNewName())));
		if (i != notDeletedInfos.size() - 1) {
			// not the last parameter
			if (info.isNewVarargs())
				return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.ChangeSignatureRefactoring_vararg_must_be_last, BasicElementLabels.getJavaElementName(info.getNewName())));
		}
	}
	return null;
}
 
Example #18
Source File: ExtractInterfaceProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Checks whether the type name is valid.
 *
 * @param name
 *            the name to check
 * @return the status of the condition checking
 */
public final RefactoringStatus checkTypeName(final String name) {
	Assert.isNotNull(name);
	try {
		final RefactoringStatus result= Checks.checkTypeName(name, fSubType);
		if (result.hasFatalError())
			return result;
		final String unitName= JavaModelUtil.getRenamedCUName(fSubType.getCompilationUnit(), name);
		result.merge(Checks.checkCompilationUnitName(unitName, fSubType));
		if (result.hasFatalError())
			return result;
		final IPackageFragment fragment= fSubType.getPackageFragment();
		if (fragment.getCompilationUnit(unitName).exists()) {
			result.addFatalError(Messages.format(RefactoringCoreMessages.ExtractInterfaceProcessor_existing_compilation_unit, new String[] { BasicElementLabels.getResourceName(unitName), JavaElementLabels.getElementLabel(fragment, JavaElementLabels.ALL_DEFAULT) }));
			return result;
		}
		result.merge(checkSuperType());
		return result;
	} catch (JavaModelException exception) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractInterfaceProcessor_internal_error);
	}
}
 
Example #19
Source File: ModifyDialogTabPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void updateWidget() {
    final boolean hasKey= getKey() != null;

    fNumberLabel.setEnabled(hasKey && getEnabled());
	fNumberText.setEnabled(hasKey && getEnabled());

	if (hasKey) {
	    String s= getPreferences().get(getKey());
	    try {
	        fSelected= Integer.parseInt(s);
	    } catch (NumberFormatException e) {
	        final String message= Messages.format(FormatterMessages.ModifyDialogTabPage_NumberPreference_error_invalid_key, getKey());
	        JavaPlugin.log(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IStatus.OK, message, e));
	        s= ""; //$NON-NLS-1$
	    }
	    fNumberText.setText(s);
	} else {
	    fNumberText.setText(""); //$NON-NLS-1$
	}
}
 
Example #20
Source File: UnusedCodeFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static String getDisplayString(SimpleName simpleName, IBinding binding, boolean removeAllAssignements) {
	String name= BasicElementLabels.getJavaElementName(simpleName.getIdentifier());
	switch (binding.getKind()) {
		case IBinding.TYPE:
			return Messages.format(FixMessages.UnusedCodeFix_RemoveType_description, name);
		case IBinding.METHOD:
			if (((IMethodBinding) binding).isConstructor()) {
				return Messages.format(FixMessages.UnusedCodeFix_RemoveConstructor_description, name);
			} else {
				return Messages.format(FixMessages.UnusedCodeFix_RemoveMethod_description, name);
			}
		case IBinding.VARIABLE:
			if (removeAllAssignements) {
				return Messages.format(FixMessages.UnusedCodeFix_RemoveFieldOrLocalWithInitializer_description, name);
			} else {
				return Messages.format(FixMessages.UnusedCodeFix_RemoveFieldOrLocal_description, name);
			}
		default:
			return ""; //$NON-NLS-1$
	}
}
 
Example #21
Source File: NativeLibrariesPropertyPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private IClasspathEntry handleContainerEntry(IPath containerPath, IJavaProject jproject, IPath jarPath) throws JavaModelException {
	ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(containerPath.segment(0));
	IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, jproject);
	if (initializer == null || container == null) {
		setDescription(Messages.format(PreferencesMessages.NativeLibrariesPropertyPage_invalid_container, BasicElementLabels.getPathLabel(containerPath, false)));
		return null;
	}
	String containerName= container.getDescription();
	IStatus status= initializer.getAttributeStatus(containerPath, jproject, JavaRuntime.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY);
	if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_NOT_SUPPORTED) {
		setDescription(Messages.format(PreferencesMessages.NativeLibrariesPropertyPage_not_supported, containerName));
		return null;
	}
	IClasspathEntry entry= JavaModelUtil.findEntryInContainer(container, jarPath);
	if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY) {
		setDescription(Messages.format(PreferencesMessages.NativeLibrariesPropertyPage_read_only, containerName));
		fIsReadOnly= true;
		return entry;
	}
	Assert.isNotNull(entry);
	return entry;
}
 
Example #22
Source File: CompilationUnitRewriteOperationsFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public CompilationUnitChange createChange(IProgressMonitor progressMonitor) throws CoreException {
	CompilationUnitRewrite cuRewrite= new CompilationUnitRewrite((ICompilationUnit)fCompilationUnit.getJavaElement(), fCompilationUnit);

	fLinkedProposalModel.clear();
	for (int i= 0; i < fOperations.length; i++) {
		CompilationUnitRewriteOperation operation= fOperations[i];
		operation.rewriteAST(cuRewrite, fLinkedProposalModel);
	}

	CompilationUnitChange result= cuRewrite.createChange(getDisplayString(), true, null);
	if (result == null)
		throw new CoreException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, Messages.format(FixMessages.CompilationUnitRewriteOperationsFix_nullChangeError, getDisplayString())));

	return result;
}
 
Example #23
Source File: NLSSourceModifier.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void addAccessor(NLSSubstitution sub, TextChange change, String accessorName) {
	if (sub.getState() == NLSSubstitution.EXTERNALIZED) {
		NLSElement element= sub.getNLSElement();
		Region position= element.getPosition();
		String[] args= {sub.getValueNonEmpty(), BasicElementLabels.getJavaElementName(sub.getKey())};
		String text= Messages.format(NLSMessages.NLSSourceModifier_externalize, args);

		String resourceGetter= createResourceGetter(sub.getKey(), accessorName);

		TextEdit edit= new ReplaceEdit(position.getOffset(), position.getLength(), resourceGetter);
		if (fIsEclipseNLS && element.getTagPosition() != null) {
			MultiTextEdit multiEdit= new MultiTextEdit();
			multiEdit.addChild(edit);
			Region tagPosition= element.getTagPosition();
			multiEdit.addChild(new DeleteEdit(tagPosition.getOffset(), tagPosition.getLength()));
			edit= multiEdit;
		}
		TextChangeCompatibility.addTextEdit(change, text, edit);
	}
}
 
Example #24
Source File: MemberVisibilityAdjustor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public void rewriteVisibility(final MemberVisibilityAdjustor adjustor, final IProgressMonitor monitor) throws JavaModelException {
	Assert.isNotNull(adjustor);
	Assert.isNotNull(monitor);
	try {
		monitor.beginTask("", 1); //$NON-NLS-1$
		monitor.setTaskName(RefactoringCoreMessages.MemberVisibilityAdjustor_adjusting);
		if (fNeedsRewriting) {
			if (adjustor.fRewrite != null && adjustor.fRoot != null)
				rewriteVisibility(adjustor, adjustor.fRewrite, adjustor.fRoot, null, fRefactoringStatus);
			else {
				final CompilationUnitRewrite rewrite= adjustor.getCompilationUnitRewrite(fMember.getCompilationUnit());
				rewriteVisibility(adjustor, rewrite.getASTRewrite(), rewrite.getRoot(), rewrite.createCategorizedGroupDescription(Messages.format(RefactoringCoreMessages.MemberVisibilityAdjustor_change_visibility, getLabel(getKeyword())), SET_VISIBILITY_ADJUSTMENTS), fRefactoringStatus);
			}
		} else if (fRefactoringStatus != null)
			adjustor.fStatus.merge(fRefactoringStatus);
		monitor.worked(1);
	} finally {
		monitor.done();
	}
}
 
Example #25
Source File: AddUnimplementedConstructorsAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public IStatus validate(Object[] selection) {
	int count= countSelectedMethods(selection);
	if (count == 0)
		return new StatusInfo(IStatus.ERROR, ""); //$NON-NLS-1$
	String message= Messages.format(ActionMessages.AddUnimplementedConstructorsAction_methods_selected, new Object[] { String.valueOf(count), String.valueOf(fEntries)});
	return new StatusInfo(IStatus.INFO, message);
}
 
Example #26
Source File: ExtractConstantRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private ExtractConstantDescriptor createRefactoringDescriptor() {
	final Map<String, String> arguments= new HashMap<String, String>();
	String project= null;
	IJavaProject javaProject= fCu.getJavaProject();
	if (javaProject != null)
		project= javaProject.getElementName();
	int flags= JavaRefactoringDescriptor.JAR_REFACTORING | JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT;
	if (JdtFlags.getVisibilityCode(fVisibility) != Modifier.PRIVATE)
		flags|= RefactoringDescriptor.STRUCTURAL_CHANGE;

	final String expression= ASTNodes.asString(fSelectedExpression.getAssociatedExpression());
	final String description= Messages.format(RefactoringCoreMessages.ExtractConstantRefactoring_descriptor_description_short, BasicElementLabels.getJavaElementName(fConstantName));
	final String header= Messages.format(RefactoringCoreMessages.ExtractConstantRefactoring_descriptor_description, new String[] { BasicElementLabels.getJavaElementName(fConstantName), BasicElementLabels.getJavaCodeString(expression)});
	final JDTRefactoringDescriptorComment comment= new JDTRefactoringDescriptorComment(project, this, header);
	comment.addSetting(Messages.format(RefactoringCoreMessages.ExtractConstantRefactoring_constant_name_pattern, BasicElementLabels.getJavaElementName(fConstantName)));
	comment.addSetting(Messages.format(RefactoringCoreMessages.ExtractConstantRefactoring_constant_expression_pattern, BasicElementLabels.getJavaCodeString(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);
	arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(project, fCu));
	arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME, fConstantName);
	arguments.put(JavaRefactoringDescriptorUtil.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());

	ExtractConstantDescriptor descriptor= RefactoringSignatureDescriptorFactory.createExtractConstantDescriptor(project, description, comment.asString(), arguments, flags);
	return descriptor;
}
 
Example #27
Source File: TableTextCellEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
   * Processes a modify event that occurred in this text cell editor.
   * This framework method performs validation and sets the error message
   * accordingly, and then reports a change via <code>fireEditorValueChanged</code>.
   * Subclasses should call this method at appropriate times. Subclasses
   * may extend or reimplement.
   *
   * @param e the SWT modify event
   */
  protected void editOccured(ModifyEvent e) {
      String value = text.getText();
      boolean oldValidState = isValueValid();
      boolean newValidState = isCorrect(value);
      if (!newValidState) {
          // try to insert the current value into the error message.
          setErrorMessage(Messages.format(getErrorMessage(),
                  new Object[] { value }));
      }
      valueChanged(oldValidState, newValidState);
fireModifyEvent(text.getText()); // update model on-the-fly
  }
 
Example #28
Source File: CompletionProposalCategory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Checks that the given attribute value is not <code>null</code>.
 *
 * @param value the element to be checked
 * @param attribute the attribute
 * @throws CoreException if <code>value</code> is <code>null</code>
 */
private void checkNotNull(Object value, String attribute) throws CoreException {
	if (value == null) {
		Object[] args= { getId(), fElement.getContributor().getName(), attribute };
		String message= Messages.format(JavaTextMessages.CompletionProposalComputerDescriptor_illegal_attribute_message, args);
		IStatus status= new Status(IStatus.WARNING, JavaPlugin.getPluginId(), IStatus.OK, message, null);
		throw new CoreException(status);
	}
}
 
Example #29
Source File: LinkedNamesAssistProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public StyledString getStyledDisplayString() {
	StyledString str= new StyledString(fLabel);

	String shortCutString= CorrectionCommandHandler.getShortCutString(getCommandId());
	if (shortCutString != null) {
		String decorated= Messages.format(CorrectionMessages.ChangeCorrectionProposal_name_with_shortcut, new String[] { fLabel, shortCutString });
		return StyledCellLabelProvider.styleDecoratedString(decorated, StyledString.QUALIFIER_STYLER, str);
	}
	return str;
}
 
Example #30
Source File: UnimplementedCodeFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static UnimplementedCodeFix createMakeTypeAbstractFix(CompilationUnit root, IProblemLocation problem) {
	ASTNode typeNode= getSelectedTypeNode(root, problem);
	if (!(typeNode instanceof TypeDeclaration))
		return null;

	TypeDeclaration typeDeclaration= (TypeDeclaration) typeNode;
	MakeTypeAbstractOperation operation= new MakeTypeAbstractOperation(typeDeclaration);

	String label= Messages.format(CorrectionMessages.ModifierCorrectionSubProcessor_addabstract_description, BasicElementLabels.getJavaElementName(typeDeclaration.getName().getIdentifier()));
	return new UnimplementedCodeFix(label, root, new CompilationUnitRewriteOperation[] { operation });
}