Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support change signature refactoring #2497

Merged
merged 5 commits into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
}
}


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();
}
}