Java Code Examples for org.eclipse.jdt.ui.JavaUI#ID_PLUGIN

The following examples show how to use org.eclipse.jdt.ui.JavaUI#ID_PLUGIN . 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: BuildSettingWizardPage.java    From sarl with Apache License 2.0 6 votes vote down vote up
private static File createBackup(IFileStore source, String name) throws CoreException {
	try {
		final File bak = File.createTempFile("eclipse-" + name, ".bak"); //$NON-NLS-1$//$NON-NLS-2$
		copyFile(source, bak);
		return bak;
	} catch (IOException e) {
		final IStatus status = new Status(
				IStatus.ERROR,
				JavaUI.ID_PLUGIN,
				IStatus.ERROR,
				MessageFormat.format(
				NewWizardMessages.NewJavaProjectWizardPageTwo_problem_backup,
				name),
				e);
		throw new CoreException(status);
	}
}
 
Example 2
Source File: CompilationUnitRewriteOperationsFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public CompilationUnitChange createChange(IProgressMonitor progressMonitor) throws CoreException {
	CompilationUnitRewrite cuRewrite= new CompilationUnitRewrite((ICompilationUnit)fCompilationUnit.getJavaElement(), fCompilationUnit);

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

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

	return result;
}
 
Example 3
Source File: CPListElement.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private IStatus evaluateContainerChildStatus(CPListElementAttribute attrib) {
	if (fProject != null) {
		ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(fPath.segment(0));
		if (initializer != null && initializer.canUpdateClasspathContainer(fPath, fProject)) {
			if (attrib.isBuiltIn()) {
				if (CPListElement.SOURCEATTACHMENT.equals(attrib.getKey())) {
					return initializer.getSourceAttachmentStatus(fPath, fProject);
				} else if (CPListElement.ACCESSRULES.equals(attrib.getKey())) {
					return initializer.getAccessRulesStatus(fPath, fProject);
				}
			} else {
				return initializer.getAttributeStatus(fPath, fProject, attrib.getKey());
			}
		}
		return new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY, "", null); //$NON-NLS-1$
	}
	return null;
}
 
Example 4
Source File: BuildPathSupport.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static void updateContainerClasspath(IJavaProject jproject, IPath containerPath, IClasspathEntry newEntry, String[] changedAttributes, IProgressMonitor monitor) throws CoreException {
	IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, jproject);
	if (container == null) {
		throw new CoreException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, IStatus.ERROR, "Container " + containerPath + " cannot be resolved", null));  //$NON-NLS-1$//$NON-NLS-2$
	}
	IClasspathEntry[] entries= container.getClasspathEntries();
	IClasspathEntry[] newEntries= new IClasspathEntry[entries.length];
	for (int i= 0; i < entries.length; i++) {
		IClasspathEntry curr= entries[i];
		if (curr.getEntryKind() == newEntry.getEntryKind() && curr.getPath().equals(newEntry.getPath())) {
			newEntries[i]= getUpdatedEntry(curr, newEntry, changedAttributes, jproject);
		} else {
			newEntries[i]= curr;
		}
	}
	requestContainerUpdate(jproject, container, newEntries);
	monitor.worked(1);
}
 
Example 5
Source File: ClasspathContainerDescriptor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public ClasspathContainerDescriptor(IConfigurationElement configElement) throws CoreException {
	super();
	fConfigElement = configElement;
	fPage= null;

	String id = fConfigElement.getAttribute(ATT_ID);
	String name = configElement.getAttribute(ATT_NAME);
	String pageClassName = configElement.getAttribute(ATT_PAGE_CLASS);

	if (name == null) {
		throw new CoreException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, 0, "Invalid extension (missing name): " + id, null)); //$NON-NLS-1$
	}
	if (pageClassName == null) {
		throw new CoreException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, 0, "Invalid extension (missing page class name): " + id, null)); //$NON-NLS-1$
	}
}
 
Example 6
Source File: CleanUpSelectionDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void updateStatus(IStatus status) {
	int count= 0;
	for (int i= 0; i < fPages.length; i++) {
		count+= fPages[i].getSelectedCleanUpCount();
	}
	if (count == 0) {
		super.updateStatus(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, getEmptySelectionMessage()));
	} else {
		if (status == null) {
			super.updateStatus(StatusInfo.OK_STATUS);
		} else {
			super.updateStatus(status);
		}
	}
}
 
Example 7
Source File: SerialVersionHashOperation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static IFile getClassfile(ITypeBinding typeBinding) throws CoreException {
	// bug 191943
	IType type= (IType) typeBinding.getJavaElement();
	if (type == null || type.getCompilationUnit() == null) {
		return null;
	}

	IRegion region= JavaCore.newRegion();
	region.add(type.getCompilationUnit());

	String name= typeBinding.getBinaryName();
	if (name != null) {
		int packStart= name.lastIndexOf('.');
		if (packStart != -1) {
			name= name.substring(packStart + 1);
		}
	} else {
		throw new CoreException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, CorrectionMessages.SerialVersionHashOperation_error_classnotfound));
	}

	name += ".class"; //$NON-NLS-1$

	IResource[] classFiles= JavaCore.getGeneratedResources(region, false);
	for (int i= 0; i < classFiles.length; i++) {
		IResource resource= classFiles[i];
		if (resource.getType() == IResource.FILE && resource.getName().equals(name)) {
			return (IFile) resource;
		}
	}
	throw new CoreException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, CorrectionMessages.SerialVersionHashOperation_error_classnotfound));
}
 
Example 8
Source File: FormatterModifyDialog.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public FormatterModifyDialog(Shell parentShell, Profile profile, ProfileManager profileManager, ProfileStore profileStore,
		boolean newProfile, String dialogPreferencesKey, String lastSavePathKey) {
	super(parentShell, profile, profileManager, profileStore, newProfile, dialogPreferencesKey, lastSavePathKey);
	this.fProfile = profile;
	this.fKeyLastFocus = JavaUI.ID_PLUGIN + dialogPreferencesKey + DS_KEY_LAST_FOCUS;
	this.fDialogSettings = JavaPlugin.getDefault().getDialogSettings();
}
 
Example 9
Source File: CleanUpAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void runOnMultiple(final ICompilationUnit[] cus) {
	ICleanUp[] cleanUps= getCleanUps(cus);
	if (cleanUps == null)
		return;

	MultiStatus status= new MultiStatus(JavaUI.ID_PLUGIN, IStatus.OK, ActionMessages.CleanUpAction_MultiStateErrorTitle, null);
	for (int i= 0; i < cus.length; i++) {
		ICompilationUnit cu= cus[i];

		if (!ActionUtil.isOnBuildPath(cu)) {
			String cuLocation= BasicElementLabels.getPathLabel(cu.getPath(), false);
			String message= Messages.format(ActionMessages.CleanUpAction_CUNotOnBuildpathMessage, cuLocation);
			status.add(new Status(IStatus.INFO, JavaUI.ID_PLUGIN, IStatus.ERROR, message, null));
		}
	}
	if (!status.isOK()) {
		ErrorDialog.openError(getShell(), getActionName(), null, status);
		return;
	}

	try {
		performRefactoring(cus, cleanUps);
	} catch (InvocationTargetException e) {
		JavaPlugin.log(e);
		if (e.getCause() instanceof CoreException)
			showUnexpectedError((CoreException)e.getCause());
	}
}
 
Example 10
Source File: ClasspathAttributeConfigurationDescriptors.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public ClasspathAttributeConfiguration getInstance() throws CoreException  {
	if (fInstance == null) {
		Object elem= CoreUtility.createExtension(fConfigElement, ATT_CLASS);
		if (elem instanceof ClasspathAttributeConfiguration) {
			fInstance= (ClasspathAttributeConfiguration) elem;
		} else {
			throw new CoreException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, 0, "Invalid extension (page not of type IClasspathContainerPage): " + getKey(), null)); //$NON-NLS-1$
		}
	}
	return fInstance;
}
 
Example 11
Source File: ASTProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Checks whether the given Java element has accessible source.
 *
 * @param je the Java element to test
 * @return <code>true</code> if the element has source
 * @since 3.2
 */
private static boolean hasSource(ITypeRoot je) {
	if (je == null || !je.exists())
		return false;

	try {
		return je.getBuffer() != null;
	} catch (JavaModelException ex) {
		IStatus status= new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, IStatus.OK, "Error in JDT Core during AST creation", ex);  //$NON-NLS-1$
		JavaPlugin.getDefault().getLog().log(status);
	}
	return false;
}
 
Example 12
Source File: SaveParticipantRegistry.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Tells whether one of the active post save listeners needs to be informed about the changed
 * region in this save cycle.
 * 
 * @param unit the unit which is about to be saved
 * @return true if the change regions need do be determined
 * @throws CoreException if something went wrong
 * @since 3.4
 */
public static boolean isChangedRegionsRequired(final ICompilationUnit unit) throws CoreException {
	String message= SaveParticipantMessages.SaveParticipantRegistry_needsChangedRegionFailed;
	final MultiStatus errorStatus= new MultiStatus(JavaUI.ID_PLUGIN, IJavaStatusConstants.EDITOR_CHANGED_REGION_CALCULATION, message, null);

	IPostSaveListener[] listeners= JavaPlugin.getDefault().getSaveParticipantRegistry().getEnabledPostSaveListeners(unit.getJavaProject().getProject());
	try {
		final boolean result[]= new boolean[] {false};
		for (int i= 0; i < listeners.length; i++) {
			final IPostSaveListener listener= listeners[i];
			SafeRunner.run(new ISafeRunnable() {

				public void run() throws Exception {
					if (listener.needsChangedRegions(unit))
						result[0]= true;
				}

				public void handleException(Throwable ex) {
					String msg= Messages.format("The save participant ''{0}'' caused an exception.", new String[] { listener.getId() }); //$NON-NLS-1$
					JavaPlugin.log(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, IJavaStatusConstants.EDITOR_POST_SAVE_NOTIFICATION, msg, ex));

					final String participantName= listener.getName();
					msg= Messages.format(SaveParticipantMessages.SaveParticipantRegistry_needsChangedRegionCausedException, new String[] { participantName, ex.toString() });
					errorStatus.add(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, IJavaStatusConstants.EDITOR_CHANGED_REGION_CALCULATION, msg, null));
				}

			});
			if (result[0])
				return true;
		}
	} finally {
		if (!errorStatus.isOK())
			throw new CoreException(errorStatus);
	}

	return false;
}
 
Example 13
Source File: NewPackageWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void createPackageHtml(IPackageFragmentRoot root, IProgressMonitor monitor) throws CoreException {
	IWorkspace workspace= ResourcesPlugin.getWorkspace();
	IFolder createdPackage= workspace.getRoot().getFolder(fCreatedPackageFragment.getPath());
	IFile packageHtml= createdPackage.getFile(PACKAGE_HTML_FILENAME);
	String charset= packageHtml.getCharset();
	String content= buildPackageHtmlContent(root, charset);
	try {
		packageHtml.create(new ByteArrayInputStream(content.getBytes(charset)), false, monitor);
	} catch (UnsupportedEncodingException e) {
		String message= "charset " + charset + " not supported by platform"; //$NON-NLS-1$ //$NON-NLS-2$
		throw new CoreException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, message, e));
	}
}
 
Example 14
Source File: NewJavaProjectWizardPageTwo.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private File createBackup(IFileStore source, String name) throws CoreException {
	try {
		File bak= File.createTempFile("eclipse-" + name, ".bak");  //$NON-NLS-1$//$NON-NLS-2$
		copyFile(source, bak);
		return bak;
	} catch (IOException e) {
		IStatus status= new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, IStatus.ERROR, Messages.format(NewWizardMessages.NewJavaProjectWizardPageTwo_problem_backup, name), e);
		throw new CoreException(status);
	}
}
 
Example 15
Source File: CleanUpPostSaveListener.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static ICleanUp[] getCleanUps(IProject project) throws CoreException {
	ICleanUp[] cleanUps;
	Map<String, String> settings= CleanUpPreferenceUtil.loadSaveParticipantOptions(new ProjectScope(project));
	if (settings == null) {
		IEclipsePreferences contextNode= InstanceScope.INSTANCE.getNode(JavaUI.ID_PLUGIN);
		String id= contextNode.get(CleanUpConstants.CLEANUP_ON_SAVE_PROFILE, null);
		if (id == null) {
			id= DefaultScope.INSTANCE.getNode(JavaUI.ID_PLUGIN).get(CleanUpConstants.CLEANUP_ON_SAVE_PROFILE, CleanUpConstants.DEFAULT_SAVE_PARTICIPANT_PROFILE);
		}
		throw new CoreException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, Messages.format(FixMessages.CleanUpPostSaveListener_unknown_profile_error_message, id)));
	}

	if (CleanUpOptions.TRUE.equals(settings.get(CleanUpConstants.CLEANUP_ON_SAVE_ADDITIONAL_OPTIONS))) {
		cleanUps= getCleanUps(settings, null);
	} else {
		HashMap<String, String> filteredSettins= new HashMap<String, String>();
		filteredSettins.put(CleanUpConstants.FORMAT_SOURCE_CODE, settings.get(CleanUpConstants.FORMAT_SOURCE_CODE));
		filteredSettins.put(CleanUpConstants.FORMAT_SOURCE_CODE_CHANGES_ONLY, settings.get(CleanUpConstants.FORMAT_SOURCE_CODE_CHANGES_ONLY));
		filteredSettins.put(CleanUpConstants.ORGANIZE_IMPORTS, settings.get(CleanUpConstants.ORGANIZE_IMPORTS));
		Set<String> ids= new HashSet<String>(2);
		ids.add("org.eclipse.jdt.ui.cleanup.format"); //$NON-NLS-1$
		ids.add("org.eclipse.jdt.ui.cleanup.imports"); //$NON-NLS-1$
		cleanUps= getCleanUps(filteredSettins, ids);
	}

	return cleanUps;
}
 
Example 16
Source File: EditorUtility.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private static void throwPartInitException(String message, int code) throws PartInitException {
	IStatus status= new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, code, message, null);
	throw new PartInitException(status);
}
 
Example 17
Source File: StatusInfo.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public String getPlugin() {
	return JavaUI.ID_PLUGIN;
}
 
Example 18
Source File: CleanUpPostSaveListener.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private static CoreException wrapBadLocationException(BadLocationException e) {
	String message= e.getMessage();
	if (message == null)
		message= "BadLocationException"; //$NON-NLS-1$
	return new CoreException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, IRefactoringCoreStatusCodes.BAD_LOCATION, message, e));
}
 
Example 19
Source File: CleanUpAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private void showUnexpectedError(CoreException e) {
	String message2= Messages.format(ActionMessages.CleanUpAction_UnexpectedErrorMessage, e.getStatus().getMessage());
	IStatus status= new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, IStatus.ERROR, message2, null);
	ErrorDialog.openError(getShell(), getActionName(), null, status);
}
 
Example 20
Source File: JarPackagerUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Creates a <code>CoreException</code> with the given parameters.
 *
 * @param	message	a string with the message
 * @param	ex		the exception to be wrapped or <code>null</code> if none
 * @return a CoreException
 */
public static CoreException createCoreException(String message, Exception ex) {
	if (message == null)
		message= ""; //$NON-NLS-1$
	return new CoreException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, IJavaStatusConstants.INTERNAL_ERROR, message, ex));
}