Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* 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.
*/
package org.openjdk.tools.javac.comp;
import org.openjdk.source.tree.LambdaExpressionTree;
import org.openjdk.tools.javac.code.Source;
import org.openjdk.tools.javac.code.Type;
import org.openjdk.tools.javac.code.Types;
import org.openjdk.tools.javac.comp.ArgumentAttr.LocalCacheContext;
import org.openjdk.tools.javac.tree.JCTree;
import org.openjdk.tools.javac.tree.JCTree.JCBlock;
import org.openjdk.tools.javac.tree.JCTree.JCClassDecl;
import org.openjdk.tools.javac.tree.JCTree.JCDoWhileLoop;
import org.openjdk.tools.javac.tree.JCTree.JCEnhancedForLoop;
import org.openjdk.tools.javac.tree.JCTree.JCForLoop;
import org.openjdk.tools.javac.tree.JCTree.JCIf;
import org.openjdk.tools.javac.tree.JCTree.JCLambda;
import org.openjdk.tools.javac.tree.JCTree.JCLambda.ParameterKind;
import org.openjdk.tools.javac.tree.JCTree.JCMethodDecl;
import org.openjdk.tools.javac.tree.JCTree.JCMethodInvocation;
import org.openjdk.tools.javac.tree.JCTree.JCNewClass;
import org.openjdk.tools.javac.tree.JCTree.JCStatement;
import org.openjdk.tools.javac.tree.JCTree.JCSwitch;
import org.openjdk.tools.javac.tree.JCTree.JCTypeApply;
import org.openjdk.tools.javac.tree.JCTree.JCVariableDecl;
import org.openjdk.tools.javac.tree.JCTree.JCWhileLoop;
import org.openjdk.tools.javac.tree.JCTree.Tag;
import org.openjdk.tools.javac.tree.TreeCopier;
import org.openjdk.tools.javac.tree.TreeInfo;
import org.openjdk.tools.javac.tree.TreeMaker;
import org.openjdk.tools.javac.tree.TreeScanner;
import org.openjdk.tools.javac.util.Context;
import org.openjdk.tools.javac.util.DefinedBy;
import org.openjdk.tools.javac.util.DefinedBy.Api;
import org.openjdk.tools.javac.util.JCDiagnostic;
import org.openjdk.tools.javac.util.JCDiagnostic.DiagnosticType;
import org.openjdk.tools.javac.util.List;
import org.openjdk.tools.javac.util.ListBuffer;
import org.openjdk.tools.javac.util.Log;
import org.openjdk.tools.javac.util.Names;
import org.openjdk.tools.javac.util.Options;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Predicate;
import static org.openjdk.tools.javac.code.Flags.GENERATEDCONSTR;
import static org.openjdk.tools.javac.code.Flags.SYNTHETIC;
import static org.openjdk.tools.javac.code.TypeTag.CLASS;
import static org.openjdk.tools.javac.tree.JCTree.Tag.APPLY;
import static org.openjdk.tools.javac.tree.JCTree.Tag.METHODDEF;
import static org.openjdk.tools.javac.tree.JCTree.Tag.NEWCLASS;
import static org.openjdk.tools.javac.tree.JCTree.Tag.TYPEAPPLY;
/**
* Helper class for defining custom code analysis, such as finding instance creation expression
* that can benefit from diamond syntax.
*/
public class Analyzer {
protected static final Context.Key analyzerKey = new Context.Key<>();
final Types types;
final Log log;
final Attr attr;
final DeferredAttr deferredAttr;
final ArgumentAttr argumentAttr;
final TreeMaker make;
final Names names;
private final boolean allowDiamondWithAnonymousClassCreation;
final EnumSet analyzerModes;
public static Analyzer instance(Context context) {
Analyzer instance = context.get(analyzerKey);
if (instance == null)
instance = new Analyzer(context);
return instance;
}
protected Analyzer(Context context) {
context.put(analyzerKey, this);
types = Types.instance(context);
log = Log.instance(context);
attr = Attr.instance(context);
deferredAttr = DeferredAttr.instance(context);
argumentAttr = ArgumentAttr.instance(context);
make = TreeMaker.instance(context);
names = Names.instance(context);
Options options = Options.instance(context);
String findOpt = options.get("find");
//parse modes
Source source = Source.instance(context);
allowDiamondWithAnonymousClassCreation = source.allowDiamondWithAnonymousClassCreation();
analyzerModes = AnalyzerMode.getAnalyzerModes(findOpt, source);
}
/**
* This enum defines supported analyzer modes, as well as defining the logic for decoding
* the {@code -XDfind} option.
*/
enum AnalyzerMode {
DIAMOND("diamond", Source::allowDiamond),
LAMBDA("lambda", Source::allowLambda),
METHOD("method", Source::allowGraphInference);
final String opt;
final Predicate