本文整理汇总了Java中com.sun.tools.javac.code.Symbol.MethodSymbol类的典型用法代码示例。如果您正苦于以下问题:Java MethodSymbol类的具体用法?Java MethodSymbol怎么用?Java MethodSymbol使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MethodSymbol类属于com.sun.tools.javac.code.Symbol包,在下文中一共展示了MethodSymbol类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: overridesMethod
import com.sun.tools.javac.code.Symbol.MethodSymbol; //导入依赖的package包/类
/**
* Returns true if this element represents a method which overrides a
* method in one of its superclasses.
*/
public boolean overridesMethod(ExecutableElement element) {
MethodSymbol m = (MethodSymbol)element;
if ((m.flags() & Flags.STATIC) == 0) {
ClassSymbol owner = (ClassSymbol) m.owner;
for (Type sup = jctypes.supertype(m.owner.type);
sup.hasTag(TypeTag.CLASS);
sup = jctypes.supertype(sup)) {
for (Symbol sym : sup.tsym.members().getSymbolsByName(m.name)) {
if (m.overrides(sym, owner, jctypes, true))
return true;
}
}
}
return false;
}
示例2: javaDocFor
import com.sun.tools.javac.code.Symbol.MethodSymbol; //导入依赖的package包/类
/**Get javadoc for given element.
* @deprecated The new DocTree API should be used to traverse Javadoc comments.
* Use {@link DocTrees#getDocCommentTree(javax.lang.model.element.Element)} instead.
*/
@Deprecated
public Doc javaDocFor(Element element) {
if (element != null) {
DocEnv env = DocEnv.instance(ctx);
switch (element.getKind()) {
case ANNOTATION_TYPE:
case CLASS:
case ENUM:
case INTERFACE:
return env.getClassDoc((ClassSymbol)element);
case ENUM_CONSTANT:
case FIELD:
return env.getFieldDoc((VarSymbol)element);
case METHOD:
if (((MethodSymbol)element).enclClass().getKind() == ElementKind.ANNOTATION_TYPE)
return env.getAnnotationTypeElementDoc((MethodSymbol)element);
return env.getMethodDoc((MethodSymbol)element);
case CONSTRUCTOR:
return env.getConstructorDoc((MethodSymbol)element);
case PACKAGE:
return env.getPackageDoc((PackageSymbol)element);
}
}
return null;
}
示例3: fillArtificalParamNames
import com.sun.tools.javac.code.Symbol.MethodSymbol; //导入依赖的package包/类
private void fillArtificalParamNames(final ClassSymbol clazz) {
for (Symbol s : clazz.getEnclosedElements()) {
if (s instanceof MethodSymbol) {
MethodSymbol ms = (MethodSymbol) s;
if (ms.getParameters().isEmpty()) {
continue;
}
Set<String> usedNames = new HashSet<String>();
for (VarSymbol vs : ms.getParameters()) {
String name = JavaSourceAccessor.getINSTANCE().generateReadableParameterName(vs.asType().toString(), usedNames);
vs.setName(clazz.name.table.fromString(name));
}
}
}
}
示例4: JCMethodDecl
import com.sun.tools.javac.code.Symbol.MethodSymbol; //导入依赖的package包/类
protected JCMethodDecl(JCModifiers mods,
Name name,
JCExpression restype,
List<JCTypeParameter> typarams,
List<JCVariableDecl> params,
List<JCExpression> thrown,
JCBlock body,
JCExpression defaultValue,
MethodSymbol sym) {
this.mods = mods;
this.name = name;
this.restype = restype;
this.typarams = typarams;
this.params = params;
this.thrown = thrown;
this.body = body;
this.defaultValue = defaultValue;
this.sym = sym;
}
示例5: getAllReflectedValues
import com.sun.tools.javac.code.Symbol.MethodSymbol; //导入依赖的package包/类
/**
* Returns a map from element names to their values in "dynamic
* proxy return form". Includes all elements, whether explicit or
* defaulted.
*/
private Map<String, Object> getAllReflectedValues() {
Map<String, Object> res = new LinkedHashMap<String, Object>();
for (Map.Entry<MethodSymbol, Attribute> entry :
getAllValues().entrySet()) {
MethodSymbol meth = entry.getKey();
Object value = generateValue(meth, entry.getValue());
if (value != null) {
res.put(meth.name.toString(), value);
} else {
// Ignore this element. May (properly) lead to
// IncompleteAnnotationException somewhere down the line.
}
}
return res;
}
示例6: getAllValues
import com.sun.tools.javac.code.Symbol.MethodSymbol; //导入依赖的package包/类
/**
* Returns a map from element symbols to their values.
* Includes all elements, whether explicit or defaulted.
*/
private Map<MethodSymbol, Attribute> getAllValues() {
Map<MethodSymbol, Attribute> res =
new LinkedHashMap<MethodSymbol, Attribute>();
// First find the default values.
ClassSymbol sym = (ClassSymbol) anno.type.tsym;
for (Scope.Entry e = sym.members().elems; e != null; e = e.sibling) {
if (e.sym.kind == Kinds.MTH) {
MethodSymbol m = (MethodSymbol) e.sym;
Attribute def = m.getDefaultValue();
if (def != null)
res.put(m, def);
}
}
// Next find the explicit values, possibly overriding defaults.
for (Pair<MethodSymbol, Attribute> p : anno.values)
res.put(p.fst, p.snd);
return res;
}
示例7: toString
import com.sun.tools.javac.code.Symbol.MethodSymbol; //导入依赖的package包/类
/**
* Returns a string representation of this annotation.
* String is of one of the forms:
* @com.example.foo(name1=val1, name2=val2)
* @com.example.foo(val)
* @com.example.foo
* Omit parens for marker annotations, and omit "value=" when allowed.
*/
public String toString() {
StringBuilder buf = new StringBuilder();
buf.append("@");
buf.append(type);
int len = values.length();
if (len > 0) {
buf.append('(');
boolean first = true;
for (Pair<MethodSymbol, Attribute> value : values) {
if (!first) buf.append(", ");
first = false;
Name name = value.fst.name;
if (len > 1 || name != name.table.names.value) {
buf.append(name);
buf.append('=');
}
buf.append(value.snd);
}
buf.append(')');
}
return buf.toString();
}
示例8: visitMethodSymbol
import com.sun.tools.javac.code.Symbol.MethodSymbol; //导入依赖的package包/类
@Override
public String visitMethodSymbol(MethodSymbol s, Locale locale) {
if (s.isStaticOrInstanceInit()) {
return s.owner.name.toString();
} else {
String ms = (s.name == s.name.table.names.init)
? s.owner.name.toString()
: s.name.toString();
if (s.type != null) {
if (s.type.tag == FORALL) {
ms = "<" + visitTypes(s.type.getTypeArguments(), locale) + ">" + ms;
}
ms += "(" + printMethodArgs(
s.type.getParameterTypes(),
(s.flags() & VARARGS) != 0,
locale) + ")";
}
return ms;
}
}
示例9: visitMethodSymbol
import com.sun.tools.javac.code.Symbol.MethodSymbol; //导入依赖的package包/类
@Override
public String visitMethodSymbol(MethodSymbol s, Locale locale) {
String ownerName = visit(s.owner, locale);
if (s.isStaticOrInstanceInit()) {
return ownerName;
} else {
String ms = (s.name == s.name.table.names.init)
? ownerName
: s.name.toString();
if (s.type != null) {
if (s.type.tag == FORALL) {
ms = "<" + visitTypes(s.type.getTypeArguments(), locale) + ">" + ms;
}
ms += "(" + printMethodArgs(
s.type.getParameterTypes(),
(s.flags() & VARARGS) != 0,
locale) + ")";
}
return ms;
}
}
示例10: addMethodIfExist
import com.sun.tools.javac.code.Symbol.MethodSymbol; //导入依赖的package包/类
private void addMethodIfExist(DocEnv env, ClassSymbol def, String methodName) {
Names names = def.name.table.names;
for (Scope.Entry e = def.members().lookup(names.fromString(methodName)); e.scope != null; e = e.next()) {
if (e.sym.kind == Kinds.MTH) {
MethodSymbol md = (MethodSymbol)e.sym;
if ((md.flags() & Flags.STATIC) == 0) {
/*
* WARNING: not robust if unqualifiedMethodName is overloaded
* method. Signature checking could make more robust.
* READOBJECT takes a single parameter, java.io.ObjectInputStream.
* WRITEOBJECT takes a single parameter, java.io.ObjectOutputStream.
*/
methods.append(env.getMethodDoc(md));
}
}
}
}
示例11: toString
import com.sun.tools.javac.code.Symbol.MethodSymbol; //导入依赖的package包/类
@Override
public String toString() {
String result = "";
for (Entry<MethodSymbol, Map<JCTree, List<VarSymbol>>> mainEntry: aliveRangeClosingTrees.entrySet()) {
result += "Method: \n" + mainEntry.getKey().flatName() + "\n";
int i = 1;
for (Entry<JCTree, List<VarSymbol>> treeEntry: mainEntry.getValue().entrySet()) {
result += " Tree " + i + ": \n" + treeEntry.getKey().toString() + "\n";
result += " Variables closed:\n";
for (VarSymbol var: treeEntry.getValue()) {
result += " " + var.toString();
}
result += "\n";
i++;
}
}
return result;
}
示例12: attributeParamIdentifier
import com.sun.tools.javac.code.Symbol.MethodSymbol; //导入依赖的package包/类
private Symbol attributeParamIdentifier(TreePath path, DCParam ptag) {
Symbol javadocSymbol = getElement(path);
if (javadocSymbol == null)
return null;
ElementKind kind = javadocSymbol.getKind();
List<? extends Symbol> params = List.nil();
if (kind == ElementKind.METHOD || kind == ElementKind.CONSTRUCTOR) {
MethodSymbol ee = (MethodSymbol) javadocSymbol;
params = ptag.isTypeParameter()
? ee.getTypeParameters()
: ee.getParameters();
} else if (kind.isClass() || kind.isInterface()) {
ClassSymbol te = (ClassSymbol) javadocSymbol;
params = te.getTypeParameters();
}
for (Symbol param : params) {
if (param.getSimpleName() == ptag.getName().getName()) {
return param;
}
}
return null;
}
示例13: overriddenType
import com.sun.tools.javac.code.Symbol.MethodSymbol; //导入依赖的package包/类
/**
* Return the type containing the method that this method overrides.
* It may be a <code>TypeElement</code> or a <code>TypeParameterElement</code>.
* @param method target
* @return a type
*/
public TypeMirror overriddenType(ExecutableElement method) {
if (utils.isStatic(method)) {
return null;
}
MethodSymbol sym = (MethodSymbol)method;
ClassSymbol origin = (ClassSymbol) sym.owner;
for (com.sun.tools.javac.code.Type t = toolEnv.getTypes().supertype(origin.type);
t.hasTag(com.sun.tools.javac.code.TypeTag.CLASS);
t = toolEnv.getTypes().supertype(t)) {
ClassSymbol c = (ClassSymbol) t.tsym;
for (com.sun.tools.javac.code.Symbol sym2 : c.members().getSymbolsByName(sym.name)) {
if (sym.overrides(sym2, origin, toolEnv.getTypes(), true)) {
return t;
}
}
}
return null;
}
示例14: overrides
import com.sun.tools.javac.code.Symbol.MethodSymbol; //导入依赖的package包/类
public boolean overrides(ExecutableElement e1, ExecutableElement e2, TypeElement cls) {
MethodSymbol rider = (MethodSymbol)e1;
MethodSymbol ridee = (MethodSymbol)e2;
ClassSymbol origin = (ClassSymbol)cls;
return rider.name == ridee.name &&
// not reflexive as per JLS
rider != ridee &&
// we don't care if ridee is static, though that wouldn't
// compile
!rider.isStatic() &&
// Symbol.overrides assumes the following
ridee.isMemberOf(origin, toolEnv.getTypes()) &&
// check access, signatures and check return types
rider.overrides(ridee, origin, toolEnv.getTypes(), true);
}
示例15: addMethodIfExist
import com.sun.tools.javac.code.Symbol.MethodSymbol; //导入依赖的package包/类
private void addMethodIfExist(ClassSymbol def, String methodName) {
Names names = def.name.table.names;
for (Symbol sym : def.members().getSymbolsByName(names.fromString(methodName))) {
if (sym.kind == MTH) {
MethodSymbol md = (MethodSymbol) sym;
if ((md.flags() & Flags.STATIC) == 0) {
/*
* WARNING: not robust if unqualifiedMethodName is overloaded
* method. Signature checking could make more robust.
* READOBJECT takes a single parameter, java.io.ObjectInputStream.
* WRITEOBJECT takes a single parameter, java.io.ObjectOutputStream.
*/
methods.add(md);
}
}
}
}