Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: b55c28e71704c2c35d7b64c58543f41f657fcb14 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/**
 * Copyright (c) 2006 IBM Corporation and others.
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v2.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v20.html
 * 
 * Contributors: 
 *   IBM - Initial API and implementation
 */
package org.eclipse.emf.codegen.merge.java.facade;

import java.util.Collections;
import java.util.List;

/**
 * @since 2.2.0
 */
public abstract class AbstractJNode implements JNode
{
  protected static final String[] EMPTY_STRING_ARRAY = new String[0];
  
  protected String qualifiedName;
  
  abstract public void dispose();
  abstract public boolean isDisposed();
  
  abstract protected Object getWrappedObject();
  abstract public void setFacadeHelper(FacadeHelper facadeHelper);
  abstract public FacadeHelper getFacadeHelper();
  
  public String getQualifiedName()
  {
    if (qualifiedName == null)
    {
      qualifiedName = computeQualifiedName();
    }
    return qualifiedName;
  }

  protected String computeQualifiedName()
  {
    JNode parent = getParent();
    return parent == null || parent instanceof JCompilationUnit ?
      getName() :
      parent.getQualifiedName() + "." + getName();
  }
  
  protected String getName(JInitializer initializer)
  {
    JNode parent = initializer.getParent();
    if (parent != null)
    {
      int index = getFacadeHelper().getChildren(parent, JInitializer.class).indexOf(initializer);
      return parent.getName() + "." +  index;
    }
    return null;    
  }
  
  protected String computeQualifiedName(JInitializer initializer)
  {
    JNode parent = initializer.getParent();
    if (parent != null)
    {
      int index = getFacadeHelper().getChildren(parent, JInitializer.class).indexOf(initializer);
      return parent.getQualifiedName() + "." +  index;
    }
    return null;
  }  
  
  protected String computeQualifiedName(JAbstractType abstractType)
  {
    JNode parent = abstractType.getParent();
    if (parent instanceof JAbstractType)
    {
      return parent.getQualifiedName() + "." + abstractType.getName();
    }
      
    JPackage jPackage = getFacadeHelper().getPackage(this);
    return jPackage != null ? jPackage.getName() + "." + abstractType.getName() : abstractType.getName();
  }
  
  protected String computeQualifiedName(JMethod method)
  {
    StringBuilder result = new StringBuilder(getParent().getQualifiedName());
    result.append(".");
    if (method.isConstructor())
    {
      result.append(getParent().getName());
    }
    else
    {
      result.append(getName());
    }
    result.append("(");
    String[] parameters = method.getParameterTypes();
    if (parameters != null)
    {
      for (int i = 0; i < parameters.length; ++i)
      {
        if (i != 0)
        {
          result.append(", ");
        }
        result.append(parameters[i]);
      }
    }
    result.append(")");
    return result.toString();
  }
  
  public List<JNode> getChildren()
  {
    return Collections.emptyList();
  }  
  
  public int getFlags()
  {
    return FacadeFlags.DEFAULT;
  }  
}

Back to the top