org.eclipse.jdt.ui.cleanup.ICleanUp Java Examples

The following examples show how to use org.eclipse.jdt.ui.cleanup.ICleanUp. 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: CleanUpRefactoringWizard.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void initializeRefactoring() {
CleanUpRefactoring refactoring= (CleanUpRefactoring)getRefactoring();

CleanUpOptions options= null;
if (fUseCustomField.isSelected()) {
	refactoring.setUseOptionsFromProfile(false);
	options= new MapCleanUpOptions(fCustomSettings);
} else {
	refactoring.setUseOptionsFromProfile(true);
}

refactoring.clearCleanUps();
ICleanUp[] cleanups= JavaPlugin.getDefault().getCleanUpRegistry().createCleanUps();
for (int i= 0; i < cleanups.length; i++) {
	if (options != null)
		cleanups[i].setOptions(options);
          refactoring.addCleanUp(cleanups[i]);
         }
     }
 
Example #2
Source File: CleanUpRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private RefactoringStatus checkPreConditions(IJavaProject javaProject, CleanUpTarget[] targets, IProgressMonitor monitor) throws CoreException {
	RefactoringStatus result= new RefactoringStatus();

	ICompilationUnit[] compilationUnits= new ICompilationUnit[targets.length];
	for (int i= 0; i < targets.length; i++) {
		compilationUnits[i]= targets[i].getCompilationUnit();
	}

	ICleanUp[] cleanUps= getCleanUps();
	monitor.beginTask("", compilationUnits.length * cleanUps.length); //$NON-NLS-1$
	monitor.subTask(Messages.format(FixMessages.CleanUpRefactoring_Initialize_message, BasicElementLabels.getResourceName(javaProject.getProject())));
	try {
		for (int j= 0; j < cleanUps.length; j++) {
			result.merge(cleanUps[j].checkPreConditions(javaProject, compilationUnits, new SubProgressMonitor(monitor, compilationUnits.length)));
			if (result.hasFatalError())
				return result;
		}
	} finally {
		monitor.done();
	}

	return result;
}
 
Example #3
Source File: CleanUpRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private Change[] cleanUpProject(IJavaProject project, CleanUpTarget[] targets, ICleanUp[] cleanUps, IProgressMonitor monitor) throws CoreException {
	CleanUpFixpointIterator iter= new CleanUpFixpointIterator(targets, cleanUps);

	SubProgressMonitor subMonitor= new SubProgressMonitor(monitor, 2 * targets.length * cleanUps.length);
	subMonitor.beginTask("", targets.length); //$NON-NLS-1$
	subMonitor.subTask(Messages.format(FixMessages.CleanUpRefactoring_Parser_Startup_message, BasicElementLabels.getResourceName(project.getProject())));
	try {
		while (iter.hasNext()) {
			iter.next(subMonitor);
		}

		return iter.getResult();
	} finally {
		iter.dispose();
		subMonitor.done();
	}
}
 
Example #4
Source File: CleanUpAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void run(ICompilationUnit cu) {
	if (!ActionUtil.isEditable(fEditor, getShell(), cu))
		return;

	ICleanUp[] cleanUps= getCleanUps(new ICompilationUnit[] {
		cu
	});
	if (cleanUps == null)
		return;

	if (!ElementValidator.check(cu, getShell(), getActionName(), fEditor != null))
		return;

	try {
		performRefactoring(new ICompilationUnit[] {
			cu
		}, cleanUps);
	} catch (InvocationTargetException e) {
		JavaPlugin.log(e);
		if (e.getCause() instanceof CoreException)
			showUnexpectedError((CoreException)e.getCause());
	}
}
 
Example #5
Source File: CleanUpRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public CleanUpFixpointIterator(CleanUpTarget[] targets, ICleanUp[] cleanUps) {
	fSolutions= new Hashtable<ICompilationUnit, List<CleanUpChange>>(targets.length);
	fWorkingCopies= new Hashtable<ICompilationUnit, ICompilationUnit>();

	fParseList= new ArrayList<ParseListElement>(targets.length);
	for (int i= 0; i < targets.length; i++) {
		fParseList.add(new ParseListElement(targets[i], cleanUps));
	}

	fCleanUpOptions= new Hashtable<String, String>();
	for (int i= 0; i < cleanUps.length; i++) {
		ICleanUp cleanUp= cleanUps[i];
		Map<String, String> currentCleanUpOption= cleanUp.getRequirements().getCompilerOptions();
		if (currentCleanUpOption != null)
			fCleanUpOptions.putAll(currentCleanUpOption);
	}

	fSize= targets.length;
	fIndex= 1;
}
 
Example #6
Source File: MultiSortMembersAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected ICleanUp[] getCleanUps(ICompilationUnit[] units) {
	try {
        if (!hasMembersToSort(units)) {
			MessageDialog.openInformation(getShell(), ActionMessages.MultiSortMembersAction_noElementsToSortDialog_title, ActionMessages.MultiSortMembersAction_noElementsToSortDialog_message);
        	return null;
        }
       } catch (JavaModelException e) {
       	JavaPlugin.log(e);
        return null;
       }

	Map<String, String> settings= getSettings();
	if (settings == null)
		return null;

	return new ICleanUp[] {
		new SortMembersCleanUp(settings)
	};
}
 
Example #7
Source File: QuickAssistProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static boolean getRemoveBlockProposals(IInvocationContext context, ASTNode coveringNode, Collection<ICommandAccess> resultingCollections) {
	IProposableFix[] fixes= ControlStatementsFix.createRemoveBlockFix(context.getASTRoot(), coveringNode);
	if (fixes != null) {
		if (resultingCollections == null) {
			return true;
		}
		Map<String, String> options= new Hashtable<String, String>();
		options.put(CleanUpConstants.CONTROL_STATEMENTS_USE_BLOCKS, CleanUpOptions.TRUE);
		options.put(CleanUpConstants.CONTROL_STATMENTS_USE_BLOCKS_NEVER, CleanUpOptions.TRUE);
		ICleanUp cleanUp= new ControlStatementsCleanUp(options);
		for (int i= 0; i < fixes.length; i++) {
			IProposableFix fix= fixes[i];
			Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
			FixCorrectionProposal proposal= new FixCorrectionProposal(fix, cleanUp, IProposalRelevance.REMOVE_BLOCK_FIX, image, context);
			resultingCollections.add(proposal);
		}
		return true;
	}
	return false;
}
 
Example #8
Source File: QuickAssistProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static boolean getConvertForLoopProposal(IInvocationContext context, ASTNode node, Collection<ICommandAccess> resultingCollections) {
	ForStatement forStatement= getEnclosingForStatementHeader(node);
	if (forStatement == null)
		return false;

	if (resultingCollections == null)
		return true;

	IProposableFix fix= ConvertLoopFix.createConvertForLoopToEnhancedFix(context.getASTRoot(), forStatement);
	if (fix == null)
		return false;

	Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
	Map<String, String> options= new HashMap<String, String>();
	options.put(CleanUpConstants.CONTROL_STATMENTS_CONVERT_FOR_LOOP_TO_ENHANCED, CleanUpOptions.TRUE);
	ICleanUp cleanUp= new ConvertLoopCleanUp(options);
	FixCorrectionProposal proposal= new FixCorrectionProposal(fix, cleanUp, IProposalRelevance.CONVERT_FOR_LOOP_TO_ENHANCED, image, context);
	proposal.setCommandId(CONVERT_FOR_LOOP_ID);

	resultingCollections.add(proposal);
	return true;
}
 
Example #9
Source File: QuickAssistProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static boolean getConvertIterableLoopProposal(IInvocationContext context, ASTNode node, Collection<ICommandAccess> resultingCollections) {
	ForStatement forStatement= getEnclosingForStatementHeader(node);
	if (forStatement == null)
		return false;

	if (resultingCollections == null)
		return true;

	IProposableFix fix= ConvertLoopFix.createConvertIterableLoopToEnhancedFix(context.getASTRoot(), forStatement);
	if (fix == null)
		return false;

	Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
	Map<String, String> options= new HashMap<String, String>();
	options.put(CleanUpConstants.CONTROL_STATMENTS_CONVERT_FOR_LOOP_TO_ENHANCED, CleanUpOptions.TRUE);
	ICleanUp cleanUp= new ConvertLoopCleanUp(options);
	FixCorrectionProposal proposal= new FixCorrectionProposal(fix, cleanUp, IProposalRelevance.CONVERT_ITERABLE_LOOP_TO_ENHANCED, image, context);
	proposal.setCommandId(CONVERT_FOR_LOOP_ID);

	resultingCollections.add(proposal);
	return true;
}
 
Example #10
Source File: CleanUpPostSaveListener.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void showSlowCleanUpsWarning(HashSet<ICleanUp> slowCleanUps) {

		final StringBuffer cleanUpNames= new StringBuffer();
		for (Iterator<ICleanUp> iterator= slowCleanUps.iterator(); iterator.hasNext();) {
			ICleanUp cleanUp= iterator.next();
			String[] descriptions= cleanUp.getStepDescriptions();
			if (descriptions != null) {
				for (int i= 0; i < descriptions.length; i++) {
					if (cleanUpNames.length() > 0)
						cleanUpNames.append('\n');

					cleanUpNames.append(descriptions[i]);
				}
			}
		}

		if (Display.getCurrent() != null) {
			showSlowCleanUpDialog(cleanUpNames);
		} else {
			Display.getDefault().asyncExec(new Runnable() {
				public void run() {
					showSlowCleanUpDialog(cleanUpNames);
				}
			});
		}
	}
 
Example #11
Source File: CleanUpConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private String getSelectedCleanUpsInfo(ICleanUp[] cleanUps) {
	if (cleanUps.length == 0)
		return ""; //$NON-NLS-1$

	StringBuffer buf= new StringBuffer();

	boolean first= true;
	for (int i= 0; i < cleanUps.length; i++) {
     String[] descriptions= cleanUps[i].getStepDescriptions();
     if (descriptions != null) {
	        for (int j= 0; j < descriptions.length; j++) {
	        	if (first) {
	        		first= false;
	        	} else {
	        		buf.append('\n');
	        	}
	            buf.append(descriptions[j]);
            }
     }
    }

	return buf.toString();
}
 
Example #12
Source File: CleanUpSaveParticipantPreferenceConfiguration.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private String getSelectedCleanUpsText(CleanUpOptions options) {
	StringBuffer buf= new StringBuffer();

	final ICleanUp[] cleanUps= JavaPlugin.getDefault().getCleanUpRegistry().createCleanUps();
	for (int i= 0; i < cleanUps.length; i++) {
		cleanUps[i].setOptions(options);
		String[] descriptions= cleanUps[i].getStepDescriptions();
		if (descriptions != null) {
			for (int j= 0; j < descriptions.length; j++) {
				if (buf.length() > 0) {
					buf.append('\n');
				}
				buf.append(descriptions[j]);
			}
        }
       }
	String string= buf.toString();
	return string;
}
 
Example #13
Source File: CleanUpRefactoringWizard.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void showCustomSettings(BulletListBlock bulletListBlock) {
StringBuffer buf= new StringBuffer();

final ICleanUp[] cleanUps= JavaPlugin.getDefault().getCleanUpRegistry().createCleanUps();
CleanUpOptions options= new MapCleanUpOptions(fCustomSettings);
  	for (int i= 0; i < cleanUps.length; i++) {
  		cleanUps[i].setOptions(options);
       String[] descriptions= cleanUps[i].getStepDescriptions();
       if (descriptions != null) {
  	        for (int j= 0; j < descriptions.length; j++) {
  	        	if (buf.length() > 0) {
  	        		buf.append('\n');
  	        	}
  	            buf.append(descriptions[j]);
              }
       }
      }
  	bulletListBlock.setText(buf.toString());
     }
 
Example #14
Source File: CleanUpConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
    * {@inheritDoc}
    */
   @Override
protected void configurePreview(Composite composite, int numColumns, final ProfileManager profileManager) {
   	Map<String, String> settings= profileManager.getSelected().getSettings();
	final Map<String, String> sharedSettings= new Hashtable<String, String>();
	fill(settings, sharedSettings);

	final ICleanUp[] cleanUps= JavaPlugin.getDefault().getCleanUpRegistry().createCleanUps();
	CleanUpOptions options= new MapCleanUpOptions(sharedSettings);
	for (int i= 0; i < cleanUps.length; i++) {
		cleanUps[i].setOptions(options);
	}

	createLabel(composite, CleanUpMessages.CleanUpConfigurationBlock_SelectedCleanUps_label, numColumns);

	final BulletListBlock cleanUpListBlock= new BulletListBlock(composite, SWT.NONE);
	GridData gridData= new GridData(SWT.FILL, SWT.FILL, true, true);
	gridData.horizontalSpan= numColumns;
	cleanUpListBlock.setLayoutData(gridData);
	cleanUpListBlock.setText(getSelectedCleanUpsInfo(cleanUps));

	profileManager.addObserver(new Observer() {

		public void update(Observable o, Object arg) {
			final int value= ((Integer)arg).intValue();
			switch (value) {
			case ProfileManager.PROFILE_CREATED_EVENT:
			case ProfileManager.PROFILE_DELETED_EVENT:
			case ProfileManager.SELECTION_CHANGED_EVENT:
			case ProfileManager.SETTINGS_CHANGED_EVENT:
				fill(profileManager.getSelected().getSettings(), sharedSettings);
				cleanUpListBlock.setText(getSelectedCleanUpsInfo(cleanUps));
			}
           }

	});
   }
 
Example #15
Source File: SerialVersionSubProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static ICleanUp createCleanUp(boolean isDefault) {
	Map<String, String> options= new Hashtable<String, String>();
	options.put(CleanUpConstants.ADD_MISSING_SERIAL_VERSION_ID, CleanUpOptions.TRUE);
	if (isDefault) {
		options.put(CleanUpConstants.ADD_MISSING_SERIAL_VERSION_ID_DEFAULT, CleanUpOptions.TRUE);
	} else {
		options.put(CleanUpConstants.ADD_MISSING_SERIAL_VERSION_ID_GENERATED, CleanUpOptions.TRUE);
	}
	return new PotentialProgrammingProblemsCleanUp(options);
}
 
Example #16
Source File: MultiFormatAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected ICleanUp[] getCleanUps(ICompilationUnit[] units) {
	Map<String, String> settings= new Hashtable<String, String>();
	settings.put(CleanUpConstants.FORMAT_SOURCE_CODE, CleanUpOptions.TRUE);

	return new ICleanUp[] {
			new CodeFormatCleanUp(settings)
	};
}
 
Example #17
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 #18
Source File: MultiOrganizeImportAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected ICleanUp[] getCleanUps(ICompilationUnit[] units) {
	Map<String, String> settings= new Hashtable<String, String>();
	settings.put(CleanUpConstants.ORGANIZE_IMPORTS, CleanUpOptions.TRUE);
	ImportsCleanUp importsCleanUp= new ImportsCleanUp(settings);

	return new ICleanUp[] {
		importsCleanUp
	};
}
 
Example #19
Source File: CleanUpRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private RefactoringStatus checkPostConditions(SubProgressMonitor monitor) throws CoreException {
	RefactoringStatus result= new RefactoringStatus();

	ICleanUp[] cleanUps= getCleanUps();
	monitor.beginTask("", cleanUps.length); //$NON-NLS-1$
	monitor.subTask(FixMessages.CleanUpRefactoring_checkingPostConditions_message);
	try {
		for (int j= 0; j < cleanUps.length; j++) {
			result.merge(cleanUps[j].checkPostConditions(new SubProgressMonitor(monitor, 1)));
		}
	} finally {
		monitor.done();
	}
	return result;
}
 
Example #20
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 #21
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(Map<String, String> settings, Set<String> ids) {
	ICleanUp[] result= JavaPlugin.getDefault().getCleanUpRegistry().createCleanUps(ids);

	for (int i= 0; i < result.length; i++) {
		result[i].setOptions(new MapCleanUpOptions(settings));
	}

	return result;
}
 
Example #22
Source File: CleanUpPostSaveListener.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean requiresAST(ICleanUp[] cleanUps) {
for (int i= 0; i < cleanUps.length; i++) {
       if (cleanUps[i].getRequirements().requiresAST())
       	return true;
      }

   return false;
  }
 
Example #23
Source File: CleanUpPostSaveListener.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean requiresChangedRegions(ICleanUp[] cleanUps) {
	for (int i= 0; i < cleanUps.length; i++) {
		CleanUpRequirements requirements= cleanUps[i].getRequirements();
		if (requirements.requiresChangedRegions())
			return true;
	}

	return false;
}
 
Example #24
Source File: CleanUpRegistry.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @return the clean up or <code>null</code> if the clean up could not be instantiated
 */
public ICleanUp createCleanUp() {
	try {
		return (ICleanUp)fElement.createExecutableExtension(ATTRIBUTE_ID_CLASS);
	} catch (CoreException e) {
		String msg= Messages.format(FixMessages.CleanUpRegistry_cleanUpCreation_error, new String[] { fElement.getAttribute(ATTRIBUTE_ID_ID), fElement.getContributor().getName() });
		JavaPlugin.logErrorStatus(msg, e.getStatus());
		return null;
	}
}
 
Example #25
Source File: CleanUpRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean requiresAST(ICleanUp[] cleanUps) {
	for (int i= 0; i < cleanUps.length; i++) {
		if (cleanUps[i].getRequirements().requiresAST())
			return true;
	}
	return false;
}
 
Example #26
Source File: CleanUpRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private ICleanUp[] calculateSolutions(CleanUpContext context, ICleanUp[] cleanUps) {
	List<ICleanUp>result= new ArrayList<ICleanUp>();
	CleanUpChange solution;
	try {
		solution= calculateChange(context, cleanUps, result, null);
	} catch (CoreException e) {
		throw new FixCalculationException(e);
	}

	if (solution != null) {
		integrateSolution(solution, context.getCompilationUnit());
	}

	return result.toArray(new ICleanUp[result.size()]);
}
 
Example #27
Source File: CleanUpRegistry.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates and returns the registered clean ups that don't fail upon creation.
 * 
 * @param ids the ids of the clean ups to create, or <code>null</code> to create all
 * @return an array of clean ups
 * @since 3.5
 */
public synchronized ICleanUp[] createCleanUps(Set<String> ids) {
	ensureCleanUpsRegistered();
	ArrayList<ICleanUp> result= new ArrayList<ICleanUp>(fCleanUpDescriptors.length);
	for (int i= 0; i < fCleanUpDescriptors.length; i++) {
		if (ids == null || ids.contains(fCleanUpDescriptors[i].getId())) {
			ICleanUp cleanUp= fCleanUpDescriptors[i].createCleanUp();
			if (cleanUp != null)
				result.add(cleanUp);
		}
	}
	return result.toArray(new ICleanUp[result.size()]);
}
 
Example #28
Source File: CleanUpRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private RefactoringStatus setOptionsFromProfile(IJavaProject javaProject, ICleanUp[] cleanUps) {
	Map<String, String> options= CleanUpPreferenceUtil.loadOptions(new ProjectScope(javaProject.getProject()));
	if (options == null)
		return RefactoringStatus.createFatalErrorStatus(Messages.format(FixMessages.CleanUpRefactoring_could_not_retrive_profile, BasicElementLabels.getResourceName(javaProject.getProject())));

	CleanUpOptions cleanUpOptions= new MapCleanUpOptions(options);
	for (int i= 0; i < cleanUps.length; i++)
		cleanUps[i].setOptions(cleanUpOptions);

	return new RefactoringStatus();
}
 
Example #29
Source File: CleanUpRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public ParseListElement(CleanUpTarget cleanUpTarget, ICleanUp[] cleanUps) {
	fTarget= cleanUpTarget;
	fCleanUpsArray= cleanUps;
}
 
Example #30
Source File: CleanUpPostSaveListener.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public boolean needsChangedRegions(ICompilationUnit unit) throws CoreException {
	ICleanUp[] cleanUps= getCleanUps(unit.getJavaProject().getProject());
	return requiresChangedRegions(cleanUps);
}