Java Code Examples for org.eclipse.jdt.ui.JavaElementLabels#getElementLabel()

The following examples show how to use org.eclipse.jdt.ui.JavaElementLabels#getElementLabel() . 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: AbstractInfoView.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Computes the contents description that will be displayed for the current element.
 *
 * @param part the part that triggered the current element update, or <code>null</code>
 * @param selection the new selection, or <code>null</code>
 * @param inputElement the new java element that will be displayed
 * @param localASTMonitor a progress monitor
 * @return the contents description for the provided <code>inputElement</code>
 * @since 3.4
 */
protected String computeDescription(IWorkbenchPart part, ISelection selection, IJavaElement inputElement, IProgressMonitor localASTMonitor) {
	long flags;
	if (inputElement instanceof ILocalVariable)
		flags= LOCAL_VARIABLE_TITLE_FLAGS;
	else if (inputElement instanceof ITypeParameter)
		flags= TYPE_PARAMETER_TITLE_FLAGS;
	else
		flags= TITLE_FLAGS;

	return JavaElementLabels.getElementLabel(inputElement, flags);
}
 
Example 2
Source File: JavaSearchQuery.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private String getSearchPatternDescription() {
	if (fPatternData instanceof ElementQuerySpecification) {
		IJavaElement element= ((ElementQuerySpecification) fPatternData).getElement();
		return JavaElementLabels.getElementLabel(element, JavaElementLabels.ALL_DEFAULT
				| JavaElementLabels.ALL_FULLY_QUALIFIED | JavaElementLabels.USE_RESOLVED | JavaElementLabels.P_COMPRESSED);
	}
	return BasicElementLabels.getFilePattern(((PatternQuerySpecification) fPatternData).getPattern());
}
 
Example 3
Source File: JavaElementHyperlink.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public String getHyperlinkText() {
	if (fQualify && fElement != null) {
		String elementLabel= JavaElementLabels.getElementLabel(fElement, JavaElementLabels.ALL_POST_QUALIFIED);
		return Messages.format(JavaEditorMessages.JavaElementHyperlink_hyperlinkText_qualified, new Object[] { elementLabel });
	} else {
		return JavaEditorMessages.JavaElementHyperlink_hyperlinkText;
	}
}
 
Example 4
Source File: JavaDeleteProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static boolean skipDeletingReferencedRoot(IConfirmQuery query, IPackageFragmentRoot root, List<IJavaProject> referencingProjects) throws OperationCanceledException {
	if (referencingProjects.isEmpty() || root == null || ! root.exists() ||! root.isArchive())
		return false;
	String label= JavaElementLabels.getElementLabel(root, JavaElementLabels.ALL_DEFAULT);
	String question= referencingProjects.size() == 1 ? Messages.format(RefactoringCoreMessages.DeleteRefactoring_3_singular, label) : Messages.format(
			RefactoringCoreMessages.DeleteRefactoring_3_plural, label);
	return ! query.confirm(question, referencingProjects.toArray());
}
 
Example 5
Source File: JavaElementReturnTypeHyperlink.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public String getHyperlinkText() {
	if (fQualify) {
		String methodLabel= JavaElementLabels.getElementLabel(fMethod, JavaElementLabels.ALL_FULLY_QUALIFIED);
		return Messages.format(JavaEditorMessages.JavaElementReturnTypeHyperlink_hyperlinkText_qualified, new Object[] { methodLabel });
	} else {
		return JavaEditorMessages.JavaElementReturnTypeHyperlink_hyperlinkText;
	}
}
 
Example 6
Source File: JavaElementDeclaredTypeHyperlink.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public String getHyperlinkText() {
	if (fQualify) {
		if (fTypeSig == null) {
			String elementLabel= JavaElementLabels.getElementLabel(fElement, JavaElementLabels.ALL_FULLY_QUALIFIED);
			return Messages.format(JavaEditorMessages.JavaElementDeclaredTypeHyperlink_hyperlinkText_qualified, new Object[] { elementLabel });
		} else {
			String type= Signature.toString(fTypeSig);
			return Messages.format(JavaEditorMessages.JavaElementDeclaredTypeHyperlink_hyperlinkText_qualified_signature, new Object[] { type });
		}
	} else {
		return JavaEditorMessages.JavaElementDeclaredTypeHyperlink_hyperlinkText;
	}
}
 
Example 7
Source File: JdtHyperlinkFactory.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public void createHyperlink(Region region, EObject to, IHyperlinkAcceptor acceptor) {
	JvmIdentifiableElement element = (JvmIdentifiableElement) to;
	IJavaElement javaElement = javaElementFinder.findElementFor(element);
	if (javaElement == null)
		return;
	String label = JavaElementLabels.getElementLabel(javaElement, JavaElementLabels.ALL_DEFAULT);
	JdtHyperlink result = jdtHyperlinkProvider.get();
	result.setHyperlinkRegion(region);
	result.setHyperlinkText(label);
	result.setJavaElement(javaElement);
	acceptor.accept(result);
}
 
Example 8
Source File: JavaElementSuperImplementationHyperlink.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public String getHyperlinkText() {
	if (fQualify) {
		String methodLabel= JavaElementLabels.getElementLabel(fMethod, JavaElementLabels.ALL_FULLY_QUALIFIED);
		return Messages.format(JavaEditorMessages.JavaElementSuperImplementationHyperlink_hyperlinkText_qualified, new Object[] { methodLabel });
	} else {
		return JavaEditorMessages.JavaElementSuperImplementationHyperlink_hyperlinkText;
	}
}
 
Example 9
Source File: CallHierarchyViewPart.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Computes the content description for the call hierarchy computation.
 * 
 * @param includeMask the include mask
 * @return the content description
 * @since 3.7
 */
private String computeContentDescription(int includeMask) {
	// see also HistoryAction.getElementLabel(IMember[])
	String scopeDescription= fSearchScopeActions.getFullDescription(includeMask);

	if (fInputElements.length == 1) {
		IMember element= fInputElements[0];
		String elementName= JavaElementLabels.getElementLabel(element, JavaElementLabels.ALL_DEFAULT);
		String[] args= new String[] { elementName, scopeDescription };
		if (fCurrentCallMode == CALL_MODE_CALLERS) {
			switch (element.getElementType()) {
				case IJavaElement.TYPE:
					return Messages.format(CallHierarchyMessages.CallHierarchyViewPart_callsToConstructors, args);
				case IJavaElement.FIELD:
					switch (this.fCurrentFieldMode) {
			            case IJavaSearchConstants.READ_ACCESSES:
							return Messages.format(CallHierarchyMessages.CallHierarchyViewPart_callsToFieldRead, args);
			            case IJavaSearchConstants.WRITE_ACCESSES:
							return Messages.format(CallHierarchyMessages.CallHierarchyViewPart_callsToFieldWrite, args);
						default: // all references
							return Messages.format(CallHierarchyMessages.CallHierarchyViewPart_callsToField, args);
					}
				case IJavaElement.METHOD:
				case IJavaElement.INITIALIZER:
				default:
					return Messages.format(CallHierarchyMessages.CallHierarchyViewPart_callsToMethod, args);
			}
		} else {
			switch (element.getElementType()) {
				case IJavaElement.TYPE:
					return Messages.format(CallHierarchyMessages.CallHierarchyViewPart_callsFromConstructors, args);
				case IJavaElement.FIELD:
				case IJavaElement.METHOD:
				case IJavaElement.INITIALIZER:
				default:
					return Messages.format(CallHierarchyMessages.CallHierarchyViewPart_callsFromMethod, args);
			}
		}

	} else {
		if (fCurrentCallMode == CALL_MODE_CALLERS) {
			switch (fInputElements.length) {
	        	case 0:
	        		Assert.isTrue(false);
	        		return null;
	        	case 2:
	        		return Messages.format(CallHierarchyMessages.CallHierarchyViewPart_callsToMembers_2,
	        				new String[] { getShortLabel(fInputElements[0]), getShortLabel(fInputElements[1]), scopeDescription });

	        	default:
	        		return Messages.format(CallHierarchyMessages.CallHierarchyViewPart_callsToMembers_more,
	        				new String[] { getShortLabel(fInputElements[0]), getShortLabel(fInputElements[1]), scopeDescription });
			}
		} else {
			switch (fInputElements.length) {
				case 0:
					Assert.isTrue(false);
					return null;
				case 2:
					return Messages.format(CallHierarchyMessages.CallHierarchyViewPart_callsFromMembers_2,
							new String[] { getShortLabel(fInputElements[0]), getShortLabel(fInputElements[1]), scopeDescription });

				default:
					return Messages.format(CallHierarchyMessages.CallHierarchyViewPart_callsFromMembers_more,
							new String[] { getShortLabel(fInputElements[0]), getShortLabel(fInputElements[1]), scopeDescription });
			}
		}
	}
}
 
Example 10
Source File: DeletePackageFragmentRootChange.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public String getName() {
	String rootName= JavaElementLabels.getElementLabel(getRoot(), JavaElementLabels.ALL_DEFAULT);
	return Messages.format(RefactoringCoreMessages.DeletePackageFragmentRootChange_delete, rootName);
}
 
Example 11
Source File: MovePackageFragmentRootChange.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public String getName() {
	String rootName= JavaElementLabels.getElementLabel(getRoot(), JavaElementLabels.ALL_DEFAULT);
	String destinationName= BasicElementLabels.getResourceName(getDestination());
	return Messages.format(RefactoringCoreMessages.MovePackageFragmentRootChange_move, new String[] { rootName, destinationName });
}
 
Example 12
Source File: IntroduceIndirectionRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private RefactoringStatus createWarningAboutCall(IMember enclosing, ASTNode concreteNode, String message) {
	String name= JavaElementLabels.getElementLabel(enclosing, JavaElementLabels.ALL_DEFAULT);
	String container= JavaElementLabels.getElementLabel(enclosing.getDeclaringType(), JavaElementLabels.ALL_FULLY_QUALIFIED);
	return RefactoringStatus.createWarningStatus(Messages.format(message, new String[] { name, container }), JavaStatusContext.create(enclosing.getCompilationUnit(), concreteNode));
}
 
Example 13
Source File: RenameSourceFolderChange.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private static String getRootLabel(IPackageFragmentRoot root) {
	return JavaElementLabels.getElementLabel(root, JavaElementLabels.ALL_DEFAULT);
}
 
Example 14
Source File: RenameFieldProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private String getDeclaringTypeLabel() {
	return JavaElementLabels.getElementLabel(fField.getDeclaringType(), JavaElementLabels.ALL_DEFAULT);
}
 
Example 15
Source File: ReplaceInvocationsInputPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private void createMethodSignature(Composite parent) {
	JavaSourceViewer signatureViewer= InputPageUtil.createSignaturePreview(parent);
	String signatureLabel= JavaElementLabels.getElementLabel(fRefactoring.getMethod(), LABEL_FLAGS);
	signatureViewer.getDocument().set(signatureLabel);
}
 
Example 16
Source File: ExtractInterfaceProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public final Change createChange(final IProgressMonitor monitor) throws CoreException, OperationCanceledException {
	Assert.isNotNull(monitor);
	try {
		monitor.beginTask("", 1); //$NON-NLS-1$
		monitor.setTaskName(RefactoringCoreMessages.ExtractInterfaceProcessor_creating);
		final Map<String, String> arguments= new HashMap<String, String>();
		String project= null;
		final IJavaProject javaProject= fSubType.getJavaProject();
		if (javaProject != null)
			project= javaProject.getElementName();
		int flags= JavaRefactoringDescriptor.JAR_MIGRATION | JavaRefactoringDescriptor.JAR_REFACTORING | RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE;
		try {
			if (fSubType.isLocal() || fSubType.isAnonymous())
				flags|= JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT;
		} catch (JavaModelException exception) {
			JavaPlugin.log(exception);
		}
		final IPackageFragment fragment= fSubType.getPackageFragment();
		final ICompilationUnit cu= fragment.getCompilationUnit(JavaModelUtil.getRenamedCUName(fSubType.getCompilationUnit(), fSuperName));
		final IType type= cu.getType(fSuperName);
		final String description= Messages.format(RefactoringCoreMessages.ExtractInterfaceProcessor_description_descriptor_short, BasicElementLabels.getJavaElementName(fSuperName));
		final String header= Messages.format(RefactoringCoreMessages.ExtractInterfaceProcessor_descriptor_description, new String[] { JavaElementLabels.getElementLabel(type, JavaElementLabels.ALL_FULLY_QUALIFIED), JavaElementLabels.getElementLabel(fSubType, JavaElementLabels.ALL_FULLY_QUALIFIED) });
		final JDTRefactoringDescriptorComment comment= new JDTRefactoringDescriptorComment(project, this, header);
		comment.addSetting(Messages.format(RefactoringCoreMessages.ExtractInterfaceProcessor_refactored_element_pattern, JavaElementLabels.getElementLabel(type, JavaElementLabels.ALL_FULLY_QUALIFIED)));
		final String[] settings= new String[fMembers.length];
		for (int index= 0; index < settings.length; index++)
			settings[index]= JavaElementLabels.getElementLabel(fMembers[index], JavaElementLabels.ALL_FULLY_QUALIFIED);
		comment.addSetting(JDTRefactoringDescriptorComment.createCompositeSetting(RefactoringCoreMessages.ExtractInterfaceProcessor_extracted_members_pattern, settings));
		addSuperTypeSettings(comment, true);
		final ExtractInterfaceDescriptor descriptor= RefactoringSignatureDescriptorFactory.createExtractInterfaceDescriptor(project, description, comment.asString(), arguments, flags);
		arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(project, fSubType));
		arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME, fSuperName);
		for (int index= 0; index < fMembers.length; index++)
			arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + (index + 1), JavaRefactoringDescriptorUtil.elementToHandle(project, fMembers[index]));
		arguments.put(ATTRIBUTE_ABSTRACT, Boolean.valueOf(fAbstract).toString());
		arguments.put(ATTRIBUTE_COMMENTS, Boolean.valueOf(fComments).toString());
		arguments.put(ATTRIBUTE_PUBLIC, Boolean.valueOf(fPublic).toString());
		arguments.put(ATTRIBUTE_REPLACE, Boolean.valueOf(fReplace).toString());
		arguments.put(ATTRIBUTE_INSTANCEOF, Boolean.valueOf(fInstanceOf).toString());
		final DynamicValidationRefactoringChange change= new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.ExtractInterfaceRefactoring_name, fChangeManager.getAllChanges());
		final IFile file= ResourceUtil.getFile(fSubType.getCompilationUnit());
		if (fSuperSource != null && fSuperSource.length() > 0)
			change.add(new CreateCompilationUnitChange(fSubType.getPackageFragment().getCompilationUnit(JavaModelUtil.getRenamedCUName(fSubType.getCompilationUnit(), fSuperName)), fSuperSource, file.getCharset(false)));
		monitor.worked(1);
		return change;
	} finally {
		monitor.done();
	}
}
 
Example 17
Source File: SourceActionDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public SourceActionDialog(Shell parent, ILabelProvider labelProvider, ITreeContentProvider contentProvider, CompilationUnitEditor editor, IType type, boolean isConstructor) throws JavaModelException {
	super(parent, labelProvider, contentProvider);
	fEditor= editor;
	fContentProvider= contentProvider;
	fType= type;
	fCommentString= ActionMessages.SourceActionDialog_createMethodComment;
	setEmptyListMessage(ActionMessages.SourceActionDialog_no_entries);

	fWidth= 60;
	fHeight= 18;

	boolean generateCommentsDefault= JavaPreferencesSettings.getCodeGenerationSettings(type.getJavaProject()).createComments;

	IDialogSettings dialogSettings= JavaPlugin.getDefault().getDialogSettings();
	String sectionId= isConstructor ? SETTINGS_SECTION_CONSTRUCTORS : SETTINGS_SECTION_METHODS;
	fSettings= dialogSettings.getSection(sectionId);
	if (fSettings == null)  {
		fSettings= dialogSettings.addNewSection(sectionId);
	}

	fVisibilityModifier= asInt(fSettings.get(SETTINGS_VISIBILITY_MODIFIER), Modifier.PUBLIC);
	fFinal= asBoolean(fSettings.get(SETTINGS_FINAL_MODIFIER), false);
	fSynchronized= asBoolean(fSettings.get(SETTINGS_SYNCHRONIZED_MODIFIER), false);
	fGenerateComment= asBoolean(fSettings.get(SETTINGS_COMMENTS), generateCommentsDefault);
	fInsertPositions= new ArrayList<IJavaElement>();
	fLabels= new ArrayList<String>();

	IJavaElement[] members= fType.getChildren();

	fInsertPositions.add(members.length > 0 ? members[0]: null); // first
	fInsertPositions.add(null); // last

	fLabels.add(ActionMessages.SourceActionDialog_first);
	fLabels.add(ActionMessages.SourceActionDialog_last);

	for (int i = 0; i < members.length; i++) {
		IJavaElement curr= members[i];
		String methodLabel= JavaElementLabels.getElementLabel(curr, JavaElementLabels.M_PARAMETER_TYPES);
		fLabels.add(Messages.format(ActionMessages.SourceActionDialog_after, methodLabel));
		fInsertPositions.add(findSibling(curr, members));
	}
	fInsertPositions.add(null);

	int storedPositionIndex= asInt(fSettings.get(SETTINGS_INSERT_POSITION), INSERT_POSITION_FROM_EDITOR);
	if (storedPositionIndex == INSERT_POSITION_FROM_EDITOR) {
		int indexAfterCursor= getElementAfterCursorPosition(fEditor, members);
		if (indexAfterCursor == -1)
			fCurrentPositionIndex= isConstructor ? INSERT_FIRST_INDEX : INSERT_LAST_INDEX;
		else if (indexAfterCursor == 0)
			fCurrentPositionIndex= INSERT_FIRST_INDEX;
		else if (indexAfterCursor > 0)
			fCurrentPositionIndex= indexAfterCursor + 1;
	} else
		fCurrentPositionIndex= storedPositionIndex <= INSERT_FIRST_INDEX ? INSERT_FIRST_INDEX : INSERT_LAST_INDEX; // handle illegal values already present in the dialog store
}
 
Example 18
Source File: ExtractSupertypeProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Change createChange(final IProgressMonitor monitor) throws CoreException, OperationCanceledException {
	try {
		final Map<String, String> arguments= new HashMap<String, String>();
		String project= null;
		final IType declaring= getDeclaringType();
		final IJavaProject javaProject= declaring.getJavaProject();
		if (javaProject != null)
			project= javaProject.getElementName();
		int flags= JavaRefactoringDescriptor.JAR_MIGRATION | JavaRefactoringDescriptor.JAR_REFACTORING | RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE;
		try {
			if (declaring.isLocal() || declaring.isAnonymous())
				flags|= JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT;
		} catch (JavaModelException exception) {
			JavaPlugin.log(exception);
		}
		final String description= Messages.format(RefactoringCoreMessages.ExtractSupertypeProcessor_descriptor_description_short, BasicElementLabels.getJavaElementName(fTypeName));
		final String header= Messages.format(RefactoringCoreMessages.ExtractSupertypeProcessor_descriptor_description, new String[] { JavaElementLabels.getElementLabel(fDestinationType, JavaElementLabels.ALL_FULLY_QUALIFIED), JavaElementLabels.getElementLabel(fCachedDeclaringType, JavaElementLabels.ALL_FULLY_QUALIFIED)});
		final JDTRefactoringDescriptorComment comment= new JDTRefactoringDescriptorComment(project, this, header);
		final IType[] types= getTypesToExtract();
		String[] settings= new String[types.length];
		for (int index= 0; index < settings.length; index++)
			settings[index]= JavaElementLabels.getElementLabel(types[index], JavaElementLabels.ALL_FULLY_QUALIFIED);
		comment.addSetting(JDTRefactoringDescriptorComment.createCompositeSetting(RefactoringCoreMessages.ExtractSupertypeProcessor_subtypes_pattern, settings));
		comment.addSetting(Messages.format(RefactoringCoreMessages.ExtractSupertypeProcessor_refactored_element_pattern, JavaElementLabels.getElementLabel(fDestinationType, JavaElementLabels.ALL_FULLY_QUALIFIED)));
		settings= new String[fMembersToMove.length];
		for (int index= 0; index < settings.length; index++)
			settings[index]= JavaElementLabels.getElementLabel(fMembersToMove[index], JavaElementLabels.ALL_FULLY_QUALIFIED);
		comment.addSetting(JDTRefactoringDescriptorComment.createCompositeSetting(RefactoringCoreMessages.ExtractInterfaceProcessor_extracted_members_pattern, settings));
		addSuperTypeSettings(comment, true);
		final ExtractSuperclassDescriptor descriptor= RefactoringSignatureDescriptorFactory.createExtractSuperclassDescriptor(project, description, comment.asString(), arguments, flags);
		arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME, fTypeName);
		arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(project, getDeclaringType()));
		arguments.put(ATTRIBUTE_REPLACE, Boolean.valueOf(fReplace).toString());
		arguments.put(ATTRIBUTE_INSTANCEOF, Boolean.valueOf(fInstanceOf).toString());
		arguments.put(ATTRIBUTE_STUBS, Boolean.valueOf(fCreateMethodStubs).toString());
		arguments.put(ATTRIBUTE_EXTRACT, new Integer(fMembersToMove.length).toString());
		for (int offset= 0; offset < fMembersToMove.length; offset++)
			arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + (offset + 1), JavaRefactoringDescriptorUtil.elementToHandle(project, fMembersToMove[offset]));
		arguments.put(ATTRIBUTE_DELETE, new Integer(fDeletedMethods.length).toString());
		for (int offset= 0; offset < fDeletedMethods.length; offset++)
			arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + (offset + fMembersToMove.length + 1), JavaRefactoringDescriptorUtil.elementToHandle(project, fDeletedMethods[offset]));
		arguments.put(ATTRIBUTE_ABSTRACT, new Integer(fAbstractMethods.length).toString());
		for (int offset= 0; offset < fAbstractMethods.length; offset++)
			arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + (offset + fMembersToMove.length + fDeletedMethods.length + 1), JavaRefactoringDescriptorUtil.elementToHandle(project, fAbstractMethods[offset]));
		arguments.put(ATTRIBUTE_TYPES, new Integer(fTypesToExtract.length).toString());
		for (int offset= 0; offset < fTypesToExtract.length; offset++)
			arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + (offset + fMembersToMove.length + fDeletedMethods.length + fAbstractMethods.length + 1), JavaRefactoringDescriptorUtil.elementToHandle(project, fTypesToExtract[offset]));
		final DynamicValidationRefactoringChange change= new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.ExtractSupertypeProcessor_extract_supertype, fChangeManager.getAllChanges());
		final IFile file= ResourceUtil.getFile(declaring.getCompilationUnit());
		if (fSuperSource != null && fSuperSource.length() > 0)
			change.add(new CreateCompilationUnitChange(declaring.getPackageFragment().getCompilationUnit(JavaModelUtil.getRenamedCUName(declaring.getCompilationUnit(), fTypeName)), fSuperSource, file.getCharset(false)));
		return change;
	} finally {
		monitor.done();
		clearCaches();
	}
}
 
Example 19
Source File: IntroduceParameterObjectWizard.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
protected void validateRefactoring() {
	List<String> names= new ArrayList<String>();
	boolean oneChecked= false;
	setMessage(null);
	setErrorMessage(null);
	setPageComplete(true);
	IJavaProject project= fProcessor.getMethod().getJavaProject();
	String sourceLevel= project.getOption(JavaCore.COMPILER_SOURCE, true);
	String compliance= project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
	List<ParameterInfo> parameterInfos= fProcessor.getParameterInfos();
	for (Iterator<ParameterInfo> iter= parameterInfos.iterator(); iter.hasNext();) {
		ParameterInfo pi= iter.next();
		if (names.contains(pi.getNewName())) {
			setErrorMessage(Messages.format(RefactoringMessages.IntroduceParameterObjectWizard_parametername_check_notunique, BasicElementLabels.getJavaElementName(pi.getNewName())));
			setPageComplete(false);
			return;
		}
		names.add(pi.getNewName());
		IStatus validateIdentifier= JavaConventions.validateIdentifier(pi.getNewName(), sourceLevel, compliance);
		if (isErrorMessage(validateIdentifier))
			return;
		if (pi.isCreateField())
			oneChecked= true;
	}
	if (!oneChecked) {
		setErrorMessage(RefactoringMessages.IntroduceParameterObjectWizard_parametername_check_atleastoneparameter);
		setPageComplete(false);
		return;
	}
	IStatus validateJavaTypeName= JavaConventions.validateJavaTypeName(fProcessor.getClassName(), sourceLevel, compliance);
	if (isErrorMessage(validateJavaTypeName))
		return;
	if (fProcessor.getClassName().indexOf('.') != -1) {
		setErrorMessage(RefactoringMessages.IntroduceParameterObjectWizard_dot_not_allowed_error);
		setPageComplete(false);
	}
	if (!"".equals(fProcessor.getPackage())) { //$NON-NLS-1$
		IStatus validatePackageName= JavaConventions.validatePackageName(fProcessor.getPackage(), sourceLevel, compliance);
		if (isErrorMessage(validatePackageName))
			return;
	}
	try {
		IType type= project.findType(fProcessor.getNewTypeName());
		if (type != null) {
			String packageLabel= JavaElementLabels.getElementLabel(type.getPackageFragment(), JavaElementLabels.ALL_DEFAULT);
			if (fProcessor.isCreateAsTopLevel()) {
				setErrorMessage(Messages.format(RefactoringMessages.IntroduceParameterObjectWizard_type_already_exists_in_package_info,
						new Object[] { BasicElementLabels.getJavaElementName(fProcessor.getClassName()), packageLabel }));
				setPageComplete(false);
				return;
			} else {
				setErrorMessage(Messages.format(RefactoringMessages.IntroduceParameterObjectWizard_parametername_check_alreadyexists,
						new Object[] { BasicElementLabels.getJavaElementName(fProcessor.getClassName()), BasicElementLabels.getFileName(type.getCompilationUnit()) }));
				setPageComplete(false);
				return;
			}
		}
	} catch (JavaModelException e) {
		// Don't care. The error will popup later anyway..
	}
}
 
Example 20
Source File: MemberVisibilityAdjustor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Returns the label for the specified java element.
 *
 * @param element the element to get the label for
 * @return the label for the element
 */
public static String getLabel(final IJavaElement element) {
	Assert.isNotNull(element);
	return JavaElementLabels.getElementLabel(element, JavaElementLabels.ALL_FULLY_QUALIFIED | JavaElementLabels.ALL_DEFAULT);
}