Package com.intellij.pom.java.types

Source Code of com.intellij.pom.java.types.PomPrimitiveType

/*
* Copyright 2000-2007 JetBrains s.r.o.
*
* 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.intellij.pom.java.types;

import com.intellij.pom.PomScope;
import com.intellij.pom.java.PomClass;
import com.intellij.pom.java.PomJavaAspect;
import com.intellij.pom.java.PomMemberOwner;
import com.intellij.pom.java.PomReferenceTypeElement;
import com.intellij.util.containers.HashMap;

import java.util.Map;

import org.jetbrains.annotations.NonNls;

public class PomPrimitiveType implements PomType {
  protected static final PomPrimitiveType VOID = new PomPrimitiveType("void");
  protected static final PomPrimitiveType BYTE = new PomPrimitiveType("byte");
  protected static final PomPrimitiveType CHAR = new PomPrimitiveType("char");
  protected static final PomPrimitiveType DOUBLE = new PomPrimitiveType("double");
  protected static final PomPrimitiveType FLOAT = new PomPrimitiveType("float");
  protected static final PomPrimitiveType LONG = new PomPrimitiveType("long");
  protected static final PomPrimitiveType INT = new PomPrimitiveType("int");
  protected static final PomPrimitiveType SHORT = new PomPrimitiveType("short");
  protected static final PomPrimitiveType BOOLEAN = new PomPrimitiveType("boolean");
  protected static final PomPrimitiveType NULL = new PomPrimitiveType("null");

  private final String myName;

  private PomPrimitiveType(@NonNls String name) {
    myName = name;
  }

  public String getPresentableText() {
    return myName;
  }

  public String getCanonicalText() {
    return myName;
  }

  public boolean equalsToText(String text) {
    return myName.equals(text);
  }

  public <A> A accept(PomTypeVisitor<A> visitor) {
    return visitor.visitPrimitiveType(this);
  }

  public static PomPrimitiveType getUnboxedType(PomType type) {
    if (!(type instanceof PomClassType)) return null;
    final PomReferenceTypeElement pomClass = ((PomClassType)type).getReferenceClass();
    if (!(pomClass instanceof PomClass)) return null;
    if (!PomJavaAspect.getInstance(pomClass.getModel()).getLanguageLevel().hasEnumKeywordAndAutoboxing()) return null;
    return ourQNameToUnboxed.get(((PomClass)pomClass).getQualifiedName());
  }

  public PomClassType getBoxedType(PomJavaAspect manager, PomScope resolveScope) {
    if (!manager.getLanguageLevel().hasEnumKeywordAndAutoboxing()) return null;
    final String boxedQName = ourUnboxedToQName.get(this);

    //[ven]previous call returns null for NULL, VOID
    if (boxedQName == null) return null;

    final PomMemberOwner aClass = manager.findClass(boxedQName, resolveScope);
    if (!(aClass instanceof PomClass)) return null;

    return /*PomClassType.create(aClass);*/ null; //TODO
  }

  public boolean isAssignableFrom(PomType type) {
    //TODO
    return false;
  }

  public boolean isConvertibleTo(PomType type) {
    //TODO
    return false;
  }

  private static final Map<String, PomPrimitiveType> ourQNameToUnboxed = new HashMap<String, PomPrimitiveType>();
  private static final Map<PomPrimitiveType, String> ourUnboxedToQName = new HashMap<PomPrimitiveType, String>();

  static {
    ourQNameToUnboxed.put("java.lang.Boolean", BOOLEAN);
    ourUnboxedToQName.put(BOOLEAN, "java.lang.Boolean");
    ourQNameToUnboxed.put("java.lang.Byte", BYTE);
    ourUnboxedToQName.put(BYTE, "java.lang.Byte");
    ourQNameToUnboxed.put("java.lang.Character", CHAR);
    ourUnboxedToQName.put(CHAR, "java.lang.Character");
    ourQNameToUnboxed.put("java.lang.Short", SHORT);
    ourUnboxedToQName.put(SHORT, "java.lang.Short");
    ourQNameToUnboxed.put("java.lang.Integer", INT);
    ourUnboxedToQName.put(INT, "java.lang.Integer");
    ourQNameToUnboxed.put("java.lang.Long", LONG);
    ourUnboxedToQName.put(LONG, "java.lang.Long");
    ourQNameToUnboxed.put("java.lang.Float", FLOAT);
    ourUnboxedToQName.put(FLOAT, "java.lang.Float");
    ourQNameToUnboxed.put("java.lang.Double", DOUBLE);
    ourUnboxedToQName.put(DOUBLE, "java.lang.Double");
  }

}
TOP

Related Classes of com.intellij.pom.java.types.PomPrimitiveType

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.