org.eclipse.jdt.ui.JavaElementLabels Java Examples

The following examples show how to use org.eclipse.jdt.ui.JavaElementLabels. 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: ConfigureWorkingSetAssignementAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void run(IStructuredSelection selection) {
	IAdaptable[] elements= getSelectedElements(selection);
	GrayedCheckedModel model= createGrayedCheckedModel(elements, getAllWorkingSets(), null);
	WorkingSetModelAwareSelectionDialog dialog= new WorkingSetModelAwareSelectionDialog(fSite.getShell(), model, elements);

	if (elements.length == 1) {
		IAdaptable element= elements[0];
		String elementName;
		if (element instanceof IResource) {
			elementName= BasicElementLabels.getResourceName((IResource) element);
		} else {
			elementName= JavaElementLabels.getElementLabel((IJavaElement)element, JavaElementLabels.ALL_DEFAULT);
		}
		dialog.setMessage(Messages.format(WorkingSetMessages.ConfigureWorkingSetAssignementAction_DialogMessage_specific, elementName));
	} else {
		dialog.setMessage(Messages.format(WorkingSetMessages.ConfigureWorkingSetAssignementAction_DialogMessage_multi, new Integer(elements.length)));
	}
	if (dialog.open() == Window.OK) {
		updateWorkingSets(dialog.getSelection(), dialog.getGrayed(), elements);
		selectAndReveal(elements);
	}
}
 
Example #2
Source File: PushDownRefactoringProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private RefactoringStatus checkAccessedMethods(IType[] subclasses, IProgressMonitor pm) throws JavaModelException {
	RefactoringStatus result= new RefactoringStatus();
	IMember[] membersToPushDown= MemberActionInfo.getMembers(getInfosForMembersToBeCreatedInSubclassesOfDeclaringClass());
	List<IMember> pushedDownList= Arrays.asList(membersToPushDown);
	IMethod[] accessedMethods= ReferenceFinderUtil.getMethodsReferencedIn(membersToPushDown, pm);
	for (int index= 0; index < subclasses.length; index++) {
		IType targetClass= subclasses[index];
		ITypeHierarchy targetSupertypes= targetClass.newSupertypeHierarchy(null);
		for (int offset= 0; offset < accessedMethods.length; offset++) {
			IMethod method= accessedMethods[offset];
			boolean isAccessible= pushedDownList.contains(method) || canBeAccessedFrom(method, targetClass, targetSupertypes);
			if (!isAccessible) {
				String message= Messages.format(RefactoringCoreMessages.PushDownRefactoring_method_not_accessible, new String[] { JavaElementLabels.getTextLabel(method, JavaElementLabels.ALL_FULLY_QUALIFIED), JavaElementLabels.getTextLabel(targetClass, JavaElementLabels.ALL_FULLY_QUALIFIED) });
				result.addError(message, JavaStatusContext.create(method));
			}
		}
	}
	pm.done();
	return result;
}
 
Example #3
Source File: PushDownRefactoringProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private RefactoringStatus checkAccessedTypes(IType[] subclasses, IProgressMonitor pm) throws JavaModelException {
	RefactoringStatus result= new RefactoringStatus();
	IType[] accessedTypes= getTypesReferencedInMovedMembers(pm);
	for (int index= 0; index < subclasses.length; index++) {
		IType targetClass= subclasses[index];
		ITypeHierarchy targetSupertypes= targetClass.newSupertypeHierarchy(null);
		for (int offset= 0; offset < accessedTypes.length; offset++) {
			IType type= accessedTypes[offset];
			if (!canBeAccessedFrom(type, targetClass, targetSupertypes)) {
				String message= Messages.format(RefactoringCoreMessages.PushDownRefactoring_type_not_accessible, new String[] { JavaElementLabels.getTextLabel(type, JavaElementLabels.ALL_FULLY_QUALIFIED), JavaElementLabels.getTextLabel(targetClass, JavaElementLabels.ALL_FULLY_QUALIFIED) });
				result.addError(message, JavaStatusContext.create(type));
			}
		}
	}
	pm.done();
	return result;
}
 
Example #4
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 #5
Source File: PushDownWizard.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= getSelectedMemberActionInfos();
		final String labelText= selectedMembers.length == 1 ? Messages.format(RefactoringMessages.PushDownInputPage_Mark_selected_members_singular, JavaElementLabels.getElementLabel(
				selectedMembers[0].getMember(), JavaElementLabels.M_PARAMETER_TYPES)) : Messages.format(RefactoringMessages.PushDownInputPage_Mark_selected_members_plural, String
				.valueOf(selectedMembers.length));
		final Map<String, Integer> stringMapping= createStringMappingForSelectedElements();
		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(), RefactoringMessages.PushDownInputPage_Edit_members, labelText, keys, initialSelectionIndex);
		dialog.setBlockOnOpen(true);
		if (dialog.open() == Window.CANCEL)
			return;
		final int action= stringMapping.get(dialog.getSelectedString()).intValue();
		setInfoAction(selectedMembers, action);
	} finally {
		updateWizardPage(preserved, true);
	}
}
 
Example #6
Source File: ReorgUserInputPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
protected Control addLabel(Composite parent) {
	Label label= new Label(parent, SWT.WRAP);
	String text;
	int resources= getResources().length;
	int javaElements= getJavaElements().length;

	if (resources == 0 && javaElements == 1) {
		text= Messages.format(
				ReorgMessages.ReorgUserInputPage_choose_destination_single,
				JavaElementLabels.getElementLabel(getJavaElements()[0], LABEL_FLAGS));
	} else if (resources == 1 && javaElements == 0) {
		text= Messages.format(
				ReorgMessages.ReorgUserInputPage_choose_destination_single,
				BasicElementLabels.getResourceName(getResources()[0]));
	} else {
		text= Messages.format(
				ReorgMessages.ReorgUserInputPage_choose_destination_multi,
				String.valueOf(resources + javaElements));
	}

	label.setText(text);
	GridData data= new GridData(SWT.FILL, SWT.END, true, false);
	data.widthHint= convertWidthInCharsToPixels(50);
	label.setLayoutData(data);
	return label;
}
 
Example #7
Source File: JavaElementLabelComposer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Appends the label for a initializer. Considers the I_* flags.
 *
 * @param initializer the element to render
 * @param flags the rendering flags. Flags with names starting with 'I_' are considered.
 */
public void appendInitializerLabel(IInitializer initializer, long flags) {
	// qualification
	if (getFlag(flags, JavaElementLabels.I_FULLY_QUALIFIED)) {
		appendTypeLabel(initializer.getDeclaringType(), JavaElementLabels.T_FULLY_QUALIFIED | (flags & QUALIFIER_FLAGS));
		fBuffer.append('.');
	}
	fBuffer.append(JavaUIMessages.JavaElementLabels_initializer);

	// post qualification
	if (getFlag(flags, JavaElementLabels.I_POST_QUALIFIED)) {
		int offset= fBuffer.length();
		fBuffer.append(JavaElementLabels.CONCAT_STRING);
		appendTypeLabel(initializer.getDeclaringType(), JavaElementLabels.T_FULLY_QUALIFIED | (flags & QUALIFIER_FLAGS));
		if (getFlag(flags, JavaElementLabels.COLORIZE)) {
			fBuffer.setStyle(offset, fBuffer.length() - offset, QUALIFIER_STYLE);
		}
	}
}
 
Example #8
Source File: MoveInstanceMethodProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
protected final void adjustTypeVisibility(final ITypeBinding binding) throws JavaModelException {
	Assert.isNotNull(binding);
	final IJavaElement element= binding.getJavaElement();
	if (element instanceof IType) {
		final IType type= (IType) element;
		if (!type.isBinary() && !type.isReadOnly() && !Flags.isPublic(type.getFlags())) {
			boolean same= false;
			final CompilationUnitRewrite rewrite= getCompilationUnitRewrite(fRewrites, type.getCompilationUnit());
			final AbstractTypeDeclaration declaration= ASTNodeSearchUtil.getAbstractTypeDeclarationNode(type, rewrite.getRoot());
			if (declaration != null) {
				final ITypeBinding declaring= declaration.resolveBinding();
				if (declaring != null && Bindings.equals(declaring.getPackage(), fTarget.getType().getPackage()))
					same= true;
				final Modifier.ModifierKeyword keyword= same ? null : Modifier.ModifierKeyword.PUBLIC_KEYWORD;
				final String modifier= same ? RefactoringCoreMessages.MemberVisibilityAdjustor_change_visibility_default : RefactoringCoreMessages.MemberVisibilityAdjustor_change_visibility_public;
				if (MemberVisibilityAdjustor.hasLowerVisibility(binding.getModifiers(), same ? Modifier.NONE : keyword == null ? Modifier.NONE : keyword.toFlagValue()) && MemberVisibilityAdjustor.needsVisibilityAdjustments(type, keyword, fAdjustments))
					fAdjustments.put(type, new MemberVisibilityAdjustor.OutgoingMemberVisibilityAdjustment(type, keyword, RefactoringStatus.createWarningStatus(Messages.format(RefactoringCoreMessages.MemberVisibilityAdjustor_change_visibility_type_warning, new String[] { BindingLabelProvider.getBindingLabel(declaration.resolveBinding(), JavaElementLabels.ALL_FULLY_QUALIFIED), modifier }), JavaStatusContext.create(type.getCompilationUnit(), declaration))));
			}
		}
	}
}
 
Example #9
Source File: NLSSearchResultLabelProvider2.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private StyledString internalGetText(Object element) {
	String description;
	StyledString elementLabel;

	if (element instanceof FileEntry) {
		FileEntry fileEntry= (FileEntry) element;
		description= fileEntry.getMessage();
		elementLabel= getPropertiesName(fileEntry.getPropertiesFile());
	} else if (element instanceof CompilationUnitEntry) {
		CompilationUnitEntry cuEntry= (CompilationUnitEntry) element;
		description= cuEntry.getMessage();
		elementLabel= JavaElementLabels.getStyledTextLabel(cuEntry.getCompilationUnit(), (JavaElementLabels.ALL_POST_QUALIFIED | JavaElementLabels.COLORIZE));
	} else {
		description= NLSSearchMessages.NLSSearchResultLabelProvider2_undefinedKeys;
		elementLabel= JavaElementLabels.getStyledTextLabel(element, (JavaElementLabels.ALL_POST_QUALIFIED | JavaElementLabels.COLORIZE));
	}
	return new StyledString(description).append(' ').append(elementLabel);
}
 
Example #10
Source File: PullUpRefactoringProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void checkFieldTypes(final IProgressMonitor monitor, final RefactoringStatus status) throws JavaModelException {
	final Map<IMember, Set<IMember>> mapping= getMatchingMembers(getDestinationTypeHierarchy(monitor), getDestinationType(), true);
	for (int i= 0; i < fMembersToMove.length; i++) {
		if (fMembersToMove[i].getElementType() != IJavaElement.FIELD)
			continue;
		final IField field= (IField) fMembersToMove[i];
		final String type= Signature.toString(field.getTypeSignature());
		Assert.isTrue(mapping.containsKey(field));
		for (final Iterator<IMember> iter= mapping.get(field).iterator(); iter.hasNext();) {
			final IField matchingField= (IField) iter.next();
			if (field.equals(matchingField))
				continue;
			if (type.equals(Signature.toString(matchingField.getTypeSignature())))
				continue;
			final String[] keys= { JavaElementLabels.getTextLabel(matchingField, JavaElementLabels.ALL_FULLY_QUALIFIED), JavaElementLabels.getTextLabel(matchingField.getDeclaringType(), JavaElementLabels.ALL_FULLY_QUALIFIED)};
			final String message= Messages.format(RefactoringCoreMessages.PullUpRefactoring_different_field_type, keys);
			final RefactoringStatusContext context= JavaStatusContext.create(matchingField.getCompilationUnit(), matchingField.getSourceRange());
			status.addError(message, context);
		}
	}
}
 
Example #11
Source File: JavadocHover.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static void addAnnotation(StringBuffer buf, IJavaElement element, IAnnotationBinding annotation) throws URISyntaxException {
	IJavaElement javaElement= annotation.getAnnotationType().getJavaElement();
	buf.append('@');
	if (javaElement != null) {
		String uri= JavaElementLinks.createURI(JavaElementLinks.JAVADOC_SCHEME, javaElement);
		addLink(buf, uri, annotation.getName());
	} else {
		buf.append(annotation.getName());
	}
	
	IMemberValuePairBinding[] mvPairs= annotation.getDeclaredMemberValuePairs();
	if (mvPairs.length > 0) {
		buf.append('(');
		for (int j= 0; j < mvPairs.length; j++) {
			if (j > 0) {
				buf.append(JavaElementLabels.COMMA_STRING);
			}
			IMemberValuePairBinding mvPair= mvPairs[j];
			String memberURI= JavaElementLinks.createURI(JavaElementLinks.JAVADOC_SCHEME, mvPair.getMethodBinding().getJavaElement());
			addLink(buf, memberURI, mvPair.getName());
			buf.append('=');
			addValue(buf, element, mvPair.getValue());
		}
		buf.append(')');
	}
}
 
Example #12
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 #13
Source File: SelfEncapsulateFieldInputPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void fillWithPossibleInsertPositions(Combo combo, IField field) {
	int select= 0;
	combo.add(RefactoringMessages.SelfEncapsulateFieldInputPage_first_method);
	try {
		IMethod[] methods= field.getDeclaringType().getMethods();
		for (int i= 0; i < methods.length; i++) {
			combo.add(JavaElementLabels.getElementLabel(methods[i], JavaElementLabels.M_PARAMETER_TYPES));
		}
		if (methods.length > 0)
			select= methods.length;
	} catch (JavaModelException e) {
		// Fall through
	}
	combo.select(select);
	fRefactoring.setInsertionIndex(select - 1);
}
 
Example #14
Source File: RenameLocalVariableProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private RenameJavaElementDescriptor createRefactoringDescriptor() {
	String project= null;
	IJavaProject javaProject= fCu.getJavaProject();
	if (javaProject != null)
		project= javaProject.getElementName();
	final String header= Messages.format(RefactoringCoreMessages.RenameLocalVariableProcessor_descriptor_description, new String[] { BasicElementLabels.getJavaElementName(fCurrentName), JavaElementLabels.getElementLabel(fLocalVariable.getParent(), JavaElementLabels.ALL_FULLY_QUALIFIED), BasicElementLabels.getJavaElementName(fNewName)});
	final String description= Messages.format(RefactoringCoreMessages.RenameLocalVariableProcessor_descriptor_description_short, BasicElementLabels.getJavaElementName(fCurrentName));
	final String comment= new JDTRefactoringDescriptorComment(project, this, header).asString();
	final RenameJavaElementDescriptor descriptor= RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_LOCAL_VARIABLE);
	descriptor.setProject(project);
	descriptor.setDescription(description);
	descriptor.setComment(comment);
	descriptor.setFlags(RefactoringDescriptor.NONE);
	descriptor.setJavaElement(fLocalVariable);
	descriptor.setNewName(getNewElementName());
	descriptor.setUpdateReferences(fUpdateReferences);
	return descriptor;
}
 
Example #15
Source File: JavaOutlineInformationControl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public String getText(Object element) {
	// XXX: This method is NOT USED any more since this is an IStyledLabelProvider.
	// Furthermore, we have no idea what fShowDefiningType is supposed to do if inherited members are shown...
	// If this is put into use again, remember that this needs to be considered in setMatcherString(..)!
	String text= super.getText(element);
	if (fShowDefiningType) {
		try {
			IType type= getDefiningType(element);
			if (type != null) {
				StringBuffer buf= new StringBuffer(super.getText(type));
				buf.append(JavaElementLabels.CONCAT_STRING);
				buf.append(text);
				return buf.toString();
			}
		} catch (JavaModelException e) {
			// go with the simple label
		}
	}
	return text;
}
 
Example #16
Source File: ExternalizeStringsAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private List<NonNLSElement> analyze(IPackageFragmentRoot sourceFolder, IProgressMonitor pm) throws CoreException {
	try{
		IJavaElement[] children= sourceFolder.getChildren();
		pm.beginTask("", children.length); //$NON-NLS-1$
		pm.setTaskName(JavaElementLabels.getElementLabel(sourceFolder, JavaElementLabels.ALL_DEFAULT));
		List<NonNLSElement> result= new ArrayList<NonNLSElement>();
		for (int i= 0; i < children.length; i++) {
			IJavaElement iJavaElement= children[i];
			if (iJavaElement.getElementType() == IJavaElement.PACKAGE_FRAGMENT){
				IPackageFragment pack= (IPackageFragment)iJavaElement;
				if (! pack.isReadOnly())
					result.addAll(analyze(pack, new SubProgressMonitor(pm, 1)));
				else
					pm.worked(1);
			} else
				pm.worked(1);
		}
		return result;
	} finally{
		pm.done();
	}
}
 
Example #17
Source File: BindingLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static void getLocalVariableLabel(IVariableBinding binding, long flags, StringBuffer buffer) {
	if (((flags & JavaElementLabels.F_PRE_TYPE_SIGNATURE) != 0)) {
		getTypeLabel(binding.getType(), (flags & JavaElementLabels.T_TYPE_PARAMETERS), buffer);
		buffer.append(' ');
	}
	if (((flags & JavaElementLabels.F_FULLY_QUALIFIED) != 0)) {
		IMethodBinding declaringMethod= binding.getDeclaringMethod();
		if (declaringMethod != null) {
			getMethodLabel(declaringMethod, flags, buffer);
			buffer.append('.');
		}
	}
	buffer.append(binding.getName());
	if (((flags & JavaElementLabels.F_APP_TYPE_SIGNATURE) != 0)) {
		buffer.append(JavaElementLabels.DECL_STRING);
		getTypeLabel(binding.getType(), (flags & JavaElementLabels.T_TYPE_PARAMETERS), buffer);
	}
}
 
Example #18
Source File: LoggedCreateTargetChange.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public RefactoringStatus isValid(IProgressMonitor monitor) throws CoreException, OperationCanceledException {
	if (fSelection instanceof IJavaElement) {
		final IJavaElement element= (IJavaElement) fSelection;
		if (!Checks.isAvailable(element))
			RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.RenameResourceChange_does_not_exist, JavaElementLabels.getTextLabel(fSelection, JavaElementLabels.ALL_DEFAULT)));
	} else if (fSelection instanceof IResource) {
		final IResource resource= (IResource) fSelection;
		if (!resource.exists())
			RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.RenameResourceChange_does_not_exist, JavaElementLabels.getTextLabel(fSelection, JavaElementLabels.ALL_DEFAULT)));
	}
	return new RefactoringStatus();
}
 
Example #19
Source File: StatusBarUpdater.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected String formatMessage(ISelection sel) {
	if (sel instanceof IStructuredSelection && !sel.isEmpty()) {
		IStructuredSelection selection= (IStructuredSelection) sel;

		int nElements= selection.size();
		if (nElements > 1) {
			return Messages.format(JavaUIMessages.StatusBarUpdater_num_elements_selected, String.valueOf(nElements));
		} else {
			Object elem= selection.getFirstElement();
			if (elem instanceof IJavaElement) {
				return formatJavaElementMessage((IJavaElement) elem);
			} else if (elem instanceof IResource) {
				return formatResourceMessage((IResource) elem);
			} else if (elem instanceof PackageFragmentRootContainer) {
				PackageFragmentRootContainer container= (PackageFragmentRootContainer) elem;
				return container.getLabel() + JavaElementLabels.CONCAT_STRING + container.getJavaProject().getElementName();
			} else if (elem instanceof IJarEntryResource) {
				IJarEntryResource jarEntryResource= (IJarEntryResource) elem;
				StringBuffer buf= new StringBuffer(BasicElementLabels.getResourceName(jarEntryResource.getName()));
				buf.append(JavaElementLabels.CONCAT_STRING);
				IPath fullPath= jarEntryResource.getFullPath();
				if (fullPath.segmentCount() > 1) {
					buf.append(BasicElementLabels.getPathLabel(fullPath.removeLastSegments(1), false));
					buf.append(JavaElementLabels.CONCAT_STRING);
				}
				buf.append(JavaElementLabels.getElementLabel(jarEntryResource.getPackageFragmentRoot(), JavaElementLabels.ROOT_POST_QUALIFIED));
				return buf.toString();
			} else if (elem instanceof IAdaptable) {
				IWorkbenchAdapter wbadapter= (IWorkbenchAdapter) ((IAdaptable)elem).getAdapter(IWorkbenchAdapter.class);
				if (wbadapter != null) {
					return wbadapter.getLabel(elem);
				}
			}
		}
	}
	return "";  //$NON-NLS-1$
}
 
Example #20
Source File: BindingLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static void getTypeArgumentsLabel(ITypeBinding[] typeArgs, long flags, StringBuffer buf) {
	if (typeArgs.length > 0) {
		buf.append('<');
		for (int i = 0; i < typeArgs.length; i++) {
			if (i > 0) {
				buf.append(JavaElementLabels.COMMA_STRING);
			}
			getTypeLabel(typeArgs[i], flags & JavaElementLabels.T_TYPE_PARAMETERS, buf);
		}
		buf.append('>');
	}
}
 
Example #21
Source File: ConvertAnonymousToNestedRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private RefactoringChangeDescriptor createRefactoringDescriptor() {
	final ITypeBinding binding= fAnonymousInnerClassNode.resolveBinding();
	final String[] labels= new String[] { BindingLabelProvider.getBindingLabel(binding, JavaElementLabels.ALL_FULLY_QUALIFIED), BindingLabelProvider.getBindingLabel(binding.getDeclaringMethod(), JavaElementLabels.ALL_FULLY_QUALIFIED)};
	final Map<String, String> arguments= new HashMap<String, String>();
	final String projectName= fCu.getJavaProject().getElementName();
	final int flags= RefactoringDescriptor.STRUCTURAL_CHANGE | JavaRefactoringDescriptor.JAR_REFACTORING | JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT;
	final String description= RefactoringCoreMessages.ConvertAnonymousToNestedRefactoring_descriptor_description_short;
	final String header= Messages.format(RefactoringCoreMessages.ConvertAnonymousToNestedRefactoring_descriptor_description, labels);
	final JDTRefactoringDescriptorComment comment= new JDTRefactoringDescriptorComment(projectName, this, header);
	comment.addSetting(Messages.format(RefactoringCoreMessages.ConvertAnonymousToNestedRefactoring_original_pattern, BindingLabelProvider.getBindingLabel(binding, JavaElementLabels.ALL_FULLY_QUALIFIED)));
	comment.addSetting(Messages.format(RefactoringCoreMessages.ConvertAnonymousToNestedRefactoring_class_name_pattern, BasicElementLabels.getJavaElementName(fClassName)));
	String visibility= JdtFlags.getVisibilityString(fVisibility);
	if (visibility.length() == 0)
		visibility= RefactoringCoreMessages.ConvertAnonymousToNestedRefactoring_default_visibility;
	comment.addSetting(Messages.format(RefactoringCoreMessages.ConvertAnonymousToNestedRefactoring_visibility_pattern, visibility));
	if (fDeclareFinal && fDeclareStatic)
		comment.addSetting(RefactoringCoreMessages.ConvertAnonymousToNestedRefactoring_declare_final_static);
	else if (fDeclareFinal)
		comment.addSetting(RefactoringCoreMessages.ConvertAnonymousToNestedRefactoring_declare_final);
	else if (fDeclareStatic)
		comment.addSetting(RefactoringCoreMessages.ConvertAnonymousToNestedRefactoring_declare_static);
	arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(projectName, fCu));
	arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME, fClassName);
	arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_SELECTION, new Integer(fSelectionStart).toString() + ' ' + new Integer(fSelectionLength).toString());
	arguments.put(ATTRIBUTE_FINAL, Boolean.valueOf(fDeclareFinal).toString());
	arguments.put(ATTRIBUTE_STATIC, Boolean.valueOf(fDeclareStatic).toString());
	arguments.put(ATTRIBUTE_VISIBILITY, new Integer(fVisibility).toString());

	ConvertAnonymousDescriptor descriptor= RefactoringSignatureDescriptorFactory.createConvertAnonymousDescriptor(projectName, description, comment.asString(), arguments, flags);
	return new RefactoringChangeDescriptor(descriptor);
}
 
Example #22
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 #23
Source File: JavaEditorBreadcrumb.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the label provider to use for the tool tips.
 *
 * @return a label provider for the tool tips
 */
private ILabelProvider createToolTipLabelProvider() {
	final AppearanceAwareLabelProvider result= new AppearanceAwareLabelProvider(AppearanceAwareLabelProvider.DEFAULT_TEXTFLAGS | JavaElementLabels.F_APP_TYPE_SIGNATURE
			| JavaElementLabels.ALL_CATEGORY, JavaElementImageProvider.SMALL_ICONS | AppearanceAwareLabelProvider.DEFAULT_IMAGEFLAGS);

	return new DecoratingJavaLabelProvider(result);
}
 
Example #24
Source File: GenerateHashCodeEqualsAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private RefactoringStatus checkHashCodeEqualsExists(ITypeBinding someType, boolean superClass) {

		RefactoringStatus status= new RefactoringStatus();
		HashCodeEqualsInfo info= getTypeInfo(someType, true);

		String concreteTypeWarning= superClass ? ActionMessages.GenerateMethodAbstractAction_super_class : ActionMessages.GenerateHashCodeEqualsAction_field_type;
		String concreteMethWarning= (someType.isInterface() || Modifier.isAbstract(someType.getModifiers()))
				? ActionMessages.GenerateHashCodeEqualsAction_interface_does_not_declare_hashCode_equals_error
				: ActionMessages.GenerateHashCodeEqualsAction_type_does_not_implement_hashCode_equals_error;
		String concreteHCEWarning= null;

		if (!info.foundEquals && (!info.foundHashCode))
			concreteHCEWarning= ActionMessages.GenerateHashCodeEqualsAction_equals_and_hashCode;
		else if (!info.foundEquals)
			concreteHCEWarning= ActionMessages.GenerateHashCodeEqualsAction_equals;
		else if (!info.foundHashCode)
			concreteHCEWarning= ActionMessages.GenerateHashCodeEqualsAction_hashCode;

		if (!info.foundEquals || !info.foundHashCode)
			status.addWarning(Messages.format(concreteMethWarning, new String[] {
					Messages.format(concreteTypeWarning, BindingLabelProvider.getBindingLabel(someType, JavaElementLabels.ALL_FULLY_QUALIFIED)), concreteHCEWarning }),
					createRefactoringStatusContext(someType.getJavaElement()));

		if (superClass && (info.foundFinalEquals || info.foundFinalHashCode)) {
			status.addError(Messages.format(ActionMessages.GenerateMethodAbstractAction_final_method_in_superclass_error, new String[] {
					Messages.format(concreteTypeWarning, BasicElementLabels.getJavaElementName(someType.getQualifiedName())), ActionMessages.GenerateHashCodeEqualsAction_hashcode_or_equals }),
					createRefactoringStatusContext(someType.getJavaElement()));
		}

		return status;
	}
 
Example #25
Source File: RenameTypeProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException {
	IType primary= (IType) fType.getPrimaryElement();
	if (primary == null || !primary.exists()) {
		String qualifiedTypeName= JavaElementLabels.getElementLabel(fType, JavaElementLabels.F_FULLY_QUALIFIED);
		String message= Messages.format(RefactoringCoreMessages.RenameTypeRefactoring_does_not_exist, new String[] { BasicElementLabels.getJavaElementName(qualifiedTypeName), BasicElementLabels.getFileName(fType.getCompilationUnit())});
		return RefactoringStatus.createFatalErrorStatus(message);
	}
	fType= primary;
	return Checks.checkIfCuBroken(fType);
}
 
Example #26
Source File: MethodsViewer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void showInheritedMethodsNoRedraw(boolean on) {
	MethodsContentProvider cprovider= (MethodsContentProvider) getContentProvider();
	cprovider.showInheritedMethods(on);
	fShowInheritedMembersAction.setChecked(on);
	if (on) {
		fLabelProvider.setTextFlags(fLabelProvider.getTextFlags() | JavaElementLabels.ALL_POST_QUALIFIED);
	} else {
		fLabelProvider.setTextFlags(fLabelProvider.getTextFlags() & ~JavaElementLabels.ALL_POST_QUALIFIED);
	}
	if (on) {
		sortByDefiningTypeNoRedraw(false);
	}
	fSortByDefiningTypeAction.setEnabled(!on);

}
 
Example #27
Source File: MoveMembersWizard.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void setVisible(boolean visible){
	if (visible){
		IMember[] membersToMove= getMoveProcessor().getMembersToMove();
		int membersToMoveCount= membersToMove.length;
		String label= JavaElementLabels.getElementLabel(getMoveProcessor().getDeclaringType(), JavaElementLabels.ALL_FULLY_QUALIFIED);
		String message= membersToMoveCount == 1 ? Messages.format(RefactoringMessages.MoveMembersInputPage_descriptionKey_singular, new String[] {
				JavaElementLabels.getTextLabel(membersToMove[0], JavaElementLabels.ALL_FULLY_QUALIFIED), label }) : Messages.format(
				RefactoringMessages.MoveMembersInputPage_descriptionKey_plural, new String[] { new Integer(membersToMoveCount).toString(), label });
		setDescription(message);
	}
	super.setVisible(visible);
}
 
Example #28
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 #29
Source File: RenameEnumConstProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected RenameJavaElementDescriptor createRefactoringDescriptor() {
	final IField field= getField();
	String project= null;
	IJavaProject javaProject= field.getJavaProject();
	if (javaProject != null)
		project= javaProject.getElementName();
	int flags= JavaRefactoringDescriptor.JAR_MIGRATION | JavaRefactoringDescriptor.JAR_REFACTORING | RefactoringDescriptor.STRUCTURAL_CHANGE;
	final IType declaring= field.getDeclaringType();
	try {
		if (!Flags.isPrivate(declaring.getFlags()))
			flags|= RefactoringDescriptor.MULTI_CHANGE;
		if (declaring.isAnonymous() || declaring.isLocal())
			flags|= JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT;
	} catch (JavaModelException exception) {
		JavaPlugin.log(exception);
	}
	final String description= Messages.format(RefactoringCoreMessages.RenameEnumConstProcessor_descriptor_description_short, BasicElementLabels.getJavaElementName(fField.getElementName()));
	final String header= Messages.format(RefactoringCoreMessages.RenameEnumConstProcessor_descriptor_description, new String[] { BasicElementLabels.getJavaElementName(field.getElementName()), JavaElementLabels.getElementLabel(field.getParent(), JavaElementLabels.ALL_FULLY_QUALIFIED), BasicElementLabels.getJavaElementName(getNewElementName())});
	final String comment= new JDTRefactoringDescriptorComment(project, this, header).asString();
	final RenameJavaElementDescriptor descriptor= RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_ENUM_CONSTANT);
	descriptor.setProject(project);
	descriptor.setDescription(description);
	descriptor.setComment(comment);
	descriptor.setFlags(flags);
	descriptor.setJavaElement(field);
	descriptor.setNewName(getNewElementName());
	descriptor.setUpdateReferences(fUpdateReferences);
	descriptor.setUpdateTextualOccurrences(fUpdateTextualMatches);
	return descriptor;
}
 
Example #30
Source File: RenameLocalVariableProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public RefactoringStatus checkNewElementName(String newName) throws JavaModelException {
	RefactoringStatus result= Checks.checkFieldName(newName, fCu);
	if (! Checks.startsWithLowerCase(newName))
		if (fIsComposite) {
			final String nameOfParent= JavaElementLabels.getElementLabel(fLocalVariable.getParent(), JavaElementLabels.ALL_DEFAULT);
			final String nameOfType= JavaElementLabels.getElementLabel(fLocalVariable.getAncestor(IJavaElement.TYPE), JavaElementLabels.ALL_DEFAULT);
			result.addWarning(Messages.format(RefactoringCoreMessages.RenameTempRefactoring_lowercase2, new String[] { BasicElementLabels.getJavaElementName(newName), nameOfParent, nameOfType }));
		} else {
			result.addWarning(RefactoringCoreMessages.RenameTempRefactoring_lowercase);
		}
	return result;
}