/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* A rich diagnostic formatter is a formatter that provides better integration
* with javac's type system. A diagostic is first preprocessed in order to keep
* has been replaced by a more refined version provided by this rich formatter.
* The rich formatter currently enables three different features: (i) simple class
* names - that is class names are displayed used a non qualified name (thus
* omitting package info) whenever possible - (ii) where clause list - a list of
* additional subdiagnostics that provide specific info about type-variables,
* captured types, intersection types that occur in the diagnostic that is to be
* formatted and (iii) type-variable disambiguation - when the diagnostic refers
* to two different type-variables with the same name, their representation is
* disambiguated by appending an index to the type variable name.
*
* <p><b>This is NOT part of any supported API.
* If you write code that depends on this, you do so at your own risk.
* This code and its internal interfaces are subject to change or
* deletion without notice.</b>
*/
public class RichDiagnosticFormatter extends
/* name simplifier used by this formatter */
/* map for keeping track of a where clause associated to a given type */
/** Get the DiagnosticFormatter instance for this context. */
return instance;
}
setRichPrinter(new RichPrinter());
}
nameSimplifier = new ClassNameSimplifier();
for (JCDiagnostic d : clauses) {
}
}
}
}
/**
* @param printer the rich printer to be set
*/
}
/**
*/
return printer;
}
/**
* Preprocess a given diagnostic by looking both into its arguments and into
* its subdiagnostics (if any). This preprocessing is responsible for
* generating info corresponding to features like where clauses, name
* simplification, etc.
*
* @param diag the diagnostic to be preprocessed
*/
if (o != null) {
}
}
if (diag.isMultiline()) {
}
}
/**
*
* @param arg the argument to be translated
*/
}
}
else if (arg instanceof JCDiagnostic) {
}
}
}
}
/**
* Build a list of multiline diagnostics containing detailed info about
* type-variables, captured types, and intersection types
*
* @return where clause list
*/
}
key += ".1";
}
}
}
int index = 1;
return index;
}
index++;
}
}
return -1;
}
int found = 0;
found++;
}
}
if (found < 1)
return found == 1;
}
//where
/**
* This enum defines all posssible kinds of where clauses that can be
* attached by a rich diagnostic formatter to a given diagnostic
*/
enum WhereClauseKind {
/** where clause regarding a type variable */
/** where clause regarding a captured type */
/** where clause regarding an intersection type */
/** resource key for this where clause kind */
}
return key;
}
}
// <editor-fold defaultstate="collapsed" desc="name simplifier">
/**
* A name simplifier keeps track of class names usages in order to determine
* whether a class name can be compacted or not. Short names are not used
* if a conflict is detected, e.g. when two classes with the same simple
* name belong to different packages - in this case the formatter reverts
* to fullnames as compact names might lead to a confusing diagnostic.
*/
protected class ClassNameSimplifier {
/* table for keeping track of all short name usages */
/**
* Add a name usage to the simplifier's internal cache
*/
}
}
if (!s.type.isCompound()) {
}
sep = ".";
}
}
}
return name;
}
};
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="rich printer">
/**
* and type variable disambiguation. This enriched printer exploits the info
*/
}
}
return s;
}
"compiler.misc.captured.type",
}
else
return super.visitCapturedType(t, locale);
}
if (t.isCompound() &&
"compiler.misc.intersection.type",
}
else
return super.visitClassType(t, locale);
}
}
else if (longform)
else
}
if (unique(t) ||
return t.toString();
}
else {
"compiler.misc.type.var",
}
}
}
return super.visitClassSymbol(s, locale);
}
else {
return name;
}
}
if (s.isStaticOrInstanceInit()) {
return ownerName;
} else {
}
s.type.getParameterTypes(),
locale) + ")";
}
return ms;
}
}
};
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="type scanner">
/**
* Preprocess a given type looking for (i) additional info (where clauses) to be
* added to the main diagnostic (ii) names to be compacted.
*/
}
//where
visit(t);
return null;
}
return null;
}
return null;
}
return null;
}
return null;
}
return null;
}
return null;
}
}
return null;
}
if (t.isCompound()) {
}
}
visit(t.getTypeArguments());
visit(t.getEnclosingType());
return null;
}
//access the bound type and skip error types
//retrieve the bound list - if the type variable
//has not been attributed the bound is not set
}
return null;
}
};
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="symbol scanner">
/**
* Preprocess a given symbol looking for (i) additional info (where clauses) to be
* asdded to the main diagnostic (ii) names to be compacted
*/
}
//where
return null;
}
return null;
}
return null;
}
};
// </editor-fold>
//the following cast is always safe - see init
return (RichConfiguration)configuration;
}
/**
* Configuration object provided by the rich formatter.
*/
public static class RichConfiguration extends ForwardingDiagnosticFormatter.ForwardingConfiguration {
/** set of enabled rich formatter's features */
@SuppressWarnings("fallthrough")
super(formatter.getConfiguration());
}
}
}
}
}
}
}
}
}
/**
* Returns a list of all the features supported by the rich formatter.
* @return list of supported features
*/
return RichFormatterFeature.values();
}
/**
* Enable a specific feature on this rich formatter.
* @param feature feature to be enabled
*/
}
/**
* Disable a specific feature on this rich formatter.
* @param feature feature to be disabled
*/
}
/**
* Is a given feature enabled on this formatter?
* @param feature feature to be tested
*/
}
/**
* The advanced formatting features provided by the rich formatter
*/
public enum RichFormatterFeature {
/** full class names simplification (where possible) */
/** type-variable names disambiguation */
}
}
}