-
Notifications
You must be signed in to change notification settings - Fork 378
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support change signature refactoring
Signed-off-by: Shi Chen <chenshi@microsoft.com>
- Loading branch information
Showing
23 changed files
with
6,977 additions
and
1 deletion.
There are no files selected for viewing
98 changes: 98 additions & 0 deletions
98
....ls.core/src/org/eclipse/jdt/internal/corext/refactoring/CuCollectingSearchRequestor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2000, 2011 IBM Corporation and others. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* IBM Corporation - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.jdt.internal.corext.refactoring; | ||
|
||
import org.eclipse.core.runtime.CoreException; | ||
|
||
import org.eclipse.jdt.core.ICompilationUnit; | ||
import org.eclipse.jdt.core.IJavaProject; | ||
import org.eclipse.jdt.core.JavaCore; | ||
import org.eclipse.jdt.core.ToolFactory; | ||
import org.eclipse.jdt.core.compiler.IScanner; | ||
import org.eclipse.jdt.core.search.SearchMatch; | ||
|
||
import org.eclipse.jdt.internal.corext.refactoring.base.ReferencesInBinaryContext; | ||
import org.eclipse.jdt.internal.corext.util.SearchUtils; | ||
|
||
/** | ||
* Collects the results returned by a <code>SearchEngine</code>. | ||
* Only collects matches in CUs ands offers a scanner to trim match ranges. | ||
* If a {@link ReferencesInBinaryContext} is passed, matches that are | ||
* inside a binary element are not collected (but added to the context if they are accurate). | ||
*/ | ||
public class CuCollectingSearchRequestor extends CollectingSearchRequestor { | ||
|
||
private IJavaProject fProjectCache; | ||
private IScanner fScannerCache; | ||
|
||
public CuCollectingSearchRequestor() { | ||
this(null); | ||
} | ||
|
||
public CuCollectingSearchRequestor(ReferencesInBinaryContext binaryRefs) { | ||
super(binaryRefs); | ||
} | ||
|
||
protected IScanner getScanner(ICompilationUnit unit) { | ||
IJavaProject project= unit.getJavaProject(); | ||
if (project.equals(fProjectCache)) | ||
return fScannerCache; | ||
|
||
fProjectCache= project; | ||
String sourceLevel= project.getOption(JavaCore.COMPILER_SOURCE, true); | ||
String complianceLevel= project.getOption(JavaCore.COMPILER_COMPLIANCE, true); | ||
fScannerCache= ToolFactory.createScanner(false, false, false, sourceLevel, complianceLevel); | ||
return fScannerCache; | ||
} | ||
|
||
/** | ||
* This is an internal method. Do not call from subclasses! | ||
* Use {@link #collectMatch(SearchMatch)} instead. | ||
* @param match | ||
* @throws CoreException | ||
* @deprecated | ||
*/ | ||
@Deprecated | ||
@Override | ||
public final void acceptSearchMatch(SearchMatch match) throws CoreException { | ||
if (filterMatch(match)) | ||
return; | ||
|
||
ICompilationUnit unit= SearchUtils.getCompilationUnit(match); | ||
if (unit != null) { | ||
acceptSearchMatch(unit, match); | ||
} | ||
} | ||
|
||
/** | ||
* Handles the given match in the given compilation unit. | ||
* The default implementation accepts all matches. | ||
* Subclasses can override and call {@link #collectMatch(SearchMatch)} to collect matches. | ||
* | ||
* @param unit the enclosing CU of the match, never <code>null</code> | ||
* @param match the match | ||
* @throws CoreException if something bad happens | ||
*/ | ||
protected void acceptSearchMatch(ICompilationUnit unit, SearchMatch match) throws CoreException { | ||
collectMatch(match); | ||
} | ||
|
||
@Override | ||
public void endReporting() { | ||
fProjectCache= null; | ||
fScannerCache= null; | ||
} | ||
} | ||
|
||
|
103 changes: 103 additions & 0 deletions
103
org.eclipse.jdt.ls.core/src/org/eclipse/jdt/internal/corext/refactoring/ExceptionInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2000, 2011 IBM Corporation and others. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* IBM Corporation - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.jdt.internal.corext.refactoring; | ||
|
||
import org.eclipse.core.runtime.Assert; | ||
|
||
import org.eclipse.jdt.core.IJavaElement; | ||
import org.eclipse.jdt.core.IType; | ||
import org.eclipse.jdt.core.ITypeParameter; | ||
import org.eclipse.jdt.core.dom.ITypeBinding; | ||
|
||
|
||
public class ExceptionInfo { | ||
private final IJavaElement fElement; | ||
private final ITypeBinding fTypeBinding; | ||
private int fKind; | ||
|
||
public static final int OLD= 0; | ||
public static final int ADDED= 1; | ||
public static final int DELETED= 2; | ||
|
||
public ExceptionInfo(IJavaElement element, int kind, ITypeBinding binding) { | ||
Assert.isNotNull(element); | ||
Assert.isTrue(element instanceof IType || element instanceof ITypeParameter); | ||
fElement= element; | ||
fKind= kind; | ||
fTypeBinding= binding; | ||
} | ||
|
||
public static ExceptionInfo createInfoForOldException(IJavaElement element, ITypeBinding binding){ | ||
return new ExceptionInfo(element, OLD, binding); | ||
} | ||
public static ExceptionInfo createInfoForAddedException(IType type){ | ||
return new ExceptionInfo(type, ADDED, null); | ||
} | ||
|
||
public void markAsDeleted(){ | ||
Assert.isTrue(! isAdded());//added exception infos should be simply removed from the list | ||
fKind= DELETED; | ||
} | ||
|
||
public void markAsOld(){ | ||
Assert.isTrue(isDeleted()); | ||
fKind= OLD; | ||
} | ||
|
||
public boolean isAdded(){ | ||
return fKind == ADDED; | ||
} | ||
|
||
public boolean isDeleted(){ | ||
return fKind == DELETED; | ||
} | ||
|
||
public boolean isOld(){ | ||
return fKind == OLD; | ||
} | ||
|
||
public IJavaElement getElement() { | ||
return fElement; | ||
} | ||
|
||
public String getFullyQualifiedName() { | ||
return fElement instanceof IType ? ((IType) fElement).getFullyQualifiedName('.') : fElement.getElementName(); | ||
} | ||
|
||
public int getKind() { | ||
return fKind; | ||
} | ||
|
||
/** | ||
* @return ITypeBinding the typeBinding (for OLD and DELETED exceptions) or <code>null</code> | ||
*/ | ||
public ITypeBinding getTypeBinding() { | ||
return fTypeBinding; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuilder result= new StringBuilder(); | ||
switch (fKind) { | ||
case OLD : result.append("OLD: "); break; //$NON-NLS-1$ | ||
case ADDED : result.append("ADDED: "); break; //$NON-NLS-1$ | ||
case DELETED : result.append("DELETED: "); break; //$NON-NLS-1$ | ||
} | ||
if (fElement == null) | ||
result.append("null"); //$NON-NLS-1$ | ||
else | ||
result.append(fElement.toString()); | ||
return result.toString(); | ||
} | ||
} |
Oops, something went wrong.