List of usage examples for org.eclipse.jdt.core IJavaElement METHOD
int METHOD
To view the source code for org.eclipse.jdt.core IJavaElement METHOD.
Click Source Link
From source file:org.playframework.playclipse.handlers.GoToViewHandler.java
License:Apache License
/** * @param selection/*from w w w . java2 s . c o m*/ * @param unit */ private String getEnclosingActionName(ITextSelection selection, ICompilationUnit unit) { IJavaElement selected; try { selected = unit.getElementAt(selection.getOffset()); List<IJavaElement> path = getJavaElementsPath(selected); if (path.size() >= 7) { IJavaElement el = path.get(6); if (el.getElementType() == IJavaElement.METHOD) { IMethod sm = (IMethod) el; int flags = sm.getFlags(); String actionMethodName = el.getElementName(); if (/*Flags.isPublic(flags) &&*/ Flags.isStatic(flags)) { return actionMethodName; } else { info("The enclosig method " + actionMethodName + " is not public static, thus not a valid action method."); } } } } catch (JavaModelException e) { PlayPlugin.showError(e); } return null; }
From source file:org.playframework.playclipse.handlers.OpenWithBrowserHandler.java
License:Apache License
/** * @param selection//from ww w. ja va 2 s . c o m * @param unit */ private String getEnclosingActionName(ITextSelection selection, ICompilationUnit unit) { IJavaElement selected; try { selected = unit.getElementAt(selection.getOffset()); List<IJavaElement> path = getJavaElementsPath(selected); if (path.size() >= 7) { IJavaElement el = path.get(6); if (el.getElementType() == IJavaElement.METHOD) { IMethod sm = (IMethod) el; int flags = sm.getFlags(); String actionMethodName = el.getElementName(); if (Flags.isPublic(flags) && Flags.isStatic(flags)) { return actionMethodName; } else { info("The enclosig method " + actionMethodName + " is not public static, thus not a valid action method."); } } } } catch (JavaModelException e) { PlayPlugin.showError(e); } return null; }
From source file:org.projectusus.ui.internal.proportions.infopresenter.infomodel.UsusInfoBuilder.java
License:Open Source License
public static IUsusInfo of(IJavaElement element) { try {/* w w w . j a va 2 s .co m*/ IJavaElement currentElement = element; while (currentElement != null) { if (currentElement.getElementType() == IJavaElement.METHOD) { return new UsusInfoForMethod((IMethod) currentElement); } if (currentElement.getElementType() == IJavaElement.TYPE) { return new UsusInfoForClass((IType) currentElement); } if (currentElement.getElementType() == IJavaElement.COMPILATION_UNIT) { return new UsusInfoForFile(currentElement.getUnderlyingResource()); } currentElement = currentElement.getParent(); } } catch (JavaModelException e) { // do nothing } return new UnavailableUsusInfo(element); }
From source file:org.projectusus.ui.internal.proportions.infopresenter.infomodel.UsusInfoBuilderTest.java
License:Open Source License
@Test public void availableDataYieldsMeaningfulInfo() throws JavaModelException { IMethod method = mock(IMethod.class); IType classMock = mock(IType.class); IFile fileMock = mock(IFile.class); when(Integer.valueOf(method.getElementType())).thenReturn(Integer.valueOf(IJavaElement.METHOD)); when(method.getDeclaringType()).thenReturn(classMock); when(classMock.getUnderlyingResource()).thenReturn(fileMock); IUsusInfo info = UsusInfoBuilder.of(method); assertEquals(UsusInfoForMethod.class, info.getClass()); }
From source file:org.seasar.s2junit4plugin.wizard.S2JUnit4StubUtility.java
License:Apache License
public static boolean isVisible(IMember member, IPackageFragment pack) throws JavaModelException { int type = member.getElementType(); if (type == IJavaElement.INITIALIZER || (type == IJavaElement.METHOD && member.getElementName().startsWith("<"))) { //$NON-NLS-1$ return false; }/* w w w . j av a 2 s .c o m*/ int otherflags = member.getFlags(); IType declaringType = member.getDeclaringType(); if (Flags.isPublic(otherflags) || (declaringType != null && declaringType.isInterface())) { return true; } else if (Flags.isPrivate(otherflags)) { return false; } IPackageFragment otherpack = (IPackageFragment) member.getAncestor(IJavaElement.PACKAGE_FRAGMENT); return (pack != null && otherpack != null && pack.getElementName().equals(otherpack.getElementName())); }
From source file:org.springframework.ide.eclipse.beans.ui.refactoring.actions.BeansRenameRefactorAction.java
License:Open Source License
private boolean isRenameAvailable(IJavaElement element) throws CoreException { switch (element.getElementType()) { case IJavaElement.JAVA_PROJECT: return RefactoringAvailabilityTester.isRenameAvailable((IJavaProject) element); case IJavaElement.PACKAGE_FRAGMENT_ROOT: return RefactoringAvailabilityTester.isRenameAvailable((IPackageFragmentRoot) element); case IJavaElement.PACKAGE_FRAGMENT: return RefactoringAvailabilityTester.isRenameAvailable((IPackageFragment) element); case IJavaElement.COMPILATION_UNIT: return RefactoringAvailabilityTester.isRenameAvailable((ICompilationUnit) element); case IJavaElement.TYPE: return RefactoringAvailabilityTester.isRenameAvailable((IType) element); case IJavaElement.METHOD: final IMethod method = (IMethod) element; if (method.isConstructor()) return RefactoringAvailabilityTester.isRenameAvailable(method.getDeclaringType()); else/* w ww. j a v a2s .co m*/ return RefactoringAvailabilityTester.isRenameAvailable(method); case IJavaElement.FIELD: final IField field = (IField) element; if (Flags.isEnum(field.getFlags())) return RefactoringAvailabilityTester.isRenameEnumConstAvailable(field); else return RefactoringAvailabilityTester.isRenameFieldAvailable(field); case IJavaElement.TYPE_PARAMETER: return RefactoringAvailabilityTester.isRenameAvailable((ITypeParameter) element); case IJavaElement.LOCAL_VARIABLE: return RefactoringAvailabilityTester.isRenameAvailable((ILocalVariable) element); } return false; }
From source file:org.springframework.ide.eclipse.beans.ui.search.jdt.BeansJavaSearchParticipant.java
License:Open Source License
public void search(final ISearchRequestor requestor, QuerySpecification querySpecification, IProgressMonitor monitor) {//from w ww . ja v a 2 s . c o m if (querySpecification.getLimitTo() != LIMIT_TO_REF && querySpecification.getLimitTo() != LIMIT_TO_ALL) { return; } String search = null; List<String> requiredTypeNames = new ArrayList<String>(); IJavaProject project = null; if (querySpecification instanceof ElementQuerySpecification) { ElementQuerySpecification elementQuerySpecification = (ElementQuerySpecification) querySpecification; if (elementQuerySpecification.getElement() instanceof IType) { search = ((IType) elementQuerySpecification.getElement()).getFullyQualifiedName(); project = ((IType) elementQuerySpecification.getElement()).getJavaProject(); } else if (elementQuerySpecification.getElement() instanceof IField) { IField field = ((IField) elementQuerySpecification.getElement()); search = field.getElementName(); getTypeHierachy(monitor, requiredTypeNames, field.getDeclaringType()); project = field.getJavaProject(); } else if (elementQuerySpecification.getElement() instanceof IMethod) { IMethod method = ((IMethod) elementQuerySpecification.getElement()); search = method.getElementName(); // do property name magic if (search.startsWith("set")) { search = StringUtils.uncapitalize(search.substring(3)); } getTypeHierachy(monitor, requiredTypeNames, method.getDeclaringType()); project = method.getJavaProject(); } else { search = elementQuerySpecification.getElement().getElementName(); } int type = ((ElementQuerySpecification) querySpecification).getElement().getElementType(); if (type == IJavaElement.TYPE) { searchFor = SEARCH_FOR_TYPES; } else if (type == IJavaElement.FIELD || type == IJavaElement.METHOD) { searchFor = SEARCH_FOR_FIELDS; } } else { searchFor = ((PatternQuerySpecification) querySpecification).getSearchFor(); search = ((PatternQuerySpecification) querySpecification).getPattern(); } List<ISearchQuery> queries = new ArrayList<ISearchQuery>(); BeansSearchScope scope = BeansSearchScope.newSearchScope(); if (searchFor == SEARCH_FOR_TYPES) { queries.add(new BeanClassQuery(scope, search, true, false)); } else if (searchFor == SEARCH_FOR_FIELDS) { queries.add(new BeanPropertyQuery(scope, search, true, false)); queries.add(new BeanReferenceQuery(scope, search, true, false)); } for (ISearchQuery query : queries) { query.run(monitor); BeansSearchResult searchResult = (BeansSearchResult) query.getSearchResult(); for (Object obj : searchResult.getElements()) { Match[] matches = searchResult.getMatches(obj); if (matches != null && matches.length > 0) { for (Match match : matches) { if (match.getElement() instanceof IBean) { IBean bean = (IBean) match.getElement(); IType type = JdtUtils.getJavaType(bean.getElementResource().getProject(), bean.getClassName()); if (project == null || (type != null && project.isOnClasspath(type))) { if (searchFor == SEARCH_FOR_FIELDS) { // check if the match fits to the selected class String beanClass = BeansModelUtils.getBeanClass(bean, null); if (requiredTypeNames.contains(beanClass)) { requestor.reportMatch(match); } } else { requestor.reportMatch(match); } } } else { requestor.reportMatch(match); } } } } } }
From source file:org.springsource.ide.eclipse.gradle.core.test.util.JUnitLaunchConfigUtil.java
License:Open Source License
public static ILaunchConfigurationWorkingCopy createLaunchConfiguration(IJavaElement element) throws CoreException { final String testName; final String mainTypeQualifiedName; final String containerHandleId; switch (element.getElementType()) { case IJavaElement.JAVA_PROJECT: case IJavaElement.PACKAGE_FRAGMENT_ROOT: case IJavaElement.PACKAGE_FRAGMENT: { String name = JavaElementLabels.getTextLabel(element, JavaElementLabels.ALL_FULLY_QUALIFIED); containerHandleId = element.getHandleIdentifier(); mainTypeQualifiedName = EMPTY_STRING; testName = name.substring(name.lastIndexOf(IPath.SEPARATOR) + 1); }//from w ww . j a va 2 s . c om break; case IJavaElement.TYPE: { containerHandleId = EMPTY_STRING; mainTypeQualifiedName = ((IType) element).getFullyQualifiedName('.'); // don't replace, fix for binary inner types testName = element.getElementName(); } break; case IJavaElement.METHOD: { IMethod method = (IMethod) element; containerHandleId = EMPTY_STRING; mainTypeQualifiedName = method.getDeclaringType().getFullyQualifiedName('.'); testName = method.getDeclaringType().getElementName() + '.' + method.getElementName(); } break; default: throw new IllegalArgumentException( "Invalid element type to create a launch configuration: " + element.getClass().getName()); //$NON-NLS-1$ } String testKindId = TestKindRegistry.getContainerTestKindId(element); ILaunchConfigurationType configType = getLaunchManager() .getLaunchConfigurationType(JUnitLaunchConfigurationConstants.ID_JUNIT_APPLICATION); ILaunchConfigurationWorkingCopy wc = configType.newInstance(null, getLaunchManager().generateLaunchConfigurationName(testName)); wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, mainTypeQualifiedName); wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, element.getJavaProject().getElementName()); wc.setAttribute(JUnitLaunchConfigurationConstants.ATTR_KEEPRUNNING, false); wc.setAttribute(JUnitLaunchConfigurationConstants.ATTR_TEST_CONTAINER, containerHandleId); wc.setAttribute(JUnitLaunchConfigurationConstants.ATTR_TEST_RUNNER_KIND, testKindId); JUnitMigrationDelegate.mapResources(wc); AssertionVMArg.setArgDefault(wc); if (element instanceof IMethod) { wc.setAttribute(JUnitLaunchConfigurationConstants.ATTR_TEST_METHOD_NAME, element.getElementName()); // only set for methods } return wc; }
From source file:org.summer.dsl.model.ui.refactoring.JdtRenameRefactoringProcessorFactory.java
License:Open Source License
public JavaRenameProcessor createRenameProcessor(IJavaElement element) { try {/* w w w . j a va 2s .c o m*/ switch (element.getElementType()) { case IJavaElement.TYPE: return new RenameTypeProcessor((IType) element); case IJavaElement.FIELD: return new RenameFieldProcessor((IField) element); case IJavaElement.METHOD: if (((IMethod) element).isConstructor()) break; if (Flags.isStatic(((IMethod) element).getFlags())) return new RenameNonVirtualMethodProcessor((IMethod) element); else return new RenameVirtualMethodProcessor((IMethod) element); case IJavaElement.TYPE_PARAMETER: return new RenameTypeParameterProcessor((ITypeParameter) element); case IJavaElement.LOCAL_VARIABLE: return new RenameLocalVariableProcessor((ILocalVariable) element); } } catch (JavaModelException exc) { LOG.error("Error creating refactoring processor for " + element.getElementName(), exc); } return null; }
From source file:qwickie.util.TypeHelper.java
License:Apache License
public static boolean isWicketJavaElement(final IJavaElement javaElement) throws JavaModelException { Assert.isNotNull(javaElement);//from w w w. j a va2 s . co m if (javaElement != null && javaElement instanceof NamedMember) { if (javaElement.getElementName().equals(DocumentHelper.GET_STRING)) { return true; } else if (javaElement.getElementType() == IJavaElement.TYPE) { final NamedMember method = (NamedMember) javaElement; final IType type = method.getTypeRoot().findPrimaryType(); return hierarchyContainsComponent(type); } else if (javaElement.getElementType() == IJavaElement.METHOD) { return isWicketComponent(javaElement); } return isWicketJavaElement(javaElement.getParent()); } return false; }