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

The following examples show how to use org.eclipse.jdt.core.IMethod#getFlags() . 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: JavaElementDelegateMainLaunch.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected boolean containsElementsSearchedFor(IFile file) {
	IJavaElement element = JavaCore.create(file);
	if (element == null || !element.exists() || ! (element instanceof ICompilationUnit)) {
		return false;
	}
	try {
		ICompilationUnit cu = (ICompilationUnit) element;
		for (IType type : cu.getAllTypes()) {
			for (IMethod method : type.getMethods()) {
				int flags = method.getFlags();
				if (Modifier.isPublic(flags) && Modifier.isStatic(flags) && "main".equals(method.getElementName())
						&& method.getParameterTypes().length == 1 && method.getParameterTypes()[0].equals("[QString;")) { //$NON-NLS-1$
					return true;
				}
			}
		}
	} catch (JavaModelException e) {
		log.error(e.getMessage(), e);
	}
	return super.containsElementsSearchedFor(file);
}
 
Example 2
Source File: MethodOverrideTester.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Finds an overridden method in a type. With generics it is possible that 2 methods in the same type are overridden at the same time.
 * In that case the first overridden method found is returned.
 * @param overriddenType The type to find methods in
 * @param overriding The overriding method
 * @return The first overridden method or <code>null</code> if no method is overridden
 * @throws JavaModelException if a problem occurs
 */
public IMethod findOverriddenMethodInType(IType overriddenType, IMethod overriding) throws JavaModelException {
	int flags= overriding.getFlags();
	if (Flags.isPrivate(flags) || Flags.isStatic(flags) || overriding.isConstructor())
		return null;
	IMethod[] overriddenMethods= overriddenType.getMethods();
	for (int i= 0; i < overriddenMethods.length; i++) {
		IMethod overridden= overriddenMethods[i];
		flags= overridden.getFlags();
		if (Flags.isPrivate(flags) || Flags.isStatic(flags) || overridden.isConstructor())
			continue;
		if (isSubsignature(overriding, overridden)) {
			return overridden;
		}
	}
	return null;
}
 
Example 3
Source File: MethodOverrideTester.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Finds an overriding method in a type.
 * @param overridingType The type to find methods in
 * @param overridden The overridden method
 * @return The overriding method or <code>null</code> if no method is overriding.
 * @throws JavaModelException if a problem occurs
 */
public IMethod findOverridingMethodInType(IType overridingType, IMethod overridden) throws JavaModelException {
	int flags= overridden.getFlags();
	if (Flags.isPrivate(flags) || Flags.isStatic(flags) || overridden.isConstructor())
		return null;
	IMethod[] overridingMethods= overridingType.getMethods();
	for (int i= 0; i < overridingMethods.length; i++) {
		IMethod overriding= overridingMethods[i];
		flags= overriding.getFlags();
		if (Flags.isPrivate(flags) || Flags.isStatic(flags) || overriding.isConstructor())
			continue;
		if (isSubsignature(overriding, overridden)) {
			return overriding;
		}
	}
	return null;
}
 
Example 4
Source File: OpenSuperImplementationAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private boolean checkMethod(IMethod method) {
	try {
		int flags= method.getFlags();
		if (!Flags.isStatic(flags) && !Flags.isPrivate(flags)) {
			IType declaringType= method.getDeclaringType();
			if (SuperTypeHierarchyCache.hasInCache(declaringType)) {
				if (findSuperImplementation(method) == null) {
					return false;
				}
			}
			return true;
		}
	} catch (JavaModelException e) {
		if (!e.isDoesNotExist()) {
			JavaPlugin.log(e);
		}
	}
	return false;
}
 
Example 5
Source File: OverrideIndicatorLabelDecorator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Note: This method is for internal use only. Clients should not call this method.
 * @param element The element to decorate
 * @return Resulting decorations (combination of JavaElementImageDescriptor.IMPLEMENTS
 * and JavaElementImageDescriptor.OVERRIDES)
 *
 * @noreference This method is not intended to be referenced by clients.
 */
public int computeAdornmentFlags(Object element) {
	if (element instanceof IMethod) {
		try {
			IMethod method= (IMethod) element;
			if (!method.getJavaProject().isOnClasspath(method)) {
				return 0;
			}
			int flags= method.getFlags();
			if (!method.isConstructor() && !Flags.isPrivate(flags) && !Flags.isStatic(flags)) {
				int res= getOverrideIndicators(method);
				if (res != 0 && Flags.isSynchronized(flags)) {
					return res | JavaElementImageDescriptor.SYNCHRONIZED;
				}
				return res;
			}
		} catch (JavaModelException e) {
			if (!e.isDoesNotExist()) {
				JavaPlugin.log(e);
			}
		}
	}
	return 0;
}
 
Example 6
Source File: FindBrokenNLSKeysAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static boolean isValueAccessor(IMethod method) throws JavaModelException {
	if (!"getString".equals(method.getElementName())) //$NON-NLS-1$
		return false;

	int flags= method.getFlags();
	if (!Modifier.isStatic(flags) || !Modifier.isPublic(flags))
		return false;

	String returnType= method.getReturnType();
	if (!JAVA_LANG_STRING.equals(returnType))
		return false;

	String[] parameters= method.getParameterTypes();
	if (parameters.length != 1 || !JAVA_LANG_STRING.equals(parameters[0]))
		return false;

	return true;
}
 
Example 7
Source File: AbstractHierarchyViewerSorter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private IType getDefiningType(IMethod method) throws JavaModelException {
	int flags= method.getFlags();
	if (Flags.isPrivate(flags) || Flags.isStatic(flags) || method.isConstructor()) {
		return null;
	}

	IType declaringType= method.getDeclaringType();
	ITypeHierarchy hierarchy= getHierarchy(declaringType);
	if (hierarchy != null) {
		MethodOverrideTester tester= new MethodOverrideTester(declaringType, hierarchy);
		IMethod res= tester.findDeclaringMethod(method, true);
		if (res != null) {
			return res.getDeclaringType();
		}
	}
	return null;
}
 
Example 8
Source File: TypeHierarchyContentProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void addCompatibleMethods(IMethod filterMethod, IType typeToFindIn, List<IMember> children) throws JavaModelException {
	int flags= filterMethod.getFlags();
	if (Flags.isPrivate(flags) || Flags.isStatic(flags) || filterMethod.isConstructor())
		return;
	synchronized (fTypeHierarchyLifeCycleListener) {
		boolean filterMethodOverrides= initializeMethodOverrideTester(filterMethod, typeToFindIn);
		IMethod[] methods= typeToFindIn.getMethods();
		for (int i= 0; i < methods.length; i++) {
			IMethod curr= methods[i];
			flags= curr.getFlags();
			if (Flags.isPrivate(flags) || Flags.isStatic(flags) || curr.isConstructor())
				continue;
			if (isCompatibleMethod(filterMethod, curr, filterMethodOverrides) && !children.contains(curr)) {
				children.add(curr);
			}
		}
	}
}
 
Example 9
Source File: TypeHierarchyContentProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private boolean hasCompatibleMethod(IMethod filterMethod, IType typeToFindIn) throws JavaModelException {
	int flags= filterMethod.getFlags();
	if (Flags.isPrivate(flags) || Flags.isStatic(flags) || filterMethod.isConstructor())
		return false;
	synchronized (fTypeHierarchyLifeCycleListener) {
		boolean filterMethodOverrides= initializeMethodOverrideTester(filterMethod, typeToFindIn);
		IMethod[] methods= typeToFindIn.getMethods();
		for (int i= 0; i < methods.length; i++) {
			IMethod curr= methods[i];
			flags= curr.getFlags();
			if (Flags.isPrivate(flags) || Flags.isStatic(flags) || curr.isConstructor())
				continue;
			if (isCompatibleMethod(filterMethod, curr, filterMethodOverrides)) {
				return true;
			}
		}
		return false;
	}
}
 
Example 10
Source File: GroovyDocumentUtil.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
public static void refreshUserLibrary(Repository repository) {
    try {
        FunctionsRepositoryFactory.getUserFunctionCatgory().removeAllFunctions();
        GroovyRepositoryStore store = repository.getRepositoryStore(GroovyRepositoryStore.class);
        IJavaProject javaProject = repository.getJavaProject();
        for (IRepositoryFileStore artifact : store.getChildren()) {
            IType type = javaProject.findType(artifact.getDisplayName().replace("/", "."));
            if (type != null) {
                for (IMethod m : type.getMethods()) {
                    if (m.getFlags() == (Flags.AccStatic | Flags.AccPublic)) {
                        FunctionsRepositoryFactory.getUserFunctionCatgory()
                                .addFunction(new GroovyFunction(m, FunctionsRepositoryFactory.getUserFunctionCatgory()));
                    }
                }
            }
        }
    } catch (Exception e) {
        GroovyPlugin.logError(e);
    }
}
 
Example 11
Source File: IJUnitMethodTester.java    From jdt-codemining with Eclipse Public License 1.0 5 votes vote down vote up
public static boolean isMethod(IMethod method, boolean onlyPublicMethod) {
	try {
		int flags = method.getFlags();
		if (onlyPublicMethod && !Flags.isPublic(flags)) {
			return false;
		}
		// 'V' is void signature
		return !(method.isConstructor() || Flags.isAbstract(flags) || Flags.isStatic(flags)
				|| !"V".equals(method.getReturnType()));
	} catch (JavaModelException e) {
		// ignore
		return false;
	}
}
 
Example 12
Source File: JavaElementDelegateJunitLaunch.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected boolean containsJUnitTestMethod(IType type) throws JavaModelException {
	for (IMethod method : type.getMethods()) {
		int flags = method.getFlags();
		if (Modifier.isPublic(flags) && !Modifier.isStatic(flags) &&
				method.getNumberOfParameters() == 0 && Signature.SIG_VOID.equals(method.getReturnType()) &&
				method.getElementName().startsWith("test")) { //$NON-NLS-1$
			return true;
		}
		IAnnotation annotation= method.getAnnotation("Test"); //$NON-NLS-1$
		if (annotation.exists())
			return true;
	}
	return false;
}
 
Example 13
Source File: ConstructorPattern.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public ConstructorPattern(
	char[] declaringSimpleName,
	char[] declaringQualification,
	char[][] parameterQualifications,
	char[][] parameterSimpleNames,
	String[] parameterSignatures,
	IMethod method,
	int limitTo,
	int matchRule) {

	this(declaringSimpleName,
		declaringQualification,
		parameterQualifications,
		parameterSimpleNames,
		limitTo,
		matchRule);

	// Set flags
	try {
		this.varargs = (method.getFlags() & Flags.AccVarargs) != 0;
	} catch (JavaModelException e) {
		// do nothing
	}

	// Get unique key for parameterized constructors
	String genericDeclaringTypeSignature = null;
	if (method.isResolved()) {
		String key = method.getKey();
		BindingKey bindingKey = new BindingKey(key);
		if (bindingKey.isParameterizedType()) {
			genericDeclaringTypeSignature = Util.getDeclaringTypeSignature(key);
			// Store type signature and arguments for declaring type
			if (genericDeclaringTypeSignature != null) {
					this.typeSignatures = Util.splitTypeLevelsSignature(genericDeclaringTypeSignature);
					setTypeArguments(Util.getAllTypeArguments(this.typeSignatures));
			}
		}
	} else {
		this.constructorParameters = true;
		storeTypeSignaturesAndArguments(method.getDeclaringType());
	}

	// store type signatures and arguments for method parameters type
	if (parameterSignatures != null) {
		int length = parameterSignatures.length;
		if (length > 0) {
			this.parametersTypeSignatures = new char[length][][];
			this.parametersTypeArguments = new char[length][][][];
			for (int i=0; i<length; i++) {
				this.parametersTypeSignatures[i] = Util.splitTypeLevelsSignature(parameterSignatures[i]);
				this.parametersTypeArguments[i] = Util.getAllTypeArguments(this.parametersTypeSignatures[i]);
			}
		}
	}

	// Store type signatures and arguments for method
	this.constructorArguments = extractMethodArguments(method);
	if (hasConstructorArguments())  this.mustResolve = true;
}