List of usage examples for org.eclipse.jdt.core ITypeHierarchy getAllSuperclasses
IType[] getAllSuperclasses(IType type);
From source file:com.android.ide.eclipse.adt.internal.lint.EclipseLintClient.java
License:Open Source License
@Override @Nullable/*from w w w . ja v a 2 s. com*/ public Boolean isSubclassOf(@NonNull Project project, @NonNull String name, @NonNull String superClassName) { if (!mSearchForSuperClasses) { // Super type search using the Eclipse index is potentially slow, so // only do this when necessary return null; } IProject eclipseProject = getProject(project); if (eclipseProject == null) { return null; } try { IJavaProject javaProject = BaseProjectHelper.getJavaProject(eclipseProject); if (javaProject == null) { return null; } String typeFqcn = ClassContext.getFqcn(name); IType type = javaProject.findType(typeFqcn); if (type != null) { ITypeHierarchy hierarchy = type.newSupertypeHierarchy(new NullProgressMonitor()); IType[] allSupertypes = hierarchy.getAllSuperclasses(type); if (allSupertypes != null) { String target = 'L' + superClassName + ';'; for (IType superType : allSupertypes) { if (target.equals(superType.getKey())) { return Boolean.TRUE; } } return Boolean.FALSE; } } } catch (JavaModelException e) { log(Severity.INFORMATIONAL, e, null); } catch (CoreException e) { log(Severity.INFORMATIONAL, e, null); } return null; }
From source file:com.android.ide.eclipse.adt.internal.refactoring.core.AndroidTypeMoveParticipant.java
License:Open Source License
@Override protected boolean initialize(Object element) { if (element instanceof IType) { IType type = (IType) element;/*from w w w. j a v a2 s.c om*/ IJavaProject javaProject = (IJavaProject) type.getAncestor(IJavaElement.JAVA_PROJECT); IProject project = javaProject.getProject(); IResource manifestResource = project .findMember(AdtConstants.WS_SEP + SdkConstants.FN_ANDROID_MANIFEST_XML); if (manifestResource == null || !manifestResource.exists() || !(manifestResource instanceof IFile)) { RefactoringUtil.logInfo("Invalid or missing the " + SdkConstants.FN_ANDROID_MANIFEST_XML + " in the " + project.getName() + " project."); return false; } mAndroidManifest = (IFile) manifestResource; ManifestData manifestData; manifestData = AndroidManifestHelper.parseForData(mAndroidManifest); if (manifestData == null) { return false; } mJavaPackage = manifestData.getPackage(); mOldName = type.getFullyQualifiedName(); Object destination = getArguments().getDestination(); if (destination instanceof IPackageFragment) { IPackageFragment packageFragment = (IPackageFragment) destination; mNewName = packageFragment.getElementName() + "." + type.getElementName(); } if (mOldName == null || mNewName == null) { return false; } mAndroidElements = addAndroidElements(); try { ITypeHierarchy typeHierarchy = type.newSupertypeHierarchy(null); if (typeHierarchy == null) { return false; } IType[] superTypes = typeHierarchy.getAllSuperclasses(type); for (int i = 0; i < superTypes.length; i++) { IType superType = superTypes[i]; String className = superType.getFullyQualifiedName(); if (className.equals(SdkConstants.CLASS_VIEW)) { addLayoutChanges(project, type.getFullyQualifiedName()); break; } } } catch (JavaModelException ignore) { } return mAndroidElements.size() > 0 || mFileChanges.size() > 0; } return false; }
From source file:com.android.ide.eclipse.adt.internal.refactoring.core.AndroidTypeRenameParticipant.java
License:Open Source License
@Override protected boolean initialize(Object element) { if (element instanceof IType) { IType type = (IType) element;// w w w . j av a 2 s. com IJavaProject javaProject = (IJavaProject) type.getAncestor(IJavaElement.JAVA_PROJECT); IProject project = javaProject.getProject(); IResource manifestResource = project .findMember(AdtConstants.WS_SEP + SdkConstants.FN_ANDROID_MANIFEST_XML); if (manifestResource == null || !manifestResource.exists() || !(manifestResource instanceof IFile)) { RefactoringUtil.logInfo("Invalid or missing the " + SdkConstants.FN_ANDROID_MANIFEST_XML + " in the " + project.getName() + " project."); return false; } mAndroidManifest = (IFile) manifestResource; ManifestData manifestData; manifestData = AndroidManifestHelper.parseForData(mAndroidManifest); if (manifestData == null) { return false; } mAppPackage = manifestData.getPackage(); mOldName = type.getFullyQualifiedName(); String packageName = type.getPackageFragment().getElementName(); mNewName = getArguments().getNewName(); if (packageName != null) { mLayoutNewName = packageName + "." + getArguments().getNewName(); //$NON-NLS-1$ } else { mLayoutNewName = getArguments().getNewName(); } if (mOldName == null || mNewName == null) { return false; } if (!RefactoringUtil.isRefactorAppPackage() && mNewName.indexOf(".") == -1) { //$NON-NLS-1$ mNewName = packageName + "." + mNewName; //$NON-NLS-1$ } mAndroidElements = addAndroidElements(); try { ITypeHierarchy typeHierarchy = type.newSupertypeHierarchy(null); if (typeHierarchy == null) { return false; } IType[] superTypes = typeHierarchy.getAllSuperclasses(type); for (int i = 0; i < superTypes.length; i++) { IType superType = superTypes[i]; String className = superType.getFullyQualifiedName(); if (className.equals(SdkConstants.CLASS_VIEW)) { addLayoutChanges(project, type.getFullyQualifiedName()); break; } } } catch (JavaModelException ignore) { } return mAndroidElements.size() > 0 || mFileChanges.size() > 0; } return false; }
From source file:com.aqua.wikiwizard.ObjectsJavaModel.java
License:Apache License
/** * Create an object from a given java type * @param javaObject// www . j a va 2 s .co m * Any given java type * @throws Exception */ public ObjectsJavaModel(IType javaObject) throws Exception { this.javaObject = javaObject; if (javaObject.getTypeQualifiedName().equals("Linux")) { System.out.println(""); } ITypeHierarchy hierarchy = javaObject.newTypeHierarchy(null); IType[] superTypes = hierarchy.getAllSuperclasses(javaObject); IType[] allTypes = new IType[superTypes.length + 1]; // Create a new array and add this type to the end of the list System.arraycopy(superTypes, 0, allTypes, 0, superTypes.length); allTypes[superTypes.length] = javaObject; ArrayList<IJavaElement> elements = new ArrayList<IJavaElement>(); for (IType curObject : allTypes) { // Don't need the actual SystemObjectImpl & Object fields if (curObject.getElementName().equals("SystemObjectImpl") || curObject.getElementName().equals("Object")) { continue; } // Add all children of this type elements.addAll(Arrays.asList(curObject.getChildren())); } allChildrens = elements.toArray(new IJavaElement[elements.size()]); }
From source file:com.google.gwt.eclipse.core.launch.GWTJUnitPropertyTester.java
License:Open Source License
private static boolean isGWTTestCaseOrSuite(IType type) { try {//from ww w. j av a2 s .co m ITypeHierarchy hierarchy = type.newSupertypeHierarchy(null); IType[] superclasses = hierarchy.getAllSuperclasses(type); for (IType superclass : superclasses) { if (GWT_TEST_CASE.equals(superclass.getFullyQualifiedName()) || GWT_TEST_SUITE.equals(superclass.getFullyQualifiedName())) { return true; } } return false; } catch (CoreException e) { GWTPluginLog.logError(e); return false; } }
From source file:com.halware.nakedide.eclipse.ext.builders.checkers.TypeChecker.java
License:Open Source License
public void checkTitle() throws JavaModelException, CoreException { if (type.isInterface()) { return;//from w w w. j a v a 2 s. com } // ignore anything that isn't an @Entity. ASTParser newParser = ASTParser.newParser(AST.JLS3); ; newParser.setSource(type.getCompilationUnit()); newParser.setResolveBindings(true); ASTNode astNode = newParser.createAST(null); CompilationUnit parsedCompilationUnit = (CompilationUnit) astNode; TypeDeclaration typeDeclaration = AstUtils.determineTypeDeclaration(parsedCompilationUnit); if (!TypeUtils.isEntityType(typeDeclaration.resolveBinding())) { return; } IMethod titleMethod = titleMethod(type); if (titleMethod.exists()) { if (!titleMethodReturnsString(titleMethod)) { createProblemMarker(titleMethod, MarkerConstants.ID_TITLE_NOT_RETURNING_STRING, "title method must return a String"); } return; } if (toStringMethod(type).exists()) { return; } ITypeHierarchy supertypes = type.newSupertypeHierarchy(null); IType[] allSuperclasses = supertypes.getAllSuperclasses(type); for (IType superclass : allSuperclasses) { if ("Ljava/lang/Object;".equals(superclass.getKey())) { continue; } if (toStringMethod(superclass).exists()) { return; } titleMethod = titleMethod(superclass); if (MethodUtils.checkExists(titleMethod) != null) { return; } } createProblemMarker(type, MarkerConstants.ID_NO_TITLE_OR_OVERRIDDEN_STRING, "No title or overridden toString"); }
From source file:com.sabre.buildergenerator.eclipsejavamodel.ModelHelper.java
License:Open Source License
private Collection<IMethod> findAllMethods(IType type) throws JavaModelException { List<IMethod> methods = new ArrayList<IMethod>(Arrays.asList(type.getMethods())); ITypeHierarchy typeHierarchy = type.newSupertypeHierarchy(new NullProgressMonitor()); IType[] superTypes = typeHierarchy.getAllSuperclasses(type); for (IType superType : superTypes) { if (superType.getTypeParameters().length > 0) { break; }// w ww. j a v a 2 s . c om IMethod[] superMethods = superType.getMethods(); if (superMethods != null) { methods.addAll(Arrays.asList(superMethods)); } } return methods; }
From source file:de.enough.mepose.core.model.MiDletChangeListener.java
License:Open Source License
protected MidletItem generateMiDLetFromResource(IResource resource) { IJavaElement javaElement = JavaCore.create(resource); if (javaElement == null) { return null; }// w w w . j av a 2s.c om if (javaElement.getElementType() != IJavaElement.COMPILATION_UNIT) { return null; } ICompilationUnit compilationUnit = (ICompilationUnit) javaElement; IType primaryType = compilationUnit.findPrimaryType(); if (primaryType == null) { return null; } int flags; try { flags = primaryType.getFlags(); } catch (JavaModelException exception) { MeposePlugin.log(exception); return null; } if (Flags.isAbstract(flags)) { return null; } ITypeHierarchy supertypeHierarchy; try { supertypeHierarchy = primaryType.newSupertypeHierarchy(new NullProgressMonitor()); } catch (JavaModelException exception) { return null; } IType[] allSuperclasses = supertypeHierarchy.getAllSuperclasses(primaryType); for (int i = 0; i < allSuperclasses.length; i++) { if ("MIDlet".equals(allSuperclasses[i].getElementName())) { MidletItem midletItem = new MidletItem(); midletItem.setResource(resource); midletItem.setClassName(primaryType.getFullyQualifiedName()); midletItem.setName(primaryType.getElementName()); return midletItem; } } return null; }
From source file:edu.brown.cs.bubbles.bedrock.BedrockUtil.java
License:Open Source License
/********************************************************************************/ static void outputTypeHierarchy(ITypeHierarchy th, IvyXmlWriter xw) { xw.begin("HIERARCHY"); IType[] typs = th.getAllTypes();//from www .j av a 2s .com for (IType typ : typs) { xw.begin("TYPE"); try { xw.field("NAME", typ.getFullyQualifiedName()); xw.field("QNAME", typ.getTypeQualifiedName()); xw.field("PNAME", typ.getFullyQualifiedParameterizedName()); if (typ.isClass()) xw.field("KIND", "CLASS"); else if (typ.isEnum()) xw.field("KIND", "ENUM"); else if (typ.isInterface()) xw.field("KIND", "INTERFACE"); xw.field("LOCAL", typ.isLocal()); xw.field("MEMBER", typ.isMember()); xw.field("KEY", typ.getKey()); IType[] subs = th.getAllSubtypes(typ); for (IType styp : subs) { xw.begin("SUBTYPE"); xw.field("NAME", styp.getFullyQualifiedName()); xw.field("KEY", styp.getKey()); xw.end("SUBTYPE"); } IType[] sups = th.getAllSuperclasses(typ); for (IType styp : sups) { xw.begin("SUPERCLASS"); xw.field("NAME", styp.getFullyQualifiedName()); xw.field("KEY", styp.getKey()); xw.end("SUPERCLASS"); } sups = th.getAllSuperInterfaces(typ); for (IType styp : sups) { xw.begin("SUPERIFACE"); xw.field("NAME", styp.getFullyQualifiedName()); xw.field("KEY", styp.getKey()); xw.end("SUPERIFACE"); } sups = th.getAllSupertypes(typ); for (IType styp : sups) { xw.begin("SUPERTYPE"); xw.field("NAME", styp.getFullyQualifiedName()); xw.field("KEY", styp.getKey()); xw.end("SUPERTYPE"); } sups = th.getExtendingInterfaces(typ); for (IType styp : sups) { xw.begin("EXTENDIFACE"); xw.field("NAME", styp.getFullyQualifiedName()); xw.field("KEY", styp.getKey()); xw.end("EXTENDIFACE"); } sups = th.getImplementingClasses(typ); for (IType styp : sups) { xw.begin("IMPLEMENTOR"); xw.field("NAME", styp.getFullyQualifiedName()); xw.field("KEY", styp.getKey()); xw.end("IMPLEMENTOR"); } } catch (JavaModelException e) { } xw.end("TYPE"); } xw.end("HIERARCHY"); }
From source file:net.hillsdon.testlink.model.impl.AbstractLinker.java
License:Open Source License
public Linkage getLinkageFor(final IType type) throws JavaModelException { final ITypeHierarchy supertypeHierarchy = type.newSupertypeHierarchy(new NullProgressMonitor()); // JUnit 4./*w w w. j a va 2 s. com*/ for (IMethod method : type.getMethods()) { for (IAnnotation annotation : method.getAnnotations()) { final String name = annotation.getElementName(); if (name != null) { final String[][] resolutions = type.resolveType(name); if (resolutions != null) { for (String[] resolved : resolutions) { if ("org.junit".equals(resolved[0])) { return Linkage.TEST; } } } } } } // JUnit 3. for (IType superClass : supertypeHierarchy.getAllSuperclasses(type)) { if (TEST_SUPER_CLASSES.contains(superClass.getFullyQualifiedName())) { return Linkage.TEST; } } return Linkage.IMPL; }