summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYohann Roussel <yroussel@google.com>2014-11-13 15:01:05 +0100
committerYohann Roussel <yroussel@google.com>2014-11-14 14:47:31 +0000
commit836d870a072249758364fb04c70045f2eb97f103 (patch)
tree6a2fb69387978044467e20c82415fdc0b4aeaf97
parent3bf0561b591d0eff187d42679057e19de80d081e (diff)
downloadtoolchain_jack-836d870a072249758364fb04c70045f2eb97f103.zip
toolchain_jack-836d870a072249758364fb04c70045f2eb97f103.tar.gz
toolchain_jack-836d870a072249758364fb04c70045f2eb97f103.tar.bz2
Get rid of PackageChecker
And add better package checks in checkValidity() methods. Change-Id: I804056b7867e2b0345e9659905eafabf737104ed
-rw-r--r--jack/src/com/android/jack/Jack.java11
-rw-r--r--jack/src/com/android/jack/ir/ast/JDefinedClassOrInterface.java5
-rw-r--r--jack/src/com/android/jack/ir/ast/JPackage.java12
-rw-r--r--jack/src/com/android/jack/transformations/parent/DeclaredTypePackageChecker.java48
-rw-r--r--jack/src/com/android/jack/transformations/parent/PackageChecker.java62
5 files changed, 13 insertions, 125 deletions
diff --git a/jack/src/com/android/jack/Jack.java b/jack/src/com/android/jack/Jack.java
index 72d35d2..74bb4f4 100644
--- a/jack/src/com/android/jack/Jack.java
+++ b/jack/src/com/android/jack/Jack.java
@@ -235,8 +235,6 @@ import com.android.jack.transformations.finallyblock.FinallyRemover;
import com.android.jack.transformations.flow.FlowNormalizer;
import com.android.jack.transformations.flow.FlowNormalizerSchedulingSeparator;
import com.android.jack.transformations.parent.AstChecker;
-import com.android.jack.transformations.parent.DeclaredTypePackageChecker;
-import com.android.jack.transformations.parent.PackageChecker;
import com.android.jack.transformations.parent.TypeAstChecker;
import com.android.jack.transformations.renamepackage.PackageRenamer;
import com.android.jack.transformations.rop.cast.RopCastLegalizer;
@@ -1232,15 +1230,6 @@ public abstract class Jack {
if (hasSanityChecks) {
planBuilder.append(AstChecker.class);
- {
- SubPlanBuilder<JDefinedClassOrInterface> typePlan =
- planBuilder.appendSubPlan(ExcludeTypeFromLibWithBinaryAdapter.class);
- typePlan.append(DeclaredTypePackageChecker.class);
- }
- {
- SubPlanBuilder<JPackage> packagePlan = planBuilder.appendSubPlan(JPackageAdapter.class);
- packagePlan.append(PackageChecker.class);
- }
}
}
diff --git a/jack/src/com/android/jack/ir/ast/JDefinedClassOrInterface.java b/jack/src/com/android/jack/ir/ast/JDefinedClassOrInterface.java
index edf392d..6d7c89b 100644
--- a/jack/src/com/android/jack/ir/ast/JDefinedClassOrInterface.java
+++ b/jack/src/com/android/jack/ir/ast/JDefinedClassOrInterface.java
@@ -595,8 +595,9 @@ public abstract class JDefinedClassOrInterface extends JDefinedReferenceType
@Override
public void checkValidity() {
- if (!(parent instanceof JPackage)) {
- throw new JNodeInternalError(this, "Invalid parent");
+ if (parent == null || parent != enclosingPackage) {
+ throw new JNodeInternalError(this, "Invalid parent or enclosing package");
}
+
}
}
diff --git a/jack/src/com/android/jack/ir/ast/JPackage.java b/jack/src/com/android/jack/ir/ast/JPackage.java
index 454f9d7..b522e86 100644
--- a/jack/src/com/android/jack/ir/ast/JPackage.java
+++ b/jack/src/com/android/jack/ir/ast/JPackage.java
@@ -502,8 +502,16 @@ public class JPackage extends JNode implements HasName, CanBeRenamed, HasEnclosi
@Override
public void checkValidity() {
- if (!(parent instanceof JPackage || parent instanceof JSession)) {
- throw new JNodeInternalError(this, "Invalid parent");
+ if (parent instanceof JPackage) {
+ if (parent != enclosingPackage) {
+ throw new JNodeInternalError(this, "Invalid parent or enclosing package");
+ }
+ } else if (parent instanceof JSession) {
+ if (enclosingPackage != null) {
+ throw new JNodeInternalError(this, "Invalid parent or enclosing package");
+ }
+ } else {
+ throw new JNodeInternalError(this, "Invalid parent or enclosing package");
}
}
}
diff --git a/jack/src/com/android/jack/transformations/parent/DeclaredTypePackageChecker.java b/jack/src/com/android/jack/transformations/parent/DeclaredTypePackageChecker.java
deleted file mode 100644
index cde475b..0000000
--- a/jack/src/com/android/jack/transformations/parent/DeclaredTypePackageChecker.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed 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 com.android.jack.transformations.parent;
-
-import com.android.jack.Jack;
-import com.android.jack.ir.ast.JDefinedClassOrInterface;
-import com.android.jack.ir.ast.JPackage;
-import com.android.jack.transformations.SanityChecks;
-import com.android.sched.item.Description;
-import com.android.sched.item.Name;
-import com.android.sched.schedulable.RunnableSchedulable;
-import com.android.sched.schedulable.Support;
-
-import javax.annotation.Nonnull;
-
-/**
- * Check that the {@link JDefinedClassOrInterface} name is consistent with its enclosing package.
- */
-@Description(
- "Check that the JDefinedClassOrInterface name is consistent with its enclosing package.")
-@Name("DeclaredTypePackageChecker")
-@Support(SanityChecks.class)
-public class DeclaredTypePackageChecker implements RunnableSchedulable<JDefinedClassOrInterface> {
-
- @Override
- public void run(@Nonnull JDefinedClassOrInterface type) throws Exception {
- JPackage pack = type.getEnclosingPackage();
-
- if (!pack.getTypes().contains(type)) {
- throw new AssertionError("Package '" + Jack.getUserFriendlyFormatter().getName(pack)
- + "' does not contain '" + type.getName() + '\'');
- }
- }
-} \ No newline at end of file
diff --git a/jack/src/com/android/jack/transformations/parent/PackageChecker.java b/jack/src/com/android/jack/transformations/parent/PackageChecker.java
deleted file mode 100644
index 5026149..0000000
--- a/jack/src/com/android/jack/transformations/parent/PackageChecker.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed 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 com.android.jack.transformations.parent;
-
-import com.android.jack.ir.ast.JClassOrInterface;
-import com.android.jack.ir.ast.JNode;
-import com.android.jack.ir.ast.JPackage;
-import com.android.jack.ir.ast.JSession;
-import com.android.jack.transformations.SanityChecks;
-import com.android.sched.item.Description;
-import com.android.sched.item.Name;
-import com.android.sched.schedulable.RunnableSchedulable;
-import com.android.sched.schedulable.Support;
-
-import javax.annotation.Nonnull;
-
-/**
- * Check that the package is consistent with the {@link JClassOrInterface} name.
- */
-@Description("Check that the package is consistent with the DeclareType name.")
-@Name("PackageChecker")
-@Support(SanityChecks.class)
-public class PackageChecker implements RunnableSchedulable<JPackage> {
-
- @Override
- public void run(@Nonnull JPackage pack) throws Exception {
- /* Use pack.getLoadedTypes() to avoid loading of every class in every package */
- for (JClassOrInterface type : pack.getLoadedTypes()) {
- //TODO(delphinemartin): remove this condition when external types will be properly handled
- if (!type.isExternal()) {
- if (type.getEnclosingPackage() != pack) {
- throw new AssertionError("Wrong enclosing package");
- }
- }
- }
-
- JNode parent = pack.getParent();
- if (parent instanceof JSession) {
- if (pack.getEnclosingPackage() != null) {
- throw new AssertionError("Wrong enclosing package");
- }
- } else {
- if (parent != pack.getEnclosingPackage()) {
- throw new AssertionError("Wrong enclosing package");
- }
- }
- }
-} \ No newline at end of file