List of usage examples for org.eclipse.jdt.core ITypeHierarchy exists
boolean exists();
From source file:at.bestsolution.fxide.jdt.corext.util.SuperTypeHierarchyCache.java
License:Open Source License
private static void addTypeHierarchyToCache(ITypeHierarchy hierarchy) { synchronized (fgHierarchyCache) { int nEntries = fgHierarchyCache.size(); if (nEntries >= CACHE_SIZE) { // find obsolete entries or remove entry that was least recently accessed HierarchyCacheEntry oldest = null; ArrayList<HierarchyCacheEntry> obsoleteHierarchies = new ArrayList<>(CACHE_SIZE); for (int i = 0; i < nEntries; i++) { HierarchyCacheEntry entry = fgHierarchyCache.get(i); ITypeHierarchy curr = entry.getTypeHierarchy(); if (!curr.exists() || hierarchy.contains(curr.getType())) { obsoleteHierarchies.add(entry); } else { if (oldest == null || entry.getLastAccess() < oldest.getLastAccess()) { oldest = entry;/* w w w . jav a 2 s. c o m*/ } } } if (!obsoleteHierarchies.isEmpty()) { for (int i = 0; i < obsoleteHierarchies.size(); i++) { removeHierarchyEntryFromCache(obsoleteHierarchies.get(i)); } } else if (oldest != null) { removeHierarchyEntryFromCache(oldest); } } HierarchyCacheEntry newEntry = new HierarchyCacheEntry(hierarchy); fgHierarchyCache.add(newEntry); } }
From source file:at.bestsolution.fxide.jdt.corext.util.SuperTypeHierarchyCache.java
License:Open Source License
private static ITypeHierarchy findTypeHierarchyInCache(IType type) { synchronized (fgHierarchyCache) { for (int i = fgHierarchyCache.size() - 1; i >= 0; i--) { HierarchyCacheEntry curr = fgHierarchyCache.get(i); ITypeHierarchy hierarchy = curr.getTypeHierarchy(); if (!hierarchy.exists()) { removeHierarchyEntryFromCache(curr); } else { if (hierarchy.contains(type)) { curr.markAsAccessed(); return hierarchy; }/*w w w . j a v a 2 s .co m*/ } } } return null; }
From source file:com.iw.plugins.spindle.core.builder.WebXMLScanner.java
License:Mozilla Public License
protected boolean checkJavaSubclassOfImplements(IType superclass, IType candidate, ISourceLocation location) { boolean match = false; if (superclass.equals(candidate)) return match; try {/*from w ww . j a va 2 s . c o m*/ if (candidate.isInterface()) addProblem(IProblem.ERROR, location, "web-xml-must-be-class-not-interface", false, IProblem.WEB_XML_INCORRECT_APPLICATION_SERVLET_CLASS); ITypeHierarchy hierarchy = candidate.newSupertypeHierarchy(null); if (hierarchy.exists()) { IType[] superClasses = hierarchy.getAllSupertypes(candidate); for (int i = 0; i < superClasses.length; i++) { match = superClasses[i].equals(superclass); if (match) break; } } } catch (JavaModelException e) { TapestryCore.log(e); e.printStackTrace(); } // if (!match) // addProblem(IProblem.ERROR, location, "web-xml-does-not-subclass"); return match; }
From source file:com.iw.plugins.spindle.core.util.CoreUtils.java
License:Mozilla Public License
/** * Answer true iff the candidate type is a subclass of the base Type * /*www .j a v a 2s . c o m*/ * @param candidate * the supposed subclass of the base Type * @param baseType * the supposed superclass of the candidate Type * @return true iff the candidate type is a subclass of the base Type * @throws JavaModelException */ public static boolean extendsType(IType candidate, IType baseType) throws JavaModelException { Assert.isNotNull(candidate); Assert.isNotNull(baseType); boolean match = false; ITypeHierarchy hierarchy = candidate.newSupertypeHierarchy(null); if (hierarchy.exists()) { IType[] superClasses = hierarchy.getAllSupertypes(candidate); for (int i = 0; i < superClasses.length; i++) { match = superClasses[i].equals(baseType); if (match) break; } } return match; }
From source file:com.iw.plugins.spindle.ui.wizards.fields.ApplicationServletClassDialog.java
License:Mozilla Public License
private IStatus hasTapestryServletClassAsSuperType(String superclassName, IPackageFragmentRoot root) { SpindleStatus status = new SpindleStatus(); enableButton(root == null);// w w w. ja va2 s.c om if (root == null) { return status; } String superclassBaseTypeName = UIPlugin.getString("TapestryEngine.defaultServlet"); if (superclassBaseTypeName == null) { throw new Error("tapestry servlet type: " + superclassBaseTypeName + " does not exist in properties!"); } if (!superclassName.equals(superclassBaseTypeName)) { try { IType chosenSuperclassType = resolveTypeName(root.getJavaProject(), superclassName); if (chosenSuperclassType == null) { status.setWarning(UIPlugin.getString(name + ".warning.TypeNotExists", superclassName)); return status; } boolean isBinary = chosenSuperclassType.isBinary(); IType superclassBaseType = resolveTypeName(root.getJavaProject(), superclassBaseTypeName); if (superclassBaseType == null || !superclassBaseType.exists()) { status.setError(UIPlugin.getString(name + ".warning.TypeNotExists", superclassBaseTypeName)); return status; } boolean match = false; ITypeHierarchy hierarchy = chosenSuperclassType.newSupertypeHierarchy(null); if (hierarchy.exists()) { IType[] superClasses = hierarchy.getAllSupertypes(chosenSuperclassType); for (int i = 0; i < superClasses.length; i++) { if (superClasses[i].equals(superclassBaseType)) { match = true; } } } if (!match) { status.setError( UIPlugin.getString(name + ".warning.SuperclassClassNotExtend", superclassBaseTypeName)); return status; } } catch (JavaModelException e) { status.setError(name + ".error.couldn't.do.it"); } } return status; }
From source file:com.iw.plugins.spindle.ui.wizards.fields.EngineClassDialog.java
License:Mozilla Public License
protected IStatus typeChanged() { SpindleStatus status = new SpindleStatus(); String engineClassname = getTextValue(); IPackageFragmentRoot root = packageChooser.getContainer().getPackageFragmentRoot(); enableButton(root != null);//from ww w.j ava 2 s . c o m chosenType = null; if (root == null || engineClassname == null || "".equals(engineClassname)) { status.setError(UIPlugin.getString(name + ".warning.TypeNotExists", "'empty string'")); return status; } try { IType engineType = resolveTypeName(root.getJavaProject(), engineClassname); if (engineType == null) { status.setError(UIPlugin.getString(name + ".warning.TypeNotExists", engineClassname)); return status; } boolean isBinary = engineType.isBinary(); String engineBaseTypeName = UIPlugin.getString("TapestryEngine.classname"); if (engineBaseTypeName == null) { throw new Error( "tapestry engine base type: " + engineBaseTypeName + " does not exist in properties!"); } IType engineBaseType = resolveTypeName(root.getJavaProject(), engineBaseTypeName); if (engineBaseType == null || !engineBaseType.exists()) { status.setError(UIPlugin.getString(name + ".warning.EngineBaseTypeNotExists", engineBaseTypeName)); return status; } boolean match = false; if (engineBaseType.isInterface()) { String[] superInterfaces = engineType.getSuperInterfaceNames(); if (superInterfaces != null && superInterfaces.length > 0) { for (int i = 0; i < superInterfaces.length; i++) { if (isBinary && engineBaseTypeName.endsWith(superInterfaces[i])) { match = true; } else { match = engineBaseTypeName.equals(superInterfaces[i]); } } } else { match = false; } if (!match) { status.setWarning(UIPlugin.getString(name + ".warning.EngineDoesNotImplementInterface", engineBaseTypeName)); return status; } } else { ITypeHierarchy hierarchy = engineType.newSupertypeHierarchy(null); if (hierarchy.exists()) { IType[] superClasses = hierarchy.getAllSupertypes(engineType); for (int i = 0; i < superClasses.length; i++) { if (superClasses[i].equals(engineBaseType)) { match = true; } } } if (!match) { if (!canFindJavaxServletJar(root.getJavaProject())) { status.setError(UIPlugin.getString(name + ".error.javax.servlet.jar.NOTFOUND")); } else { status.setError( UIPlugin.getString(name + ".warning.EngineClassNotExtend", engineBaseTypeName)); } return status; } chosenType = engineType; } } catch (JavaModelException e) { status.setError(name + ".error.couldn't.do.it"); } return status; }
From source file:com.iw.plugins.spindle.ui.wizards.fields.RawTypeDialogField.java
License:Mozilla Public License
protected boolean extendsType(IType candidate, IType baseType) throws JavaModelException { boolean match = false; ITypeHierarchy hierarchy = candidate.newSupertypeHierarchy(null); if (hierarchy.exists()) { IType[] superClasses = hierarchy.getAllSupertypes(candidate); for (int i = 0; i < superClasses.length; i++) { if (superClasses[i].equals(baseType)) { match = true;// w ww. j a v a2 s . co m } } } return match; }
From source file:com.iw.plugins.spindle.ui.wizards.fields.RawTypeDialogField.java
License:Mozilla Public License
protected boolean implementsInterface(IType candidate, String interfaceName) throws JavaModelException { if (interfaceMatch(candidate, interfaceName)) { return true; }/* w w w. ja v a2 s . c o m*/ ITypeHierarchy hierarchy = candidate.newSupertypeHierarchy(null); if (hierarchy.exists()) { IType[] superClasses = hierarchy.getAllSupertypes(candidate); for (int i = 0; i < superClasses.length; i++) { if (interfaceMatch(superClasses[i], interfaceName)) { return true; } } } return false; }
From source file:com.iw.plugins.spindle.util.Utils.java
License:Mozilla Public License
public static boolean extendsType(IType candidate, IType baseType) throws JavaModelException { boolean match = false; ITypeHierarchy hierarchy = candidate.newSupertypeHierarchy(null); if (hierarchy.exists()) { IType[] superClasses = hierarchy.getAllSupertypes(candidate); for (int i = 0; i < superClasses.length; i++) { if (superClasses[i].equals(baseType)) { match = true;/* w w w. jav a 2 s . com*/ } } } return match; }
From source file:com.iw.plugins.spindle.wizards.fields.ApplicationServletClassDialog.java
License:Mozilla Public License
private IStatus hasTapestryServletClassAsSuperType(String superclassName, IPackageFragmentRoot root) { SpindleStatus status = new SpindleStatus(); enableButton(root == null);//from w w w .j av a2 s . c om if (root == null) { return status; } String superclassBaseTypeName = MessageUtil.getString("TapestryEngine.defaultServlet"); if (superclassBaseTypeName == null) { throw new Error("tapestry servlet type: " + superclassBaseTypeName + " does not exist in properties!"); } if (!superclassName.equals(superclassBaseTypeName)) { try { IType chosenSuperclassType = resolveTypeName(root.getJavaProject(), superclassName); if (chosenSuperclassType == null) { status.setWarning( MessageUtil.getFormattedString(name + ".warning.TypeNotExists", superclassName)); return status; } boolean isBinary = chosenSuperclassType.isBinary(); IType superclassBaseType = resolveTypeName(root.getJavaProject(), superclassBaseTypeName); if (superclassBaseType == null || !superclassBaseType.exists()) { status.setError(MessageUtil.getFormattedString(name + ".warning.TypeNotExists", superclassBaseTypeName)); return status; } boolean match = false; ITypeHierarchy hierarchy = chosenSuperclassType.newSupertypeHierarchy(null); if (hierarchy.exists()) { IType[] superClasses = hierarchy.getAllSupertypes(chosenSuperclassType); for (int i = 0; i < superClasses.length; i++) { if (superClasses[i].equals(superclassBaseType)) { match = true; } } } if (!match) { status.setError(MessageUtil.getFormattedString(name + ".warning.SuperclassClassNotExtend", superclassBaseTypeName)); return status; } } catch (JavaModelException e) { status.setError(name + ".error.couldn't.do.it"); } } return status; }