Java Code Examples for org.eclipse.jdt.core.IType
The following examples show how to use
org.eclipse.jdt.core.IType.
These examples are extracted from open source projects.
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 Project: eclipse.jdt.ls Author: eclipse File: JavaElementLinks.java License: Eclipse Public License 2.0 | 6 votes |
private static IType resolveType(IType baseType, String refTypeName) throws JavaModelException { if (refTypeName.length() == 0) { return baseType; } String[][] resolvedNames = baseType.resolveType(refTypeName); if (resolvedNames != null && resolvedNames.length > 0) { return baseType.getJavaProject().findType(resolvedNames[0][0], resolvedNames[0][1].replace('$', '.'), (IProgressMonitor) null); } else if (baseType.isBinary()) { // workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=206597 IType type = baseType.getJavaProject().findType(refTypeName, (IProgressMonitor) null); if (type == null) { // could be unqualified reference: type = baseType.getJavaProject().findType(baseType.getPackageFragment().getElementName() + '.' + refTypeName, (IProgressMonitor) null); } return type; } else { return null; } }
Example #2
Source Project: Eclipse-Postfix-Code-Completion Author: trylimits File: PullUpRefactoringProcessor.java License: Eclipse Public License 1.0 | 6 votes |
private RefactoringStatus checkAccessedTypes(final IProgressMonitor monitor, final ITypeHierarchy hierarchy) throws JavaModelException { final RefactoringStatus result= new RefactoringStatus(); final IType[] accessedTypes= getTypesReferencedInMovedMembers(monitor); final IType destination= getDestinationType(); final List<IMember> pulledUpList= Arrays.asList(fMembersToMove); for (int index= 0; index < accessedTypes.length; index++) { final IType type= accessedTypes[index]; if (!type.exists()) continue; if (!canBeAccessedFrom(type, destination, hierarchy) && !pulledUpList.contains(type)) { final String message= Messages.format(RefactoringCoreMessages.PullUpRefactoring_type_not_accessible, new String[] { JavaElementLabels.getTextLabel(type, JavaElementLabels.ALL_FULLY_QUALIFIED), JavaElementLabels.getTextLabel(destination, JavaElementLabels.ALL_FULLY_QUALIFIED)}); result.addError(message, JavaStatusContext.create(type)); } } monitor.done(); return result; }
Example #3
Source Project: Eclipse-Postfix-Code-Completion Author: trylimits File: CompilationUnitCompletion.java License: Eclipse Public License 1.0 | 6 votes |
/** * Finds and returns the super type signature in the * <code>extends</code> or <code>implements</code> clause of * <code>subType</code> that corresponds to <code>superType</code>. * * @param subType a direct and true sub type of <code>superType</code> * @param superType a direct super type (super class or interface) of * <code>subType</code> * @return the super type signature of <code>subType</code> referring * to <code>superType</code> * @throws JavaModelException if extracting the super type signatures * fails, or if <code>subType</code> contains no super type * signature to <code>superType</code> */ private String findMatchingSuperTypeSignature(IType subType, IType superType) throws JavaModelException { String[] signatures= getSuperTypeSignatures(subType, superType); for (int i= 0; i < signatures.length; i++) { String signature= signatures[i]; String qualified= SignatureUtil.qualifySignature(signature, subType); String subFQN= SignatureUtil.stripSignatureToFQN(qualified); String superFQN= superType.getFullyQualifiedName(); if (subFQN.equals(superFQN)) { return signature; } // handle local types if (fLocalTypes.containsValue(subFQN)) { return signature; } } throw new JavaModelException(new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IStatus.OK, "Illegal hierarchy", null))); //$NON-NLS-1$ }
Example #4
Source Project: Eclipse-Postfix-Code-Completion Author: trylimits File: AbstractHierarchyViewerSorter.java License: Eclipse Public License 1.0 | 6 votes |
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 #5
Source Project: Eclipse-Postfix-Code-Completion Author: trylimits File: Implementors.java License: Eclipse Public License 1.0 | 6 votes |
/** * Searches for interfaces which are implemented by the declaring classes of the * specified Java elements. Currently, only IMethod instances are searched for. * Also, only the first element of the elements parameter is taken into * consideration. * * @param elements * * @return An array of found interfaces implemented by the declaring classes of the * specified Java elements (currently only IMethod instances) */ public IJavaElement[] searchForInterfaces(IJavaElement[] elements, IProgressMonitor progressMonitor) { if ((elements != null) && (elements.length > 0)) { IJavaElement element = elements[0]; if (element instanceof IMember) { IMember member = (IMember) element; IType type = member.getDeclaringType(); IType[] implementingTypes = findInterfaces(type, progressMonitor); if (!progressMonitor.isCanceled()) { if (member.getElementType() == IJavaElement.METHOD) { return findMethods((IMethod)member, implementingTypes, progressMonitor); } else { return implementingTypes; } } } } return null; }
Example #6
Source Project: gwt-eclipse-plugin Author: gwt-plugins File: GWTDeleteCompilationUnitParticipantTest.java License: Eclipse Public License 1.0 | 6 votes |
public void testCreateChange() throws OperationCanceledException, CoreException { // We're going to delete compilation unit R.java ICompilationUnit cu = rClass.getCompilationUnit(); IType r = cu.getType("R"); // Verify that the index currently contains one JSNI reference to R Set<IIndexedJavaRef> refs = JavaRefIndex.getInstance().findTypeReferences( r.getFullyQualifiedName()); assertEquals(1, refs.size()); // Delete R.java cu.delete(true, null); assertFalse(cu.exists()); // Now verify that the index entries pointing to R have been purged refs = JavaRefIndex.getInstance().findTypeReferences(r.getElementName()); assertEquals(0, refs.size()); }
Example #7
Source Project: xtext-xtend Author: eclipse File: DetectImplHyperlinksTest.java License: Eclipse Public License 2.0 | 6 votes |
@Test public void testComputeHyperlink_1() throws Exception { String content = "package foo class Foo { def b|ar(String a) {} }"; XtextEditor xtextEditor = openEditor(content.replace("|", "")); int offset = content.indexOf("|"); IHyperlink[] detectHyperlinks = hyperlinkDetector.detectHyperlinks(xtextEditor.getInternalSourceViewer(), new Region(offset,1), true); assertEquals(2, detectHyperlinks.length); IHyperlink hyperlink = detectHyperlinks[0]; assertTrue(hyperlink instanceof JdtHyperlink); JdtHyperlink casted = (JdtHyperlink) hyperlink; assertEquals(offset -1, casted.getHyperlinkRegion().getOffset()); assertEquals(3, casted.getHyperlinkRegion().getLength()); IJavaElement element = ((JdtHyperlink) hyperlink).getJavaElement(); assertTrue(element instanceof IType); assertEquals("Object", element.getElementName()); assertEquals("Open Inferred Type - Object", casted.getHyperlinkText()); }
Example #8
Source Project: bonita-studio Author: bonitasoft File: JavaSetterOperatorConstraintTest.java License: GNU General Public License v2.0 | 6 votes |
@Test public void should_fail_if_setter_method_doesnt_exist_in_left_variable_class() throws Exception { final JavaSetterOperatorConstraint constraint = createConstraint(); final IType employeeType = typeWithMethods(constraint, aPublicMethod("setChecked", Boolean.class.getName())); doReturn(employeeType).when(javaProject).findType("com.test.Employee"); final IValidationContext aValidationContext = aValidationContext(anOperator() .withType(ExpressionConstants.JAVA_METHOD_OPERATOR) .withExpression("setIsChecked") .havingInputTypes(Boolean.class.getName()) .in(anOperation().havingLeftOperand(anExpression().withName("myEmployee").withReturnType("com.test.Employee"))) .build()); constraint.performBatchValidation(aValidationContext); verify(aValidationContext).createFailureStatus( NLS.bind(Messages.methodDoesnotExistInLeftOperandType, new String[] { "setIsChecked", Boolean.class.getName(), "myEmployee" })); }
Example #9
Source Project: bonita-studio Author: bonitasoft File: JDTMethodHelper.java License: GNU General Public License v2.0 | 6 votes |
private static List<IField> getAllDeclaredFields(final IType type) throws JavaModelException { List<IField> fields = new ArrayList<>(); fields.addAll(Arrays.asList(type.getFields())); ITypeHierarchy typeHierarchy = type.newSupertypeHierarchy(Repository.NULL_PROGRESS_MONITOR); Stream.of(typeHierarchy.getAllSuperclasses(type)) .filter(t -> !Object.class.getName().equals(t.getElementName())) .filter(t -> isGroovySourceType(t)) .flatMap(t -> { try { return Stream.of(t.getFields()); } catch (JavaModelException e) { return Stream.empty(); } }) .forEach(fields::add); return fields; }
Example #10
Source Project: Eclipse-Postfix-Code-Completion Author: trylimits File: JavaTypeCompletionProposal.java License: Eclipse Public License 1.0 | 6 votes |
/** * Updates the replacement string. * * @param document the document * @param trigger the trigger * @param offset the offset * @param impRewrite the import rewrite * @return <code>true</code> if the cursor position should be updated, <code>false</code> otherwise * @throws BadLocationException if accessing the document fails * @throws CoreException if something else fails */ protected boolean updateReplacementString(IDocument document, char trigger, int offset, ImportRewrite impRewrite) throws CoreException, BadLocationException { // avoid adding imports when inside imports container if (impRewrite != null && fFullyQualifiedTypeName != null) { String replacementString= getReplacementString(); String qualifiedType= fFullyQualifiedTypeName; if (qualifiedType.indexOf('.') != -1 && replacementString.startsWith(qualifiedType) && !replacementString.endsWith(String.valueOf(';'))) { IType[] types= impRewrite.getCompilationUnit().getTypes(); if (types.length > 0 && types[0].getSourceRange().getOffset() <= offset) { // ignore positions above type. setReplacementString(impRewrite.addImport(getReplacementString())); return true; } } } return false; }
Example #11
Source Project: JDeodorant Author: tsantalis File: MethodCallAnalyzer.java License: MIT License | 6 votes |
private IType exactSubType(AbstractVariable variableDeclaration, Set<IType> subTypes) { if(variableDeclaration != null) { PlainVariable plainVariable = null; if(variableDeclaration instanceof PlainVariable) { plainVariable = (PlainVariable)variableDeclaration; } else if(variableDeclaration instanceof CompositeVariable) { plainVariable = ((CompositeVariable)variableDeclaration).getFinalVariable(); } for(IType subType : subTypes) { if(plainVariable.getVariableType().startsWith(subType.getFullyQualifiedName())) { return subType; } } } return null; }
Example #12
Source Project: sarl Author: sarl File: AbstractNewSarlElementWizardPage.java License: Apache License 2.0 | 6 votes |
@Override protected IType chooseSuperClass() { final IJavaProject project = getJavaProject(); if (project == null) { return null; } final IJvmTypeProvider typeProvider = this.jdtTypeProviderFactory.findOrCreateTypeProvider( this.resourceSetFactory.get(project.getProject())); final SarlSpecificTypeSelectionExtension extension = new SarlSpecificTypeSelectionExtension(typeProvider); this.injector.injectMembers(extension); final AbstractSuperTypeSelectionDialog<?> dialog = createSuperClassSelectionDialog(getShell(), getWizard().getContainer(), project, extension, false); if (dialog == null) { return super.chooseSuperClass(); } this.injector.injectMembers(dialog); dialog.setTitle(NewWizardMessages.NewTypeWizardPage_SuperClassDialog_title); dialog.setMessage(NewWizardMessages.NewTypeWizardPage_SuperClassDialog_message); dialog.setInitialPattern(getSuperClass()); if (dialog.open() == Window.OK) { return (IType) dialog.getFirstResult(); } return null; }
Example #13
Source Project: Eclipse-Postfix-Code-Completion Author: trylimits File: OpenSuperImplementationAction.java License: Eclipse Public License 1.0 | 6 votes |
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 #14
Source Project: Eclipse-Postfix-Code-Completion Author: trylimits File: ExpandWithConstructorsConfigurationBlock.java License: Eclipse Public License 1.0 | 6 votes |
/** * Creates the type hierarchy for type selection. */ private void doBrowseTypes() { IRunnableContext context= new BusyIndicatorRunnableContext(); IJavaSearchScope scope= SearchEngine.createWorkspaceScope(); int style= IJavaElementSearchConstants.CONSIDER_ALL_TYPES; try { SelectionDialog dialog= JavaUI.createTypeDialog(getShell(), context, scope, style, false, fNameDialogField.getText()); dialog.setTitle(CallHierarchyMessages.CallHierarchyTypesOrMembersDialog_ChooseTypeDialog_title); dialog.setMessage(CallHierarchyMessages.CallHierarchyTypesOrMembersDialog_ChooseTypeDialog_description); if (dialog.open() == Window.OK) { IType res= (IType)dialog.getResult()[0]; fNameDialogField.setText(res.getFullyQualifiedName('.')); } } catch (JavaModelException e) { ExceptionHandler.handle(e, getShell(), CallHierarchyMessages.CallHierarchyTypesOrMembersDialog_ChooseTypeDialog_title, CallHierarchyMessages.CallHierarchyTypesOrMembersDialog_ChooseTypeDialog_error_message); } }
Example #15
Source Project: eclipse.jdt.ls Author: eclipse File: OverrideMethodsTestCase.java License: Eclipse Public License 2.0 | 6 votes |
@Test public void test4() throws Exception { ICompilationUnit cu = fPackageP.getCompilationUnit("Test4.java"); IType testClass = cu.createType("public class Test4 implements B, E {\n}\n", null, true, null); List<OverridableMethod> overridableMethods = getOverridableMethods(testClass); checkUnimplementedMethods(new String[] { "c(Hashtable)", "e()" }, overridableMethods); addAndApplyOverridableMethods(testClass, overridableMethods); IMethod[] methods = testClass.getMethods(); checkMethods(new String[] { "c", "e", "equals", "clone", "toString", "finalize", "hashCode" }, methods); IImportDeclaration[] imports = cu.getImports(); checkImports(new String[] { "java.util.Hashtable", "java.util.NoSuchElementException" }, imports); }
Example #16
Source Project: xtext-eclipse Author: eclipse File: AbstractXbaseContentAssistTest.java License: Eclipse Public License 2.0 | 6 votes |
protected static void doInitBigDecimalFeatures(IJavaProject javaProject) throws JavaModelException { IType bigDecimalType = javaProject.findType(BigDecimal.class.getName()); Set<String> featuresOrTypes = Sets.newHashSet(); List<String> features = Lists.newArrayList(); List<String> staticFeatures = Lists.newArrayList(); addMethods(bigDecimalType, features, staticFeatures, featuresOrTypes); // compareTo(T) is actually overridden by compareTo(String) but contained twice in String.class#getMethods features.remove("compareTo()"); Set<String> featuresAsSet = Sets.newHashSet(features); Set<String> staticFeaturesAsSet = Sets.newHashSet(staticFeatures); Set<String> types = Sets.newHashSet(); addFields(bigDecimalType, features, staticFeatures, featuresAsSet, staticFeaturesAsSet, types); // Object extensions features.add("identityEquals()"); BIGDECIMAL_FEATURES = features.toArray(new String[features.size()]); STATIC_BIGDECIMAL_FEATURES = staticFeatures.toArray(new String[staticFeatures.size()]); }
Example #17
Source Project: jdt-codemining Author: angelozerr File: JavaMethodParameterCodeMining.java License: Eclipse Public License 1.0 | 5 votes |
private IMethod getMethod(IMethodBinding calledMethodBinding) throws JavaModelException { if (calledMethodBinding == null) { return null; } ITypeBinding calledTypeBinding = calledMethodBinding.getDeclaringClass(); IType calledType = (IType) calledTypeBinding.getJavaElement(); return Bindings.findMethod(calledMethodBinding, calledType); }
Example #18
Source Project: xtext-xtend Author: eclipse File: XtendUIValidator.java License: Eclipse Public License 2.0 | 5 votes |
protected boolean isSameProject(XAnnotation annotation, JvmType annotationType) throws JavaModelException { IJavaProject project = projectProvider.getJavaProject(annotation.eResource().getResourceSet()); if (annotationType.eResource().getURI().isPlatformResource()) { String projectName = annotationType.eResource().getURI().segments()[1]; return project.getProject().getName().equals(projectName); } else { // assume java type resource IType type = project.findType(annotationType.getIdentifier()); if (type != null && type.getUnderlyingResource() instanceof IFile) { return isInSourceFolder(project, (IFile) type.getUnderlyingResource()); } return false; } }
Example #19
Source Project: Eclipse-Postfix-Code-Completion Author: trylimits File: JavaCompareUtilities.java License: Eclipse Public License 1.0 | 5 votes |
static ImageDescriptor getImageDescriptor(IMember element) { int t= element.getElementType(); if (t == IJavaElement.TYPE) { IType type= (IType) element; try { return getTypeImageDescriptor(type.isClass()); } catch (CoreException e) { JavaPlugin.log(e); return JavaPluginImages.DESC_OBJS_GHOST; } } return getImageDescriptor(t); }
Example #20
Source Project: xtext-xtend Author: eclipse File: JavaRefactoringIntegrationTest.java License: Eclipse Public License 2.0 | 5 votes |
@Test public void testRenameInnerJavaClassImportInner() throws Exception { createFile("test/JavaClass.java", "package test; public class JavaClass { public static class Inner {} }"); String xtendModel = "import test.JavaClass$Inner\n" + "\n" + "class XtendClass extends Inner { }"; IFile xtendClass = createFile("XtendClass.xtend", xtendModel); IType javaClass = findJavaType("test.JavaClass.Inner"); assertNotNull(javaClass); renameJavaElement(javaClass, "NewInner"); fileAsserts.assertFileContains(xtendClass, xtendModel.replace("Inner", "NewInner").replace('$', '.')); }
Example #21
Source Project: Eclipse-Postfix-Code-Completion Author: trylimits File: SelectionConverter.java License: Eclipse Public License 1.0 | 5 votes |
public static IType getTypeAtOffset(JavaEditor editor) throws JavaModelException { IJavaElement element= SelectionConverter.getElementAtOffset(editor); IType type= (IType)element.getAncestor(IJavaElement.TYPE); if (type == null) { ICompilationUnit unit= SelectionConverter.getInputAsCompilationUnit(editor); if (unit != null) type= unit.findPrimaryType(); } return type; }
Example #22
Source Project: gwt-eclipse-plugin Author: gwt-plugins File: WidgetBasedUiBinderResourceCreator.java License: Eclipse Public License 1.0 | 5 votes |
private String createGetter(IType ownerClass) { StringBuilder sb = new StringBuilder(); sb.append("public void setText(String text) {\n"); sb.append("\tbutton.setText(text);\n"); sb.append("}"); return sb.toString(); }
Example #23
Source Project: eclipse.jdt.ls Author: eclipse File: JavaElementUtil.java License: Eclipse Public License 2.0 | 5 votes |
public static String createSignature(IMember member){ switch (member.getElementType()){ case IJavaElement.FIELD: return createFieldSignature((IField)member); case IJavaElement.TYPE: return BasicElementLabels.getJavaElementName(((IType)member).getFullyQualifiedName('.')); case IJavaElement.INITIALIZER: return RefactoringCoreMessages.JavaElementUtil_initializer; case IJavaElement.METHOD: return createMethodSignature((IMethod)member); default: Assert.isTrue(false); return null; } }
Example #24
Source Project: gwt-eclipse-plugin Author: gwt-plugins File: RemoteServiceUtilities.java License: Eclipse Public License 1.0 | 5 votes |
public static IType resolveSyncType(IType asyncInterface) throws JavaModelException { String asyncQualifiedName = asyncInterface.getFullyQualifiedName('.'); String syncQualifiedName = computeSyncTypeName(asyncQualifiedName); if (syncQualifiedName == null) { return null; } return asyncInterface.getJavaProject().findType(syncQualifiedName); }
Example #25
Source Project: Eclipse-Postfix-Code-Completion Author: trylimits File: AddGetterSetterAction.java License: Eclipse Public License 1.0 | 5 votes |
@Override public void run(IStructuredSelection selection) { try { IField[] selectedFields= getSelectedFields(selection); if (canRunOn(selectedFields)) { run(selectedFields[0].getDeclaringType(), selectedFields, false); return; } Object firstElement= selection.getFirstElement(); if (firstElement instanceof IType) run((IType) firstElement, new IField[0], false); else if (firstElement instanceof ICompilationUnit) { // http://bugs.eclipse.org/bugs/show_bug.cgi?id=38500 IType type= ((ICompilationUnit) firstElement).findPrimaryType(); // type can be null if file has a bad encoding if (type == null) { MessageDialog.openError(getShell(), ActionMessages.AddGetterSetterAction_no_primary_type_title, ActionMessages.AddGetterSetterAction_no_primary_type_message); notifyResult(false); return; } if (type.isAnnotation()) { MessageDialog.openInformation(getShell(), DIALOG_TITLE, ActionMessages.AddGetterSetterAction_annotation_not_applicable); notifyResult(false); return; } else if (type.isInterface()) { MessageDialog.openInformation(getShell(), DIALOG_TITLE, ActionMessages.AddGetterSetterAction_interface_not_applicable); notifyResult(false); return; } else run(((ICompilationUnit) firstElement).findPrimaryType(), new IField[0], false); } } catch (CoreException e) { ExceptionHandler.handle(e, getShell(), DIALOG_TITLE, ActionMessages.AddGetterSetterAction_error_actionfailed); } }
Example #26
Source Project: xtext-xtend Author: eclipse File: JavaRefactoringIntegrationTest.java License: Eclipse Public License 2.0 | 5 votes |
@Test public void testRenameOuterJavaClass() throws Exception { createFile("test/JavaClass.java", "package test; public class JavaClass { public static class Inner {} }"); String xtendModel = "import test.JavaClass\n" + "\n" + "class XtendClass extends JavaClass$Inner { }"; IFile xtendClass = createFile("XtendClass.xtend", xtendModel); IType javaClass = findJavaType("test.JavaClass"); assertNotNull(javaClass); renameJavaElement(javaClass, "NewJavaClass"); fileAsserts.assertFileContains(xtendClass, xtendModel.replace("JavaClass", "NewJavaClass").replace('$', '.')); }
Example #27
Source Project: birt Author: eclipse File: ClassFinder.java License: Eclipse Public License 1.0 | 5 votes |
private List findCLasses( IJavaElement element, IProgressMonitor pm ) throws JavaModelException { List found = new ArrayList( ); IJavaProject javaProject = element.getJavaProject( ); IType testCaseType = classType( javaProject ); if ( testCaseType == null ) return found; IType[] subtypes = javaProject.newTypeHierarchy( testCaseType, getRegion( element ), pm ).getAllSubtypes( testCaseType ); if ( subtypes == null ) throw new JavaModelException( new CoreException( new Status( IStatus.ERROR, ID, IJavaLaunchConfigurationConstants.ERR_UNSPECIFIED_MAIN_TYPE, ERROR_MESSAGE, null ) ) ); for ( int i = 0; i < subtypes.length; i++ ) { try { if ( hasValidModifiers( subtypes[i] ) ) found.add( subtypes[i] ); } catch ( JavaModelException e ) { logger.log(Level.SEVERE, e.getMessage(),e); } } return found; }
Example #28
Source Project: sarl Author: sarl File: FixedFatJarExportPage.java License: Apache License 2.0 | 5 votes |
protected static IType findMainMethodByName(String name, IPackageFragmentRoot[] classpathResources, IRunnableContext context) { List<IResource> resources= JarPackagerUtil.asResources(classpathResources); if (resources == null) { return null; } for (Iterator<IResource> iterator= resources.iterator(); iterator.hasNext();) { IResource element= iterator.next(); if (element == null) iterator.remove(); } IJavaSearchScope searchScope= JavaSearchScopeFactory.getInstance().createJavaSearchScope(resources.toArray(new IResource[resources.size()]), true); MainMethodSearchEngine engine= new MainMethodSearchEngine(); try { IType[] mainTypes= engine.searchMainMethods(context, searchScope, 0); for (int i= 0; i < mainTypes.length; i++) { if (mainTypes[i].getFullyQualifiedName().equals(name)) return mainTypes[i]; } } catch (InvocationTargetException ex) { JavaPlugin.log(ex); } catch (InterruptedException e) { // null } return null; }
Example #29
Source Project: Eclipse-Postfix-Code-Completion Author: trylimits File: ReorgUtils.java License: Eclipse Public License 1.0 | 5 votes |
public static IType[] getMainTypes(IJavaElement[] javaElements) throws JavaModelException { List<IJavaElement> result= new ArrayList<IJavaElement>(); for (int i= 0; i < javaElements.length; i++) { IJavaElement element= javaElements[i]; if (element instanceof IType && JavaElementUtil.isMainType((IType)element)) result.add(element); } return result.toArray(new IType[result.size()]); }
Example #30
Source Project: Eclipse-Postfix-Code-Completion Author: trylimits File: MemberVisibilityAdjustor.java License: Eclipse Public License 1.0 | 5 votes |
/** * Returns the message string for the specified member. * * @param member the member to get the string for * @return the string for the member */ public static String getMessage(final IMember member) { Assert.isTrue(member instanceof IType || member instanceof IMethod || member instanceof IField); if (member instanceof IType) return RefactoringCoreMessages.MemberVisibilityAdjustor_change_visibility_type_warning; else if (member instanceof IMethod) return RefactoringCoreMessages.MemberVisibilityAdjustor_change_visibility_method_warning; else return RefactoringCoreMessages.MemberVisibilityAdjustor_change_visibility_field_warning; }