本文整理匯總了Java中com.sun.tools.javac.util.Name類的典型用法代碼示例。如果您正苦於以下問題:Java Name類的具體用法?Java Name怎麽用?Java Name使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Name類屬於com.sun.tools.javac.util包,在下文中一共展示了Name類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: alreadyDefinedIn
import com.sun.tools.javac.util.Name; //導入依賴的package包/類
public boolean alreadyDefinedIn(CharSequence name, TypeMirror returnType, List<TypeMirror> paramTypes, TypeElement enclClass) {
ClassSymbol clazz = (ClassSymbol)enclClass;
Scope scope = clazz.members();
Name n = names.fromString(name.toString());
ListBuffer<Type> buff = new ListBuffer<>();
for (TypeMirror tm : paramTypes) {
buff.append((Type)tm);
}
for (Symbol sym : scope.getSymbolsByName(n, Scope.LookupKind.NON_RECURSIVE)) {
if(sym.type instanceof ExecutableType &&
jctypes.containsTypeEquivalent(sym.type.asMethodType().getParameterTypes(), buff.toList()) &&
jctypes.isSameType(sym.type.asMethodType().getReturnType(), (Type)returnType))
return true;
}
return false;
}
示例2: getAnnotations
import com.sun.tools.javac.util.Name; //導入依賴的package包/類
static List<AnnotationMirror> getAnnotations(Element e, String name) {
Name valueName = ((Symbol)e).getSimpleName().table.names.value;
List<AnnotationMirror> res = new ArrayList<>();
for (AnnotationMirror m : e.getAnnotationMirrors()) {
TypeElement te = (TypeElement) m.getAnnotationType().asElement();
if (te.getQualifiedName().contentEquals(name)) {
Compound theAnno = (Compound)m;
Array valueArray = (Array)theAnno.member(valueName);
for (Attribute a : valueArray.getValue()) {
AnnotationMirror theMirror = (AnnotationMirror) a;
res.add(theMirror);
}
}
}
return res;
}
示例3: testConvertNameCandidates
import com.sun.tools.javac.util.Name; //導入依賴的package包/類
@Test
public void testConvertNameCandidates(Path base) throws Exception {
Context ctx = new Context();
Names names = Names.instance(ctx);
Name name = names.fromString("com.sun.tools.javac.Attr.BreakAttr");
com.sun.tools.javac.util.List<String> actual =
Convert.classCandidates(name).map(n -> n.toString());
List<String> expected = Arrays.asList(
"com.sun$tools$javac$Attr$BreakAttr",
"com.sun.tools$javac$Attr$BreakAttr",
"com.sun.tools.javac$Attr$BreakAttr",
"com.sun.tools.javac.Attr$BreakAttr",
"com.sun.tools.javac.Attr.BreakAttr"
);
if (!expected.equals(actual)) {
throw new Exception("Expected names not generated: " + actual);
}
}
示例4: getClassSymbol
import com.sun.tools.javac.util.Name; //導入依賴的package包/類
/** Retrieve class symbol by fully-qualified name.
*/
ClassSymbol getClassSymbol(String name) {
// Name may contain nested class qualification.
// Generate candidate flatnames with successively shorter
// package qualifiers and longer nested class qualifiers.
int nameLen = name.length();
char[] nameChars = name.toCharArray();
int idx = name.length();
for (;;) {
Name nameImpl = names.fromChars(nameChars, 0, nameLen);
ModuleSymbol mod = syms.inferModule(Convert.packagePart(nameImpl));
ClassSymbol s = mod != null ? syms.getClass(mod, nameImpl) : null;
if (s != null)
return s; // found it!
idx = name.substring(0, idx).lastIndexOf('.');
if (idx < 0) break;
nameChars[idx] = '$';
}
return null;
}
示例5: nameToSymbol
import com.sun.tools.javac.util.Name; //導入依賴的package包/類
/**
* Returns a symbol given the type's or packages's canonical name,
* or null if the name isn't found.
*/
private <S extends Symbol> S nameToSymbol(String nameStr, Class<S> clazz) {
Name name = names.fromString(nameStr);
// First check cache.
Symbol sym = (clazz == ClassSymbol.class)
? syms.classes.get(name)
: syms.packages.get(name);
try {
if (sym == null)
sym = javaCompiler.resolveIdent(nameStr);
sym.complete();
return (sym.kind != Kinds.ERR &&
sym.exists() &&
clazz.isInstance(sym) &&
name.equals(sym.getQualifiedName()))
? clazz.cast(sym)
: null;
} catch (CompletionFailure e) {
return null;
}
}
示例6: enterClassFiles
import com.sun.tools.javac.util.Name; //導入依賴的package包/類
/** Enter a set of generated class files. */
private List<ClassSymbol> enterClassFiles(Map<String, JavaFileObject> classFiles) {
ClassReader reader = ClassReader.instance(context);
Names names = Names.instance(context);
List<ClassSymbol> list = List.nil();
for (Map.Entry<String,JavaFileObject> entry : classFiles.entrySet()) {
Name name = names.fromString(entry.getKey());
JavaFileObject file = entry.getValue();
if (file.getKind() != JavaFileObject.Kind.CLASS)
throw new AssertionError(file);
ClassSymbol cs;
if (isPkgInfo(file, JavaFileObject.Kind.CLASS)) {
Name packageName = Convert.packagePart(name);
PackageSymbol p = reader.enterPackage(packageName);
if (p.package_info == null)
p.package_info = reader.enterClass(Convert.shortName(name), p);
cs = p.package_info;
if (cs.classfile == null)
cs.classfile = file;
} else
cs = reader.enterClass(name, file);
list = list.prepend(cs);
}
return list.reverse();
}
示例7: toString
import com.sun.tools.javac.util.Name; //導入依賴的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: rewriteChildren
import com.sun.tools.javac.util.Name; //導入依賴的package包/類
protected final AttributeTree rewriteChildren(AttributeTree tree) {
AttributeTree value = tree;
List<? extends DocTree> vl = translateDoc(tree.getValue());
if (vl != tree.getValue()) {
value = make.Attribute((Name) tree.getName(), tree.getValueKind(), vl);
}
return value;
}
示例9: nameChanged
import com.sun.tools.javac.util.Name; //導入依賴的package包/類
protected boolean nameChanged(Name oldName, Name newName) {
if (oldName == newName)
return false;
if (oldName == null || newName == null)
return true;
byte[] arr1 = oldName.toUtf();
byte[] arr2 = newName.toUtf();
int len = arr1.length;
if (len != arr2.length)
return true;
for (int i = 0; i < len; i++)
if (arr1[i] != arr2[i])
return true;
return false;
}
示例10: diffIdentifier
import com.sun.tools.javac.util.Name; //導入依賴的package包/類
private int diffIdentifier(DCDocComment doc, DCIdentifier oldT, DCIdentifier newT, int[] elementBounds) {
if(oldT.name.equals(newT.name)) {
copyTo(elementBounds[0], elementBounds[1]);
} else {
printer.print((Name) newT.name);
}
return elementBounds[1];
}
示例11: diffStartElement
import com.sun.tools.javac.util.Name; //導入依賴的package包/類
private int diffStartElement(DCDocComment doc, DCStartElement oldT, DCStartElement newT, int[] elementBounds) {
int localpointer = oldT.attrs.isEmpty()? elementBounds[1] - 1 : getOldPos(oldT.attrs.get(0), doc);
if(oldT.name.equals(newT.name)) {
copyTo(elementBounds[0], localpointer);
} else {
printer.print("<");
printer.print((Name) newT.name);
}
localpointer = diffList(doc, oldT.attrs, newT.attrs, localpointer, Measure.DOCTREE);
if(localpointer < elementBounds[1]) {
copyTo(localpointer, elementBounds[1]);
}
return elementBounds[1];
}
示例12: ClassSymbol
import com.sun.tools.javac.util.Name; //導入依賴的package包/類
public ClassSymbol(long flags, Name name, Symbol owner) {
this(
flags,
name,
new ClassType(Type.noType, null, null),
owner);
this.type.tsym = this;
}
示例13: create
import com.sun.tools.javac.util.Name; //導入依賴的package包/類
/**
* Create a ModuleSymbol with an associated module-info ClassSymbol.
*/
public static ModuleSymbol create(Name name, Name module_info) {
ModuleSymbol msym = new ModuleSymbol(name, null);
ClassSymbol info = new ClassSymbol(Flags.MODULE, module_info, msym);
info.fullname = formFullName(module_info, msym);
info.flatname = info.fullname;
info.members_field = WriteableScope.create(info);
msym.module_info = info;
return msym;
}
示例14: formFlatName
import com.sun.tools.javac.util.Name; //導入依賴的package包/類
/** form a fully qualified name from a name and an owner, after
* converting to flat representation
*/
static public Name formFlatName(Name name, Symbol owner) {
if (owner == null ||
(owner.kind & (VAR | MTH)) != 0
|| (owner.kind == TYP && owner.type.hasTag(TYPEVAR))
) return name;
char sep = owner.kind == TYP ? '$' : '.';
Name prefix = owner.flatName();
if (prefix == null || prefix == prefix.table.names.empty)
return name;
else return prefix.append(sep, name);
}
示例15: ClassSymbol
import com.sun.tools.javac.util.Name; //導入依賴的package包/類
public ClassSymbol(long flags, Name name, Type type, Symbol owner) {
super(flags, name, type, owner);
this.members_field = null;
this.fullname = formFullName(name, owner);
this.flatname = formFlatName(name, owner);
this.sourcefile = null;
this.classfile = null;
this.pool = null;
}