Java Code Examples for org.eclipse.jdt.core.IMethod#isBinary()

The following examples show how to use org.eclipse.jdt.core.IMethod#isBinary() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RippleMethodFinder.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private void findAllDeclarations(IProgressMonitor monitor, WorkingCopyOwner owner) throws CoreException {
	fDeclarations = new ArrayList<>();

	class MethodRequestor extends SearchRequestor {
		@Override
		public void acceptSearchMatch(SearchMatch match) throws CoreException {
			IMethod method = (IMethod) match.getElement();
			boolean isBinary = method.isBinary();
			if (!isBinary) {
				fDeclarations.add(method);
			}
		}
	}

	int limitTo = IJavaSearchConstants.DECLARATIONS | IJavaSearchConstants.IGNORE_DECLARING_TYPE | IJavaSearchConstants.IGNORE_RETURN_TYPE;
	int matchRule = SearchPattern.R_ERASURE_MATCH | SearchPattern.R_CASE_SENSITIVE;
	SearchPattern pattern = SearchPattern.createPattern(fMethod, limitTo, matchRule);
	MethodRequestor requestor = new MethodRequestor();
	SearchEngine searchEngine = owner != null ? new SearchEngine(owner) : new SearchEngine();

	searchEngine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, createSearchScope(), requestor, monitor);
}
 
Example 2
Source File: RenameMethodProcessor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private RefactoringStatus checkRelatedMethods() throws CoreException {
	RefactoringStatus result= new RefactoringStatus();
	for (Iterator<IMethod> iter= fMethodsToRename.iterator(); iter.hasNext(); ) {
		IMethod method= iter.next();

		result.merge(Checks.checkIfConstructorName(method, getNewElementName(), method.getDeclaringType().getElementName()));

		String[] msgData= new String[]{BasicElementLabels.getJavaElementName(method.getElementName()), BasicElementLabels.getJavaElementName(method.getDeclaringType().getFullyQualifiedName('.'))};
		if (! method.exists()){
			result.addFatalError(Messages.format(RefactoringCoreMessages.RenameMethodRefactoring_not_in_model, msgData));
			continue;
		}
		if (method.isBinary()) {
			result.addFatalError(Messages.format(RefactoringCoreMessages.RenameMethodRefactoring_no_binary, msgData));
		}
		if (method.isReadOnly()) {
			result.addFatalError(Messages.format(RefactoringCoreMessages.RenameMethodRefactoring_no_read_only, msgData));
		}
		if (JdtFlags.isNative(method)) {
			result.addError(Messages.format(RefactoringCoreMessages.RenameMethodRefactoring_no_native_1, msgData));
		}
	}
	return result;
}
 
Example 3
Source File: RefactoringAvailabilityTester.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
public static boolean isInlineMethodAvailable(IMethod method) throws JavaModelException {
	if (method == null) {
		return false;
	}
	if (!method.exists()) {
		return false;
	}
	if (!method.isStructureKnown()) {
		return false;
	}
	if (!method.isBinary()) {
		return true;
	}
	if (method.isConstructor()) {
		return false;
	}
	return SourceRange.isAvailable(method.getNameRange());
}
 
Example 4
Source File: RenameMethodProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private RefactoringStatus checkRelatedMethods() throws CoreException {
	RefactoringStatus result= new RefactoringStatus();
	for (Iterator<IMethod> iter= fMethodsToRename.iterator(); iter.hasNext(); ) {
		IMethod method= iter.next();

		result.merge(Checks.checkIfConstructorName(method, getNewElementName(), method.getDeclaringType().getElementName()));

		String[] msgData= new String[]{BasicElementLabels.getJavaElementName(method.getElementName()), BasicElementLabels.getJavaElementName(method.getDeclaringType().getFullyQualifiedName('.'))};
		if (! method.exists()){
			result.addFatalError(Messages.format(RefactoringCoreMessages.RenameMethodRefactoring_not_in_model, msgData));
			continue;
		}
		if (method.isBinary())
			result.addFatalError(Messages.format(RefactoringCoreMessages.RenameMethodRefactoring_no_binary, msgData));
		if (method.isReadOnly())
			result.addFatalError(Messages.format(RefactoringCoreMessages.RenameMethodRefactoring_no_read_only, msgData));
		if (JdtFlags.isNative(method))
			result.addError(Messages.format(RefactoringCoreMessages.RenameMethodRefactoring_no_native_1, msgData));
	}
	return result;
}
 
Example 5
Source File: MainMethodSearchEngine.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
	Object enclosingElement= match.getElement();
	if (enclosingElement instanceof IMethod) { // defensive code
		try {
			IMethod curr= (IMethod) enclosingElement;
			if (curr.isMainMethod()) {
				if (!considerExternalJars()) {
					IPackageFragmentRoot root= JavaModelUtil.getPackageFragmentRoot(curr);
					if (root == null || root.isArchive()) {
						return;
					}
				}
				if (!considerBinaries() && curr.isBinary()) {
					return;
				}
				fResult.add(curr.getDeclaringType());
			}
		} catch (JavaModelException e) {
			JavaPlugin.log(e.getStatus());
		}
	}
}
 
Example 6
Source File: GroovyDocumentUtil.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("restriction")
public static List<IMethod> getModuleMethods(GroovyCompilationUnit unit) {
    List<IMethod> methods = new ArrayList<>();

    try {
        IType[] types = unit.getAllTypes();
        for (IType t : types) {
            for (IMethod m : t.getMethods()) {
                if (!m.isBinary() && !m.isMainMethod() && !m.isConstructor() && !m.getElementName().equals("run")) {
                    methods.add(m);
                }
            }
        }

    } catch (JavaModelException e) {
        BonitaStudioLog.error(e);
    }

    return methods;

}
 
Example 7
Source File: JavaMethodParameterCodeMining.java    From jdt-codemining with Eclipse Public License 1.0 5 votes vote down vote up
private static boolean isArgNumber(String paramName, IMethod method) {
	if (method.isBinary()) {
		// check param name is not arg0, arg1, etc
		if (paramName.length() > 3 && paramName.startsWith("arg")) {
			try {
				Integer.parseInt(paramName.substring(3, paramName.length()));
				return true;
			} catch (Exception e) {

			}
		}
	}
	return false;
}
 
Example 8
Source File: RippleMethodFinder2.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private void findAllDeclarations(IProgressMonitor monitor, WorkingCopyOwner owner) throws CoreException {
	fDeclarations= new ArrayList<>();

	class MethodRequestor extends SearchRequestor {
		@Override
		public void acceptSearchMatch(SearchMatch match) throws CoreException {
			IMethod method= (IMethod) match.getElement();
			boolean isBinary= method.isBinary();
			if (fBinaryRefs != null || ! (fExcludeBinaries && isBinary)) {
				fDeclarations.add(method);
			}
			if (isBinary && fBinaryRefs != null) {
				fDeclarationToMatch.put(method, match);
			}
		}
	}

	int limitTo = IJavaSearchConstants.DECLARATIONS | IJavaSearchConstants.IGNORE_DECLARING_TYPE | IJavaSearchConstants.IGNORE_RETURN_TYPE;
	int matchRule= SearchPattern.R_ERASURE_MATCH | SearchPattern.R_CASE_SENSITIVE;
	SearchPattern pattern= SearchPattern.createPattern(fMethod, limitTo, matchRule);
	SearchParticipant[] participants= SearchUtils.getDefaultSearchParticipants();
	IJavaSearchScope scope= RefactoringScopeFactory.createRelatedProjectsScope(fMethod.getJavaProject(), IJavaSearchScope.SOURCES | IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SYSTEM_LIBRARIES);
	MethodRequestor requestor= new MethodRequestor();
	SearchEngine searchEngine= owner != null ? new SearchEngine(owner) : new SearchEngine();

	searchEngine.search(pattern, participants, scope, requestor, monitor);
}
 
Example 9
Source File: ChangeTypeRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean checkOverriddenBinaryMethods() {
	if (fMethodBinding != null){
		Set<ITypeBinding> declaringSupertypes= getDeclaringSuperTypes(fMethodBinding);
		for (Iterator<ITypeBinding> iter= declaringSupertypes.iterator(); iter.hasNext();) {
			ITypeBinding superType= iter.next();
			IMethodBinding overriddenMethod= findMethod(fMethodBinding, superType);
			Assert.isNotNull(overriddenMethod);//because we asked for declaring types
			IMethod iMethod= (IMethod) overriddenMethod.getJavaElement();
			if (iMethod.isBinary()){
				return true;
			}
		}
	}
	return false;
}
 
Example 10
Source File: RippleMethodFinder2.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void findAllDeclarations(IProgressMonitor monitor, WorkingCopyOwner owner) throws CoreException {
	fDeclarations= new ArrayList<IMethod>();

	class MethodRequestor extends SearchRequestor {
		@Override
		public void acceptSearchMatch(SearchMatch match) throws CoreException {
			IMethod method= (IMethod) match.getElement();
			boolean isBinary= method.isBinary();
			if (fBinaryRefs != null || ! (fExcludeBinaries && isBinary)) {
				fDeclarations.add(method);
			}
			if (isBinary && fBinaryRefs != null) {
				fDeclarationToMatch.put(method, match);
			}
		}
	}

	int limitTo = IJavaSearchConstants.DECLARATIONS | IJavaSearchConstants.IGNORE_DECLARING_TYPE | IJavaSearchConstants.IGNORE_RETURN_TYPE;
	int matchRule= SearchPattern.R_ERASURE_MATCH | SearchPattern.R_CASE_SENSITIVE;
	SearchPattern pattern= SearchPattern.createPattern(fMethod, limitTo, matchRule);
	SearchParticipant[] participants= SearchUtils.getDefaultSearchParticipants();
	IJavaSearchScope scope= RefactoringScopeFactory.createRelatedProjectsScope(fMethod.getJavaProject(), IJavaSearchScope.SOURCES | IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SYSTEM_LIBRARIES);
	MethodRequestor requestor= new MethodRequestor();
	SearchEngine searchEngine= owner != null ? new SearchEngine(owner) : new SearchEngine();

	searchEngine.search(pattern, participants, scope, requestor, monitor);
}
 
Example 11
Source File: RefactoringAvailabilityTester.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static boolean isInlineMethodAvailable(IMethod method) throws JavaModelException {
	if (method == null)
		return false;
	if (!method.exists())
		return false;
	if (!method.isStructureKnown())
		return false;
	if (!method.isBinary())
		return true;
	if (method.isConstructor())
		return false;
	return SourceRange.isAvailable(method.getNameRange());
}
 
Example 12
Source File: MethodProposalInfo.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Tests if a method equals to the given signature. Parameter types are only
 * compared by the simple name, no resolving for the fully qualified type
 * name is done. Constructors are only compared by parameters, not the name.
 *
 * @param name Name of the method
 * @param paramTypes The type signatures of the parameters e.g.
 *        <code>{"QString;","I"}</code>
 * @param isConstructor Specifies if the method is a constructor
 * @param method the method to be compared with this info's method
 * @param typeVariables a map from type variables to types
 * @param type the given type that declares the method
 * @return Returns <code>true</code> if the method has the given name and
 *         parameter types and constructor state.
 * @throws JavaModelException if the method does not exist or if an exception occurs while accessing its corresponding resource
 */
private boolean isSameMethodSignature(String name, String[] paramTypes, boolean isConstructor, IMethod method, Map<String, char[]> typeVariables, IType type) throws JavaModelException {
	if (isConstructor || name.equals(method.getElementName())) {
		if (isConstructor == method.isConstructor()) {
			String[] otherParams= method.getParameterTypes(); // types may be type variables
			boolean isBinaryConstructorForNonStaticMemberClass=
					method.isBinary()
					&& type.isMember()
					&& !Flags.isStatic(type.getFlags());
			int syntheticParameterCorrection= isBinaryConstructorForNonStaticMemberClass && paramTypes.length == otherParams.length - 1 ? 1 : 0;
			if (paramTypes.length == otherParams.length - syntheticParameterCorrection) {
				fFallbackMatch= method;
				String signature= method.getSignature();
				String[] otherParamsFromSignature= Signature.getParameterTypes(signature); // types are resolved / upper-bounded
				// no need to check method type variables since these are
				// not yet bound when proposing a method
				for (int i= 0; i < paramTypes.length; i++) {
					String ourParamName= computeSimpleTypeName(paramTypes[i], typeVariables);
					String otherParamName1= computeSimpleTypeName(otherParams[i + syntheticParameterCorrection], typeVariables);
					String otherParamName2= computeSimpleTypeName(otherParamsFromSignature[i + syntheticParameterCorrection], typeVariables);

					if (!ourParamName.equals(otherParamName1) && !ourParamName.equals(otherParamName2)) {
						return false;
					}
				}
				return true;
			}
		}
	}
	return false;
}
 
Example 13
Source File: RefactoringAvailabilityTester.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
public static boolean isMoveMethodAvailable(final IMethod method) throws JavaModelException {
	return method.exists() && !method.isConstructor() && !method.isBinary() && !method.isReadOnly() && !JdtFlags.isStatic(method) && (JdtFlags.isDefaultMethod(method) || !method.getDeclaringType().isInterface());
}
 
Example 14
Source File: RefactoringAvailabilityTester.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public static boolean isMoveMethodAvailable(final IMethod method) throws JavaModelException {
	return method.exists() && !method.isConstructor() && !method.isBinary() && !method.isReadOnly()
			&& !JdtFlags.isStatic(method) && (JdtFlags.isDefaultMethod(method) || !method.getDeclaringType().isInterface());
}