/** * Clears all classes from this project. */ public void clear() { Collection values = _cache.values(); BCClass bc; for (Iterator itr = values.iterator(); itr.hasNext();) { bc = (BCClass) itr.next(); itr.remove(); bc.invalidate(); } _names.clear(); }
/** * Return the names of all the parameter types for this method. The names * will be returned in a form suitable for a {@link Class#forName} call. * * @see BCMember#getDescriptor */ public String[] getParamNames() { // get the parameter types from the descriptor String[] params = getProject().getNameCache().getDescriptorParamNames (getDescriptor()); // convert them to external form for (int i = 0; i < params.length; i++) params[i] = getProject().getNameCache().getExternalForm(params[i], false); return params; }
/** * Return the name of the type returned by this method. The name * will be given in a form suitable for a {@link Class#forName} call. * * @see BCMember#getDescriptor */ public String getReturnName() { return getProject().getNameCache().getExternalForm(getProject(). getNameCache().getDescriptorReturnName(getDescriptor()), false); }
/** * Construct a method descriptor from the given return and parameter * types, which will be converted to internal form. */ public String getDescriptor(String returnType, String[] paramTypes) { StringBuilder buf = new StringBuilder(); buf.append("("); if (paramTypes != null) { for (int i = 0; i < paramTypes.length; i++) { if (paramTypes[i] == null) throw new NullPointerException("paramTypes[" + i + "] = null"); buf.append(getInternalForm(paramTypes[i], true)); } } buf.append(")"); if (returnType == null) throw new NullPointerException("returnType = null"); buf.append(getInternalForm(returnType, true)); return buf.toString(); }
public String getName() { return _names.getExternalForm(_type.getName(), false); }
/** * Set the name of this class, including package name. */ public void setName(String name) { name = _project.getNameCache().getExternalForm(name, false); String oldName = getName(); // get a reference to the class entry for this class int index = getIndex(); if (index == 0) index = getPool().findClassEntry(name, true); ClassEntry entry = (ClassEntry) getPool().getEntry(index); // make sure the rename is ok with the project beforeRename(oldName, name); // reset the name index of the class entry to the new name int nameIndex = getPool().findUTF8Entry(_project.getNameCache(). getInternalForm(name, false), true); entry.setNameIndex(nameIndex); // we might have just added a new entry; set the index _state.setIndex(index); }
returnType = cache.getInternalForm(returnType, true); dec = cache.getInternalForm(dec, false); for (int i = 0; i < params.length; i++) params[i] = cache.getInternalForm(params[i], true); String desc = cache.getDescriptor(returnType, params); if (getOpcode() == Constants.INVOKEINTERFACE) return setMethodIndex(getPool().findInterfaceMethodEntry(dec, name,
name = _names.getExternalForm(name, false); String componentName = _names.getComponentName(name); BCClass ret = new BCClass(this); if (componentName != null)
/** * Add a method to this class. * Note that in bytecode, constructors are named <code><init></code> * and static initializers are named <code><clinit></code>. * * @return the added method */ public BCMethod declareMethod(String name, String returnType, String[] paramTypes) { BCMethod method = new BCMethod(this); _state.getMethodsHolder().add(method); method.initialize(name, _project.getNameCache(). getDescriptor(returnType, paramTypes)); return method; }
/** * Converts the given class name to its internal form. * * @param className the name to convert * @param descriptor true if the name is to be used for a descriptor * section -- the difference seems to be that for * descriptors, non-primitives are prefixed with 'L' and ended with ';' */ public String getInternalForm(String className, boolean descriptor) { if (className == null || className.length() == 0) return className; Map cache = (descriptor) ? _internalDescriptor : _internal; String cached = (String) cache.get(className); if (cached != null) return cached; String ret = getInternalFormInternal(className, descriptor); cache.put(className, ret); return ret; }
/** * Given the internal name of the class, return the 'normal' java name. * * @param internalName the internal name being used * @param humanReadable if the returned name should be in human-readable * form, rather than a form suitable for a * {@link Class#forName} call -- the difference * lies in the handling of arrays */ public String getExternalForm(String internalName, boolean humanReadable) { if (internalName == null || internalName.length() == 0) return internalName; Map cache = (humanReadable) ? _externalHuman : _external; String cached = (String) cache.get(internalName); if (cached != null) return cached; String ret = getExternalFormInternal(internalName, humanReadable); cache.put(internalName, ret); return ret; }
/** * Construct a method descriptor from the given return and parameter * types, which will be converted to internal form. */ public String getDescriptor(String returnType, String[] paramTypes) { StringBuilder buf = new StringBuilder(); buf.append("("); if (paramTypes != null) { for (int i = 0; i < paramTypes.length; i++) { if (paramTypes[i] == null) throw new NullPointerException("paramTypes[" + i + "] = null"); buf.append(getInternalForm(paramTypes[i], true)); } } buf.append(")"); if (returnType == null) throw new NullPointerException("returnType = null"); buf.append(getInternalForm(returnType, true)); return buf.toString(); }
public String getName() { return _names.getExternalForm(_type.getName(), false); }
/** * Set the name of this class, including package name. */ public void setName(String name) { name = _project.getNameCache().getExternalForm(name, false); String oldName = getName(); // get a reference to the class entry for this class int index = getIndex(); if (index == 0) index = getPool().findClassEntry(name, true); ClassEntry entry = (ClassEntry) getPool().getEntry(index); // make sure the rename is ok with the project beforeRename(oldName, name); // reset the name index of the class entry to the new name int nameIndex = getPool().findUTF8Entry(_project.getNameCache(). getInternalForm(name, false), true); entry.setNameIndex(nameIndex); // we might have just added a new entry; set the index _state.setIndex(index); }
returnType = cache.getInternalForm(returnType, true); dec = cache.getInternalForm(dec, false); for (int i = 0; i < params.length; i++) params[i] = cache.getInternalForm(params[i], true); String desc = cache.getDescriptor(returnType, params); if (getOpcode() == Constants.INVOKEINTERFACE) return setMethodIndex(getPool().findInterfaceMethodEntry(dec, name,
name = _names.getExternalForm(name, false); String componentName = _names.getComponentName(name); BCClass ret = new BCClass(this); if (componentName != null)
/** * Add a method to this class. * Note that in bytecode, constructors are named <code><init></code> * and static initializers are named <code><clinit></code>. * * @return the added method */ public BCMethod declareMethod(String name, String returnType, String[] paramTypes) { BCMethod method = new BCMethod(this); _state.getMethodsHolder().add(method); method.initialize(name, _project.getNameCache(). getDescriptor(returnType, paramTypes)); return method; }
/** * Converts the given class name to its internal form. * * @param className the name to convert * @param descriptor true if the name is to be used for a descriptor * section -- the difference seems to be that for * descriptors, non-primitives are prefixed with 'L' and ended with ';' */ public String getInternalForm(String className, boolean descriptor) { if (className == null || className.length() == 0) return className; Map cache = (descriptor) ? _internalDescriptor : _internal; String cached = (String) cache.get(className); if (cached != null) return cached; String ret = getInternalFormInternal(className, descriptor); cache.put(className, ret); return ret; }
/** * Given the internal name of the class, return the 'normal' java name. * * @param internalName the internal name being used * @param humanReadable if the returned name should be in human-readable * form, rather than a form suitable for a * {@link Class#forName} call -- the difference * lies in the handling of arrays */ public String getExternalForm(String internalName, boolean humanReadable) { if (internalName == null || internalName.length() == 0) return internalName; Map cache = (humanReadable) ? _externalHuman : _external; String cached = (String) cache.get(internalName); if (cached != null) return cached; String ret = getExternalFormInternal(internalName, humanReadable); cache.put(internalName, ret); return ret; }
return intern; intern = getInternalForm(intern, false); return intern.replace('/', '.');