You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by jo...@apache.org on 2022/10/05 20:19:43 UTC

[royale-compiler] branch develop updated (dc79c93d4 -> 2834c0f8b)

This is an automated email from the ASF dual-hosted git repository.

joshtynjala pushed a change to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git


    from dc79c93d4 linter: add ILinterProblem interface to allow for easier detection of linter problems
     new ab3820d00 linter: clean up public API
     new 2834c0f8b formatter: clean up API to better match linter's more streamlined approach

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../org/apache/royale/formatter/FORMATTER.java     | 147 ++++++++++++++++++---
 .../apache/royale/formatter/FormatterUtils.java    |  47 +++++++
 .../main/java/org/apache/royale/linter/LINTER.java |  50 ++-----
 3 files changed, 182 insertions(+), 62 deletions(-)
 create mode 100644 formatter/src/main/java/org/apache/royale/formatter/FormatterUtils.java


[royale-compiler] 02/02: formatter: clean up API to better match linter's more streamlined approach

Posted by jo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

joshtynjala pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git

commit 2834c0f8b3b6dad7802d7df82d3e15c6acfd626c
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Wed Oct 5 12:50:30 2022 -0700

    formatter: clean up API to better match linter's more streamlined approach
    
    This involves deprecating some public methods, but they're basically only used in vscode-as3mxml, and that'll be updated quickly after the next Royale release
---
 .../org/apache/royale/formatter/FORMATTER.java     | 147 ++++++++++++++++++---
 .../apache/royale/formatter/FormatterUtils.java    |  47 +++++++
 2 files changed, 172 insertions(+), 22 deletions(-)

diff --git a/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java b/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
index 29fd7dd1c..38dab06e2 100644
--- a/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
+++ b/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
@@ -89,24 +89,110 @@ public class FORMATTER {
 
 	}
 
+	/**
+	 * @deprecated Use an FormatterSettings instead
+	 */
+	@Deprecated
 	public int tabSize = 4;
+
+	/**
+	 * @deprecated Use an FormatterSettings instead
+	 */
+	@Deprecated
 	public boolean insertSpaces = false;
+
+	/**
+	 * @deprecated Use an FormatterSettings instead
+	 */
+	@Deprecated
 	public boolean insertFinalNewLine = false;
+
+	/**
+	 * @deprecated Use an FormatterSettings instead
+	 */
+	@Deprecated
 	public boolean placeOpenBraceOnNewLine = true;
+
+	/**
+	 * @deprecated Use an FormatterSettings instead
+	 */
+	@Deprecated
 	public boolean insertSpaceAfterSemicolonInForStatements = true;
+
+	/**
+	 * @deprecated Use an FormatterSettings instead
+	 */
+	@Deprecated
 	public boolean insertSpaceAfterKeywordsInControlFlowStatements = true;
+
+	/**
+	 * @deprecated Use an FormatterSettings instead
+	 */
+	@Deprecated
 	public boolean insertSpaceAfterFunctionKeywordForAnonymousFunctions = false;
+
+	/**
+	 * @deprecated Use an FormatterSettings instead
+	 */
+	@Deprecated
 	public boolean insertSpaceBeforeAndAfterBinaryOperators = true;
+
+	/**
+	 * @deprecated Use an FormatterSettings instead
+	 */
+	@Deprecated
 	public boolean insertSpaceAfterCommaDelimiter = true;
+
+	/**
+	 * @deprecated Use an FormatterSettings instead
+	 */
+	@Deprecated
 	public boolean insertSpaceBetweenMetadataAttributes = true;
+
+	/**
+	 * @deprecated Use an FormatterSettings instead
+	 */
+	@Deprecated
 	public boolean insertSpaceAtStartOfLineComment = true;
+
+	/**
+	 * @deprecated Use an FormatterSettings instead
+	 */
+	@Deprecated
 	public int maxPreserveNewLines = 2;
+
+	/**
+	 * @deprecated Use an FormatterSettings instead
+	 */
+	@Deprecated
 	public Semicolons semicolons = Semicolons.INSERT;
+
+	/**
+	 * @deprecated Use an FormatterSettings instead
+	 */
+	@Deprecated
 	public boolean ignoreProblems = false;
+
+	/**
+	 * @deprecated Use an FormatterSettings instead
+	 */
+	@Deprecated
 	public boolean collapseEmptyBlocks = false;
+
+	/**
+	 * @deprecated Use an FormatterSettings instead
+	 */
+	@Deprecated
 	public boolean mxmlAlignAttributes = false;
+
+	/**
+	 * @deprecated Use an FormatterSettings instead
+	 */
+	@Deprecated
 	public boolean mxmlInsertNewLineBetweenAttributes = false;
 
+	private FormatterSettings settings = new FormatterSettings();
+
 	private ProblemQuery problemQuery;
 	private List<File> inputFiles = new ArrayList<File>();
 	private boolean writeBackToInputFiles = false;
@@ -183,6 +269,10 @@ public class FORMATTER {
 		return exitCode.getCode();
 	}
 
+	/**
+	 * @deprecated Use an ASTokenFormatter or MXMLTokenFormatter instead
+	 */
+	@Deprecated
 	public String formatFile(File file, Collection<ICompilerProblem> problems) throws IOException {
 		String filePath = FilenameNormalization.normalize(file.getAbsolutePath());
 		FileSpecification fileSpec = new FileSpecification(filePath);
@@ -190,11 +280,20 @@ public class FORMATTER {
 		return formatFileText(filePath, fileText, problems);
 	}
 
+	/**
+	 * @deprecated Use an ASTokenFormatter or MXMLTokenFormatter instead
+	 */
+	@Deprecated
 	public String formatFile(File file) throws IOException {
 		return formatFile(file, null);
 	}
 
+	/**
+	 * @deprecated Use an ASTokenFormatter or MXMLTokenFormatter instead
+	 */
+	@Deprecated
 	public String formatFileText(String filePath, String text, Collection<ICompilerProblem> problems) {
+		settings = getLegacyFormatterSettings();
 		filePath = FilenameNormalization.normalize(filePath);
 		String result = null;
 		if (filePath.endsWith(".mxml")) {
@@ -208,39 +307,61 @@ public class FORMATTER {
 		return result;
 	}
 
+	/**
+	 * @deprecated Use an ASTokenFormatter or MXMLTokenFormatter instead
+	 */
+	@Deprecated
 	public String formatFileText(String filePath, String text) {
 		return formatFileText(filePath, text, null);
 	}
 
+	/**
+	 * @deprecated Use an ASTokenFormatter or MXMLTokenFormatter instead
+	 */
+	@Deprecated
 	public String formatActionScriptText(String text, Collection<ICompilerProblem> problems) {
+		settings = getLegacyFormatterSettings();
 		String filePath = FilenameNormalization.normalize("stdin.as");
 		return formatASTokens(filePath, text, problems);
 	}
 
+	/**
+	 * @deprecated Use an ASTokenFormatter or MXMLTokenFormatter instead
+	 */
+	@Deprecated
 	public String formatActionScriptText(String text) {
 		return formatActionScriptText(text, null);
 	}
 
+	/**
+	 * @deprecated Use an ASTokenFormatter or MXMLTokenFormatter instead
+	 */
+	@Deprecated
 	public String formatMXMLText(String text, Collection<ICompilerProblem> problems) {
+		settings = getLegacyFormatterSettings();
 		String filePath = FilenameNormalization.normalize("stdin.mxml");
 		return formatMXMLTokens(filePath, text, problems);
 	}
 
+	/**
+	 * @deprecated Use an ASTokenFormatter or MXMLTokenFormatter instead
+	 */
+	@Deprecated
 	public String formatMXMLText(String text) {
 		return formatMXMLText(text, null);
 	}
 
 	private String formatASTokens(String filePath, String text, Collection<ICompilerProblem> problems) {
-		ASTokenFormatter asFormatter = new ASTokenFormatter(getFormatterSettings());
+		ASTokenFormatter asFormatter = new ASTokenFormatter(settings);
 		return asFormatter.format(filePath, text, problems);
 	}
 
 	private String formatMXMLTokens(String filePath, String text, Collection<ICompilerProblem> problems) {
-		MXMLTokenFormatter mxmlFormatter = new MXMLTokenFormatter(getFormatterSettings());
+		MXMLTokenFormatter mxmlFormatter = new MXMLTokenFormatter(settings);
 		return mxmlFormatter.format(filePath, text, problems);
 	}
 
-	private FormatterSettings getFormatterSettings() {
+	private FormatterSettings getLegacyFormatterSettings() {
 		FormatterSettings result = new FormatterSettings();
 		result.tabSize = tabSize;
 		result.insertSpaces = insertSpaces;
@@ -336,26 +457,8 @@ public class FORMATTER {
 				return false;
 			}
 
-			collapseEmptyBlocks = configuration.getCollapseEmptyBlocks();
-			ignoreProblems = configuration.getIgnoreParsingProblems();
-			insertFinalNewLine = configuration.getInsertFinalNewLine();
-			insertSpaceAfterCommaDelimiter = configuration.getInsertSpaceAfterCommaDelimiter();
-			insertSpaceBetweenMetadataAttributes = configuration.getInsertSpaceBetweenMetadataAttributes();
-			insertSpaceAfterFunctionKeywordForAnonymousFunctions = configuration
-					.getInsertSpaceAfterFunctionKeywordForAnonymousFunctions();
-			insertSpaceAfterKeywordsInControlFlowStatements = configuration
-					.getInsertSpaceAfterKeywordsInControlFlowStatements();
-			insertSpaceAfterSemicolonInForStatements = configuration.getInsertSpaceAfterSemicolonInForStatements();
-			insertSpaceBeforeAndAfterBinaryOperators = configuration.getInsertSpaceBeforeAndAfterBinaryOperators();
-			insertSpaceAtStartOfLineComment = configuration.getInsertSpaceAtStartOfLineComment();
-			insertSpaces = configuration.getInsertSpaces();
-			mxmlInsertNewLineBetweenAttributes = configuration.getMxmlInsertNewLineBetweenAttributes();
-			mxmlAlignAttributes = configuration.getMxmlAlignAttributes();
+			settings = FormatterUtils.configurationToFormatterSettings(configuration);
 			listChangedFiles = configuration.getListFiles();
-			maxPreserveNewLines = configuration.getMaxPreserveNewLines();
-			placeOpenBraceOnNewLine = configuration.getPlaceOpenBraceOnNewLine();
-			semicolons = Semicolons.valueOf(configuration.getSemicolons().toUpperCase());
-			tabSize = configuration.getTabSize();
 			writeBackToInputFiles = configuration.getWriteFiles();
 			for (String filePath : configuration.getFiles()) {
 				File inputFile = new File(filePath);
diff --git a/formatter/src/main/java/org/apache/royale/formatter/FormatterUtils.java b/formatter/src/main/java/org/apache/royale/formatter/FormatterUtils.java
new file mode 100644
index 000000000..39e6b89bc
--- /dev/null
+++ b/formatter/src/main/java/org/apache/royale/formatter/FormatterUtils.java
@@ -0,0 +1,47 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+
+package org.apache.royale.formatter;
+
+import org.apache.royale.formatter.config.Configuration;
+import org.apache.royale.formatter.config.Semicolons;
+
+public class FormatterUtils {
+	public static FormatterSettings configurationToFormatterSettings(Configuration configuration) {
+		FormatterSettings settings = new FormatterSettings();
+		settings.tabSize = configuration.getTabSize();
+		settings.insertSpaces = configuration.getInsertSpaces();
+		settings.insertFinalNewLine = configuration.getInsertFinalNewLine();
+		settings.placeOpenBraceOnNewLine = configuration.getPlaceOpenBraceOnNewLine();
+		settings.insertSpaceAfterSemicolonInForStatements = configuration.getInsertSpaceAfterSemicolonInForStatements();
+		settings.insertSpaceAfterKeywordsInControlFlowStatements = configuration.getInsertSpaceAfterKeywordsInControlFlowStatements();
+		settings.insertSpaceAfterFunctionKeywordForAnonymousFunctions = configuration.getInsertSpaceAfterFunctionKeywordForAnonymousFunctions();
+		settings.insertSpaceBeforeAndAfterBinaryOperators = configuration.getInsertSpaceBeforeAndAfterBinaryOperators();
+		settings.insertSpaceAfterCommaDelimiter = configuration.getInsertSpaceAfterCommaDelimiter();
+		settings.insertSpaceBetweenMetadataAttributes = configuration.getInsertSpaceBetweenMetadataAttributes();
+		settings.insertSpaceAtStartOfLineComment = configuration.getInsertSpaceAtStartOfLineComment();
+		settings.maxPreserveNewLines = configuration.getMaxPreserveNewLines();
+		settings.semicolons = Semicolons.valueOf(configuration.getSemicolons().toUpperCase());
+		settings.ignoreProblems = configuration.getIgnoreParsingProblems();
+		settings.collapseEmptyBlocks = configuration.getCollapseEmptyBlocks();
+		settings.mxmlAlignAttributes = configuration.getMxmlAlignAttributes();
+		settings.mxmlInsertNewLineBetweenAttributes = configuration.getMxmlInsertNewLineBetweenAttributes();
+		return settings;
+	}
+}


[royale-compiler] 01/02: linter: clean up public API

Posted by jo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

joshtynjala pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git

commit ab3820d00cd2469d69d5b77f2b30a48e1df2b87e
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Wed Oct 5 12:40:02 2022 -0700

    linter: clean up public API
---
 .../main/java/org/apache/royale/linter/LINTER.java | 50 +++++-----------------
 1 file changed, 10 insertions(+), 40 deletions(-)

diff --git a/linter/src/main/java/org/apache/royale/linter/LINTER.java b/linter/src/main/java/org/apache/royale/linter/LINTER.java
index 2abc08db8..350bb831a 100644
--- a/linter/src/main/java/org/apache/royale/linter/LINTER.java
+++ b/linter/src/main/java/org/apache/royale/linter/LINTER.java
@@ -20,9 +20,7 @@
 package org.apache.royale.linter;
 
 import java.io.File;
-import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Set;
@@ -55,6 +53,8 @@ import org.apache.royale.utils.FilenameNormalization;
 public class LINTER {
 	private static final String DEFAULT_VAR = "files";
 	private static final String L10N_CONFIG_PREFIX = "org.apache.royale.compiler.internal.config.configuration";
+	private static final String FILE_EXTENSION_ACTIONSCRIPT = ".as";
+	private static final String FILE_EXTENSION_MXML = ".mxml";
 
 	static enum ExitCode {
 		SUCCESS(0), PRINT_HELP(1), FAILED_WITH_ERRORS(2), FAILED_WITH_EXCEPTIONS(3), FAILED_WITH_CONFIG_PROBLEMS(4);
@@ -104,7 +104,13 @@ public class LINTER {
 					String filePath = FilenameNormalization.normalize(inputFile.getAbsolutePath());
 					FileSpecification fileSpec = new FileSpecification(filePath);
 					String fileText = IOUtils.toString(fileSpec.createReader());
-					lintFileText(filePath, fileText, problemQuery.getProblems());
+					if (filePath.endsWith(FILE_EXTENSION_MXML)) {
+						ASLinter linter = new ASLinter(settings);
+						linter.lint(filePath, fileText, problemQuery.getProblems());
+					} else {
+						MXMLLinter linter = new MXMLLinter(settings);
+						linter.lint(filePath, fileText, problemQuery.getProblems());
+					}
 				}
 			} else if (problemQuery.hasFilteredProblems()) {
 				exitCode = ExitCode.FAILED_WITH_CONFIG_PROBLEMS;
@@ -243,45 +249,9 @@ public class LINTER {
 			}
 			if (file.isDirectory()) {
 				addDirectory(file);
-			} else if (fileName.endsWith(".as") || fileName.endsWith(".mxml")) {
+			} else if (fileName.endsWith(FILE_EXTENSION_ACTIONSCRIPT) || fileName.endsWith(FILE_EXTENSION_MXML)) {
 				inputFiles.add(file);
 			}
 		}
 	}
-
-	public void lintFile(File file, Collection<ICompilerProblem> problems) throws IOException {
-		String filePath = FilenameNormalization.normalize(file.getAbsolutePath());
-		FileSpecification fileSpec = new FileSpecification(filePath);
-		String fileText = IOUtils.toString(fileSpec.createReader());
-		lintFileText(filePath, fileText, problems);
-	}
-
-	public void lintFileText(String filePath, String text, Collection<ICompilerProblem> problems) {
-		filePath = FilenameNormalization.normalize(filePath);
-		if (filePath.endsWith(".mxml")) {
-			lintMXMLTextInternal(filePath, text, problems);
-		} else {
-			lintAS3TextInternal(filePath, text, problems);
-		}
-	}
-
-	public void lintActionScriptText(String text, Collection<ICompilerProblem> problems) {
-		String filePath = FilenameNormalization.normalize("stdin.as");
-		lintAS3TextInternal(filePath, text, problems);
-	}
-
-	public void lintMXMLText(String text, Collection<ICompilerProblem> problems) {
-		String filePath = FilenameNormalization.normalize("stdin.mxml");
-		lintMXMLTextInternal(filePath, text, problems);
-	}
-
-	private void lintAS3TextInternal(String filePath, String text, Collection<ICompilerProblem> problems) {
-		ASLinter linter = new ASLinter(settings);
-		linter.lint(filePath, text, problems);
-	}
-
-	private void lintMXMLTextInternal(String filePath, String text, Collection<ICompilerProblem> problems) {
-		MXMLLinter linter = new MXMLLinter(settings);
-		linter.lint(filePath, text, problems);
-	}
 }