|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.editor.java; import java.awt.Container; import java.awt.Cursor; import java.awt.event.FocusAdapter; import java.awt.event.FocusEvent; import java.lang.reflect.Modifier; import java.util.*; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeEvent; import javax.jmi.reflect.*; import javax.swing.text.BadLocationException; import javax.swing.text.JTextComponent; import javax.swing.JEditorPane; import org.netbeans.api.java.classpath.ClassPath; import org.netbeans.api.mdr.MDRepository; import org.netbeans.jmi.javamodel.*; import org.netbeans.jmi.javamodel.AnnotationType; import org.netbeans.modules.javacore.ClassIndex; import org.netbeans.modules.javacore.JMManager; import org.netbeans.modules.editor.NbEditorUtilities; import org.netbeans.modules.javacore.internalapi.JavaMetamodel; import org.netbeans.editor.*; import org.netbeans.editor.ext.*; import org.netbeans.editor.ext.java.JCExpression; import org.openide.filesystems.FileObject; import org.openide.loaders.DataObject; import org.openide.text.PositionBounds; import org.openide.windows.TopComponent; import org.openide.cookies.EditorCookie; import org.openide.util.RequestProcessor; import org.openide.util.NbBundle; import org.openide.awt.StatusDisplayer; public class JMIUtils { private static MDRepository repository = JavaMetamodel.getDefaultRepository (); private static JavaMetamodel javaMetamodel = JavaMetamodel.getManager(); private static boolean caseSensitive = true; private static boolean naturalSort = true; private static boolean showDeprecated = true; private static SettingsChangeListener settingsListener = new SettingsListener(); static final boolean debugCompletionFailures = Boolean.getBoolean("org.netbeans.editor.debug.completion.failures"); // NOI18N static final Comparator NATURAL_MEMBER_NAME_COMPARATOR = new NaturalMemberNameComparator(true); private static final boolean[][] assignVals = new boolean[][] { new boolean[] { true, false, false, false, false, false, false, false, false}, // boolean new boolean[] { false, true, false, true, true, true, true, true, false}, // byte new boolean[] { false, false, true, true, true, true, true, false, false}, // char new boolean[] { false, false, false, true, false, false, false, false, false}, // double new boolean[] { false, false, false, true, true, false, false, false, false}, // float new boolean[] { false, false, false, true, true, true, true, false, false}, // int new boolean[] { false, false, false, true, true, false, true, false, false}, // long new boolean[] { false, false, false, true, true, true, true, true, false}, // short new boolean[] { false, false, false, false, false, false, false, false, true} // void }; static { Settings.addSettingsChangeListener(settingsListener); refreshSettings(); } private BaseDocument doc; private FileObject fileObject = null; private boolean is15Enabled = true; // .......................................................................... public static synchronized JMIUtils get(BaseDocument doc) { JMIUtils utils = (JMIUtils)doc.getProperty(JMIUtils.class); if (utils == null) { utils = new JMIUtils(doc); doc.putProperty(JMIUtils.class, utils); } return utils; } public static boolean isCaseSensitive() { return caseSensitive; } public void beginTrans(boolean write) { repository.beginTrans(write); if (fileObject != null) { try { // needs to be done in try..catch to make sure the transaction is closed // if this operation fails javaMetamodel.setClassPath(fileObject); } catch (RuntimeException e) { repository.endTrans(write); // fail if b==true (i.e. write transaction) throw e; } catch (Error e) { repository.endTrans(write); // fail if b==true (i.e. write transaction) throw e; } } // else -> global class path should be used } public void endTrans(boolean fail) { repository.endTrans(fail); } public Type resolveType(String typeName) { JavaModelPackage pkg = getJavaModelPackage(); if (pkg != null && !"null".equals(typeName)) { // NOI18N return pkg.getType().resolve(typeName); } return null; } public Type resolveArray(Type type) { JavaModelPackage pkg = getJavaModelPackage(); if (pkg != null) { return pkg.getArray().resolveArray(type); } return null; } public Type resolveParameterizedType(JavaClass def, List params) { JavaModelPackage pkg = getJavaModelPackage(); if (pkg != null) { return pkg.getParameterizedType().resolveParameterizedType(def, params, null); } return null; } public boolean isAssignable(Type from, Type to) { if (from == null || to == null) return false; if (from.equals(to)) return true; if (from instanceof Array && to instanceof Array) return isAssignable(((Array)from).getType(), ((Array)to).getType()); if (to instanceof PrimitiveType && (is15Enabled || from instanceof PrimitiveType)) return assignVals[getPrimitiveTypeIdx(from)][getPrimitiveTypeIdx(to)]; if (to.getName().equals("java.lang.Object") && (is15Enabled || !(from instanceof PrimitiveType))) // NOI18N return true; if (to instanceof JavaClass && is15Enabled && from instanceof PrimitiveType) return isAssignable(getObjectType((PrimitiveType)from), to); if (from instanceof JavaClass && to instanceof JavaClass) return isSubTypeOf((JavaClass)from, (JavaClass)to); return false; } public boolean isSubTypeOf(JavaClass thisCls, JavaClass otherCls) { if (otherCls instanceof TypeParameter) { if (!isSubTypeOf(thisCls, otherCls.getSuperClass())) return false; for (Iterator it = otherCls.getInterfaces().iterator(); it.hasNext();) { if (!isSubTypeOf(thisCls, (JavaClass)it.next())) return false; } return true; } if (thisCls.isSubTypeOf(otherCls)) { List thisParams = thisCls instanceof ParameterizedType ? ((ParameterizedType)thisCls).getParameters() : new ArrayList(); List otherParams = otherCls instanceof ParameterizedType ? ((ParameterizedType)otherCls).getParameters() : new ArrayList(); if (thisParams.size() != otherParams.size()) return false; for (Iterator it = thisParams.iterator(), itt = otherParams.iterator(); it.hasNext();) { if (!isAssignable((Type)it.next(), (Type)itt.next())) return false; } return true; } return false; } public boolean isEqualType(Type thisCls, Type otherCls) { return isAssignable(thisCls, otherCls) && isAssignable(otherCls, thisCls); } public JavaPackage getExactPackage(String packageName) { return resolvePackage(packageName, true); } public String getPackageName(ClassDefinition jc) { if (jc instanceof UnresolvedClass) { String name = jc.getName(); int index = name.lastIndexOf('.'); return index < 0 ? "" : name.substring(0, index); } if (jc instanceof JavaClass) { Resource res = jc.getResource(); if (res != null){ String result = res.getPackageName(); if (result != null) { return result; } } } return ""; } public JavaClass getExactClass(String name, String pkgName) { return getExactClass((pkgName != null && pkgName.length() != 0) ? (pkgName + "." + name) : name); // NOI18N } public JavaClass getExactClass(String classFullName) { JavaModelPackage extent = getJavaModelPackage(); if (extent != null) { Type cls = extent.getType().resolve(classFullName); if (cls instanceof UnresolvedClass) return null; if (cls instanceof JavaClass) return (JavaClass)cls; } return null; } public List findPackages(String name, boolean exactMatch, boolean subPackages, boolean createResultItems) { ArrayList ret = new ArrayList (); NbJavaJMICompletionQuery.JMIItemFactory itemFactory = createResultItems ? NbJavaJMICompletionQuery.getJMIItemFactory() : null; if (exactMatch) { JavaPackage pkg = getExactPackage (name); if (pkg != null) { if (itemFactory != null) ret.add(itemFactory.createPackageResultItem(pkg)); else ret.add(pkg); } } else { int index = name.lastIndexOf('.'); String prefix = index > 0 ? name.substring(0, index) : ""; JavaPackage pkg = resolvePackage(prefix, caseSensitive); if (pkg != null) { Collection subpackages = pkg.getSubPackages(); for (Iterator it = subpackages.iterator(); it.hasNext();) { JavaPackage subPackage = (JavaPackage) it.next(); if (startsWith(subPackage.getName(), name)) { if (itemFactory != null) ret.add(itemFactory.createPackageResultItem(subPackage)); else ret.add(subPackage); } } } } // else if (subPackages) { int size = ret.size (); for (int x = 0; x < size; x++) { JavaPackage sPkg = (JavaPackage) ret.get(x); addSubPackages(ret, sPkg, createResultItems); } } Collections.sort(ret, NATURAL_MEMBER_NAME_COMPARATOR); return ret; } /** Find classes by name and possibly in some package * @param pkg package where the classes should be searched for. It can be null * @param name begining of the name of the class. The package name must be omitted. * @param exactMatch whether the given name is the exact requested name * of the class or not. * @return list of the matching classes */ public List findClasses(JavaPackage pkg, String name, boolean exactMatch, JavaClass context, boolean createResultItems) { TreeSet ret = new TreeSet(NATURAL_MEMBER_NAME_COMPARATOR); ClassPath cp = JavaMetamodel.getManager().getClassPath(); FileObject[] cpRoots = cp.getRoots(); NbJavaJMICompletionQuery.JMIItemFactory itemFactory = createResultItems ? NbJavaJMICompletionQuery.getJMIItemFactory() : null; for (int i = 0; i < cpRoots.length; i++) { ClassIndex ci = ClassIndex.getIndex(JavaMetamodel.getManager().getJavaExtent(cpRoots[i])); if (ci == null) continue; Collection col = null; if (pkg == null) { if (exactMatch) { col = ci.getClassesBySimpleName(name); } else { col = ci.getClassesBySNPrefix(name, caseSensitive); } } else { String clsName = pkg.getName() + '.' + name; if (exactMatch) { JavaClass cls = ci.getClassByFqn(clsName); if (cls != null) { col = Collections.singleton(cls); } } else { col = ci.getClassesByFQNPrefix(clsName); } } if (col != null) { for (Iterator it = col.iterator(); it.hasNext();) { JavaClass javaClass = (JavaClass) it.next(); if (!(javaClass instanceof AnnotationType) && !javaClass.isInner() && (showDeprecated || !javaClass.isDeprecated()) && isTopLevelClassAccessible(javaClass, context)) { if (itemFactory == null) ret.add(javaClass); else ret.add(itemFactory.createClassResultItem(javaClass)); } } } } return new ArrayList(ret); } public List findAnnotations(JavaPackage pkg, String name, boolean exactMatch, JavaClass context, boolean createResultItems) { // TODO: More effective way to get annotation list should be created NbJavaJMICompletionQuery.JMIItemFactory itemFactory = createResultItems ? NbJavaJMICompletionQuery.getJMIItemFactory() : null; TreeSet ret = new TreeSet(NATURAL_MEMBER_NAME_COMPARATOR); if (pkg != null) name = pkg.getName() + "." + name; // NOI18N ClassPath cp = JavaMetamodel.getManager().getClassPath(); FileObject[] cpRoots = cp.getRoots(); for (int i = 0; i < cpRoots.length; i++) { AnnotationTypeClass atc = JavaMetamodel.getManager().getJavaExtent(cpRoots[i]).getAnnotationType(); for (Iterator it = atc.refAllOfType().iterator(); it.hasNext();) { AnnotationType at = (AnnotationType) it.next(); if (!showDeprecated && at.isDeprecated()) continue; String atName = pkg == null ? at.getSimpleName() : at.getName(); if (exactMatch) { if (atName.equals(name)) { if (itemFactory != null) ret.add(itemFactory.createClassResultItem(at)); else ret.add(at); } } else { if (startsWith(atName, name)) { if (itemFactory != null) ret.add(itemFactory.createClassResultItem(at)); else ret.add(at); } } } } return new ArrayList(ret); } public List findFeatures(Type type, String name, boolean exactMatch, boolean inspectOuterClasses, JavaClass context, boolean staticContext, boolean thisContext, JCExpression exp, boolean createResultItems, boolean preferSources) { return findFeatures(type, name, exactMatch, true, inspectOuterClasses, context, staticContext, thisContext, Feature.class, exp, createResultItems, preferSources); } /** Find fields by name in a given class. * @param type class which is searched for the fields. * @param name start of the name of the field * @param exactMatch whether the given name of the field is exact * @param staticContext whether search for the static fields only * @return list of the matching fields */ public List findFields(Type type, String name, boolean exactMatch, boolean inspectOuterClasses, JavaClass context, boolean staticContext, boolean thisContext, boolean createResultItems, boolean preferSources) { return findFeatures(type, name, exactMatch, true, inspectOuterClasses, context, staticContext, thisContext, Field.class, null, createResultItems, preferSources); } /** Find methods by name in a given class. * @param type class which is searched for the methods. * @param name start of the name of the method * @param exactMatch whether the given name of the method is exact * @param staticContext whether search for the static methods only * @return list of the matching methods */ public List findMethods(Type type, String name, boolean exactMatch, boolean inspectOuterClasses, JavaClass context, boolean staticContext, boolean thisContext, JCExpression exp, boolean createResultItems, boolean preferSources) { return findFeatures(type, name, exactMatch, true, inspectOuterClasses, context, staticContext, thisContext, Method.class, exp, createResultItems, preferSources); } public List findConstructors(Type type, String name, boolean exactMatch, JavaClass context) { return findFeatures(type, name, exactMatch, false, false, context, false, false, Constructor.class, null, false, true); } public List findInnerClasses(Type type, String name, boolean exactMatch, boolean inspectOuterClasses, JavaClass context, boolean thisContext, boolean createResultItems, boolean preferSources) { return findFeatures(type, name, exactMatch, true, inspectOuterClasses, context, false, thisContext, JavaClass.class, null, createResultItems, preferSources); } public List findEnumConstants(JavaEnum enum, String name, boolean exactMatch, boolean createResultItems) { NbJavaJMICompletionQuery.JMIItemFactory itemFactory = createResultItems ? NbJavaJMICompletionQuery.getJMIItemFactory() : null; TreeSet ret = new TreeSet(NATURAL_MEMBER_NAME_COMPARATOR); for (Iterator it = enum.getConstants().iterator(); it.hasNext();) { Field constant = (Field) it.next(); if (!showDeprecated && constant.isDeprecated()) continue; String constantName = constant.getName(); if (exactMatch) { if (!constantName.equals(name)) continue; } else { if (!startsWith(constantName, name)) continue; } if (itemFactory != null) ret.add(itemFactory.createFieldResultItem(constant, enum)); else ret.add(constant); } return new ArrayList(ret); } public Resource getResource() { DataObject dob = NbEditorUtilities.getDataObject(doc); return dob != null ? JavaMetamodel.getManager().getResource(dob.getPrimaryFile()) : null; } public JavaClass getImportedClass(String simpleName, JavaClass topClass, JavaClass context){ JavaClass ret = null; Resource res = getResource(); if (res != null) { // class imports for (Iterator it = res.getImports().iterator(); it.hasNext();) { Element el = ((Import)it.next()).getImportedElement(); if (el instanceof JavaClass && simpleName.equals(((JavaClass)el).getSimpleName())) { return (JavaClass)el; } } // pacakge content ret = getExactClass(simpleName, getPackageName(topClass)); if (ret != null) return ret; // java.lang content List clsList = findClasses(getExactPackage("java.lang"), simpleName, true, context, false); // NOI18N if (clsList != null && clsList.size() > 0) { return (JavaClass)clsList.get(0); } // package imports for (Iterator it = res.getImports().iterator(); it.hasNext();) { Element el = ((Import)it.next()).getImportedElement(); if (el instanceof JavaPackage) { clsList = findClasses((JavaPackage)el, simpleName, true, context, false); if (clsList != null && clsList.size() > 0) { return (JavaClass)clsList.get(0); } } } } return ret; } public List getStaticallyImportedFields(String name, boolean exactMatch, JavaClass context, boolean isThisContext) { List ret = new ArrayList(); Resource res = getResource(); if (res != null) { for (Iterator it = res.getImports().iterator(); it.hasNext();) { Import imp = (Import)it.next(); if (imp.isStatic()) { NamedElement el = imp.getImportedElement(); if (el instanceof Field && (((Field)el).getModifiers() & Modifier.STATIC) != 0) { if (exactMatch) { if (el.getName() != null && el.getName().equals(name)) { ret.add(el); } } else { if (el.getName() != null && el.getName().startsWith(name)) { ret.add(el); } } } if (el instanceof JavaClass) { ret.addAll(findFeatures((JavaClass)el, name, exactMatch, true, false, context, true, isThisContext, Field.class, null, false, false)); } } } } return ret; } public List getStaticallyImportedMethods(String name, boolean exactMatch, JavaClass context, boolean isThisContext) { List ret = new ArrayList(); Resource res = getResource(); if (res != null) { for (Iterator it = res.getImports().iterator(); it.hasNext();) { Import imp = (Import)it.next(); if (imp.isStatic()) { NamedElement el = imp.getImportedElement(); if (el instanceof Method && (((Method)el).getModifiers() & Modifier.STATIC) != 0) { if (exactMatch) { if (el.getName() != null && el.getName().equals(name)) { ret.add(el); } } else { if (el.getName() != null && el.getName().startsWith(name)) { ret.add(el); } } } if (el instanceof JavaClass) { ret.addAll(findFeatures((JavaClass)el, name, exactMatch, true, false, context, true, isThisContext, Method.class, null, false, false)); } } } } return ret; } public Collection filterNames(Collection col, String namePrefix, boolean exactMatch) { Collection ret = new ArrayList(); for (Iterator it = col.iterator(); it.hasNext();) { String s = (String) it.next(); if (exactMatch) { if (s.equals(namePrefix)) ret.add(s); } else { if (startsWith(s, namePrefix)) ret.add(s); } } return ret; } public List findMatchingTypes(TypeParameter tp, JavaClass context, boolean createResultItems) { TreeSet ts = new TreeSet(NATURAL_MEMBER_NAME_COMPARATOR); JavaClass sup = tp.getSuperClass(); if (sup != null) { if ("java.lang.Object".equals(sup.getName())) { //NOI18N if (tp.getInterfaces().size() == 0) ts.addAll(findClasses(null, "", false, context, createResultItems)); else sup = null; } else { ts.add(sup); NbJavaJMICompletionQuery.JMIItemFactory itemFactory = createResultItems ? NbJavaJMICompletionQuery.getJMIItemFactory() : null; for (Iterator it = sup.findSubTypes(true).iterator(); it.hasNext();) { JavaClass subType = (JavaClass) it.next(); if ((showDeprecated || !subType.isDeprecated()) && (subType.isInner() ? isAccessible(subType, null, context) : isTopLevelClassAccessible(subType, context))) { if (itemFactory == null) ts.add(subType); else ts.add(itemFactory.createClassResultItem(subType)); } } } } if (ts.size() != 0) { for (Iterator it = tp.getInterfaces().iterator(); it.hasNext();) { ts.retainAll(((JavaClass)it.next()).findSubTypes(true)); } } else if (sup == null) { Iterator it = tp.getInterfaces().iterator(); if (it.hasNext()) { ts.addAll(((JavaClass)it.next()).findSubTypes(true)); } while(it.hasNext()) { ts.retainAll(((JavaClass)it.next()).findSubTypes(true)); } } return new ArrayList(ts); } public static boolean openElement(final Element element) { repository.beginTrans(false); try { Resource resource = element.getResource(); if (resource != null) { javaMetamodel.setClassPath(resource); StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(JMIUtils.class, "opening-element", element instanceof NamedElement ? ((NamedElement)element).getName() : "")); // NOI18N DataObject dob = javaMetamodel.getDataObject(resource); if (dob != null) { final EditorCookie.Observable ec = (EditorCookie.Observable)dob.getCookie(EditorCookie.Observable.class); if (ec != null) { JEditorPane[] panes = ec.getOpenedPanes(); if (panes != null && panes.length > 0) { selectElementInPane(panes[0], element, false); } else { ec.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (EditorCookie.Observable.PROP_OPENED_PANES.equals(evt.getPropertyName())) { final JEditorPane[] panes = ec.getOpenedPanes(); if (panes != null && panes.length > 0) { selectElementInPane(panes[0], element, true); } ec.removePropertyChangeListener(this); } } }); ec.open(); } return true; } } } } finally { repository.endTrans(false); } return false; } public static ClassDefinition getSourceElementIfExists(ClassDefinition next) { return ((JMManager)JMIUtils.javaMetamodel).getSourceElementIfExists(next); } // TODO: temporary hack - a better support from javacore needed public static Feature getDefintion(Feature e) { if (e instanceof ParameterizedType) return getDefintion(((ParameterizedType)e).getDefinition()); try { return getDefintion((Feature)e.getClass().getMethod("getWrappedObject", new Class[0]).invoke(e, new Object[0])); // NOI18N } catch (Exception e1) {} return e; } public boolean isAccessible(JavaClass cls, JavaClass from) { if (cls == null) return false; if (from == null) return true; return cls.isInner() ? isAccessible(cls, (JavaClass)cls.getDeclaringClass(), from) : isTopLevelClassAccessible(cls, from); } // .......................................................................... private JMIUtils(BaseDocument doc){ this.doc = doc; DataObject dob = NbEditorUtilities.getDataObject(doc); if (dob != null) { ClassPath sourceCP = ClassPath.getClassPath(dob.getPrimaryFile(), ClassPath.SOURCE); if (sourceCP != null) { this.fileObject = sourceCP.findOwnerRoot(dob.getPrimaryFile()); } } } private List findFeatures(Type type, String name, boolean exactMatch, boolean inspectSuperTypes, boolean inspectOuterClasses, JavaClass context, boolean staticContext, boolean thisContext, Class featureType, JCExpression exp, boolean createResultItems, boolean preferSources) { if (type == null || type instanceof PrimitiveType) { return new ArrayList (); } TreeSet ts = new TreeSet(NATURAL_MEMBER_NAME_COMPARATOR); NbJavaJMICompletionQuery.JMIItemFactory itemFactory = createResultItems ? NbJavaJMICompletionQuery.getJMIItemFactory() : null; int outerInd = 0; List outerList = (inspectOuterClasses && type instanceof JavaClass) ? getOuterClasses((JavaClass)type) : Collections.singletonList(type); for (Iterator it = outerList.iterator(); it.hasNext(); outerInd++) { for (Iterator itt = new ClassesIterator((Type)it.next(), inspectSuperTypes, preferSources); itt.hasNext();) { ClassDefinition tempClass = (ClassDefinition) itt.next(); Iterator iter = tempClass.getFeatures().iterator (); while (iter.hasNext ()) { Feature feature = (Feature) iter.next(); if (!(featureType.isInstance(feature))) continue; int mods = feature.getModifiers(); if ((staticContext && !(feature instanceof JavaClass) && (mods & Modifier.STATIC) == 0) || ((outerInd > 0) && (((JavaClass)type).getModifiers() & Modifier.STATIC) != 0 ) && ((mods & Modifier.STATIC) == 0) || (!showDeprecated && feature.isDeprecated()) || (!isAccessible(feature, thisContext ? context : type instanceof JavaClass ? (JavaClass)type : null, context))) { continue; } String featureName = feature instanceof JavaClass ? ((JavaClass)feature).getSimpleName() : feature.getName(); if (featureName == null) featureName = ""; // NOI18N if (exactMatch) { if (!featureName.equals(name)) continue; } else { if (!startsWith(featureName, name)) continue; } if (itemFactory != null) ts.add(itemFactory.createResultItem(feature, exp, context)); else ts.add(feature); } // while // HACK!!! - adding the values() and valueOf(...) Enum's methods since the new JMI Java infrastructure // does not support them. if (tempClass instanceof JavaEnum && featureType.isAssignableFrom(Method.class) && (thisContext || !(type instanceof JavaClass) || ((JavaClass)type).isInner() ? isAccessible((JavaClass)type, null, context) : isTopLevelClassAccessible((JavaClass)type, context))) { if (exactMatch) { if ("values".equals(name)) { // NOI18N List tags = Collections.singletonList(new FakeTagValue("@return", "an array containing the constants of this enum class, in the order they're declare")); // NOI18N JavaDoc jd = new FakeJavaDoc(tags, "Returns an array containing the constants of this enum class, in the order they're declared. This method may be used to iterate over the constants as follows:"); // NOI18N Method mtd = new FakeMethod("values", tempClass, resolveArray(tempClass), Collections.EMPTY_LIST, jd); // NOI18N if (itemFactory != null) ts.add(itemFactory.createResultItem(mtd, exp, context)); else ts.add(mtd); } else if ("valueOf".equals(name)) { // NOI18N List tags = new ArrayList(3); tags.add(new FakeTagValue("@param", "name the name of the constant to return")); // NOI18N tags.add(new FakeTagValue("@return", "the enum constant with the specified name")); // NOI18N tags.add(new FakeTagValue("@throws", "IllegalArgumentException if this enum class has no constant with the specified name")); // NOI18N JavaDoc jd = new FakeJavaDoc(tags, "Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)"); // NOI18N Method mtd = new FakeMethod("valueOf", tempClass, tempClass, Collections.singletonList(new FakeParameter("name", resolveType("java.lang.String"))), jd); // NOI18N if (itemFactory != null) ts.add(itemFactory.createResultItem(mtd, exp, context)); else ts.add(mtd); } } else { if (startsWith("values", name)) { // NOI18N List tags = Collections.singletonList(new FakeTagValue("@return", "an array containing the constants of this enum class, in the order they're declare")); // NOI18N JavaDoc jd = new FakeJavaDoc(tags, "Returns an array containing the constants of this enum class, in the order they're declared. This method may be used to iterate over the constants as follows:for(ClassName c : ClassName.values()) |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.