org.eclipse.jdt.internal.ui.JavaPlugin Java Examples

The following examples show how to use org.eclipse.jdt.internal.ui.JavaPlugin. 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: SpellCheckEngine.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public synchronized final void shutdown() {

		JavaPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(this);
		EditorsUI.getPreferenceStore().removePropertyChangeListener(this);

		ISpellDictionary dictionary= null;
		for (final Iterator<ISpellDictionary> iterator= fGlobalDictionaries.iterator(); iterator.hasNext();) {
			dictionary= iterator.next();
			dictionary.unload();
		}
		fGlobalDictionaries= null;

		for (final Iterator<ISpellDictionary> iterator= fLocaleDictionaries.values().iterator(); iterator.hasNext();) {
			dictionary= iterator.next();
			dictionary.unload();
		}
		fLocaleDictionaries= null;

		fUserDictionary= null;
		fChecker= null;
	}
 
Example #2
Source File: JavaContext.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Evaluates a 'java' template in the context of a compilation unit
 *
 * @param template the template to be evaluated
 * @param compilationUnit the compilation unit in which to evaluate the template
 * @param position the position inside the compilation unit for which to evaluate the template
 * @return the evaluated template
 * @throws CoreException in case the template is of an unknown context type
 * @throws BadLocationException in case the position is invalid in the compilation unit
 * @throws TemplateException in case the evaluation fails
 */
public static String evaluateTemplate(Template template, ICompilationUnit compilationUnit, int position) throws CoreException, BadLocationException, TemplateException {

	TemplateContextType contextType= JavaPlugin.getDefault().getTemplateContextRegistry().getContextType(template.getContextTypeId());
	if (!(contextType instanceof CompilationUnitContextType))
		throw new CoreException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, IStatus.ERROR, JavaTemplateMessages.JavaContext_error_message, null));

	IDocument document= new Document();
	if (compilationUnit != null && compilationUnit.exists())
		document.set(compilationUnit.getSource());

	CompilationUnitContext context= ((CompilationUnitContextType) contextType).createContext(document, position, 0, compilationUnit);
	context.setForceEvaluation(true);

	TemplateBuffer buffer= context.evaluate(template);
	if (buffer == null)
		return null;
	return buffer.getString();
}
 
Example #3
Source File: LapseView.java    From lapse-plus with GNU General Public License v3.0 6 votes vote down vote up
private CompilationUnit internalSetInput(IOpenable input) throws CoreException {
	IBuffer buffer = input.getBuffer();
	if (buffer == null) {
		JavaPlugin.logErrorMessage("Input has no buffer"); //$NON-NLS-1$
	}
	if (input instanceof ICompilationUnit) {
		fParser.setSource((ICompilationUnit) input);
	} else {
		fParser.setSource((IClassFile) input);
	}

	try {
		CompilationUnit root = (CompilationUnit) fParser.createAST(null);
		log("Recomputed the AST for " + buffer.getUnderlyingResource().getName());
						
		if (root == null) {
			JavaPlugin.logErrorMessage("Could not create AST"); //$NON-NLS-1$
		}

		return root;
	} catch (RuntimeException e) {
		JavaPlugin.logErrorMessage("Could not create AST:\n" + e.getMessage()); //$NON-NLS-1$
		return null;
	}
}
 
Example #4
Source File: CUCorrectionProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object getAdditionalProposalInfo(IProgressMonitor monitor) {
	StringBuffer buf= new StringBuffer();
	try {
		TextChange change= getTextChange();
		change.setKeepPreviewEdits(true);
		IDocument previewDocument= change.getPreviewDocument(monitor);
		TextEdit rootEdit= change.getPreviewEdit(change.getEdit());

		EditAnnotator ea= new EditAnnotator(buf, previewDocument);
		rootEdit.accept(ea);
		ea.unchangedUntil(previewDocument.getLength()); // Final pre-existing region
	} catch (CoreException e) {
		JavaPlugin.log(e);
	}
	return buf.toString();
}
 
Example #5
Source File: LibrariesWorkbookPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private IPath[] getUsedContainers(CPListElement existing) {
	ArrayList<IPath> res= new ArrayList<IPath>();
	if (fCurrJProject.exists()) {
		try {
			IPath outputLocation= fCurrJProject.getOutputLocation();
			if (outputLocation != null && outputLocation.segmentCount() > 1) { // != Project
				res.add(outputLocation);
			}
		} catch (JavaModelException e) {
			// ignore it here, just log
			JavaPlugin.log(e.getStatus());
		}
	}

	List<CPListElement> cplist= fLibrariesList.getElements();
	for (int i= 0; i < cplist.size(); i++) {
		CPListElement elem= cplist.get(i);
		if (elem.getEntryKind() == IClasspathEntry.CPE_LIBRARY && (elem != existing)) {
			IResource resource= elem.getResource();
			if (resource instanceof IContainer && !resource.equals(existing)) {
				res.add(resource.getFullPath());
			}
		}
	}
	return res.toArray(new IPath[res.size()]);
}
 
Example #6
Source File: LazyGenericTypeProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Finds and returns the super type signature in the
 * <code>extends</code> or <code>implements</code> clause of
 * <code>subType</code> that corresponds to <code>superType</code>.
 *
 * @param subType a direct and true sub type of <code>superType</code>
 * @param superType a direct super type (super class or interface) of
 *        <code>subType</code>
 * @return the super type signature of <code>subType</code> referring
 *         to <code>superType</code>
 * @throws JavaModelException if extracting the super type signatures
 *         fails, or if <code>subType</code> contains no super type
 *         signature to <code>superType</code>
 */
private String findMatchingSuperTypeSignature(IType subType, IType superType) throws JavaModelException {
	String[] signatures= getSuperTypeSignatures(subType, superType);
	for (int i= 0; i < signatures.length; i++) {
		String signature= signatures[i];
		String qualified= SignatureUtil.qualifySignature(signature, subType);
		String subFQN= SignatureUtil.stripSignatureToFQN(qualified);

		String superFQN= superType.getFullyQualifiedName();
		if (subFQN.equals(superFQN)) {
			return signature;
		}

		// TODO handle local types
	}

	throw new JavaModelException(new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IStatus.OK, "Illegal hierarchy", null))); //$NON-NLS-1$
}
 
Example #7
Source File: JavaEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void setPreferenceStore(IPreferenceStore store) {
	super.setPreferenceStore(store);
	SourceViewerConfiguration sourceViewerConfiguration= getSourceViewerConfiguration();
	if (sourceViewerConfiguration == null || sourceViewerConfiguration instanceof JavaSourceViewerConfiguration) {
		JavaTextTools textTools= JavaPlugin.getDefault().getJavaTextTools();
		setSourceViewerConfiguration(new JavaSourceViewerConfiguration(textTools.getColorManager(), store, this, IJavaPartitions.JAVA_PARTITIONING));
	}

	if (getSourceViewer() instanceof JavaSourceViewer)
		((JavaSourceViewer)getSourceViewer()).setPreferenceStore(store);

	fMarkOccurrenceAnnotations= store.getBoolean(PreferenceConstants.EDITOR_MARK_OCCURRENCES);
	fStickyOccurrenceAnnotations= store.getBoolean(PreferenceConstants.EDITOR_STICKY_OCCURRENCES);
	fMarkTypeOccurrences= store.getBoolean(PreferenceConstants.EDITOR_MARK_TYPE_OCCURRENCES);
	fMarkMethodOccurrences= store.getBoolean(PreferenceConstants.EDITOR_MARK_METHOD_OCCURRENCES);
	fMarkConstantOccurrences= store.getBoolean(PreferenceConstants.EDITOR_MARK_CONSTANT_OCCURRENCES);
	fMarkFieldOccurrences= store.getBoolean(PreferenceConstants.EDITOR_MARK_FIELD_OCCURRENCES);
	fMarkLocalVariableypeOccurrences= store.getBoolean(PreferenceConstants.EDITOR_MARK_LOCAL_VARIABLE_OCCURRENCES);
	fMarkExceptions= store.getBoolean(PreferenceConstants.EDITOR_MARK_EXCEPTION_OCCURRENCES);
	fMarkImplementors= store.getBoolean(PreferenceConstants.EDITOR_MARK_IMPLEMENTORS);
	fMarkMethodExitPoints= store.getBoolean(PreferenceConstants.EDITOR_MARK_METHOD_EXIT_POINTS);
	fMarkBreakContinueTargets= store.getBoolean(PreferenceConstants.EDITOR_MARK_BREAK_CONTINUE_TARGETS);
}
 
Example #8
Source File: FatJarPackageWizard.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @return all java projects which contain the selected elements in the active workbench window
 */
protected IStructuredSelection getSelectedJavaProjects() {
	ISelection currentSelection= JavaPlugin.getActiveWorkbenchWindow().getSelectionService().getSelection();
	if (currentSelection instanceof IStructuredSelection) {
		IStructuredSelection structuredSelection= (IStructuredSelection) currentSelection;
		HashSet<IJavaProject> selectedElements= new HashSet<IJavaProject>();
		Iterator<?> iter= structuredSelection.iterator();
		while (iter.hasNext()) {
			Object selectedElement= iter.next();
			if (selectedElement instanceof IJavaElement) {
				IJavaProject javaProject= ((IJavaElement) selectedElement).getJavaProject();
				if (javaProject != null)
					selectedElements.add(javaProject);
			}
		}
		return new StructuredSelection(selectedElements);
	} else
		return StructuredSelection.EMPTY;
}
 
Example #9
Source File: RenameCompilationUnitProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private RefactoringStatus initialize(JavaRefactoringArguments extended) {
	final String handle= extended.getAttribute(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT);
	if (handle == null) {
		return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT));
	}

	final IJavaElement element= JavaRefactoringDescriptorUtil.handleToElement(extended.getProject(), handle, false);
	if (element == null || !element.exists() || element.getElementType() != IJavaElement.COMPILATION_UNIT)
		return JavaRefactoringDescriptorUtil.createInputFatalStatus(element, getProcessorName(), IJavaRefactorings.RENAME_COMPILATION_UNIT);

	final String name= extended.getAttribute(JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME);
	if (name == null || name.length() == 0)
		return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME));

	fCu= (ICompilationUnit) element;
	try {
		computeRenameTypeRefactoring();
		setNewElementName(name);
	} catch (CoreException exception) {
		JavaPlugin.log(exception);
		return JavaRefactoringDescriptorUtil.createInputFatalStatus(element, getProcessorName(), IJavaRefactorings.RENAME_COMPILATION_UNIT);
	}
	return new RefactoringStatus();
}
 
Example #10
Source File: CorrectPackageDeclarationProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public String getName() {
	ICompilationUnit cu= getCompilationUnit();
	IPackageFragment parentPack= (IPackageFragment) cu.getParent();
	try {
		IPackageDeclaration[] decls= cu.getPackageDeclarations();
		if (parentPack.isDefaultPackage() && decls.length > 0) {
			return Messages.format(CorrectionMessages.CorrectPackageDeclarationProposal_remove_description, BasicElementLabels.getJavaElementName(decls[0].getElementName()));
		}
		if (!parentPack.isDefaultPackage() && decls.length == 0) {
			return (Messages.format(CorrectionMessages.CorrectPackageDeclarationProposal_add_description,  JavaElementLabels.getElementLabel(parentPack, JavaElementLabels.ALL_DEFAULT)));
		}
	} catch(JavaModelException e) {
		JavaPlugin.log(e);
	}
	return (Messages.format(CorrectionMessages.CorrectPackageDeclarationProposal_change_description, JavaElementLabels.getElementLabel(parentPack, JavaElementLabels.ALL_DEFAULT)));
}
 
Example #11
Source File: JavaTemplatesPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected SourceViewer createPatternViewer(Composite parent) {
	IDocument document= new Document();
	JavaTextTools tools= JavaPlugin.getDefault().getJavaTextTools();
	tools.setupJavaDocumentPartitioner(document, IJavaPartitions.JAVA_PARTITIONING);
	IPreferenceStore store= JavaPlugin.getDefault().getCombinedPreferenceStore();
	JavaSourceViewer viewer= new JavaSourceViewer(parent, null, null, false, SWT.V_SCROLL | SWT.H_SCROLL, store);
	SimpleJavaSourceViewerConfiguration configuration= new SimpleJavaSourceViewerConfiguration(tools.getColorManager(), store, null, IJavaPartitions.JAVA_PARTITIONING, false);
	viewer.configure(configuration);
	viewer.setEditable(false);
	viewer.setDocument(document);

	Font font= JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT);
	viewer.getTextWidget().setFont(font);
	new JavaSourcePreviewerUpdater(viewer, configuration, store);

	Control control= viewer.getControl();
	GridData data= new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.FILL_VERTICAL);
	control.setLayoutData(data);

	viewer.setEditable(false);
	return viewer;
}
 
Example #12
Source File: ClasspathAttributeConfigurationDescriptors.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public ClasspathAttributeConfiguration get(final String attributeKey) {
	final Descriptor desc= getDescriptors().get(attributeKey);
	if (desc == null) {
		return null;
	}
	final ClasspathAttributeConfiguration[] res= { null };
	SafeRunner.run(new ISafeRunnable() {

		public void handleException(Throwable exception) {
			JavaPlugin.log(exception);
			getDescriptors().remove(attributeKey); // remove from list
		}

		public void run() throws Exception {
			res[0]= desc.getInstance();
		}
	});
	return res[0];
}
 
Example #13
Source File: JarWriter3.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void registerInWorkspaceIfNeeded() {
	IPath jarPath= fJarPackage.getAbsoluteJarLocation();
	IProject[] projects= ResourcesPlugin.getWorkspace().getRoot().getProjects();
	for (int i= 0; i < projects.length; i++) {
		IProject project= projects[i];
		// The Jar is always put into the local file system. So it can only be
		// part of a project if the project is local as well. So using getLocation
		// is currently save here.
		IPath projectLocation= project.getLocation();
		if (projectLocation != null && projectLocation.isPrefixOf(jarPath)) {
			try {
				jarPath= jarPath.removeFirstSegments(projectLocation.segmentCount());
				jarPath= jarPath.removeLastSegments(1);
				IResource containingFolder= project.findMember(jarPath);
				if (containingFolder != null && containingFolder.isAccessible())
					containingFolder.refreshLocal(IResource.DEPTH_ONE, null);
			} catch (CoreException ex) {
				// don't refresh the folder but log the problem
				JavaPlugin.log(ex);
			}
		}
	}
}
 
Example #14
Source File: JarImportWizard.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void init(final IWorkbench workbench, final IStructuredSelection selection) {
	if (selection != null && selection.size() == 1) {
		final Object element= selection.getFirstElement();
		if (element instanceof IPackageFragmentRoot) {
			final IPackageFragmentRoot root= (IPackageFragmentRoot) element;
			try {
				final IClasspathEntry entry= root.getRawClasspathEntry();
				if (isValidClassPathEntry(entry)
						&& root.getResolvedClasspathEntry().getReferencingEntry() == null)
					fImportData.setPackageFragmentRoot(root);
			} catch (JavaModelException exception) {
				JavaPlugin.log(exception);
			}
		}
	}
}
 
Example #15
Source File: FixedFatJarExportWizard.java    From sarl with Apache License 2.0 6 votes vote down vote up
/**
 * @return all java projects which contain the selected elements in the active workbench window
 */
protected IStructuredSelection getSelectedJavaProjects() {
	ISelection currentSelection= JavaPlugin.getActiveWorkbenchWindow().getSelectionService().getSelection();
	if (currentSelection instanceof IStructuredSelection) {
		IStructuredSelection structuredSelection= (IStructuredSelection) currentSelection;
		HashSet<IJavaProject> selectedElements= new HashSet<>();
		Iterator<?> iter= structuredSelection.iterator();
		while (iter.hasNext()) {
			Object selectedElement= iter.next();
			if (selectedElement instanceof IJavaElement) {
				IJavaProject javaProject= ((IJavaElement) selectedElement).getJavaProject();
				if (javaProject != null)
					selectedElements.add(javaProject);
			}
		}
		return new StructuredSelection(selectedElements);
	} else
		return StructuredSelection.EMPTY;
}
 
Example #16
Source File: JavaHistoryActionImpl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
final JavaEditor getEditor(IFile file) {
	FileEditorInput fei= new FileEditorInput(file);
	IWorkbench workbench= JavaPlugin.getDefault().getWorkbench();
	IWorkbenchWindow[] windows= workbench.getWorkbenchWindows();
	for (int i= 0; i < windows.length; i++) {
		IWorkbenchPage[] pages= windows[i].getPages();
		for (int x= 0; x < pages.length; x++) {
			IEditorPart[] editors= pages[x].getDirtyEditors();
			for (int z= 0; z < editors.length; z++) {
				IEditorPart ep= editors[z];
				if (ep instanceof JavaEditor) {
					JavaEditor je= (JavaEditor) ep;
					if (fei.equals(je.getEditorInput()))
						return (JavaEditor) ep;
				}
			}
		}
	}
	return null;
}
 
Example #17
Source File: EditorUtility.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static void initializeHighlightRange(IEditorPart editorPart) {
	if (editorPart instanceof ITextEditor) {
		IAction toggleAction= editorPart.getEditorSite().getActionBars().getGlobalActionHandler(ITextEditorActionDefinitionIds.TOGGLE_SHOW_SELECTED_ELEMENT_ONLY);
		boolean enable= toggleAction != null;
		if (enable && editorPart instanceof JavaEditor)
			enable= JavaPlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_SHOW_SEGMENTS);
		else
			enable= enable && toggleAction.isEnabled() && toggleAction.isChecked();
		if (enable) {
			if (toggleAction instanceof TextEditorAction) {
				// Reset the action
				((TextEditorAction)toggleAction).setEditor(null);
				// Restore the action
				((TextEditorAction)toggleAction).setEditor((ITextEditor)editorPart);
			} else {
				// Uncheck
				toggleAction.run();
				// Check
				toggleAction.run();
			}
		}
	}
}
 
Example #18
Source File: SourceViewerInformationControl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns <code>null</code> if {@link SWT#COLOR_INFO_BACKGROUND} is visibly distinct from the
 * default Java source text color. Otherwise, returns the editor background color.
 * 
 * @param display the display
 * @return an RGB or <code>null</code>
 * @since 3.6.1
 */
public static RGB getVisibleBackgroundColor(Display display) {
	float[] infoBgHSB= display.getSystemColor(SWT.COLOR_INFO_BACKGROUND).getRGB().getHSB();
	
	Color javaDefaultColor= JavaUI.getColorManager().getColor(IJavaColorConstants.JAVA_DEFAULT);
	RGB javaDefaultRGB= javaDefaultColor != null ? javaDefaultColor.getRGB() : new RGB(255, 255, 255);
	float[] javaDefaultHSB= javaDefaultRGB.getHSB();
	
	if (Math.abs(infoBgHSB[2] - javaDefaultHSB[2]) < 0.5f) {
		// workaround for dark tooltip background color, see https://bugs.eclipse.org/309334
		IPreferenceStore preferenceStore= JavaPlugin.getDefault().getCombinedPreferenceStore();
		boolean useDefault= preferenceStore.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT);
		if (useDefault)
			return display.getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB();
		return PreferenceConverter.getColor(preferenceStore, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND);
	}
	return null;
}
 
Example #19
Source File: ToggleCommentAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the index of the first line whose start offset is in the given text range.
 *
 * @param region the text range in characters where to find the line
 * @param document The document
 * @return the first line whose start index is in the given range, -1 if there is no such line
 */
private int getFirstCompleteLineOfRegion(IRegion region, IDocument document) {

	try {

		final int startLine= document.getLineOfOffset(region.getOffset());

		int offset= document.getLineOffset(startLine);
		if (offset >= region.getOffset())
			return startLine;

		final int nextLine= startLine + 1;
		if (nextLine == document.getNumberOfLines())
			return -1;

		offset= document.getLineOffset(nextLine);
		return (offset > region.getOffset() + region.getLength() ? -1 : nextLine);

	} catch (BadLocationException x) {
		// should not happen
		JavaPlugin.log(x);
	}

	return -1;
}
 
Example #20
Source File: IntroduceFactoryAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void selectionChanged(IStructuredSelection selection) {
	try {
		setEnabled(RefactoringAvailabilityTester.isIntroduceFactoryAvailable(selection));
	} catch (JavaModelException e) {
		if (JavaModelUtil.isExceptionToBeLogged(e))
			JavaPlugin.log(e);
		setEnabled(false);//no UI here - happens on selection changes
	}
}
 
Example #21
Source File: FixedFatJarExportPage.java    From sarl with Apache License 2.0 5 votes vote down vote up
public Object[] getSelectedElementsWithoutContainedChildren(MultiStatus status) {
	try {
		LaunchConfigurationElement element= fLauchConfigurationModel.get(fLaunchConfigurationCombo.getSelectionIndex());
		ILaunchConfiguration launchconfig= element.getLaunchConfiguration();
		fJarPackage.setLaunchConfigurationName(element.getLaunchConfigurationName());

		return getSelectedElementsWithoutContainedChildren(launchconfig, fJarPackage, getContainer(), status);
	} catch (CoreException e) {
		JavaPlugin.log(e);
		return new Object[0];
	}
}
 
Example #22
Source File: ChangeSignatureProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void updateNode() throws JavaModelException {
	int start= fNode.getStartPosition();
	int length= fNode.getLength();
	String msg= "Cannot update found node: nodeType=" + fNode.getNodeType() + "; "  //$NON-NLS-1$//$NON-NLS-2$
			+ fNode.toString() + "[" + start + ", " + length + "] in " + fCuRewrite.getCu();  //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
	JavaPlugin.log(new Exception(msg + ":\n" + fCuRewrite.getCu().getSource().substring(start, start + length))); //$NON-NLS-1$
	fResult.addError(msg, JavaStatusContext.create(fCuRewrite.getCu(), fNode));
}
 
Example #23
Source File: RenameFieldWizard.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private String checkSetterRenamingEnablement() {
	if (fSetterRenamingErrorMessage != null)
		return  fSetterRenamingErrorMessage;
	try {
		fSetterRenamingErrorMessage= getRenameFieldProcessor().canEnableSetterRenaming();
		return fSetterRenamingErrorMessage;
	} catch (CoreException e) {
		JavaPlugin.log(e);
		return ""; //$NON-NLS-1$
	}
}
 
Example #24
Source File: ChangeTypeRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Do the actual work of computing allowable types. Invoked by the wizard when
 * "compute" button is pressed
 * @param pm the progress monitor
 * @return the valid types
 */
public Collection<ITypeBinding> computeValidTypes(IProgressMonitor pm) {

	pm.beginTask(RefactoringCoreMessages.ChangeTypeRefactoring_checking_preconditions, 100);

	try {
		fCv= findConstraintVariableForSelectedNode(new SubProgressMonitor(pm, 3));
		if (DEBUG) System.out.println("selected CV: " + fCv +  //$NON-NLS-1$
									  " (" + fCv.getClass().getName() +  //$NON-NLS-1$
									  ")");  //$NON-NLS-1$

		if (pm.isCanceled())
			throw new OperationCanceledException();
		fRelevantVars= findRelevantConstraintVars(fCv, new SubProgressMonitor(pm, 50));

		if (DEBUG)
			printCollection("relevant vars:", fRelevantVars); //$NON-NLS-1$

		if (pm.isCanceled())
			throw new OperationCanceledException();
		fRelevantConstraints= findRelevantConstraints(fRelevantVars, new SubProgressMonitor(pm, 30));

		if (pm.isCanceled())
			throw new OperationCanceledException();
		fValidTypes.addAll(computeValidTypes(fSelectionTypeBinding, fRelevantVars,
											 fRelevantConstraints, new SubProgressMonitor(pm, 20)));

		if (DEBUG)
			printCollection("valid types:", getValidTypeNames()); //$NON-NLS-1$
	} catch (CoreException e) {
		JavaPlugin.logErrorMessage("Error occurred during computation of valid types: " + e.toString()); //$NON-NLS-1$
		fValidTypes.clear(); // error occurred during computation of valid types
	}

	pm.done();

	return fValidTypes;
}
 
Example #25
Source File: AbstractJavaCompletionProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public IInformationControlCreator getInformationControlCreator() {
	Shell shell= JavaPlugin.getActiveWorkbenchShell();
	if (shell == null || !BrowserInformationControl.isAvailable(shell))
		return null;

	if (fCreator == null) {
		/*
		 * FIXME: Take control creators (and link handling) out of JavadocHover,
		 * see https://bugs.eclipse.org/bugs/show_bug.cgi?id=232024
		 */
		JavadocHover.PresenterControlCreator presenterControlCreator= new JavadocHover.PresenterControlCreator(getSite());
		fCreator= new JavadocHover.HoverControlCreator(presenterControlCreator, true);
	}
	return fCreator;
}
 
Example #26
Source File: AbstractInformationControl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void gotoSelectedElement() {
	Object selectedElement= getSelectedElement();
	if (selectedElement != null) {
		try {
			dispose();
			IEditorPart part= EditorUtility.openInEditor(selectedElement, true);
			if (part != null && selectedElement instanceof IJavaElement)
				EditorUtility.revealInEditor(part, (IJavaElement) selectedElement);
		} catch (CoreException ex) {
			JavaPlugin.log(ex);
		}
	}
}
 
Example #27
Source File: JavaOutlinePage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void setTopLevelTypeOnly(boolean show) {
	fTopLevelTypeOnly= show;
	setChecked(show);
	fOutlineViewer.refresh(false);

	IPreferenceStore preferenceStore= JavaPlugin.getDefault().getPreferenceStore();
	preferenceStore.setValue("GoIntoTopLevelTypeAction.isChecked", show); //$NON-NLS-1$
}
 
Example #28
Source File: JavaBrowsingPart.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void menuAboutToShow(IMenuManager menu) {
	JavaPlugin.createStandardGroups(menu);

	IStructuredSelection selection= (IStructuredSelection) fViewer.getSelection();
	int size= selection.size();
	Object element= selection.getFirstElement();

	if (size == 1)
		addOpenNewWindowAction(menu, element);
	fActionGroups.setContext(new ActionContext(selection));
	fActionGroups.fillContextMenu(menu);
	fActionGroups.setContext(null);
}
 
Example #29
Source File: FindStringsToExternalizeAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void selectionChanged(IStructuredSelection selection) {
	try {
		setEnabled(computeEnablementState(selection));
	} catch (JavaModelException e) {
		if (JavaModelUtil.isExceptionToBeLogged(e))
			JavaPlugin.log(e);
		setEnabled(false);//no UI - happens on selection changes
	}
}
 
Example #30
Source File: CallHierarchyImageDescriptor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private ImageData getImageData(ImageDescriptor descriptor) {
	ImageData data= descriptor.getImageData(); // see bug 51965: getImageData can return null
	if (data == null) {
		data= DEFAULT_IMAGE_DATA;
		JavaPlugin.logErrorMessage("Image data not available: " + descriptor.toString()); //$NON-NLS-1$
	}
	return data;
}