private String getSourceName() { return sourceFile == null ? null : sourceFile.getName(); }
@Override public String getPackageName(StaticSourceFile source) { // The package name of a source file is its file path. String name = source.getName(); int lastSlash = name.lastIndexOf('/'); return lastSlash == -1 ? "" : name.substring(0, lastSlash); }
@Override public String getPackageName(StaticSourceFile source) { // The package name of a source file is its file path. String name = source.getName(); int lastSlash = name.lastIndexOf('/'); return lastSlash == -1 ? "" : name.substring(0, lastSlash); }
@Nullable public String getSourceFileName() { StaticSourceFile file = getStaticSourceFile(); return file == null ? null : file.getName(); }
private String getSourceName() { StaticSourceFile sourceFile = getSourceFile(); return sourceFile == null ? null : sourceFile.getName(); }
public String getSourceFileName() { StaticSourceFile file = getStaticSourceFile(); return file == null ? null : file.getName(); }
/** * {@inheritDoc} * * <p>In Google code, the package name of a source file is its file path. * Exceptions: if a source file's parent directory is "test", "tests", or * "testing", that directory is stripped from the package name. * If a file is generated, strip the "genfiles" prefix to try * to match the package of the generating file. */ @Override public String getPackageName(StaticSourceFile source) { String name = source.getName(); Matcher genfilesMatcher = GENFILES_DIR.matcher(name); if (genfilesMatcher.find()) { name = genfilesMatcher.group(1); } Matcher m = PACKAGE_WITH_TEST_DIR.matcher(name); if (m.find()) { return m.group(1); } else { int lastSlash = name.lastIndexOf('/'); return lastSlash == -1 ? "" : name.substring(0, lastSlash); } }
/** * {@inheritDoc} * * <p>In Google code, the package name of a source file is its file path. * Exceptions: if a source file's parent directory is "test", "tests", or * "testing", that directory is stripped from the package name. * If a file is generated, strip the "genfiles" prefix to try * to match the package of the generating file. */ @Override @GwtIncompatible // TODO(tdeegan): Remove use of Matcher#group to make this fully GWT compatible. public String getPackageName(StaticSourceFile source) { String name = source.getName(); Matcher genfilesMatcher = GENFILES_DIR.matcher(name); if (genfilesMatcher.find()) { name = genfilesMatcher.group(2); } Matcher m = PACKAGE_WITH_TEST_DIR.matcher(name); if (m.find()) { return m.group(1); } else { int lastSlash = name.lastIndexOf('/'); return lastSlash == -1 ? "" : name.substring(0, lastSlash); } }
private void addNewWarning(String messageId, String messageArg, Node nodeWarning) { // TODO(lpino): Use the exact lineno and charno, it is currently using // the lineno and charno of the parent @template // TODO(lpino): Use only constants as parameters of this method errorReporter.warning( "Bad type annotation. " + SimpleErrorReporter.getMessage1(messageId, messageArg), sourceFile.getName(), templateLineno, templateCharno); }
private void addNewWarning(String messageId, String messageArg, Node nodeWarning) { // TODO(lpino): Use the exact lineno and charno, it is currently using // the lineno and charno of the parent @template // TODO(lpino): Use only constants as parameters of this method errorReporter.warning( "Bad type annotation. " + SimpleErrorReporter.getMessage1(messageId, messageArg), sourceFile.getName(), templateLineno, templateCharno); }
private static boolean isPrivateAccessAllowed(TypedVar var, Node name, Node parent) { StaticSourceFile varSrc = var.getSourceFile(); StaticSourceFile refSrc = name.getStaticSourceFile(); JSDocInfo docInfo = var.getJSDocInfo(); if (varSrc != null && refSrc != null && !varSrc.getName().equals(refSrc.getName())) { return docInfo != null && docInfo.isConstructor() && isValidPrivateConstructorAccess(parent); } else { return true; } }
private void checkNonOverriddenPropertyVisibility( NodeTraversal t, PropertyReference propRef, Visibility visibility, JSType objectType, StaticSourceFile referenceSource, StaticSourceFile definingSource) { // private access is always allowed in the same file. if (referenceSource != null && definingSource != null && referenceSource.getName().equals(definingSource.getName())) { return; } @Nullable ObjectType ownerType = instanceTypeFor(objectType); switch (visibility) { case PACKAGE: checkPackagePropertyVisibility(t, propRef, referenceSource, definingSource); break; case PRIVATE: checkPrivatePropertyVisibility(t, propRef, ownerType); break; case PROTECTED: checkProtectedPropertyVisibility(t, propRef, ownerType); break; default: break; } }
/** * Helper for addSymbolsFrom, to determine whether a reference is * acceptable. A reference must be in the normal source tree. */ private boolean isGoodRefToAdd(@Nullable StaticRef ref) { return ref != null && ref.getNode() != null && ref.getNode().getStaticSourceFile() != null && !Compiler.SYNTHETIC_EXTERNS.equals( ref.getNode().getStaticSourceFile().getName()); }
/** * Helper for addSymbolsFrom, to determine whether a reference is acceptable. A reference must be * in the normal source tree. */ private boolean isGoodRefToAdd(@Nullable StaticRef ref) { return ref != null && ref.getNode() != null && ref.getNode().getStaticSourceFile() != null && !Compiler.SYNTHETIC_EXTERNS.equals(ref.getNode().getStaticSourceFile().getName()); }
private IRFactory(String sourceString, StaticSourceFile sourceFile, Config config, ErrorReporter errorReporter, ImmutableList<Comment> comments) { this.sourceString = sourceString; this.nextCommentIter = comments.iterator(); this.currentComment = skipNonJsDoc(nextCommentIter); this.sourceFile = sourceFile; // The template node properties are applied to all nodes in this transform. this.templateNode = createTemplateNode(); this.fileLevelJsDocBuilder = new JSDocInfoBuilder(config.jsDocParsingMode().shouldParseDescriptions()); // Sometimes this will be null in tests. this.sourceName = sourceFile == null ? null : sourceFile.getName(); this.config = config; this.errorReporter = errorReporter; this.transformDispatcher = new TransformDispatcher(); if (config.strictMode().isStrict()) { reservedKeywords = ES5_STRICT_RESERVED_KEYWORDS; } else if (config.languageMode() == LanguageMode.ECMASCRIPT3) { reservedKeywords = null; // use TokenStream.isKeyword instead } else { reservedKeywords = ES5_RESERVED_KEYWORDS; } }
public List<ClassReference> getInterfaces() { ArrayList<ClassReference> result = new ArrayList<ClassReference>(); List<JSTypeExpression> implementedInterfaces = getComment().getImplementedInterfaces(); for (JSTypeExpression jsTypeExpression : implementedInterfaces) { JSType jsType = getModel().evaluate(jsTypeExpression); String interfaceName = jsType.toAnnotationString(); ClassReference interfaceReference = getModel().getClassReference(interfaceName); if (interfaceReference != null) result.add(interfaceReference); else { IdentifierNode node = new IdentifierNode(interfaceName); String externName = AbstractCompilerPass.getSourceFileName(this.getNode().getStaticSourceFile().getName(), getModel()); node.setSourcePath(externName); node.setLine(this.getNode().getLineno()); UnresolvedClassReferenceProblem problem = new UnresolvedClassReferenceProblem(node, interfaceName); getModel().problems.add(problem); } } return result; }
public List<ClassReference> getInterfaces() { ArrayList<ClassReference> result = new ArrayList<ClassReference>(); List<JSTypeExpression> implementedInterfaces = getComment().getImplementedInterfaces(); for (JSTypeExpression jsTypeExpression : implementedInterfaces) { JSType jsType = getModel().evaluate(jsTypeExpression); String interfaceName = jsType.toAnnotationString(); ClassReference interfaceReference = getModel().getClassReference(interfaceName); if (interfaceReference != null) result.add(interfaceReference); else { DummyNode node = new DummyNode(); String externName = AbstractCompilerPass.getSourceFileName(this.getNode().getStaticSourceFile().getName(), getModel()); node.setSourcePath(externName); node.setLine(this.getNode().getLineno()); UnresolvedClassReferenceProblem problem = new UnresolvedClassReferenceProblem(node, interfaceName); getModel().problems.add(problem); } } return result; }
public List<ClassReference> getInterfaces() { ArrayList<ClassReference> result = new ArrayList<ClassReference>(); List<JSTypeExpression> implementedInterfaces = getComment().getImplementedInterfaces(); for (JSTypeExpression jsTypeExpression : implementedInterfaces) { JSType jsType = getModel().evaluate(jsTypeExpression); if (jsType.isTemplatizedType()) { jsType = ((TemplatizedType)jsType).getReferencedType(); } String interfaceName = jsType.getDisplayName(); ClassReference interfaceReference = getModel().getClassReference(interfaceName); if (interfaceReference != null) result.add(interfaceReference); else { DummyNode node = new DummyNode(); String externName = AbstractCompilerPass.getSourceFileName(this.getNode().getStaticSourceFile().getName(), getModel()); node.setSourcePath(externName); node.setLine(this.getNode().getLineno()); UnresolvedClassReferenceProblem problem = new UnresolvedClassReferenceProblem(node, interfaceName); getModel().problems.add(problem); } } return result; }
private void extractExtends(NodeTraversal t, Node classNode) { String name = ModuleNames.fileToJsIdentifier(classNode.getStaticSourceFile().getName()) + CLASS_EXTENDS_VAR + classExtendsVarCounter++; Node statement = NodeUtil.getEnclosingStatement(classNode); Node originalExtends = classNode.getSecondChild(); originalExtends.replaceWith(IR.name(name).useSourceInfoFrom(originalExtends)); Node extendsAlias = IR.constNode(IR.name(name), originalExtends) .useSourceInfoIfMissingFromForTree(originalExtends); statement.getParent().addChildBefore(extendsAlias, statement); NodeUtil.addFeatureToScript(NodeUtil.getEnclosingScript(classNode), Feature.CONST_DECLARATIONS); t.reportCodeChange(classNode); }