Java Code Examples for org.eclipse.jdt.ui.JavaElementLabels#getTextLabel()
The following examples show how to use
org.eclipse.jdt.ui.JavaElementLabels#getTextLabel() .
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: PullUpRefactoringProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
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 2
Source File: JavaBrowsingPart.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Returns the tool tip text for the given element. * @param element the element * @return the tooltip for the element */ String getToolTipText(Object element) { String result; if (!(element instanceof IResource)) { result= JavaElementLabels.getTextLabel(element, AppearanceAwareLabelProvider.DEFAULT_TEXTFLAGS); } else { IPath path= ((IResource) element).getFullPath(); if (path.isRoot()) { result= getConfigurationElement().getAttribute("name"); //$NON-NLS-1$ } else { result= path.makeRelative().toString(); } } if (fWorkingSetFilterActionGroup == null || fWorkingSetFilterActionGroup.getWorkingSet() == null) return result; IWorkingSet ws= fWorkingSetFilterActionGroup.getWorkingSet(); String wsstr= Messages.format(JavaBrowsingMessages.JavaBrowsingPart_toolTip, new String[] { BasicElementLabels.getWorkingSetLabel(ws) }); if (result.length() == 0) return wsstr; return Messages.format(JavaBrowsingMessages.JavaBrowsingPart_toolTip2, new String[] { result, BasicElementLabels.getWorkingSetLabel(ws) }); }
Example 3
Source File: AddFolderToBuildpathAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * {@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 4
Source File: PullUpRefactoringProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private RefactoringStatus checkIfMethodDeclaredIn(final IMethod iMethod, final IType type) throws JavaModelException { final IMethod methodInType= JavaModelUtil.findMethod(iMethod.getElementName(), iMethod.getParameterTypes(), iMethod.isConstructor(), type); if (methodInType == null || !methodInType.exists()) return null; final String[] keys= { JavaElementLabels.getTextLabel(methodInType, JavaElementLabels.ALL_FULLY_QUALIFIED), JavaElementLabels.getTextLabel(type, JavaElementLabels.ALL_FULLY_QUALIFIED)}; final String msg= Messages.format(RefactoringCoreMessages.PullUpRefactoring_Method_declared_in_class, keys); final RefactoringStatusContext context= JavaStatusContext.create(methodInType); return RefactoringStatus.createWarningStatus(msg, context); }
Example 5
Source File: PullUpRefactoringProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private RefactoringStatus checkIfTypeDeclaredIn(final IType iType, final IType type) { final IType typeInType= type.getType(iType.getElementName()); if (!typeInType.exists()) return null; final String[] keys= { JavaElementLabels.getTextLabel(typeInType, JavaElementLabels.ALL_FULLY_QUALIFIED), JavaElementLabels.getTextLabel(type, JavaElementLabels.ALL_FULLY_QUALIFIED)}; final String msg= Messages.format(RefactoringCoreMessages.PullUpRefactoring_Type_declared_in_class, keys); final RefactoringStatusContext context= JavaStatusContext.create(typeInType); return RefactoringStatus.createWarningStatus(msg, context); }
Example 6
Source File: PullUpRefactoringProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void checkMethodReturnTypes(final IProgressMonitor monitor, final RefactoringStatus status, final Set<IMember> notDeletedMembersInSubtypes) throws JavaModelException { final Map<IMember, Set<IMember>> mapping= getMatchingMembers(getDestinationTypeHierarchy(monitor), getDestinationType(), true); final IMember[] members= getCreatedDestinationMembers(); for (int i= 0; i < members.length; i++) { if (members[i].getElementType() != IJavaElement.METHOD) continue; final IMethod method= (IMethod) members[i]; if (mapping.containsKey(method)) { final Set<IMember> set= mapping.get(method); if (set != null) { final String returnType= Signature.toString(Signature.getReturnType(method.getSignature()).toString()); for (final Iterator<IMember> iter= set.iterator(); iter.hasNext();) { final IMethod matchingMethod= (IMethod) iter.next(); if (method.equals(matchingMethod)) continue; if (!notDeletedMembersInSubtypes.contains(matchingMethod)) continue; if (returnType.equals(Signature.toString(Signature.getReturnType(matchingMethod.getSignature()).toString()))) continue; final String[] keys= { JavaElementLabels.getTextLabel(matchingMethod, JavaElementLabels.ALL_FULLY_QUALIFIED), JavaElementLabels.getTextLabel(matchingMethod.getDeclaringType(), JavaElementLabels.ALL_FULLY_QUALIFIED)}; final String message= Messages.format(RefactoringCoreMessages.PullUpRefactoring_different_method_return_type, keys); final RefactoringStatusContext context= JavaStatusContext.create(matchingMethod.getCompilationUnit(), matchingMethod.getNameRange()); status.addError(message, context); } } } } }
Example 7
Source File: InferTypeArgumentsRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException { pm.beginTask("", 1); //$NON-NLS-1$ try { DynamicValidationStateChange result= new DynamicValidationStateChange(RefactoringCoreMessages.InferTypeArgumentsRefactoring_name, fChangeManager.getAllChanges()) { @Override public final ChangeDescriptor getDescriptor() { final Map<String, String> arguments= new HashMap<String, String>(); final IJavaProject project= getSingleProject(); final String description= RefactoringCoreMessages.InferTypeArgumentsRefactoring_descriptor_description; final String header= project != null ? Messages.format(RefactoringCoreMessages.InferTypeArgumentsRefactoring_descriptor_description_project, BasicElementLabels.getJavaElementName(project.getElementName())) : RefactoringCoreMessages.InferTypeArgumentsRefactoring_descriptor_description; final String name= project != null ? project.getElementName() : null; final JDTRefactoringDescriptorComment comment= new JDTRefactoringDescriptorComment(name, this, header); final String[] settings= new String[fElements.length]; for (int index= 0; index < settings.length; index++) settings[index]= JavaElementLabels.getTextLabel(fElements[index], JavaElementLabels.ALL_FULLY_QUALIFIED); comment.addSetting(JDTRefactoringDescriptorComment.createCompositeSetting(RefactoringCoreMessages.InferTypeArgumentsRefactoring_original_elements, settings)); if (fAssumeCloneReturnsSameType) comment.addSetting(RefactoringCoreMessages.InferTypeArgumentsRefactoring_assume_clone); if (fLeaveUnconstrainedRaw) comment.addSetting(RefactoringCoreMessages.InferTypeArgumentsRefactoring_leave_unconstrained); final InferTypeArgumentsDescriptor descriptor= RefactoringSignatureDescriptorFactory.createInferTypeArgumentsDescriptor(name, description, comment.asString(), arguments, RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE); for (int index= 0; index < fElements.length; index++) arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + (index + 1), JavaRefactoringDescriptorUtil.elementToHandle(name, fElements[index])); arguments.put(ATTRIBUTE_CLONE, Boolean.valueOf(fAssumeCloneReturnsSameType).toString()); arguments.put(ATTRIBUTE_LEAVE, Boolean.valueOf(fLeaveUnconstrainedRaw).toString()); return new RefactoringChangeDescriptor(descriptor); } }; return result; } finally { pm.done(); } }
Example 8
Source File: InlineMethodRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static SourceProvider resolveSourceProvider(RefactoringStatus status, ITypeRoot typeRoot, ASTNode invocation) { CompilationUnit root= (CompilationUnit)invocation.getRoot(); IMethodBinding methodBinding= Invocations.resolveBinding(invocation); if (methodBinding == null) { status.addFatalError(RefactoringCoreMessages.InlineMethodRefactoring_error_noMethodDeclaration); return null; } MethodDeclaration declaration= (MethodDeclaration)root.findDeclaringNode(methodBinding); if (declaration != null) { return new SourceProvider(typeRoot, declaration); } IMethod method= (IMethod)methodBinding.getJavaElement(); if (method != null) { CompilationUnit methodDeclarationAstRoot; ICompilationUnit methodCu= method.getCompilationUnit(); if (methodCu != null) { methodDeclarationAstRoot= new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL).parse(methodCu, true); } else { IClassFile classFile= method.getClassFile(); if (! JavaElementUtil.isSourceAvailable(classFile)) { String methodLabel= JavaElementLabels.getTextLabel(method, JavaElementLabels.M_FULLY_QUALIFIED | JavaElementLabels.M_PARAMETER_TYPES); status.addFatalError(Messages.format(RefactoringCoreMessages.InlineMethodRefactoring_error_classFile, methodLabel)); return null; } methodDeclarationAstRoot= new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL).parse(classFile, true); } ASTNode node= methodDeclarationAstRoot.findDeclaringNode(methodBinding.getMethodDeclaration().getKey()); if (node instanceof MethodDeclaration) { return new SourceProvider(methodDeclarationAstRoot.getTypeRoot(), (MethodDeclaration) node); } } status.addFatalError(RefactoringCoreMessages.InlineMethodRefactoring_error_noMethodDeclaration); return null; }
Example 9
Source File: PackageExplorerPart.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Updates the title text and title tool tip. * Called whenever the input of the viewer changes. */ void updateTitle() { Object input= fViewer.getInput(); if (input == null || (input instanceof IJavaModel)) { setContentDescription(""); //$NON-NLS-1$ setTitleToolTip(""); //$NON-NLS-1$ } else { String inputText= JavaElementLabels.getTextLabel(input, AppearanceAwareLabelProvider.DEFAULT_TEXTFLAGS); setContentDescription(inputText); setTitleToolTip(getToolTipText(input)); } }
Example 10
Source File: SortingLabelProvider.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private String getPostQualification(Object element) { String textLabel= JavaElementLabels.getTextLabel(element, JavaElementLabels.ALL_POST_QUALIFIED); int indexOf= textLabel.indexOf(JavaElementLabels.CONCAT_STRING); if (indexOf != -1) { return textLabel.substring(indexOf); } return new String(); }
Example 11
Source File: JavaUILabelProvider.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public String getText(Object element) { String result= JavaElementLabels.getTextLabel(element, evaluateTextFlags(element)); if (result.length() == 0 && (element instanceof IStorage)) { result= fStorageLabelProvider.getText(element); } return decorateText(result, element); }
Example 12
Source File: PullUpRefactoringProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private RefactoringStatus checkIfFieldDeclaredIn(final IField iField, final IType type) { final IField fieldInType= type.getField(iField.getElementName()); if (!fieldInType.exists()) return null; final String[] keys= { JavaElementLabels.getTextLabel(fieldInType, JavaElementLabels.ALL_FULLY_QUALIFIED), JavaElementLabels.getTextLabel(type, JavaElementLabels.ALL_FULLY_QUALIFIED)}; final String msg= Messages.format(RefactoringCoreMessages.PullUpRefactoring_Field_declared_in_class, keys); final RefactoringStatusContext context= JavaStatusContext.create(fieldInType); return RefactoringStatus.createWarningStatus(msg, context); }
Example 13
Source File: HierarchyProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
protected static String createLabel(final IMember member) { if (member instanceof IType) return JavaElementLabels.getTextLabel(member, JavaElementLabels.ALL_FULLY_QUALIFIED); else if (member instanceof IMethod) return JavaElementLabels.getTextLabel(member, JavaElementLabels.ALL_FULLY_QUALIFIED); else if (member instanceof IField) return JavaElementLabels.getTextLabel(member, JavaElementLabels.ALL_FULLY_QUALIFIED); else if (member instanceof IInitializer) return RefactoringCoreMessages.HierarchyRefactoring_initializer; Assert.isTrue(false); return null; }
Example 14
Source File: ReorgPolicyFactory.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
protected String getDestinationLabel() { Object destination= getJavaElementDestination(); if (destination == null) destination= getResourceDestination(); return JavaElementLabels.getTextLabel(destination, JavaElementLabels.ALL_FULLY_QUALIFIED); }
Example 15
Source File: JavaWorkbenchAdapter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public String getLabel(Object element) { return JavaElementLabels.getTextLabel(getJavaElement(element), JavaElementLabels.ALL_DEFAULT); }
Example 16
Source File: JavadocHelpContext.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public String getLabel() { String label= JavaElementLabels.getTextLabel(fElement, JavaElementLabels.ALL_DEFAULT | JavaElementLabels.ALL_FULLY_QUALIFIED); return Messages.format(JavaUIMessages.JavaUIHelp_link_label, label); }
Example 17
Source File: JavadocHelpContext.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public JavadocHelpContext(IContext context, Object[] elements) throws JavaModelException { Assert.isNotNull(elements); if (context instanceof IContext2) fTitle= ((IContext2)context).getTitle(); List<IHelpResource> helpResources= new ArrayList<IHelpResource>(); String javadocSummary= null; for (int i= 0; i < elements.length; i++) { if (elements[i] instanceof IJavaElement) { IJavaElement element= (IJavaElement) elements[i]; // if element isn't on the build path skip it if (!ActionUtil.isOnBuildPath(element)) continue; // Create Javadoc summary if (BUG_85721_FIXED) { if (javadocSummary == null) { javadocSummary= retrieveText(element); if (javadocSummary != null) { String elementLabel= JavaElementLabels.getTextLabel(element, JavaElementLabels.ALL_DEFAULT); // FIXME: needs to be NLSed once the code becomes active javadocSummary= "<b>Javadoc for " + elementLabel + ":</b><br>" + javadocSummary; //$NON-NLS-1$//$NON-NLS-2$ } } else { javadocSummary= ""; // no Javadoc summary for multiple selection //$NON-NLS-1$ } } URL url= JavaUI.getJavadocLocation(element, true); if (url == null || doesNotExist(url)) { IPackageFragmentRoot root= JavaModelUtil.getPackageFragmentRoot(element); if (root != null) { url= JavaUI.getJavadocBaseLocation(element); if (root.getKind() == IPackageFragmentRoot.K_SOURCE) { element= element.getJavaProject(); } else { element= root; } url= JavaUI.getJavadocLocation(element, false); } } if (url != null) { IHelpResource javaResource= new JavaUIHelpResource(element, getURLString(url)); helpResources.add(javaResource); } } } // Add static help topics if (context != null) { IHelpResource[] resources= context.getRelatedTopics(); if (resources != null) { for (int j= 0; j < resources.length; j++) { helpResources.add(resources[j]); } } } fHelpResources= helpResources.toArray(new IHelpResource[helpResources.size()]); if (context != null) fText= context.getText(); if (BUG_85721_FIXED) { if (javadocSummary != null && javadocSummary.length() > 0) { if (fText != null) fText= context.getText() + "<br><br>" + javadocSummary; //$NON-NLS-1$ else fText= javadocSummary; } } if (fText == null) fText= ""; //$NON-NLS-1$ }