com.sun.tools.javac.util.Name Java Examples
The following examples show how to use
com.sun.tools.javac.util.Name.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Dependencies.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Fetch the set of dependencies that are relevant to the compile * that has just been performed. I.e. we are only interested in * dependencies for classes that were explicitly compiled. * @return */ public Map<String,Set<String>> getDependencies() { Map<String,Set<String>> new_deps = new HashMap<String,Set<String>>(); if (explicitPackages == null) return new_deps; for (Name pkg : explicitPackages) { Set<Name> set = deps.get(pkg); if (set != null) { Set<String> new_set = new_deps.get(pkg.toString()); if (new_set == null) { new_set = new HashSet<String>(); // Modules beware.... new_deps.put(":"+pkg.toString(), new_set); } for (Name d : set) { new_set.add(":"+d.toString()); } } } return new_deps; }
Example #2
Source File: TreePruner.java From bazel with Apache License 2.0 | 6 votes |
private static boolean delegatingConstructor(List<JCStatement> stats) { if (stats.isEmpty()) { return false; } JCStatement stat = stats.get(0); if (stat.getKind() != Kind.EXPRESSION_STATEMENT) { return false; } JCExpression expr = ((JCExpressionStatement) stat).getExpression(); if (expr.getKind() != Kind.METHOD_INVOCATION) { return false; } JCExpression method = ((JCMethodInvocation) expr).getMethodSelect(); Name name; switch (method.getKind()) { case IDENTIFIER: name = ((JCIdent) method).getName(); break; case MEMBER_SELECT: name = ((JCFieldAccess) method).getIdentifier(); break; default: return false; } return name.contentEquals("this") || name.contentEquals("super"); }
Example #3
Source File: PostFlowAnalysis.java From netbeans with Apache License 2.0 | 6 votes |
@Override public void visitApply(JCMethodInvocation tree) { boolean prevCheckThis = checkThis; try { Symbol meth = TreeInfo.symbol(tree.meth); Name methName = TreeInfo.name(tree.meth); if (meth != null && meth.name == names.init) { Symbol c = meth.owner; if (c.hasOuterInstance()) { checkThis = false; if (tree.meth.getTag() != JCTree.Tag.SELECT && (c.isLocal() || methName == names._this)) { checkThis(tree.meth.pos(), c.type.getEnclosingType().tsym); } } } super.visitApply(tree); } finally { checkThis = prevCheckThis; } }
Example #4
Source File: Attribute.java From javaide with GNU General Public License v3.0 | 6 votes |
/** * 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(); }
Example #5
Source File: VeryPretty.java From netbeans with Apache License 2.0 | 6 votes |
public void printImportsBlock(java.util.List<? extends JCTree> imports, boolean maybeAppendNewLine) { boolean hasImports = !imports.isEmpty(); CodeStyle.ImportGroups importGroups = null; if (hasImports) { blankLines(Math.max(cs.getBlankLinesBeforeImports(), diffContext.origUnit.getPackageName() != null ? cs.getBlankLinesAfterPackage() : 0)); if (cs.separateImportGroups()) importGroups = cs.getImportGroups(); } int lastGroup = -1; for (JCTree importStat : imports) { if (importGroups != null) { Name name = fullName(((JCImport)importStat).qualid); int group = name != null ? importGroups.getGroupId(name.toString(), ((JCImport)importStat).staticImport) : -1; if (lastGroup >= 0 && lastGroup != group) blankline(); lastGroup = group; } printStat(importStat); newline(); } if (hasImports && maybeAppendNewLine) { blankLines(cs.getBlankLinesAfterImports()); } }
Example #6
Source File: ConvenientAccessErrorsTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@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); } }
Example #7
Source File: HandleCleanup.java From EasyMPermission with MIT License | 5 votes |
public void doAssignmentCheck0(JavacNode node, JCTree statement, Name name) { if (statement instanceof JCAssign) doAssignmentCheck0(node, ((JCAssign)statement).rhs, name); if (statement instanceof JCExpressionStatement) doAssignmentCheck0(node, ((JCExpressionStatement)statement).expr, name); if (statement instanceof JCVariableDecl) doAssignmentCheck0(node, ((JCVariableDecl)statement).init, name); if (statement instanceof JCTypeCast) doAssignmentCheck0(node, ((JCTypeCast)statement).expr, name); if (statement instanceof JCIdent) { if (((JCIdent)statement).name.contentEquals(name)) { JavacNode problemNode = node.getNodeFor(statement); if (problemNode != null) problemNode.addWarning( "You're assigning an auto-cleanup variable to something else. This is a bad idea."); } } }
Example #8
Source File: Operators.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Creates an operator symbol. */ private OperatorSymbol makeOperator(Name name, List<OperatorType> formals, OperatorType res, int... opcodes) { MethodType opType = new MethodType( formals.stream() .map(o -> o.asType(syms)) .collect(List.collector()), res.asType(syms), List.nil(), syms.methodClass); return new OperatorSymbol(name, opType, mergeOpcodes(opcodes), syms.noSymbol); }
Example #9
Source File: Operators.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Complete the initialization of an operator helper by storing it into the corresponding operator map. */ @SafeVarargs private final <O extends OperatorHelper> void initOperators(Map<Name, List<O>> opsMap, O... ops) { for (O o : ops) { Name opName = o.name; List<O> helpers = Maps.getOrDefault(opsMap,opName, List.nil()); opsMap.put(opName, helpers.prepend(o)); } }
Example #10
Source File: Symbol.java From javaide with GNU General Public License v3.0 | 5 votes |
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; }
Example #11
Source File: Symbol.java From javaide with GNU General Public License v3.0 | 5 votes |
public ClassSymbol(long flags, Name name, Symbol owner) { this( flags, name, new ClassType(Type.noType, null, null), owner); this.type.tsym = this; }
Example #12
Source File: DocCommentParser.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
protected Name readIdentifier() { int start = bp; nextChar(); while (bp < buflen && Character.isUnicodeIdentifierPart(ch)) nextChar(); return names.fromChars(buf, start, bp - start); }
Example #13
Source File: DocCommentParser.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
protected Name readJavaIdentifier() { int start = bp; nextChar(); while (bp < buflen && Character.isJavaIdentifierPart(ch)) nextChar(); return names.fromChars(buf, start, bp - start); }
Example #14
Source File: JavacJavaUtilListSetSingularizer.java From EasyMPermission with MIT License | 5 votes |
@Override public java.util.List<Name> listMethodsToBeGenerated(SingularData data, JavacNode builderType) { if (useGuavaInstead(builderType)) { return guavaListSetSingularizer.listMethodsToBeGenerated(data, builderType); } return super.listMethodsToBeGenerated(data, builderType); }
Example #15
Source File: Dependencies.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * Collect a dependency. curr_pkg is marked as depending on dep_pkg. */ public void collect(Name currPkg, Name depPkg) { if (!currPkg.equals(depPkg)) { Set<Name> theset = deps.get(currPkg); if (theset==null) { theset = new HashSet<Name>(); deps.put(currPkg, theset); } theset.add(depPkg); } }
Example #16
Source File: AnnotationProxyMaker.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void visitArray(Attribute.Array a) { Name elemName = ((ArrayType) a.type).elemtype.tsym.getQualifiedName(); if (elemName.equals(elemName.table.names.java_lang_Class)) { // Class[] // Construct a proxy for a MirroredTypesException ListBuffer<TypeMirror> elems = new ListBuffer<>(); for (Attribute value : a.values) { Type elem = ((Attribute.Class) value).classType; elems.append(elem); } value = new MirroredTypesExceptionProxy(elems.toList()); } else { int len = a.values.length; Class<?> returnClassSaved = returnClass; returnClass = returnClass.getComponentType(); try { Object res = Array.newInstance(returnClass, len); for (int i = 0; i < len; i++) { a.values[i].accept(this); if (value == null || value instanceof ExceptionProxy) { return; } try { Array.set(res, i, value); } catch (IllegalArgumentException e) { value = null; // indicates a type mismatch return; } } value = res; } finally { returnClass = returnClassSaved; } } }
Example #17
Source File: JavacGuavaSingularizer.java From EasyMPermission with MIT License | 5 votes |
@Override public void appendBuildCode(SingularData data, JavacNode builderType, JCTree source, ListBuffer<JCStatement> statements, Name targetVariableName) { JavacTreeMaker maker = builderType.getTreeMaker(); List<JCExpression> jceBlank = List.nil(); boolean mapMode = isMap(); JCExpression varType = chainDotsString(builderType, data.getTargetFqn()); varType = addTypeArgs(mapMode ? 2 : 1, false, builderType, varType, data.getTypeArgs(), source); JCExpression empty; { //ImmutableX.of() JCExpression emptyMethod = chainDots(builderType, "com", "google", "common", "collect", getSimpleTargetTypeName(data), "of"); List<JCExpression> invokeTypeArgs = createTypeArgs(mapMode ? 2 : 1, false, builderType, data.getTypeArgs(), source); empty = maker.Apply(invokeTypeArgs, emptyMethod, jceBlank); } JCExpression invokeBuild; { //this.pluralName.build(); invokeBuild = maker.Apply(jceBlank, chainDots(builderType, "this", data.getPluralName().toString(), "build"), jceBlank); } JCExpression isNull; { //this.pluralName == null isNull = maker.Binary(CTC_EQUAL, maker.Select(maker.Ident(builderType.toName("this")), data.getPluralName()), maker.Literal(CTC_BOT, null)); } JCExpression init = maker.Conditional(isNull, empty, invokeBuild); // this.pluralName == null ? ImmutableX.of() : this.pluralName.build() JCStatement jcs = maker.VarDef(maker.Modifiers(0), data.getPluralName(), varType, init); statements.append(jcs); }
Example #18
Source File: DocEnv.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Load ClassDoc by qualified name. */ public ClassDocImpl loadClass(String name) { try { Name nameImpl = names.fromString(name); ModuleSymbol mod = syms.inferModule(Convert.packagePart(nameImpl)); ClassSymbol c = finder.loadClass(mod != null ? mod : syms.errModule, nameImpl); return getClassDoc(c); } catch (CompletionFailure ex) { chk.completionError(null, ex); return null; } }
Example #19
Source File: Lower.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** Create a fresh synthetic name within a given scope - the unique name is * obtained by appending '$' chars at the end of the name until no match * is found. * * @param name base name * @param s scope in which the name has to be unique * @return fresh synthetic name */ private Name makeSyntheticName(Name name, Scope s) { do { name = name.append( target.syntheticNameChar(), names.empty); } while (lookupSynthetic(name, s) != null); return name; }
Example #20
Source File: Operators.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Report an operator lookup error. */ private OperatorSymbol reportErrorIfNeeded(DiagnosticPosition pos, Tag tag, Type... args) { if (Stream.of(args).noneMatch(Type::isErroneous)) { Name opName = operatorName(tag); JCDiagnostic.Error opError = (args.length) == 1 ? Errors.OperatorCantBeApplied(opName, args[0]) : Errors.OperatorCantBeApplied1(opName, args[0], args[1]); log.error(pos, opError); } return noOpSymbol; }
Example #21
Source File: ElementsTable.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private ModuleSymbol findModuleOfPackageName(String packageName) { Name pack = names.fromString(packageName); for (ModuleSymbol msym : modules.allModules()) { PackageSymbol p = syms.getPackage(msym, pack); if (p != null && !p.members().isEmpty()) { return msym; } } return null; }
Example #22
Source File: Symbol.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public ClassSymbol(long flags, Name name, Symbol owner) { this( flags, name, new ClassType(Type.noType, null, null), owner); this.type.tsym = this; }
Example #23
Source File: Lower.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** The name of a this$n field * @param type The class referenced by the this$n field */ Name outerThisName(Type type, Symbol owner) { Type t = type.getEnclosingType(); int nestingLevel = 0; while (t.hasTag(CLASS)) { t = t.getEnclosingType(); nestingLevel++; } Name result = names.fromString("this" + target.syntheticNameChar() + nestingLevel); while (owner.kind == TYP && ((ClassSymbol)owner).members().findFirst(result) != null) result = names.fromString(result.toString() + target.syntheticNameChar()); return result; }
Example #24
Source File: Modules.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
public ModuleSymbol getObservableModule(Name name) { ModuleSymbol mod = syms.getModule(name); if (allModules().contains(mod)) { return mod; } return null; }
Example #25
Source File: TypeVariableImpl.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * Get the bounds of a type variable as listed in the "extends" clause. */ private static List<Type> getBounds(TypeVar v, DocEnv env) { final Type upperBound = v.getUpperBound(); Name boundname = upperBound.tsym.getQualifiedName(); if (boundname == boundname.table.names.java_lang_Object && !upperBound.isAnnotated()) { return List.nil(); } else { return env.types.getBounds(v); } }
Example #26
Source File: Types.java From java-n-IDE-for-Android with Apache License 2.0 | 5 votes |
public RetentionPolicy getRetention(Attribute.Compound a) { RetentionPolicy vis = RetentionPolicy.CLASS; // the default Attribute.Compound c = a.type.tsym.attribute(syms.retentionType.tsym); if (c != null) { Attribute value = c.member(names.value); if (value != null && value instanceof Attribute.Enum) { Name levelName = ((Attribute.Enum)value).value.name; if (levelName == names.SOURCE) vis = RetentionPolicy.SOURCE; else if (levelName == names.CLASS) vis = RetentionPolicy.CLASS; else if (levelName == names.RUNTIME) vis = RetentionPolicy.RUNTIME; else ;// /* fail soft */ throw new AssertionError(levelName); } } return vis; }
Example #27
Source File: TypeVariableImpl.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * Get the bounds of a type variable as listed in the "extends" clause. */ private static List<Type> getBounds(TypeVar v, DocEnv env) { final Type upperBound = v.getUpperBound(); Name boundname = upperBound.tsym.getQualifiedName(); if (boundname == boundname.table.names.java_lang_Object && !upperBound.isAnnotated()) { return List.nil(); } else { return env.types.getBounds(v); } }
Example #28
Source File: Symbol.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** form a fully qualified name from a name and an owner */ static public Name formFullName(Name name, Symbol owner) { if (owner == null) return name; if ((owner.kind != ERR) && (owner.kind.matches(KindSelector.VAL_MTH) || (owner.kind == TYP && owner.type.hasTag(TYPEVAR)) )) return name; Name prefix = owner.getQualifiedName(); if (prefix == null || prefix == prefix.table.names.empty) return name; else return prefix.append('.', name); }
Example #29
Source File: DocCommentParser.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
protected Name readJavaIdentifier() { int start = bp; nextChar(); while (bp < buflen && Character.isJavaIdentifierPart(ch)) nextChar(); return names.fromChars(buf, start, bp - start); }
Example #30
Source File: Type.java From javaide with GNU General Public License v3.0 | 5 votes |
public CapturedType(Name name, Symbol owner, Type upper, Type lower, WildcardType wildcard) { super(name, owner, lower); this.lower = Assert.checkNonNull(lower); this.bound = upper; this.wildcard = wildcard; }