1 /******************************************************************************* 2 * Copyright (c) 2000, 2011 IBM Corporation and others. 3 * 4 * This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * which accompanies this distribution, and is available at 7 * https://www.eclipse.org/legal/epl-2.0/ 8 * 9 * SPDX-License-Identifier: EPL-2.0 10 * 11 * Contributors: 12 * IBM Corporation - initial API and implementation 13 *******************************************************************************/ 14 package org.eclipse.jdt.internal.corext.refactoring.util; 15 16 import java.util.ArrayList; 17 import java.util.List; 18 19 import org.eclipse.core.runtime.IAdaptable; 20 21 import org.eclipse.core.resources.IFile; 22 23 import org.eclipse.ltk.core.refactoring.Change; 24 import org.eclipse.ltk.core.refactoring.CompositeChange; 25 26 27 public class Changes { 28 getModifiedFiles(Change[] changes)29 public static IFile[] getModifiedFiles(Change[] changes) { 30 List<IFile> result= new ArrayList<>(); 31 getModifiedFiles(result, changes); 32 return result.toArray(new IFile[result.size()]); 33 } 34 getModifiedFiles(List<IFile> result, Change[] changes)35 private static void getModifiedFiles(List<IFile> result, Change[] changes) { 36 for (Change change : changes) { 37 Object modifiedElement= change.getModifiedElement(); 38 if (modifiedElement instanceof IAdaptable) { 39 IFile file= ((IAdaptable)modifiedElement).getAdapter(IFile.class); 40 if (file != null) 41 result.add(file); 42 } 43 if (change instanceof CompositeChange) { 44 getModifiedFiles(result, ((CompositeChange)change).getChildren()); 45 } 46 } 47 } 48 Changes()49 private Changes() { 50 } 51 } 52