org.tizen.web.privilege_2.0.0.201311011708

16:50:43.692 INFO  jd.cli.Main - Decompiling org.tizen.web.privilege_2.0.0.201311011708.jar
package org.tizen.web.privilege;

import org.eclipse.osgi.util.NLS;

public class Messages
  extends NLS
{
  private static final String BUNDLE_NAME = "org.tizen.web.privilege.messages";
  public static String PRIVILEGE_QUICK_FIX_LABEL;
  public static String PROGRESS_MONITOR_TASK_NAME;
  public static String PROGRESS_MONITOR_TASK_READ_CONFIG;
  public static String PROGRESS_MONITOR_TASK_CHECK_JS;
  public static String PROBLEMS_VIEW_MESSAGE;
  
  static
  {
    NLS.initializeMessages("org.tizen.web.privilege.messages", Messages.class);
  }
}

/* Location:
 * Qualified Name:     org.tizen.web.privilege.Messages
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.web.privilege;

import org.dom4j.Document;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
import org.tizen.web.privilege.core.PrivilegeChecker;
import org.tizen.web.privilege.core.PrivilegeIDLReader;
import org.tizen.web.project.configuration.platform.TizenWIDLPrivilegeReader;

public class PrivilegeActivator
  extends AbstractUIPlugin
{
  public static final String PLUGIN_ID = "org.tizen.web.privilege";
  private static PrivilegeActivator plugin;
  
  public void start(BundleContext context)
    throws Exception
  {
    super.start(context);
    plugin = this;
    init();
  }
  
  public void init()
  {
    Document document = TizenWIDLPrivilegeReader.getInstance().getTizenWIDLDocument();
    PrivilegeChecker pc = PrivilegeChecker.getInstance();
    PrivilegeIDLReader idlReader = PrivilegeIDLReader.getInstance();
    pc.setWidlPrivileges(idlReader.processTizenDocument(document));
  }
  
  public void stop(BundleContext context)
    throws Exception
  {
    PrivilegeChecker pc = PrivilegeChecker.getInstance();
    pc.clearResources();
    plugin = null;
    super.stop(context);
  }
  
  public static PrivilegeActivator getDefault()
  {
    return plugin;
  }
  
  public static ImageDescriptor getImageDescriptor(String path)
  {
    return imageDescriptorFromPlugin("org.tizen.web.privilege", path);
  }
}

/* Location:
 * Qualified Name:     org.tizen.web.privilege.PrivilegeActivator
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.web.privilege.core;

import java.util.HashMap;

public class PrivilegeApi
{
  private HashMap<String, String> map;
  
  public PrivilegeApi()
  {
    map = new HashMap();
  }
  
  public void add(String api, String privilege)
  {
    map.put(api, privilege);
  }
  
  public String get(String api)
  {
    return (String)map.get(api);
  }
}

/* Location:
 * Qualified Name:     org.tizen.web.privilege.core.PrivilegeApi
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.web.privilege.core;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.tizen.web.privilege.Messages;

class PrivilegeChecker$1
  implements IRunnableWithProgress
{
  PrivilegeChecker$1(PrivilegeChecker paramPrivilegeChecker, IProject paramIProject) {}
  
  public void run(IProgressMonitor monitor)
  {
    monitor.beginTask(Messages.PROGRESS_MONITOR_TASK_NAME, 100);
    PrivilegeChecker.access$3(this$0, val$project, monitor);
    monitor.done();
  }
}

/* Location:
 * Qualified Name:     org.tizen.web.privilege.core.PrivilegeChecker.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.web.privilege.core;

import org.eclipse.wst.jsdt.core.CompletionProposal;
import org.eclipse.wst.jsdt.core.CompletionRequestor;

class PrivilegeChecker$2
  extends CompletionRequestor
{
  PrivilegeChecker$2(PrivilegeChecker paramPrivilegeChecker) {}
  
  public void accept(CompletionProposal proposal) {}
}

/* Location:
 * Qualified Name:     org.tizen.web.privilege.core.PrivilegeChecker.2
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.web.privilege.core;

import java.util.HashSet;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceVisitor;
import org.eclipse.core.runtime.CoreException;

class PrivilegeChecker$JavaScriptVisitor
  implements IResourceVisitor
{
  private PrivilegeChecker$JavaScriptVisitor(PrivilegeChecker paramPrivilegeChecker) {}
  
  public boolean visit(IResource resource)
    throws CoreException
  {
    if ((resource instanceof IFolder))
    {
      if (containsExcludedPattern(resource.getName())) {
        return false;
      }
    }
    else if ((resource instanceof IFile))
    {
      String extension = resource.getFileExtension();
      if ((extension != null) && (extension.equals("js")))
      {
        if (PrivilegeChecker.access$0(this$0) == null) {
          PrivilegeChecker.access$1(this$0, new HashSet());
        }
        PrivilegeChecker.access$0(this$0).add((IFile)resource);
      }
    }
    return true;
  }
  
  private boolean containsExcludedPattern(String foldername)
  {
    if (PrivilegeChecker.access$2(this$0) == null) {
      return false;
    }
    String[] arrayOfString;
    int j = (arrayOfString = PrivilegeChecker.access$2(this$0)).length;
    for (int i = 0; i < j; i++)
    {
      String pattern = arrayOfString[i];
      if ((foldername.compareTo(pattern) == 0) || 
        (foldername.compareTo(".build") == 0)) {
        return true;
      }
    }
    return false;
  }
}

/* Location:
 * Qualified Name:     org.tizen.web.privilege.core.PrivilegeChecker.JavaScriptVisitor
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.web.privilege.core;

import java.lang.reflect.InvocationTargetException;
import java.text.MessageFormat;
import java.util.Collection;
import java.util.HashSet;
import java.util.regex.Pattern;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceVisitor;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.wst.jsdt.core.CompletionProposal;
import org.eclipse.wst.jsdt.core.CompletionRequestor;
import org.eclipse.wst.jsdt.core.IJavaScriptProject;
import org.eclipse.wst.jsdt.core.IJavaScriptUnit;
import org.eclipse.wst.jsdt.core.JavaScriptModelException;
import org.eclipse.wst.jsdt.core.ast.IExpression;
import org.eclipse.wst.jsdt.core.ast.IFieldReference;
import org.eclipse.wst.jsdt.core.ast.ISingleNameReference;
import org.eclipse.wst.jsdt.core.dom.ASTParser;
import org.eclipse.wst.jsdt.core.dom.JavaScriptUnit;
import org.eclipse.wst.jsdt.internal.compiler.ast.FieldReference;
import org.eclipse.wst.jsdt.internal.compiler.ast.MessageSend;
import org.eclipse.wst.jsdt.internal.compiler.ast.SingleNameReference;
import org.eclipse.wst.jsdt.internal.compiler.lookup.TypeBinding;
import org.eclipse.wst.jsdt.internal.core.CompilationUnit;
import org.eclipse.wst.jsdt.internal.core.JavaModelManager;
import org.eclipse.wst.jsdt.internal.core.SearchableEnvironment;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tizen.web.privilege.Messages;
import org.tizen.web.privilege.engine.PrivilegeEngine;
import org.tizen.web.privilege.engine.PrivilegeOnMessageSend;
import org.tizen.web.privilege.properties.PropertyPage;
import org.tizen.web.project.configuration.ConfigurationException;
import org.tizen.web.project.configuration.WidgetConfigurator;
import org.tizen.web.project.widl.model.PrivilegeWrapper;

public class PrivilegeChecker
{
  protected final Logger logger = LoggerFactory.getLogger(getClass());
  public static final String PRIVILEGE_MARKER_ID = "org.tizen.web.privilege.marker";
  public static final String PRIVILEGE_EXCLUEDED_PATTERN_SEP = "[,{ }]+";
  public static final int PRIVILEGE_MARKER_SEVERITY = 2;
  public static final int PRIVILEGE_MARKER_PRIORITY = 1;
  private final int PROGRESS_MONITOR_MAX = 100;
  private final int PROGRESS_MONITOR_CONFIG = 5;
  private static PrivilegeChecker instance;
  private PrivilegeModule widlPrivileges;
  private JavaScriptVisitor javaScriptVisitor;
  private ASTParser parser;
  private ProgressMonitorDialog progressDialog;
  private HashSet<String> configPrivileges;
  private HashSet<IFile> javaScriptFiles;
  private IJavaScriptUnit currentUnit;
  private IFile currentFile;
  private IProgressMonitor monitor;
  private String[] excludedPatterns;
  
  private class JavaScriptVisitor
    implements IResourceVisitor
  {
    private JavaScriptVisitor() {}
    
    public boolean visit(IResource resource)
      throws CoreException
    {
      if ((resource instanceof IFolder))
      {
        if (containsExcludedPattern(resource.getName())) {
          return false;
        }
      }
      else if ((resource instanceof IFile))
      {
        String extension = resource.getFileExtension();
        if ((extension != null) && (extension.equals("js")))
        {
          if (javaScriptFiles == null) {
            javaScriptFiles = new HashSet();
          }
          javaScriptFiles.add((IFile)resource);
        }
      }
      return true;
    }
    
    private boolean containsExcludedPattern(String foldername)
    {
      if (excludedPatterns == null) {
        return false;
      }
      String[] arrayOfString;
      int j = (arrayOfString = excludedPatterns).length;
      for (int i = 0; i < j; i++)
      {
        String pattern = arrayOfString[i];
        if ((foldername.compareTo(pattern) == 0) || 
          (foldername.compareTo(".build") == 0)) {
          return true;
        }
      }
      return false;
    }
  }
  
  public static PrivilegeChecker getInstance()
  {
    if (instance == null) {
      instance = new PrivilegeChecker();
    }
    return instance;
  }
  
  public void init()
  {
    configPrivileges = null;
    javaScriptFiles = null;
    currentFile = null;
    currentUnit = null;
    monitor = null;
    excludedPatterns = null;
  }
  
  public void clearResources()
  {
    widlPrivileges = null;
    javaScriptVisitor = null;
    parser = null;
    progressDialog = null;
    init();
  }
  
  public void setWidlPrivileges(PrivilegeModule widlPrivileges)
  {
    this.widlPrivileges = widlPrivileges;
  }
  
  public void checkPrivilege(final IProject project, IProgressMonitor monitor)
  {
    try
    {
      if (monitor != null)
      {
        checkPrivilegeMonitoring(project, monitor);
      }
      else
      {
        if (progressDialog == null) {
          progressDialog = new ProgressMonitorDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
        }
        progressDialog.run(true, true, new IRunnableWithProgress()
        {
          public void run(IProgressMonitor monitor)
          {
            monitor.beginTask(Messages.PROGRESS_MONITOR_TASK_NAME, 100);
            PrivilegeChecker.this.checkPrivilegeMonitoring(project, monitor);
            monitor.done();
          }
        });
      }
    }
    catch (InvocationTargetException e)
    {
      logger.error(e.getMessage(), e);
    }
    catch (InterruptedException e)
    {
      logger.error(e.getMessage(), e);
    }
  }
  
  private void checkPrivilegeMonitoring(IProject project, IProgressMonitor monitor)
  {
    monitor.subTask(MessageFormat.format(Messages.PROGRESS_MONITOR_TASK_READ_CONFIG, new Object[] { project.getName() }));
    readPrivilegesFromConfigXml(project);
    monitor.worked(5);
    if (!monitor.isCanceled()) {
      checkJavaScriptFiles(project, monitor);
    }
  }
  
  public void checkNode(PrivilegeOnMessageSend node)
  {
    if (monitor.isCanceled()) {
      return;
    }
    String module = "";
    String api = "";
    if (node.getReceiver() != null)
    {
      IExpression receiver = node.getReceiver();
      if ((receiver instanceof ISingleNameReference))
      {
        SingleNameReference singleNameReference = (SingleNameReference)receiver;
        if (actualReceiverType != null) {
          module = new String(actualReceiverType.constantPoolName());
        }
        api = new String(node.getSelector());
      }
      else if ((receiver instanceof IFieldReference))
      {
        FieldReference fieldReference = (FieldReference)receiver;
        module = new String(resolvedType.constantPoolName());
        api = new String(node.getSelector());
      }
    }
    String privilege = queryWidl(module, api);
    if ((privilege != null) && (!queryConfig(privilege)) && ((node instanceof MessageSend)))
    {
      if (currentUnit == null) {
        return;
      }
      addMarker(privilege, node.sourceStart());
    }
  }
  
  public int getLineNumber(IJavaScriptUnit sourceUnit, int offset)
  {
    if (parser == null)
    {
      parser = ASTParser.newParser(3);
      parser.setKind(8);
    }
    parser.setSource(sourceUnit);
    JavaScriptUnit ast = (JavaScriptUnit)parser.createAST(null);
    return ast.getLineNumber(offset);
  }
  
  private void readPrivilegesFromConfigXml(IProject project)
  {
    if (project == null) {
      return;
    }
    try
    {
      WidgetConfigurator widgetConfigurator = new WidgetConfigurator(project);
      Collection<PrivilegeWrapper> privilegeElements = widgetConfigurator.getUsedPrivileges();
      configPrivileges = new HashSet();
      for (PrivilegeWrapper privilegeElement : privilegeElements) {
        configPrivileges.add(privilegeElement.getName());
      }
    }
    catch (ConfigurationException e)
    {
      logger.error(e.getMessage(), e);
    }
  }
  
  private void checkJavaScriptFiles(IProject project, IProgressMonitor monitor)
  {
    if (project == null) {
      return;
    }
    if (javaScriptVisitor == null) {
      javaScriptVisitor = new JavaScriptVisitor(null);
    }
    excludedPatterns = getExcludedPattern(project);
    try
    {
      this.monitor = monitor;
      project.accept(javaScriptVisitor);
      if (javaScriptFiles == null) {
        return;
      }
      int progrssSize = 95 / javaScriptFiles.size();
      for (IFile javaScriptFile : javaScriptFiles)
      {
        if (monitor.isCanceled()) {
          return;
        }
        monitor.subTask(MessageFormat.format(Messages.PROGRESS_MONITOR_TASK_CHECK_JS, new Object[] { javaScriptFile.getName() }));
        currentFile = javaScriptFile;
        monitor.worked(progrssSize);
        compare(javaScriptFile, configPrivileges);
      }
    }
    catch (CoreException e)
    {
      logger.error(e.getMessage(), e);
    }
  }
  
  private String[] getExcludedPattern(IProject project)
  {
    try
    {
      Pattern p = Pattern.compile("[,{ }]+");
      String excludedPatterns = project.getPersistentProperty(PropertyPage.excludedFoldersQName);
      if (excludedPatterns == null)
      {
        project.setPersistentProperty(PropertyPage.excludedFoldersQName, "tizen-web-ui-fw");
        excludedPatterns = "tizen-web-ui-fw";
      }
      else if (excludedPatterns.compareTo("") == 0)
      {
        return null;
      }
      return p.split(excludedPatterns);
    }
    catch (CoreException e)
    {
      logger.error(e.getMessage(), e);
    }
    return null;
  }
  
  private void compare(IFile file, HashSet<String> config)
  {
    try
    {
      IJavaScriptUnit CompilationUnit = JavaModelManager.createCompilationUnitFrom(file, null).getWorkingCopy(null);
      IJavaScriptProject project = CompilationUnit.getJavaScriptProject();
      SearchableEnvironment environment = project.newSearchableNameEnvironment(CompilationUnit.getOwner());
      CompletionRequestor requestor = new CompletionRequestor()
      {
        public void accept(CompletionProposal proposal) {}
      };
      int lastOffset = ((CompilationUnit)CompilationUnit).getContents().length;
      currentUnit = CompilationUnit;
      
      PrivilegeEngine engine = new PrivilegeEngine(environment, requestor, project.getOptions(true), project);
      engine.complete((CompilationUnit)CompilationUnit, lastOffset, lastOffset);
    }
    catch (JavaScriptModelException e)
    {
      logger.error(e.getMessage(), e);
    }
  }
  
  private void addMarker(String privilege, int offset)
  {
    int line = getLineNumber(currentUnit, offset);
    try
    {
      IMarker marker = currentFile.createMarker("org.tizen.web.privilege.marker");
      marker.setAttribute("message", createMessage(privilege));
      marker.setAttribute("lineNumber", line);
      marker.setAttribute("severity", 2);
      marker.setAttribute("priority", 1);
    }
    catch (CoreException e)
    {
      logger.error(e.getMessage(), e);
    }
  }
  
  private String createMessage(String privilege)
  {
    return MessageFormat.format(Messages.PROBLEMS_VIEW_MESSAGE, new Object[] { privilege });
  }
  
  public void clearMarkers(IWorkspaceRoot workspace)
  {
    try
    {
      IProject[] projects = workspace.getProjects();
      IProject[] arrayOfIProject1;
      int j = (arrayOfIProject1 = projects).length;
      for (int i = 0; i < j; i++)
      {
        IProject project = arrayOfIProject1[i];
        if (project.isAccessible())
        {
          IMarker[] markers = project.findMarkers("org.tizen.web.privilege.marker", true, 2);
          IMarker[] arrayOfIMarker1;
          int m = (arrayOfIMarker1 = markers).length;
          for (int k = 0; k < m; k++)
          {
            IMarker marker = arrayOfIMarker1[k];
            marker.delete();
          }
        }
      }
    }
    catch (CoreException e)
    {
      logger.error(e.getMessage(), e);
    }
  }
  
  private String queryWidl(String module, String api)
  {
    return widlPrivileges.get(module, api);
  }
  
  private boolean queryConfig(String privilege)
  {
    return configPrivileges.contains(privilege);
  }
}

/* Location:
 * Qualified Name:     org.tizen.web.privilege.core.PrivilegeChecker
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.web.privilege.core;

import java.util.List;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.VisitorSupport;

public class PrivilegeIDLReader
  extends VisitorSupport
{
  private static PrivilegeIDLReader instance;
  private PrivilegeModule privileges;
  
  private PrivilegeIDLReader()
  {
    privileges = new PrivilegeModule();
  }
  
  public static synchronized PrivilegeIDLReader getInstance()
  {
    if (instance == null) {
      instance = new PrivilegeIDLReader();
    }
    return instance;
  }
  
  public PrivilegeModule processTizenDocument(Document doc)
  {
    Element root = doc.getRootElement();
    List<? extends Element> moduleElements = root.elements("Module");
    for (Element element : moduleElements) {
      element.accept(this);
    }
    return privileges;
  }
  
  public void visit(Element node)
  {
    Element privilege = node.element("privilege");
    if (privilege != null) {
      privileges.add(privilege);
    }
  }
}

/* Location:
 * Qualified Name:     org.tizen.web.privilege.core.PrivilegeIDLReader
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.web.privilege.core;

import java.util.HashMap;
import org.dom4j.Element;

public class PrivilegeModule
{
  private HashMap<String, PrivilegeApi> map;
  
  public void add(Element privilegeDomElement)
  {
    if (map == null) {
      map = new HashMap();
    }
    String privilege = privilegeDomElement.getTextTrim();
    Element operation = privilegeDomElement.getParent().getParent();
    String module = operation.attributeValue("id").split("::")[2];
    String api = operation.attributeValue("name");
    
    PrivilegeApi apis = (PrivilegeApi)map.get(module);
    if (apis == null) {
      map.put(module, new PrivilegeApi());
    }
    ((PrivilegeApi)map.get(module)).add(api, privilege);
  }
  
  public PrivilegeApi get(String module)
  {
    return (PrivilegeApi)map.get(module);
  }
  
  public String get(String module, String api)
  {
    PrivilegeApi apis = (PrivilegeApi)map.get(module);
    if (apis == null) {
      return null;
    }
    String privilege = apis.get(api);
    if (privilege != null) {
      return privilege;
    }
    return null;
  }
}

/* Location:
 * Qualified Name:     org.tizen.web.privilege.core.PrivilegeModule
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.web.privilege.engine;

import java.util.ArrayList;
import org.eclipse.wst.jsdt.core.compiler.CharOperation;
import org.eclipse.wst.jsdt.internal.codeassist.ISearchRequestor;
import org.eclipse.wst.jsdt.internal.compiler.env.AccessRestriction;

class MissingTypesGuesser$1
  implements ISearchRequestor
{
  MissingTypesGuesser$1(MissingTypesGuesser paramMissingTypesGuesser, boolean paramBoolean, char[] paramArrayOfChar, ArrayList paramArrayList) {}
  
  public void acceptPackage(char[] packageName) {}
  
  public void acceptType(char[] packageName, char[] fileName, char[] typeName, char[][] enclosingTypeNames, int modifiers, AccessRestriction accessRestriction)
  {
    char[] fullyQualifiedName = CharOperation.concat(packageName, CharOperation.concat(CharOperation.concatWith(enclosingTypeNames, '.'), typeName, '.'), '.');
    if ((val$isQualified) && (!CharOperation.endsWith(fullyQualifiedName, val$missingFullyQualifiedName))) {
      return;
    }
    char[][] compoundName = CharOperation.splitOn('.', fullyQualifiedName);
    val$results.add(compoundName);
  }
  
  public void acceptBinding(char[] packageName, char[] fileName, char[] bindingName, int bindingType, int modifiers, AccessRestriction accessRestriction) {}
  
  public void acceptConstructor(int modifiers, char[] typeName, int parameterCount, char[][] parameterTypes, char[][] parameterNames, String path, AccessRestriction access) {}
}

/* Location:
 * Qualified Name:     org.tizen.web.privilege.engine.MissingTypesGuesser.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.web.privilege.engine;

import org.eclipse.wst.jsdt.internal.compiler.lookup.Binding;
import org.eclipse.wst.jsdt.internal.compiler.lookup.TypeBinding;

public abstract interface MissingTypesGuesser$GuessedTypeRequestor
{
  public abstract void accept(TypeBinding paramTypeBinding, Binding[] paramArrayOfBinding, int[] paramArrayOfInt1, int[] paramArrayOfInt2, boolean paramBoolean);
}

/* Location:
 * Qualified Name:     org.tizen.web.privilege.engine.MissingTypesGuesser.GuessedTypeRequestor
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.web.privilege.engine;

import org.eclipse.wst.jsdt.internal.compiler.ASTVisitor;
import org.eclipse.wst.jsdt.internal.compiler.ast.ArrayQualifiedTypeReference;
import org.eclipse.wst.jsdt.internal.compiler.ast.ArrayTypeReference;
import org.eclipse.wst.jsdt.internal.compiler.ast.QualifiedTypeReference;
import org.eclipse.wst.jsdt.internal.compiler.ast.SingleTypeReference;
import org.eclipse.wst.jsdt.internal.compiler.ast.TypeReference;
import org.eclipse.wst.jsdt.internal.compiler.lookup.BlockScope;
import org.eclipse.wst.jsdt.internal.compiler.lookup.ClassScope;
import org.eclipse.wst.jsdt.internal.compiler.util.HashtableOfObjectToInt;

class MissingTypesGuesser$ResolutionCleaner
  extends ASTVisitor
{
  private HashtableOfObjectToInt bitsMap = new HashtableOfObjectToInt();
  private boolean firstCall = true;
  
  private void cleanUp(TypeReference typeReference)
  {
    if (firstCall) {
      bitsMap.put(typeReference, bits);
    } else {
      bits = bitsMap.get(typeReference);
    }
    resolvedType = null;
  }
  
  public void cleanUp(TypeReference convertedType, BlockScope scope)
  {
    convertedType.traverse(this, scope);
    firstCall = false;
  }
  
  public void cleanUp(TypeReference convertedType, ClassScope scope)
  {
    convertedType.traverse(this, scope);
    firstCall = false;
  }
  
  public boolean visit(SingleTypeReference singleTypeReference, BlockScope scope)
  {
    cleanUp(singleTypeReference);
    return true;
  }
  
  public boolean visit(SingleTypeReference singleTypeReference, ClassScope scope)
  {
    cleanUp(singleTypeReference);
    return true;
  }
  
  public boolean visit(ArrayTypeReference arrayTypeReference, BlockScope scope)
  {
    cleanUp(arrayTypeReference);
    return true;
  }
  
  public boolean visit(ArrayTypeReference arrayTypeReference, ClassScope scope)
  {
    cleanUp(arrayTypeReference);
    return true;
  }
  
  public boolean visit(QualifiedTypeReference qualifiedTypeReference, BlockScope scope)
  {
    cleanUp(qualifiedTypeReference);
    return true;
  }
  
  public boolean visit(QualifiedTypeReference qualifiedTypeReference, ClassScope scope)
  {
    cleanUp(qualifiedTypeReference);
    return true;
  }
  
  public boolean visit(ArrayQualifiedTypeReference arrayQualifiedTypeReference, BlockScope scope)
  {
    cleanUp(arrayQualifiedTypeReference);
    return true;
  }
  
  public boolean visit(ArrayQualifiedTypeReference arrayQualifiedTypeReference, ClassScope scope)
  {
    cleanUp(arrayQualifiedTypeReference);
    return true;
  }
}

/* Location:
 * Qualified Name:     org.tizen.web.privilege.engine.MissingTypesGuesser.ResolutionCleaner
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.web.privilege.engine;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;
import org.eclipse.wst.jsdt.core.compiler.CharOperation;
import org.eclipse.wst.jsdt.internal.codeassist.ISearchRequestor;
import org.eclipse.wst.jsdt.internal.compiler.ASTVisitor;
import org.eclipse.wst.jsdt.internal.compiler.ast.ArrayQualifiedTypeReference;
import org.eclipse.wst.jsdt.internal.compiler.ast.ArrayTypeReference;
import org.eclipse.wst.jsdt.internal.compiler.ast.QualifiedTypeReference;
import org.eclipse.wst.jsdt.internal.compiler.ast.SingleTypeReference;
import org.eclipse.wst.jsdt.internal.compiler.ast.TypeReference;
import org.eclipse.wst.jsdt.internal.compiler.env.AccessRestriction;
import org.eclipse.wst.jsdt.internal.compiler.lookup.Binding;
import org.eclipse.wst.jsdt.internal.compiler.lookup.BlockScope;
import org.eclipse.wst.jsdt.internal.compiler.lookup.ClassScope;
import org.eclipse.wst.jsdt.internal.compiler.lookup.ReferenceBinding;
import org.eclipse.wst.jsdt.internal.compiler.lookup.Scope;
import org.eclipse.wst.jsdt.internal.compiler.lookup.TypeBinding;
import org.eclipse.wst.jsdt.internal.compiler.util.HashtableOfObjectToInt;
import org.eclipse.wst.jsdt.internal.core.SearchableEnvironment;

public class MissingTypesGuesser
  extends ASTVisitor
{
  private PrivilegeEngine.CompletionProblemFactory problemFactory;
  private SearchableEnvironment nameEnvironment;
  private HashMap substituedTypes;
  private HashMap originalTypes;
  private int combinationsCount;
  
  public static abstract interface GuessedTypeRequestor
  {
    public abstract void accept(TypeBinding paramTypeBinding, Binding[] paramArrayOfBinding, int[] paramArrayOfInt1, int[] paramArrayOfInt2, boolean paramBoolean);
  }
  
  private static class ResolutionCleaner
    extends ASTVisitor
  {
    private HashtableOfObjectToInt bitsMap = new HashtableOfObjectToInt();
    private boolean firstCall = true;
    
    private void cleanUp(TypeReference typeReference)
    {
      if (firstCall) {
        bitsMap.put(typeReference, bits);
      } else {
        bits = bitsMap.get(typeReference);
      }
      resolvedType = null;
    }
    
    public void cleanUp(TypeReference convertedType, BlockScope scope)
    {
      convertedType.traverse(this, scope);
      firstCall = false;
    }
    
    public void cleanUp(TypeReference convertedType, ClassScope scope)
    {
      convertedType.traverse(this, scope);
      firstCall = false;
    }
    
    public boolean visit(SingleTypeReference singleTypeReference, BlockScope scope)
    {
      cleanUp(singleTypeReference);
      return true;
    }
    
    public boolean visit(SingleTypeReference singleTypeReference, ClassScope scope)
    {
      cleanUp(singleTypeReference);
      return true;
    }
    
    public boolean visit(ArrayTypeReference arrayTypeReference, BlockScope scope)
    {
      cleanUp(arrayTypeReference);
      return true;
    }
    
    public boolean visit(ArrayTypeReference arrayTypeReference, ClassScope scope)
    {
      cleanUp(arrayTypeReference);
      return true;
    }
    
    public boolean visit(QualifiedTypeReference qualifiedTypeReference, BlockScope scope)
    {
      cleanUp(qualifiedTypeReference);
      return true;
    }
    
    public boolean visit(QualifiedTypeReference qualifiedTypeReference, ClassScope scope)
    {
      cleanUp(qualifiedTypeReference);
      return true;
    }
    
    public boolean visit(ArrayQualifiedTypeReference arrayQualifiedTypeReference, BlockScope scope)
    {
      cleanUp(arrayQualifiedTypeReference);
      return true;
    }
    
    public boolean visit(ArrayQualifiedTypeReference arrayQualifiedTypeReference, ClassScope scope)
    {
      cleanUp(arrayQualifiedTypeReference);
      return true;
    }
  }
  
  public MissingTypesGuesser(PrivilegeEngine resolveEngine)
  {
    problemFactory = problemFactory;
    nameEnvironment = nameEnvironment;
  }
  
  private boolean computeMissingElements(QualifiedTypeReference[] substituedTypeNodes, char[][][] originalTypeNames, Binding[] missingElements, int[] missingElementsStarts, int[] missingElementsEnds)
  {
    int length = substituedTypeNodes.length;
    for (int i = 0; i < length; i++)
    {
      TypeReference substituedType = substituedTypeNodes[i];
      if (resolvedType == null) {
        return false;
      }
      ReferenceBinding erasure = (ReferenceBinding)resolvedType.leafComponentType();
      
      int depthToRemove = originalTypeNames[i].length - 1;
      Binding missingElement;
      if (depthToRemove == 0)
      {
        missingElement = erasure;
      }
      else
      {
        int depth = erasure.depth() + 1;
        Binding missingElement;
        if (depth > depthToRemove) {
          missingElement = erasure.enclosingTypeAt(depthToRemove);
        } else {
          return false;
        }
      }
      Binding missingElement;
      missingElements[i] = missingElement;
      missingElementsStarts[i] = sourceStart;
      missingElementsEnds[i] = (sourceEnd + 1);
    }
    return true;
  }
  
  private TypeReference convert(ArrayQualifiedTypeReference typeRef)
  {
    if (resolvedType != null)
    {
      if (resolvedType.isValidBinding())
      {
        ArrayQualifiedTypeReference convertedType = 
          new ArrayQualifiedTypeReference(
          tokens, 
          typeRef.dimensions(), 
          sourcePositions);
        sourceStart = sourceStart;
        sourceEnd = sourceEnd;
        return convertedType;
      }
      if ((resolvedType.problemId() & 0x1) != 0)
      {
        if (resolvedType.leafComponentType()).compoundName.length != 1) {
          return null;
        }
        char[][] typeName = typeRef.getTypeName();
        char[][][] typeNames = findTypeNames(typeName);
        if ((typeNames == null) || (typeNames.length == 0)) {
          return null;
        }
        ArrayQualifiedTypeReference convertedType = 
          new ArrayQualifiedTypeReference(
          typeNames[0], 
          typeRef.dimensions(), 
          new long[typeNames[0].length]);
        sourceStart = sourceStart;
        sourceEnd = ((int)(sourcePositions[0] & 0xFFFFFFFF));
        substituedTypes.put(convertedType, typeNames);
        originalTypes.put(convertedType, typeName);
        combinationsCount *= typeNames.length;
        return convertedType;
      }
    }
    return null;
  }
  
  private TypeReference convert(ArrayTypeReference typeRef)
  {
    if (resolvedType != null)
    {
      if (resolvedType.isValidBinding())
      {
        ArrayTypeReference convertedType = 
          new ArrayTypeReference(
          token, 
          dimensions, 
          0L);
        sourceStart = sourceStart;
        sourceEnd = originalSourceEnd;
        return convertedType;
      }
      if ((resolvedType.problemId() & 0x1) != 0)
      {
        char[][] typeName = typeRef.getTypeName();
        char[][][] typeNames = findTypeNames(typeName);
        if ((typeNames == null) || (typeNames.length == 0)) {
          return null;
        }
        ArrayQualifiedTypeReference convertedType = 
          new ArrayQualifiedTypeReference(
          typeNames[0], 
          dimensions, 
          new long[typeNames[0].length]);
        sourceStart = sourceStart;
        sourceEnd = originalSourceEnd;
        substituedTypes.put(convertedType, typeNames);
        originalTypes.put(convertedType, typeName);
        combinationsCount *= typeNames.length;
        return convertedType;
      }
    }
    return null;
  }
  
  private TypeReference convert(QualifiedTypeReference typeRef)
  {
    if (resolvedType != null)
    {
      if (resolvedType.isValidBinding())
      {
        QualifiedTypeReference convertedType = new QualifiedTypeReference(tokens, sourcePositions);
        sourceStart = sourceStart;
        sourceEnd = sourceEnd;
        return convertedType;
      }
      if ((resolvedType.problemId() & 0x1) != 0)
      {
        if (resolvedType).compoundName.length != 1) {
          return null;
        }
        char[][] typeName = typeRef.getTypeName();
        char[][][] typeNames = findTypeNames(typeName);
        if ((typeNames == null) || (typeNames.length == 0)) {
          return null;
        }
        QualifiedTypeReference convertedType = new QualifiedTypeReference(typeNames[0], new long[typeNames[0].length]);
        sourceStart = sourceStart;
        sourceEnd = ((int)(sourcePositions[0] & 0xFFFFFFFF));
        substituedTypes.put(convertedType, typeNames);
        originalTypes.put(convertedType, typeName);
        combinationsCount *= typeNames.length;
        return convertedType;
      }
    }
    return null;
  }
  
  private TypeReference convert(SingleTypeReference typeRef)
  {
    if (resolvedType != null)
    {
      if (resolvedType.isValidBinding())
      {
        SingleTypeReference convertedType = new SingleTypeReference(token, 0L);
        sourceStart = sourceStart;
        sourceEnd = sourceEnd;
        return convertedType;
      }
      if ((resolvedType.problemId() & 0x1) != 0)
      {
        char[][] typeName = typeRef.getTypeName();
        char[][][] typeNames = findTypeNames(typeName);
        if ((typeNames == null) || (typeNames.length == 0)) {
          return null;
        }
        QualifiedTypeReference convertedType = new QualifiedTypeReference(typeNames[0], new long[typeNames[0].length]);
        sourceStart = sourceStart;
        sourceEnd = sourceEnd;
        substituedTypes.put(convertedType, typeNames);
        originalTypes.put(convertedType, typeName);
        combinationsCount *= typeNames.length;
        return convertedType;
      }
    }
    return null;
  }
  
  private TypeReference convert(TypeReference typeRef)
  {
    if ((typeRef instanceof ArrayTypeReference)) {
      return convert((ArrayTypeReference)typeRef);
    }
    if ((typeRef instanceof ArrayQualifiedTypeReference)) {
      return convert((ArrayQualifiedTypeReference)typeRef);
    }
    if ((typeRef instanceof SingleTypeReference)) {
      return convert((SingleTypeReference)typeRef);
    }
    if ((typeRef instanceof QualifiedTypeReference)) {
      return convert((QualifiedTypeReference)typeRef);
    }
    return null;
  }
  
  private char[][][] findTypeNames(char[][] missingTypeName)
  {
    char[] missingSimpleName = missingTypeName[(missingTypeName.length - 1)];
    final boolean isQualified = missingTypeName.length > 1;
    final char[] missingFullyQualifiedName = 
      isQualified ? CharOperation.concatWith(missingTypeName, '.') : null;
    final ArrayList results = new ArrayList();
    ISearchRequestor storage = new ISearchRequestor()
    {
      public void acceptPackage(char[] packageName) {}
      
      public void acceptType(char[] packageName, char[] fileName, char[] typeName, char[][] enclosingTypeNames, int modifiers, AccessRestriction accessRestriction)
      {
        char[] fullyQualifiedName = CharOperation.concat(packageName, CharOperation.concat(CharOperation.concatWith(enclosingTypeNames, '.'), typeName, '.'), '.');
        if ((isQualified) && (!CharOperation.endsWith(fullyQualifiedName, missingFullyQualifiedName))) {
          return;
        }
        char[][] compoundName = CharOperation.splitOn('.', fullyQualifiedName);
        results.add(compoundName);
      }
      
      public void acceptBinding(char[] packageName, char[] fileName, char[] bindingName, int bindingType, int modifiers, AccessRestriction accessRestriction) {}
      
      public void acceptConstructor(int modifiers, char[] typeName, int parameterCount, char[][] parameterTypes, char[][] parameterNames, String path, AccessRestriction access) {}
    };
    nameEnvironment.findExactTypes(missingSimpleName, true, 0, storage);
    if (results.size() == 0) {
      return null;
    }
    return (char[][][])results.toArray(new char[results.size()][0][0]);
  }
  
  private char[][] getOriginal(TypeReference typeRef)
  {
    return (char[][])originalTypes.get(typeRef);
  }
  
  private QualifiedTypeReference[] getSubstituedTypes()
  {
    Set types = substituedTypes.keySet();
    return (QualifiedTypeReference[])types.toArray(new QualifiedTypeReference[types.size()]);
  }
  
  private char[][][] getSubstitution(TypeReference typeRef)
  {
    return (char[][][])substituedTypes.get(typeRef);
  }
  
  public void guess(TypeReference typeRef, Scope scope, GuessedTypeRequestor requestor)
  {
    substituedTypes = new HashMap();
    originalTypes = new HashMap();
    combinationsCount = 1;
    
    TypeReference convertedType = convert(typeRef);
    if (convertedType == null) {
      return;
    }
    QualifiedTypeReference[] substituedTypeNodes = getSubstituedTypes();
    int length = substituedTypeNodes.length;
    
    int[] substitutionsIndexes = new int[substituedTypeNodes.length];
    char[][][][] subtitutions = new char[substituedTypeNodes.length][][][];
    char[][][] originalTypeNames = new char[substituedTypeNodes.length][][];
    for (int i = 0; i < substituedTypeNodes.length; i++)
    {
      subtitutions[i] = getSubstitution(substituedTypeNodes[i]);
      originalTypeNames[i] = getOriginal(substituedTypeNodes[i]);
    }
    ResolutionCleaner resolutionCleaner = new ResolutionCleaner();
    for (int i = 0; i < combinationsCount; i++)
    {
      nextSubstitution(substituedTypeNodes, subtitutions, substitutionsIndexes);
      
      problemFactory.startCheckingProblems();
      TypeBinding guessedType = null;
      switch (kind)
      {
      case 1: 
      case 2: 
        resolutionCleaner.cleanUp(convertedType, (BlockScope)scope);
        guessedType = convertedType.resolveType((BlockScope)scope);
        break;
      case 3: 
        resolutionCleaner.cleanUp(convertedType, (ClassScope)scope);
        guessedType = convertedType.resolveType((ClassScope)scope);
      }
      problemFactory.stopCheckingProblems();
      if ((!problemFactory.hasForbiddenProblems) && 
        (guessedType != null))
      {
        Binding[] missingElements = new Binding[length];
        int[] missingElementsStarts = new int[length];
        int[] missingElementsEnds = new int[length];
        if (computeMissingElements(
          substituedTypeNodes, 
          originalTypeNames, 
          missingElements, 
          missingElementsStarts, 
          missingElementsEnds)) {
       
1 2 3 4 5 6 7 8 9 10 11 12

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd