br.com.objectos.way.code.PackageInfo Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2014 Objectos, Fábrica de Software LTDA.
*
* 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 br.com.objectos.way.code;
import br.com.objectos.way.core.auto.AutoPojo;
import br.com.objectos.way.core.testing.Testable;
import br.com.objectos.way.core.testing.Testables;
import br.com.objectos.way.core.tmpl.mustache.IsMustacheSerializable;
import br.com.objectos.way.core.tmpl.mustache.MustacheObject;
import br.com.objectos.way.core.tmpl.mustache.Mustaches;
import com.google.common.base.Objects;
import com.google.common.base.Optional;
/**
* @author [email protected] (Marcio Endo)
*/
@AutoPojo
public abstract class PackageInfo
implements
CanFilterImportInfoSet,
IsMustacheSerializable,
Testable {
static final PackageInfo JAVA_LANG = builder()
.name("java.lang")
.build();
abstract String name();
PackageInfo() {
}
public static PackageInfoBuilder builder() {
return new PackageInfoBuilderPojo();
}
public boolean hasName(String name) {
return name().equals(name);
}
@Override
public boolean isEqual(PackageInfo that) {
return Testables.isEqualHelper()
.equal(name(), that.name())
.result();
}
public boolean isJavaLang() {
return "java.lang".equals(name());
}
@Override
public boolean shouldKeep(ImportInfo importInfo) {
return importInfo.shouldKeep(this);
}
public ImportInfo toImportInfo(NameInfo name) {
return ImportInfo.newPojo()
.packageInfo(this)
.name(Optional.of(name))
.metaStatic(false)
.build();
}
@Override
public MustacheObject toMustache() {
return Mustaches.toMustacheHelper()
.add("name", name())
.toMustache();
}
public String toQualifiedName(String name) {
return name() + "." + name;
}
@Override
public String toString() {
return name();
}
@Override
public final int hashCode() {
return Objects.hashCode(name());
}
@Override
public final boolean equals(final Object obj) {
if (obj == this) {
return true;
}
if (obj instanceof PackageInfo) {
final PackageInfo that = (PackageInfo) obj;
return Objects.equal(name(), that.name());
} else {
return false;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy