summaryrefslogtreecommitdiff
path: root/src/plugins/android.codeutils/src/com/motorola/studio/android/generateviewbylayout/model/JavaLayoutData.java
blob: e8e8c8b48d94e00bcbb3a25ee9e9b15191a7ec46 (plain)
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*
 * 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.motorola.studio.android.generateviewbylayout.model;

import java.util.HashSet;
import java.util.Set;

import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.dom.CompilationUnit;

import com.motorola.studio.android.generatecode.JDTUtils;
import com.motorola.studio.android.generateviewbylayout.GenerateCodeBasedOnLayoutVisitor;

/**
 * Class encapsulating data from java code such as already declared IDs and the compilation unit.
 * It serves as a bridge to generate code inside activity/fragment based on layout
 */
public class JavaLayoutData
{
    private final Set<String> declaredViewIdsOnCode = new HashSet<String>();

    private final Set<String> savedViewIds = new HashSet<String>();

    private final Set<String> restoredViewIds = new HashSet<String>();

    private ICompilationUnit compUnit;

    private CompilationUnit compUnitAstNode;

    /**
     * If type is fragment, there may be an inflated view name.
     * This will be used to call findViewById inside fragments.
     * 
     * Null in these cases:
     * 1) if fragment does not use it (nofify it is not possible to fill fragment by layout), or 
     * 2) if it is an activity.
     */
    private String inflatedViewName = null;

    private GenerateCodeBasedOnLayoutVisitor visitor;

    /**
     * @return the inflatedViewName
     */
    public String getInflatedViewName()
    {
        return inflatedViewName;
    }

    /**
     * @param inflatedViewName the inflatedViewName to set
     */
    public void setInflatedViewName(String inflatedViewName)
    {
        this.inflatedViewName = inflatedViewName;
    }

    /**
     * @param declaredViewIdsOnCode the declaredViewIdsOnCode to set
     */
    public void setDeclaredViewIdsOnCode(Set<String> declaredViewIdsOnCode)
    {
        this.declaredViewIdsOnCode.clear();
        this.declaredViewIdsOnCode.addAll(declaredViewIdsOnCode);
    }

    /**
     * @return the declaredViewIdsOnCode
     */
    public Set<String> getDeclaredViewIdsOnCode()
    {
        return declaredViewIdsOnCode;
    }

    /**
     * @return the visitor
     */
    public GenerateCodeBasedOnLayoutVisitor getVisitor()
    {
        return visitor;
    }

    /**
     * @param visitor the visitor to set
     */
    public void setVisitor(GenerateCodeBasedOnLayoutVisitor visitor)
    {
        this.visitor = visitor;
    }

    /**
     * @return the compUnit
     */
    public ICompilationUnit getCompUnit()
    {
        return compUnit;
    }

    /**
     * Item required to write AST
     * @param compUnit the compUnit to set
     */
    public void setCompUnit(ICompilationUnit compUnit)
    {
        this.compUnit = compUnit;
    }

    /**
     * @return the compUnitAstNode
     */
    public CompilationUnit getCompUnitAstNode()
    {
        return compUnitAstNode;
    }

    /**
     * @param compUnitAstNode the compUnitAstNode to set
     */
    public void setCompUnitAstNode(CompilationUnit compUnitAstNode)
    {
        this.compUnitAstNode = compUnitAstNode;
    }

    /**
     * 
     * @return true if AST have at least one error (warnings are not considered), false otherwise
     */
    public boolean hasErrorInCompilationUnitAst()
    {
        CompilationUnit cpUnit = getCompUnitAstNode();
        return JDTUtils.hasErrorInCompilationUnitAstUtils(cpUnit);
    }

    public void setSavedViewIds(Set<String> savedViewIds)
    {
        this.savedViewIds.clear();
        this.savedViewIds.addAll(savedViewIds);

    }

    public void setRestoredViewIds(Set<String> restoredViewIds)
    {
        this.restoredViewIds.clear();
        this.restoredViewIds.addAll(restoredViewIds);
    }

    public Set<String> getSavedViewIds()
    {
        return savedViewIds;
    }

    public Set<String> getRestoredViewIds()
    {
        return restoredViewIds;
    }
}