Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2000, 2010 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.jdt.internal.core;
 
 
 import  org.eclipse.core.resources.ResourcesPlugin;
 import  org.eclipse.core.runtime.CoreException;
 import  org.eclipse.core.runtime.IPath;
 
 public class SetVariablesOperation extends ChangeClasspathOperation {
 
 	IPath[] variablePaths;
 	boolean updatePreferences;
 
 	/*
 	 * Creates a new SetVariablesOperation for the given variable values (null path meaning removal), allowing to change multiple variable values at once.
 	 */
 	public SetVariablesOperation(String[] variableNames, IPath[] variablePathsboolean updatePreferences) {
 		super(new IJavaElement[] {JavaModelManager.getJavaModelManager().getJavaModel()}, !ResourcesPlugin.getWorkspace().isTreeLocked());
 		this. = variableNames;
 		this. = variablePaths;
 		this. = updatePreferences;
 	}
 
 	protected void executeOperation() throws JavaModelException {
 		try {
 			beginTask("", 1); //$NON-NLS-1$
 
 			JavaModelManager manager = JavaModelManager.getJavaModelManager();
 				return;
 
 			int varLength = this..length;
 
 			// gather classpath information for updating
 			final HashMap affectedProjectClasspaths = new HashMap(5);
 			IJavaModel model = getJavaModel();
 
 			// filter out unmodified variables
 			int discardCount = 0;
 			for (int i = 0; i < varLengthi++){
 				String variableName = this.[i];
 				IPath oldPath = manager.variableGet(variableName); // if reentering will provide previous session value
 					oldPath = null;  //33695 - cannot filter out restored variable, must update affected project to reset cached CP
 				}
 				if (oldPath != null && oldPath.equals(this.[i])){
 					this.[i] = null;
 					discardCount++;
 				}
 			}
 			if (discardCount > 0){
 				if (discardCount == varLengthreturn;
 				int changedLength = varLength - discardCount;
 				String[] changedVariableNames = new String[changedLength];
 				IPath[] changedVariablePaths = new IPath[changedLength];
 				for (int i = 0, index = 0; i < varLengthi++){
 					if (this.[i] != null){
 						changedVariableNames[index] = this.[i];
 						changedVariablePaths[index] = this.[i];
 						index++;
 					}
 				}
 				this. = changedVariableNames;
 				this. = changedVariablePaths;
 				varLength = changedLength;
 			}
 
 			if (isCanceled())
 				return;
 
 			IJavaProject[] projects = model.getJavaProjects();
 			nextProject : for (int i = 0, projectLength = projects.lengthi < projectLengthi++){
 				JavaProject project = (JavaProjectprojects[i];
 
 				// check to see if any of the modified variables is present on the classpath
 				IClasspathEntry[] classpath = project.getRawClasspath();
 				for (int j = 0, cpLength = classpath.lengthj < cpLengthj++){
 
					IClasspathEntry entry = classpath[j];
					for (int k = 0; k < varLengthk++){
						String variableName = this.[k];
							if (variableName.equals(entry.getPath().segment(0))){
								affectedProjectClasspaths.put(projectproject.getResolvedClasspath());
								continue nextProject;
							}
							IPath sourcePathsourceRootPath;
							if (((sourcePath = entry.getSourceAttachmentPath()) != null	&& variableName.equals(sourcePath.segment(0)))
								|| ((sourceRootPath = entry.getSourceAttachmentRootPath()) != null	&& variableName.equals(sourceRootPath.segment(0)))) {
								affectedProjectClasspaths.put(projectproject.getResolvedClasspath());
								continue nextProject;
							}
						}
					}
				}
			}
			// update variables
			for (int i = 0; i < varLengthi++){
				manager.variablePut(this.[i], this.[i]);
			}
			// update affected project classpaths
			if (!affectedProjectClasspaths.isEmpty()) {
				String[] dbgVariableNames = this.;
				try {
					// propagate classpath change
					Iterator projectsToUpdate = affectedProjectClasspaths.keySet().iterator();
					while (projectsToUpdate.hasNext()) {
						if (this. != null && this..isCanceled()) return;
						JavaProject affectedProject = (JavaProjectprojectsToUpdate.next();
						// force resolved classpath to be recomputed
							verbose_update_project(dbgVariableNamesaffectedProject);
						ClasspathChange classpathChange = affectedProject.getPerProjectInfo().resetResolvedClasspath();
						// if needed, generate delta, update project ref, create markers, ...
						classpathChanged(classpathChangetrue/*refresh if external linked folder already exists*/);
						if (this.) {
							// touch project to force a build if needed
							affectedProject.getProject().touch(this.);
						}
					}
catch (CoreException e) {
						verbose_failure(dbgVariableNames);
						e.printStackTrace();
					}
					if (e instanceof JavaModelException) {
else {
						throw new JavaModelException(e);
					}
				}
			}
finally {
		}
	}
	private void verbose_failure(String[] dbgVariableNames) {
		Util.verbose(
			"CPVariable SET  - FAILED DUE TO EXCEPTION\n" + //$NON-NLS-1$
			"	variables: " + org.eclipse.jdt.internal.compiler.util.Util.toString(dbgVariableNames), //$NON-NLS-1$
	}
	private void verbose_update_project(String[] dbgVariableNames,
			JavaProject affectedProject) {
		Util.verbose(
			"CPVariable SET  - updating affected project due to setting variables\n" + //$NON-NLS-1$
			"	project: " + affectedProject.getElementName() + '\n' + //$NON-NLS-1$
			"	variables: " + org.eclipse.jdt.internal.compiler.util.Util.toString(dbgVariableNames)); //$NON-NLS-1$
	}
	private void verbose_set_variables() {
		Util.verbose(
			"CPVariable SET  - setting variables\n" + //$NON-NLS-1$
			"	variables: " + org.eclipse.jdt.internal.compiler.util.Util.toString(this.) + '\n' +//$NON-NLS-1$
			"	values: " + org.eclipse.jdt.internal.compiler.util.Util.toString(this.)); //$NON-NLS-1$
	}
New to GrepCode? Check out our FAQ X