Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2003, 2008 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: IBM Corporation - initial API and implementation /
 
 package org.eclipse.ant.internal.ui.refactoring;
 
 import java.util.List;
 
 
 
 public class LaunchConfigurationBuildfileChange extends Change {
 	
     private String fNewConfigContainerName;

    
Create a change for each launch configuration which needs to be updated for this IJavaProject rename.

Since:
3.5
 
     public static Change createChangesForProjectRename(IProject projectString newProjectNamethrows CoreException {
         String projectNameproject.getDescription().getName();
         ILaunchConfiguration[] configs = getAntLaunchConfigurations();
         List changescreateChangesForProjectRename(configsprojectNamenewProjectName);
     }
    
    
Create a change for each launch configuration which needs to be updated for this buildfile rename.
 
     public static Change createChangesForBuildfileRename(IFile fileString newBuildfileNamethrows CoreException {
         IContentDescription descriptionnull;
         try {
             descriptionfile.getContentDescription();
         } catch (CoreException e) {
             //missing file
             return null;
         }
         if (description == null) {
             return null;
         }
         IContentType contentTypedescription.getContentType();
         if (contentType == null || !..equals(contentType.getId())) {
             return null//not an Ant buildfile
         }
         ILaunchConfiguration[] configs = getAntLaunchConfigurations();
         List changescreateChangesForBuildfileRename(fileconfigsfile.getProject().getName(), newBuildfileName);
     }
 
     private static ILaunchConfiguration[] getAntLaunchConfigurations() throws CoreException {
         ILaunchManager manager= DebugPlugin.getDefault().getLaunchManager();
         // Ant launch configurations
         ILaunchConfiguration[] configsmanager.getLaunchConfigurations(configurationType);
         return configs;
     }
    
    
Take a list of Changes, and return a unique Change, a CompositeChange, or null.
    private static Change createChangeFromList(List changesString changeLabel) {
        int nbChangeschanges.size();
        if (nbChanges == 0) {
            return null;
        } else if (nbChanges == 1) {
            return (Changechanges.get(0);
        } else {
            return new CompositeChange(changeLabel, (Change[])changes.toArray(new Change[changes.size()]));
        }
    }

Create a change for each launch configuration from the given list which needs to be updated for this IProject rename.
	private static List createChangesForProjectRename(ILaunchConfiguration[] configsString projectNameString newProjectNamethrows CoreException {
		List changesnew ArrayList();
		for (int i= 0; i < configs.lengthi++) {
			ILaunchConfiguration launchConfiguration = configs[i];
			String launchConfigurationProjectNamelaunchConfiguration.getAttribute(., (String)null);
			if (projectName.equals(launchConfigurationProjectName)) {
				LaunchConfigurationBuildfileChange change = new LaunchConfigurationBuildfileChange(launchConfigurationnullnullnewProjectNamefalse);
                String newContainerName = computeNewContainerName(launchConfiguration);
                if (newContainerName != null) {
                    change.setNewContainerName(newContainerName);
                }
				changes.add(change);
			}
		}
		return changes;
	}
    
    
Create a change for each launch configuration from the given list which needs to be updated for this buildfile rename.
    private static List createChangesForBuildfileRename(IFile buildfileILaunchConfiguration[] configsString projectNameString newBuildfileNamethrows CoreException {
        List changesnew ArrayList();
        for (int i= 0; i < configs.lengthi++) {
            ILaunchConfiguration launchConfiguration = configs[i];
            String launchConfigurationProjectNamelaunchConfiguration.getAttribute(., (String)null);
            if (projectName.equals(launchConfigurationProjectName)) {
                LaunchConfigurationBuildfileChange change = new LaunchConfigurationBuildfileChange(launchConfigurationbuildfile.getName(), newBuildfileNamenullfalse);
                changes.add(change);
            }
        }
        return changes;
    }
    protected void setNewContainerName(String newContainerName) {
         = newContainerName;
    }

    
Creates a new container name for the given configuration

Parameters:
launchConfiguration
Returns:
the new container name
Since:
3.5
    private static String computeNewContainerName(ILaunchConfiguration launchConfiguration) {
        IFile file = launchConfiguration.getFile();
        if (file != null) {
            return file.getParent().getProjectRelativePath().toString();
        }
        return null;
    }
    
    protected LaunchConfigurationBuildfileChange(ILaunchConfiguration launchConfigurationString oldBuildFileNameString newBuildfileNameString newProjectNameboolean undothrows CoreException {
        launchConfiguration;
        launchConfiguration.getWorkingCopy();
        newBuildfileName;
        newProjectName;
        oldBuildFileName;
        if ( != null) {
            // generate the new configuration name
            String launchConfigurationName.getName();
            launchConfigurationName.replaceAll(oldBuildFileNamenewBuildfileName);
            if (launchConfigurationName.equals() || (!undo && DebugPlugin.getDefault().getLaunchManager().isExistingLaunchConfigurationName())) {
                null;
            }
        }
    }
    /* (non-Javadoc)
	 * @see org.eclipse.ltk.core.refactoring.Change#getName()
	 */
	public String getName() {
		if ( != null) {
		if ( == null) {
		}
	}
	/* (non-Javadoc)
	 * @see org.eclipse.ltk.core.refactoring.Change#initializeValidationData(org.eclipse.core.runtime.IProgressMonitor)
	 */
	}
	/* (non-Javadoc)
	 * @see org.eclipse.ltk.core.refactoring.Change#isValid(org.eclipse.core.runtime.IProgressMonitor)
	 */
			if ( == null || (buildFileLocation.endsWith( + '}') || buildFileLocation.endsWith())) {
				if (.equals(projectName)) {
					return new RefactoringStatus();
				}
			}
	}
	/* (non-Javadoc)
	 * @see org.eclipse.ltk.core.refactoring.Change#perform(org.eclipse.core.runtime.IProgressMonitor)
	 */
	public Change perform(IProgressMonitor pmthrows CoreException {        
        if ( != null) {
            IWorkspace workspace = ResourcesPlugin.getWorkspace();
            IWorkspaceRoot root = workspace.getRoot();
            IProject project = root.getProject();
            IContainer container = (IContainerproject.findMember();
            .setContainer(container);
        }
		String oldProjectName;
		if ( != null) {
            String newBuildFileLocationoldBuildfileLocation.replaceFirst();
            .setAttribute(.newBuildFileLocation);
            .setMappedResources(new IResource[] {getAssociatedFile(newBuildFileLocation)});
		if ( != null) {
			oldProjectName;
            String newBuildFileLocationoldBuildfileLocation.replaceFirst(oldProjectName);
            .setAttribute(.newBuildFileLocation);
            .setMappedResources(new IResource[] {getAssociatedFile(newBuildFileLocation)});
            String launchConfigurationName.getName();
            launchConfigurationName.replaceFirst(oldProjectName);
            if (launchConfigurationName.equals() || DebugPlugin.getDefault().getLaunchManager().isExistingLaunchConfigurationName()) {
                null;
            }
else {
			oldProjectNamenull;
		}
		if ( != null) {
		}
		// create the undo change
	}
	/* (non-Javadoc)
	 * @see org.eclipse.ltk.core.refactoring.Change#getModifiedElement()
	 */
	}
	private IFile getAssociatedFile(String location) {
		IFile filenull;
		try {
			String expandedLocationmanager.performStringSubstitution(location);
			if (expandedLocation != null) {
				file= AntUtil.getFileForLocation(expandedLocationnull);
			}
catch (CoreException e) {
		}
		return file;
	}
New to GrepCode? Check out our FAQ X