List of usage examples for org.eclipse.jdt.core IType getSuperInterfaceNames
String[] getSuperInterfaceNames() throws JavaModelException;
From source file:mt.com.southedge.jclockwork.plugin.codegenerator.assemblers.ClassAssembler.java
License:Open Source License
private StringBuffer getType(StringBuffer sb) throws JavaModelException { IType[] types = unit.getAllTypes();// ww w .j a v a 2 s . c om for (IType type : types) { sb.append(IGeneratorModel.PUBLIC).append(IGeneratorModel.WHITESPACE).append(IGeneratorModel.CLASS); sb.append(IGeneratorModel.WHITESPACE).append(type.getElementName()); sb.append(IGeneratorModel.WHITESPACE); String superClass = type.getSuperclassName(); if (superClass != null && !superClass.isEmpty()) { sb.append(IGeneratorModel.EXTENDS).append(IGeneratorModel.WHITESPACE); sb.append(superClass).append(IGeneratorModel.WHITESPACE); } String[] interfaces = type.getSuperInterfaceNames(); if (interfaces.length > 0) { sb.append(IGeneratorModel.IMPLEMENTS).append(IGeneratorModel.WHITESPACE); for (int i = 0; i < interfaces.length; i++) { sb.append(interfaces[i]); if ((i + 1) != interfaces.length) { sb.append(IGeneratorModel.COMMA); } sb.append(IGeneratorModel.WHITESPACE); } } sb.append(IGeneratorModel.OPENCURLYBRACE).append(IGeneratorModel.NEWLINE); } return sb; }
From source file:net.harawata.mybatipse.mybatis.JavaMapperUtil.java
License:Open Source License
private static void findMapperMethodBinary(MapperMethodStore methodStore, IJavaProject project, MethodMatcher methodMatcher, IType mapperType) throws JavaModelException { for (IMethod method : mapperType.getMethods()) { if (methodMatcher.matches(method)) { methodStore.add(method);/*from w w w . jav a 2 s.com*/ } } String[] superInterfaces = mapperType.getSuperInterfaceNames(); for (String superInterface : superInterfaces) { if (!Object.class.getName().equals(superInterface)) { findMapperMethod(methodStore, project, superInterface, methodMatcher); } } }
From source file:net.harawata.mybatipse.mybatis.XmlValidator.java
License:Open Source License
private void validateProperty(IDOMElement element, IFile file, IDOMDocument doc, ValidationResult result, IJavaProject project, IDOMAttr attr, String attrValue, IReporter reporter) throws JavaModelException { String qualifiedName = MybatipseXmlUtil.findEnclosingType(element); if (MybatipseXmlUtil.isDefaultTypeAlias(qualifiedName)) { return;//from w w w . j a v a2s . c o m } IType type = project.findType(qualifiedName); if (type == null) { qualifiedName = TypeAliasCache.getInstance().resolveAlias(project, qualifiedName, reporter); } else { for (String interfaceName : type.getSuperInterfaceNames()) { // quick check if ("java.util.Map".equals(interfaceName)) return; } } if (qualifiedName == null) { // Enclosing type is missing. Valitationg properties is meaningless. return; } Map<String, String> fields = BeanPropertyCache.searchFields(project, qualifiedName, attrValue, true, -1, true); if (fields.size() == 0) { addMarker(result, file, doc.getStructuredDocument(), attr, MISSING_TYPE, IMarker.SEVERITY_ERROR, IMarker.PRIORITY_HIGH, "Property '" + attrValue + "' not found in class " + qualifiedName); } }
From source file:org.dyno.visual.swing.parser.listener.ThisClassModel.java
License:Open Source License
public boolean createEventMethod(IType type, ImportRewrite imports, IProgressMonitor monitor) { String[] inters;/* w ww. j ava2 s . co m*/ try { inters = type.getSuperInterfaceNames(); } catch (JavaModelException e) { ParserPlugin.getLogger().error(e); return false; } Class listClass = eventSet.getListenerType(); String listClassname = listClass.getName(); String cName = imports.addImport(listClassname); boolean hasInter = false; for (String inter : inters) { if (inter.equals(cName)) { hasInter = true; } } if (!hasInter) { addImplInterface(type, cName); Method[] listMethods = eventSet.getListenerMethods(); for (Method mthd : listMethods) { addInterfaceMethod(type, imports, monitor, mthd); } } return true; }
From source file:org.eclim.plugin.jdt.command.src.ClassPrototypeCommand.java
License:Open Source License
/** * Prototype the supplied type.// w w w . j a v a2 s . co m * * @param buffer The buffer to append to. * @param type The type. * @param indent The indent. * @param imports Keep track of imports. */ protected void prototype(StringBuffer buffer, IType type, String indent, Set<String> imports) throws Exception { buffer.append(indent); prototypeFlags(buffer, type); int flags = type.getFlags(); if (Flags.isEnum(flags)) { buffer.append("enum "); } else if (Flags.isInterface(flags)) { buffer.append("interface "); } else if (Flags.isAnnotation(flags)) { buffer.append("@interface "); } else { buffer.append("class "); } buffer.append(type.getElementName()); // extends String superclass = type.getSuperclassName(); if (superclass != null) { buffer.append('\n').append(indent).append(INDENT).append("extends ").append(superclass); } // implements String[] interfaces = type.getSuperInterfaceNames(); if (interfaces != null && interfaces.length > 0) { buffer.append('\n').append(indent).append(INDENT).append("implements "); for (int ii = 0; ii < interfaces.length; ii++) { if (ii != 0) { buffer.append(", "); } buffer.append(interfaces[ii]); } } buffer.append('\n').append(indent).append("{\n"); int length = buffer.length(); // fields IField[] fields = type.getFields(); for (int ii = 0; ii < fields.length; ii++) { prototypeField(buffer, fields[ii], indent + INDENT, imports); } // methods IMethod[] methods = type.getMethods(); if (methods != null && methods.length > 0) { for (int ii = 0; ii < methods.length; ii++) { if (length != buffer.length()) { buffer.append('\n'); } length = buffer.length(); prototypeMethod(buffer, methods[ii], indent + INDENT, imports); } } // inner classes, enums, etc. IType[] types = type.getTypes(); if (types != null && types.length > 0) { if (length != buffer.length()) { buffer.append('\n'); } for (int ii = 0; ii < types.length; ii++) { if (ii > 0) { buffer.append('\n'); } prototype(buffer, types[ii], indent + INDENT, imports); buffer.append('\n'); } } buffer.append(indent).append("}"); }
From source file:org.eclim.plugin.jdt.util.TypeUtils.java
License:Open Source License
/** * Gets an array of directly implemented interfaces for the supplied type, if * any./*from w ww. ja v a 2 s . c om*/ * * @param type The type to get the interfaces of. * @return Array of interface types. */ public static IType[] getSuperInterfaces(IType type) throws Exception { String[] parents = type.getSuperInterfaceNames(); ArrayList<IType> interfaces = new ArrayList<IType>(parents.length); for (String parent : parents) { String[][] types = type.resolveType(parent); if (types != null) { for (String[] typeInfo : types) { String typeName = typeInfo[0] + "." + typeInfo[1]; IType found = type.getJavaProject().findType(typeName); if (found != null) { interfaces.add(found); } } } else { IType found = type.getJavaProject().findType(parent); if (found != null) { interfaces.add(found); } } } return interfaces.toArray(new IType[interfaces.size()]); }
From source file:org.eclipse.ajdt.core.codeconversion.AspectsConvertingParser.java
License:Open Source License
/** * @param typeName name of the type//from w w w. j ava 2 s .co m * @return new type declaration string to replace the original * that contains all of the types that are declared parents of this one * returns null if could not find the super types and super interfaces */ public char[] createImplementExtendsITDs(char[] typeName) { if (unit != null && typeName != null && typeName.length > 0) { IType type = getHandle(String.valueOf(typeName)); if (type.exists()) { List<String>[] declares = getDeclareExtendsImplements(type); if (declares[0].size() == 0 && declares[1].size() == 0) { // nothing to do return null; } try { StringBuffer sb = new StringBuffer(); sb.append(type.isInterface() ? "interface " : "class "); sb.append(typeName); ITypeParameter[] tParams = type.getTypeParameters(); if (tParams != null && tParams.length > 0) { sb.append(" <"); for (int i = 0; i < tParams.length; i++) { if (i > 0) { sb.append(", "); } sb.append(tParams[i].getSource()); } sb.append("> "); } List<String> declareExtends = declares[0]; List<String> declareImplements = declares[1]; if (type.isClass()) { String superClass = type.getSuperclassName(); if (declareExtends.size() > 0) { superClass = (String) declareExtends.get(0); superClass = superClass.replace('$', '.'); } if (superClass != null) { sb.append(" " + EXTENDS + " " + superClass); } } String[] superInterfaces = type.getSuperInterfaceNames(); List<String> interfaceParents = type.isClass() ? declareImplements : declareExtends; for (int i = 0; i < superInterfaces.length; i++) { interfaceParents.add(superInterfaces[i]); } if (interfaceParents.size() > 0) { if (type.isClass()) { sb.append(" " + IMPLEMENTS); } else { sb.append(" " + EXTENDS); } for (Iterator<String> interfaceIter = interfaceParents.iterator(); interfaceIter .hasNext();) { String interName = interfaceIter.next(); interName = interName.replace('$', '.'); sb.append(" " + interName); if (interfaceIter.hasNext()) { sb.append(","); } } } sb.append(" "); return sb.toString().toCharArray(); } catch (JavaModelException e) { AspectJPlugin.getDefault().getLog() .log(new Status(Status.ERROR, AspectJPlugin.PLUGIN_ID, e.getMessage(), e)); return null; } } } return null; }
From source file:org.eclipse.imp.prefspecs.compiler.PrefspecsCompiler.java
License:Open Source License
public boolean classImplementsInterface(IType clazz, String interfaceQualName) { try {/*from w ww . j a va 2s. c o m*/ String[] supers = clazz.getSuperInterfaceNames(); // Blah! - These aren't qualified unless they appeared that way in the source for (String sup : supers) { // The following hack works around not having qualified type names - accept unqualified ones too if (sup.equals(interfaceQualName) || sup.equals(interfaceQualName.substring(interfaceQualName.lastIndexOf('.') + 1))) { return true; } } } catch (JavaModelException e) { } return false; }
From source file:org.eclipse.imp.wizards.NewCompiler.java
License:Open Source License
public String getParseControllerClassName(IProject project) { IPluginModelBase pluginModelBase = pages[0].getPluginModel(); // Get the extension that represents the parser IPluginExtension parserExtension = ExtensionPointUtils.findExtensionByName("org.eclipse.imp.runtime.parser", pluginModelBase);// w w w .j a v a2 s. c om if (parserExtension == null) return null; // Get the plugin element that represents the class of the parser PluginElement parserPluginElement = ExtensionPointUtils.findElementByName(pluginModelBase, project, "parser", parserExtension); if (parserPluginElement == null) { parserPluginElement = ExtensionPointUtils.findElementByName(pluginModelBase, project, "parserWrapper", parserExtension); } if (parserPluginElement == null) return null; // Get the name of the parser package String parserName = parserPluginElement.getAttribute("class").getValue(); String parserPackageName = parserName.substring(0, parserName.lastIndexOf('.')); // The ParseController class should be in that package, so look for it there // Get the package (fragment) that contains the parser IPackageFragment parserPackage = ExtensionPointUtils.findPackageByName(project, parserPackageName); if (parserPackage == null) return null; // Check the classes in the parser package for one that represents an IParseController // (assume there's just one) try { ICompilationUnit[] compilationUnits = parserPackage.getCompilationUnits(); for (int i = 0; i < compilationUnits.length; i++) { ICompilationUnit unit = compilationUnits[i]; // Get the type(s) declared by this compilation unit IType[] unitTypes = unit.getTypes(); for (int j = 0; j < unitTypes.length; j++) { IType type = unitTypes[j]; String[] superInterfaceNames = type.getSuperInterfaceNames(); for (int k = 0; k < superInterfaceNames.length; k++) { if (superInterfaceNames[k].contains("IParseController")) { // Found it :-) return type.getElementName(); } } } } } catch (JavaModelException e) { WizardPlugin.getInstance().logException( "NewCompiler.getParseControllerClassName(): exception looking for IParseController", e); } // Didn't find it :-( return null; }
From source file:org.eclipse.jpt.common.core.internal.utility.TypeTools.java
License:Open Source License
/** * Return the (potentially) non-resolved names of the specified type's supertypes (class and interfaces). * This is necessary because, for whatever reason, { @link IType#getSuperInterfaceNames()} and * {@link IType#getSuperclassName()} return unqualified names when the type is from Java source. *//* w ww .ja va2 s. co m*/ @SuppressWarnings("unchecked") private static Iterable<String> getNonResolvedSuperTypeNames(IType type) throws JavaModelException { return IterableTools.concatenate( IterableTools.removeNulls(IterableTools.singletonIterable(type.getSuperclassName())), IterableTools.iterable(type.getSuperInterfaceNames())); }